Skip to content

Commit

Permalink
UI work
Browse files Browse the repository at this point in the history
  • Loading branch information
FigBug committed Aug 25, 2023
1 parent f1829ad commit 8a591b3
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 13 deletions.
6 changes: 5 additions & 1 deletion plugin/Resources/layout.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"children":
[
{ "id": "osc[1..2]", "x": "0,prevR()+1", "y": 0, "w": "parW()/2", "h": 163 }
{ "id": "osc[1..2]", "x": "0,prevR()+1", "y": 0, "w": "parW()/2", "h": 163 },
{ "id": "flt", "x": "0", "y": "prevB()+1", "w": 175, "h": 163 },
{ "id": "fltAdsr", "x": "prevR()+1", "y": "prevY()", "w": 175, "h": 163 },
{ "id": "lfo[1..3]", "x": "0,prevR()+1", "y": "prevB()+1,prevY()", "w": 175, "h": 163 },
{ "id": "scope", "x": "0", "y": "prevB()+1", "w": 175, "h": 163 }
]
}
34 changes: 25 additions & 9 deletions plugin/Source/Panels.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,29 @@ class OscillatorBox : public gin::ParamBox

addEnable (osc.enable);

addControl (new gin::Knob (osc.pos), 0, 0);
addControl (new gin::Knob (osc.tune, true), 1, 0);
addControl (new gin::Select (osc.voices), 2, 0);
addControl (detune = new gin::Knob (osc.detune), 3, 0);
addControl (new gin::Knob (osc.finetune, true), 2, 0);
addControl (new gin::Knob (osc.level, true), 3, 0);
addControl (new gin::Knob (osc.pan, true), 4, 0);

addControl (new gin::Knob (osc.pos), 0, 1);
addControl (new gin::Knob (osc.finetune, true), 1, 1);
addControl (new gin::Select (osc.voices), 0, 1);
addControl (detune = new gin::Knob (osc.detune), 1, 1);
addControl (spread = new gin::Knob (osc.spread), 2, 1);
addControl (trans = new gin::Knob (osc.voicesTrns, true), 3, 1);

watchParam (osc.voices);

wt = new gin::WavetableComponent();
wt->setName ("wt");
wt->setWavetables (idx == 0 ? &proc.osc1Tables : &proc.osc2Tables);
addControl (wt, 5, 0, 3, 2);

timer.startTimerHz (60);
timer.onTimer = [this]
{
wt->setParams (proc.getLiveWTParams (idx));
};
}

void paramChanged() override
Expand All @@ -43,6 +56,9 @@ class OscillatorBox : public gin::ParamBox
WavetableAudioProcessor& proc;
int idx = 0;
gin::ParamComponent::Ptr trans, detune, spread;
gin::WavetableComponent* wt;

gin::CoalescedTimer timer;
};

