wavetable/plugin/Source/PluginProcessor.h

359 lines
9.9 KiB
C
Raw Normal View History

2020-05-20 16:44:46 -07:00
#pragma once
#include <JuceHeader.h>
#include "WavetableVoice.h"
2023-10-08 22:44:56 -07:00
#include "FX/DeRez2.h"
#include "FX/FireAmp.h"
#include "FX/GrindAmp.h"
2020-05-20 16:44:46 -07:00
2023-10-08 14:31:14 -07:00
constexpr auto fxGate = 0;
constexpr auto fxChorus = 1;
constexpr auto fxDistort = 2;
constexpr auto fxDelay = 3;
constexpr auto fxReverb = 4;
2020-05-20 16:44:46 -07:00
//==============================================================================
class WavetableAudioProcessor : public gin::Processor,
2023-08-23 08:45:23 -07:00
public gin::Synthesiser
2020-05-20 16:44:46 -07:00
{
public:
//==============================================================================
WavetableAudioProcessor();
~WavetableAudioProcessor() override;
2023-09-06 09:53:13 -07:00
bool supportsMPE() const override { return true; }
2020-05-20 16:44:46 -07:00
void stateUpdated() override;
void updateState() override;
//==============================================================================
void reset() override;
void prepareToPlay (double sampleRate, int samplesPerBlock) override;
void releaseResources() override;
2023-09-30 07:42:15 -07:00
bool isBusesLayoutSupported (const BusesLayout&) const override;
2020-05-20 16:44:46 -07:00
2023-08-23 08:45:23 -07:00
void processBlock (juce::AudioBuffer<float>&, juce::MidiBuffer&) override;
2020-05-20 16:44:46 -07:00
//==============================================================================
2023-08-23 08:45:23 -07:00
juce::AudioProcessorEditor* createEditor() override;
2020-05-20 16:44:46 -07:00
bool hasEditor() const override;
void updateParams (int blockSize);
void setupModMatrix();
//==============================================================================
2023-08-23 08:45:23 -07:00
void handleMidiEvent (const juce::MidiMessage& m) override;
2020-05-20 16:44:46 -07:00
void handleController (int ch, int num, int val) override;
//==============================================================================
2023-08-23 11:21:37 -07:00
juce::Array<float> getLiveFilterCutoff();
2023-08-25 08:24:15 -07:00
gin::WTOscillator::Params getLiveWTParams (int osc);
2020-05-20 16:44:46 -07:00
2023-08-25 13:26:25 -07:00
void reloadWavetables();
void incWavetable (int osc, int delta);
2023-09-29 21:06:19 -07:00
bool loadUserWavetable (int osc, const juce::File& f, int sz);
2023-08-25 13:26:25 -07:00
2023-08-23 08:45:23 -07:00
void applyEffects (juce::AudioSampleBuffer& buffer);
2023-10-08 14:31:14 -07:00
void applyEffect (juce::AudioSampleBuffer& buffer, int fxId);
2025-11-13 20:10:21 -08:00
bool loadWaveTable (gin::Wavetable& table, double sr, const juce::MemoryBlock& wav, const juce::String& format, int size);
2020-05-20 16:44:46 -07:00
// Voice Params
struct OSCParams
{
OSCParams() = default;
2023-10-03 08:11:07 -07:00
gin::Parameter::Ptr enable, voices, tune, finetune, level, pos, detune, spread, pan, bend, formant, retrig;
2020-05-20 16:44:46 -07:00
void setup (WavetableAudioProcessor& p, int idx);
JUCE_DECLARE_NON_COPYABLE (OSCParams)
};
struct SubParams
{
SubParams() = default;
2023-10-03 08:11:07 -07:00
gin::Parameter::Ptr enable, wave, tune, level, pan, retrig;
void setup (WavetableAudioProcessor& p);
JUCE_DECLARE_NON_COPYABLE (SubParams)
};
struct NoiseParams
{
NoiseParams() = default;
2023-08-25 08:24:15 -07:00
2023-08-31 19:19:28 -07:00
gin::Parameter::Ptr enable, type, level, pan;
void setup (WavetableAudioProcessor& p);
JUCE_DECLARE_NON_COPYABLE (NoiseParams)
};
2020-05-20 16:44:46 -07:00
struct FilterParams
{
FilterParams() = default;
gin::Parameter::Ptr enable, type, keyTracking, velocityTracking,
2023-10-07 10:57:13 -07:00
frequency, resonance, amount, retrig,
2023-08-26 21:59:44 -07:00
attack, decay, sustain, release, wt1, wt2, sub, noise;
2020-05-20 16:44:46 -07:00
2023-08-23 11:21:37 -07:00
void setup (WavetableAudioProcessor& p);
2020-05-20 16:44:46 -07:00
JUCE_DECLARE_NON_COPYABLE (FilterParams)
};
struct EnvParams
{
EnvParams() = default;
2023-10-07 10:57:13 -07:00
gin::Parameter::Ptr enable, attack, decay, sustain, release, retrig;
2020-05-20 16:44:46 -07:00
void setup (WavetableAudioProcessor& p, int idx);
JUCE_DECLARE_NON_COPYABLE (EnvParams)
};
struct LFOParams
{
LFOParams() = default;
2024-02-14 19:34:53 -08:00
gin::Parameter::Ptr enable, sync, retrig, wave, rate, beat, depth, phase, offset, fade, delay, xgrid, ygrid;
2020-05-20 16:44:46 -07:00
void setup (WavetableAudioProcessor& p, int idx);
JUCE_DECLARE_NON_COPYABLE (LFOParams)
};
struct StepLFOParams
{
StepLFOParams() = default;
2023-09-28 08:16:31 -07:00
gin::Parameter::Ptr enable, beat, length, retrig;
2023-08-26 19:04:45 -07:00
gin::Parameter::Ptr level[Cfg::numStepLFOSteps] = { nullptr };
2020-05-20 16:44:46 -07:00
void setup (WavetableAudioProcessor& p);
JUCE_DECLARE_NON_COPYABLE (StepLFOParams)
};
struct ADSRParams
{
ADSRParams() = default;
2023-10-07 10:57:13 -07:00
gin::Parameter::Ptr attack, decay, sustain, release, velocityTracking, retrig;
2020-05-20 16:44:46 -07:00
void setup (WavetableAudioProcessor& p);
JUCE_DECLARE_NON_COPYABLE (ADSRParams)
};
// Global Params
struct GlobalParams
{
GlobalParams() = default;
2023-09-29 09:01:29 -07:00
gin::Parameter::Ptr mono, glideMode, glideRate, legato, level, voices, mpe, pitchBend;
2020-05-20 16:44:46 -07:00
void setup (WavetableAudioProcessor& p);
JUCE_DECLARE_NON_COPYABLE (GlobalParams)
};
2023-08-26 20:57:45 -07:00
// UI Params
struct UIParams
{
UIParams() = default;
2023-09-08 17:11:50 -07:00
gin::Parameter::Ptr activeLFO, activeENV, activeMOD;
2023-08-26 20:57:45 -07:00
void setup (WavetableAudioProcessor& p);
JUCE_DECLARE_NON_COPYABLE (UIParams)
};
2020-05-20 16:44:46 -07:00
struct GateParams
{
GateParams() = default;
gin::Parameter::Ptr enable, beat, length, attack, release;
2023-08-26 19:04:45 -07:00
gin::Parameter::Ptr l[Cfg::numGateSteps] = { nullptr };
gin::Parameter::Ptr r[Cfg::numGateSteps] = { nullptr };
2020-05-20 16:44:46 -07:00
void setup (WavetableAudioProcessor& p);
JUCE_DECLARE_NON_COPYABLE (GateParams)
};
struct ChorusParams
{
ChorusParams() = default;
gin::Parameter::Ptr enable, delay, rate, depth, width, mix;
void setup (WavetableAudioProcessor& p);
JUCE_DECLARE_NON_COPYABLE (ChorusParams)
};
struct DistortionParams
{
DistortionParams() = default;
2023-08-26 11:17:03 -07:00
gin::Parameter::Ptr enable, amount;
2020-05-20 16:44:46 -07:00
void setup (WavetableAudioProcessor& p);
JUCE_DECLARE_NON_COPYABLE (DistortionParams)
};
struct DelayParams
{
DelayParams() = default;
gin::Parameter::Ptr enable, sync, time, beat, fb, cf, mix, delay;
void setup (WavetableAudioProcessor& p);
JUCE_DECLARE_NON_COPYABLE (DelayParams)
};
struct ReverbParams
{
ReverbParams() = default;
gin::Parameter::Ptr enable, size, decay, lowpass, damping, predelay, mix;
2020-05-20 16:44:46 -07:00
void setup (WavetableAudioProcessor& p);
JUCE_DECLARE_NON_COPYABLE (ReverbParams)
};
2023-10-08 14:31:14 -07:00
struct FXParams
{
FXParams() = default;
2023-10-08 22:44:56 -07:00
gin::Parameter::Ptr fx1, fx2, fx3, fx4, fx5, distMode;
2023-10-08 14:31:14 -07:00
void setup (WavetableAudioProcessor& p);
JUCE_DECLARE_NON_COPYABLE (FXParams)
};
2023-10-08 22:44:56 -07:00
struct BitCrusherParams
{
BitCrusherParams() = default;
gin::Parameter::Ptr rate, rez, hard, mix;
void setup (WavetableAudioProcessor& p);
JUCE_DECLARE_NON_COPYABLE (BitCrusherParams)
};
struct FireAmpParams
{
FireAmpParams() = default;
gin::Parameter::Ptr gain, tone, output, mix;
void setup (WavetableAudioProcessor& p);
JUCE_DECLARE_NON_COPYABLE (FireAmpParams)
};
struct GrindAmpParams
{
GrindAmpParams() = default;
gin::Parameter::Ptr gain, tone, output, mix;
void setup (WavetableAudioProcessor& p);
JUCE_DECLARE_NON_COPYABLE (GrindAmpParams)
};
2020-05-20 16:44:46 -07:00
//==============================================================================
2023-09-29 09:01:29 -07:00
gin::ModSrcId modSrcPressure, modSrcTimbre, modSrcPitchbend, modScrPitchBend,
modSrcFilter, modSrcNote, modSrcVelocity, modSrcStep, modSrcMonoStep;
2020-05-20 16:44:46 -07:00
2023-08-23 11:21:37 -07:00
juce::Array<gin::ModSrcId> modSrcCC, modSrcMonoLFO, modSrcLFO, modSrcEnv;
2020-05-20 16:44:46 -07:00
//==============================================================================
OSCParams oscParams[Cfg::numOSCs];
SubParams subParams;
NoiseParams noiseParams;
2023-08-23 11:21:37 -07:00
FilterParams filterParams;
2020-05-20 16:44:46 -07:00
EnvParams envParams[Cfg::numENVs];
LFOParams lfoParams[Cfg::numLFOs];
StepLFOParams stepLfoParams;
2023-10-08 14:31:14 -07:00
FXParams fxParams;
2020-05-20 16:44:46 -07:00
ADSRParams adsrParams;
GlobalParams globalParams;
GateParams gateParams;
ChorusParams chorusParams;
DistortionParams distortionParams;
DelayParams delayParams;
ReverbParams reverbParams;
2023-10-08 22:44:56 -07:00
BitCrusherParams bitcrusherParams;
FireAmpParams fireAmpParams;
GrindAmpParams grindAmpParams;
2023-08-26 20:57:45 -07:00
UIParams uiParams;
2020-05-20 16:44:46 -07:00
//==============================================================================
gin::GateEffect gate;
gin::Modulation chorus { 0.5f };
gin::StereoDelay stereoDelay { 120.1 };
gin::PlateReverb<float, int> reverb;
2020-05-20 16:44:46 -07:00
gin::GainProcessor outputGain;
2023-08-25 13:26:25 -07:00
gin::AudioFifo scopeFifo { 2, 44100 };
2023-08-26 11:17:03 -07:00
float distortionVal = 0.0f;
2023-10-08 22:44:56 -07:00
DeRez2 bitcrusher;
FireAmp fireAmp;
GrindAmp grindAmp;
2020-05-20 16:44:46 -07:00
2025-11-13 20:10:21 -08:00
gin::Wavetable osc1Tables;
gin::Wavetable osc2Tables;
2023-08-25 08:24:15 -07:00
2023-08-26 11:17:03 -07:00
gin::BandLimitedLookupTables analogTables;
2023-08-25 13:26:25 -07:00
juce::Value osc1Table, osc2Table;
2023-08-27 07:57:23 -07:00
juce::MemoryBlock userTable1, userTable2;
2023-09-29 21:06:19 -07:00
int osc1Size = -1, osc2Size = -1;
2023-08-25 13:26:25 -07:00
2020-05-20 16:44:46 -07:00
//==============================================================================
gin::ModMatrix modMatrix;
gin::LFO modLFOs[Cfg::numLFOs];
gin::StepLFO modStepLFO;
2023-08-23 08:45:23 -07:00
juce::AudioPlayHead* playhead = nullptr;
2023-09-20 22:08:18 -07:00
bool blockMissed = false;
2023-09-23 11:10:21 -07:00
bool presetLoaded = false;
2023-09-28 08:44:58 -07:00
bool lastMono = false;
2020-05-21 21:39:47 -07:00
struct CurTable
{
juce::String name;
double sampleRate = 0.0;
};
CurTable curTables[Cfg::numOSCs];
2023-09-06 09:53:13 -07:00
juce::CriticalSection dspLock;
2023-09-29 20:20:07 -07:00
juce::Random rng;
2024-10-11 21:02:25 -07:00
MTSClient* mtsClient = nullptr;
2023-09-29 20:07:45 -07:00
private:
bool isParamLocked (gin::Parameter* p) override;
2023-09-29 20:07:45 -07:00
float getSmoothingTime (gin::Parameter*);
2020-05-20 16:44:46 -07:00
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WavetableAudioProcessor)
};