//==============================================================================
Expand Down Expand Up @@ -256,7 +272,7 @@ class ChorusBox : public gin::ParamBox
ChorusBox (WavetableAudioProcessor& proc_)
: gin::ParamBox ("Chorus"), proc (proc_)
{
setName ( "chorus" );
setName ("chorus");

addControl (new gin::Knob (proc.chorusParams.delay), 0, 0);
addControl (new gin::Knob (proc.chorusParams.rate), 1, 0);
Expand All @@ -278,7 +294,7 @@ class DistortBox : public gin::ParamBox
DistortBox (WavetableAudioProcessor& proc_)
: gin::ParamBox ("Distort"), proc (proc_)
{
setName ( "distort" );
setName ("distort");

addControl (new gin::Knob (proc.distortionParams.amount), 0, 0);
addControl (new gin::Knob (proc.distortionParams.highpass), 1, 0);
Expand All @@ -298,7 +314,7 @@ class DelayBox : public gin::ParamBox
DelayBox (WavetableAudioProcessor& proc_)
: gin::ParamBox ("Delay"), proc (proc_)
{
setName ( "delay" );
setName ("delay");

addControl (t = new gin::Knob (proc.delayParams.time), 0, 0);
addControl (b = new gin::Select (proc.delayParams.beat), 0, 0);
Expand Down Expand Up @@ -332,7 +348,7 @@ class ReverbBox : public gin::ParamBox
ReverbBox (WavetableAudioProcessor& proc_)
: gin::ParamBox ("Reverb"), proc (proc_)
{
setName ( "reverb" );
setName ("reverb");

addControl (new gin::Knob (proc.reverbParams.size), 0, 0);
addControl (new gin::Knob (proc.reverbParams.decay), 1, 0);
Expand All @@ -354,7 +370,7 @@ class ScopeArea : public gin::ParamArea
ScopeArea (WavetableAudioProcessor& proc_)
: gin::ParamArea ("Scope"), proc (proc_)
{
setName ( "scope" );
setName ("scope");

scope = new gin::TriggeredScope (proc.fifo);
scope->setNumChannels (2);
Expand Down
27 changes: 27 additions & 0 deletions plugin/Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,18 @@ void WavetableAudioProcessor::ReverbParams::setup (WavetableAudioProcessor& p)
mix = p.addExtParam ("rvbMix", "Mix", "", "", {0.0f, 1.0f, 0.0f, 1.0f}, 0.0f, 0.0f);
}

static void loadWaveTable (juce::OwnedArray<gin::BandLimitedLookupTable>& table, const juce::MemoryBlock& wav)
{
auto is = new juce::MemoryInputStream (wav, false);
if (auto reader = std::unique_ptr<juce::AudioFormatReader> (juce::WavAudioFormat().createReaderFor (is, true)))
{
juce::AudioSampleBuffer buf (1, int (reader->lengthInSamples));
reader->read (&buf, 0, int (reader->lengthInSamples), 0, true, false);

loadWavetables (table, buf, reader->sampleRate, gin::getWavetableSize (wav));
}
}

//==============================================================================
WavetableAudioProcessor::WavetableAudioProcessor()
{
Expand All @@ -342,6 +354,9 @@ WavetableAudioProcessor::WavetableAudioProcessor()
enableLegacyMode();
setVoiceStealingEnabled (true);

loadWaveTable (osc1Tables, juce::MemoryBlock (BinaryData::Analog_PWM_Square_01_wav, BinaryData::Analog_PWM_Square_01_wavSize));
loadWaveTable (osc2Tables, juce::MemoryBlock (BinaryData::Analog_PWM_Saw_01_wav, BinaryData::Analog_PWM_Saw_01_wavSize));

for (int i = 0; i < juce::numElementsInArray (oscParams); i++)
oscParams[i].setup (*this, i);

Expand Down Expand Up @@ -539,6 +554,18 @@ juce::Array<float> WavetableAudioProcessor::getLiveFilterCutoff()
return values;
}

gin::WTOscillator::Params WavetableAudioProcessor::getLiveWTParams (int osc)
{
for (auto v : voices)
if (v->isActive())
if (auto vav = dynamic_cast<WavetableVoice*>(v))
return vav->getLiveWTParams (osc);

gin::WTOscillator::Params p;
p.pw = oscParams[osc].pos->getValue();
return p;
}

void WavetableAudioProcessor::applyEffects (juce::AudioSampleBuffer& buffer)
{
// Apply gate
Expand Down
6 changes: 5 additions & 1 deletion plugin/Source/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class WavetableAudioProcessor : public gin::Processor,
void handleController (int ch, int num, int val) override;
//==============================================================================
juce::Array<float> getLiveFilterCutoff();
gin::WTOscillator::Params getLiveWTParams (int osc);

void applyEffects (juce::AudioSampleBuffer& buffer);

Expand Down Expand Up @@ -65,7 +66,7 @@ class WavetableAudioProcessor : public gin::Processor,
struct NoiseParams
{
NoiseParams() = default;

gin::Parameter::Ptr enable, level, pan;

void setup (WavetableAudioProcessor& p);
Expand Down Expand Up @@ -234,6 +235,9 @@ class WavetableAudioProcessor : public gin::Processor,
gin::GainProcessor outputGain;
gin::AudioFifo fifo { 2, 44100 };

juce::OwnedArray<gin::BandLimitedLookupTable> osc1Tables;
juce::OwnedArray<gin::BandLimitedLookupTable> osc2Tables;

//==============================================================================
gin::ModMatrix modMatrix;

Expand Down
9 changes: 8 additions & 1 deletion plugin/Source/WavetableVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void WavetableVoice::updateParams (int blockSize)
currentMidiNotes[i] += float (note.totalPitchbendInSemitones);
currentMidiNotes[i] += getValue (proc.oscParams[i].tune) + getValue (proc.oscParams[i].finetune) / 100.0f;

oscParams[i].wave = gin::Wave::silence;
oscParams[i].wave = gin::Wave::wavetable;
oscParams[i].voices = int (proc.oscParams[i].voices->getProcValue());
oscParams[i].vcTrns = int (proc.oscParams[i].voicesTrns->getProcValue());
oscParams[i].pw = getValue (proc.oscParams[i].pos) / 100.0f;
Expand Down Expand Up @@ -361,3 +361,10 @@ float WavetableVoice::getFilterCutoffNormalized()
float freq = filter.getFrequency();
return proc.filterParams.frequency->getUserRange().convertTo0to1 (gin::getMidiNoteFromHertz (freq));
}

gin::WTOscillator::Params WavetableVoice::getLiveWTParams (int osc)
{
gin::WTOscillator::Params p;
p.pw = getValue (proc.oscParams[osc].pos) / 100.0f;
return p;
}
1 change: 1 addition & 0 deletions plugin/Source/WavetableVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class WavetableVoice : public gin::SynthesiserVoice,
bool isVoiceActive() override;

float getFilterCutoffNormalized();
gin::WTOscillator::Params getLiveWTParams (int osc);

private:
void updateParams (int blockSize);
Expand Down

0 comments on commit 8a591b3

Please sign in to comment.