diff --git a/plugin/alphaosc.cpp b/plugin/alphaosc.cpp index 860e0e2..3dd5eb7 100644 --- a/plugin/alphaosc.cpp +++ b/plugin/alphaosc.cpp @@ -32,6 +32,11 @@ void AlphaOsc::initAudioPort(bool input, uint32_t index, AudioPort &port) { if (!input && index == 0) port.name = "Osc Out"; } +void AlphaOsc::activate() { + uint8_t i; + for (i = 0; i < 7; i++) notequeue[i] = 0x00; // mark note as unused +} + // Processing function void AlphaOsc::run(const float **, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount) { bzero(outputs[0], sizeof(float) * frames); @@ -40,7 +45,7 @@ void AlphaOsc::run(const float **, float **outputs, uint32_t frames, const MidiE //(void)midiEventCount; //(void)midiEvents; - uint32_t i; + uint32_t i, j; uint32_t osc; uint8_t lfo, pw; @@ -53,19 +58,48 @@ void AlphaOsc::run(const float **, float **outputs, uint32_t frames, const MidiE float out, in; // handle any MIDI events - for(i=0; i 1) { + val = midiEvents[i].data[1]; + } + if (status == 0x90) { // note on - note = midiEvents[i].data[1]; - freq = 130.81*powf(2, (note-48)/12.0f); + // if (notequeue[0] != val) { + // we're not just re-enabling the first note in the queue + for (j = 0; j < 7; j++) { + // insert note into queue, highest first + if (notequeue[j] < val) { // note is lower + // make space, dropping lowest note out + memmove(notequeue + j + 1, notequeue + j, 7 - j); + notequeue[j] = val; + break; + } + } + //} + + // first note in queue is going to play + note = notequeue[0]; + freq = 130.81 * powf(2, (note - 48) / 12.0f); gate = 1; } - if (midiEvents[i].data[0] == 0x80 && midiEvents[1].data[1] == note) { - // note off for same note - gate = 0; - } + if (status == 0x80) { + // note off + // find the note in the queue + for (j = 0; j < 7; j++) { + if (notequeue[j] == val) { + // found it, move notes down + memmove(notequeue + j, notequeue + j + 1, 7 - j); + } + } + note = notequeue[0]; + freq = 130.81 * powf(2, (note - 48) / 12.0f); + + if (notequeue[0] == 0) gate = 0; + } } // steeply "logarithmic" curve similar to the Juno 106 LFO rate curve diff --git a/plugin/alphaosc.hpp b/plugin/alphaosc.hpp index 1c2a628..f6d9799 100644 --- a/plugin/alphaosc.hpp +++ b/plugin/alphaosc.hpp @@ -50,8 +50,10 @@ class AlphaOsc : public Plugin { // Initialisation void initAudioPort(bool input, uint32_t index, AudioPort &port) override; - void initParameter(uint32_t index, Parameter ¶meter) override; + + void activate() override; + void setParameterValue(uint32_t index, float value) override; float getParameterValue(uint32_t index) const override; @@ -63,6 +65,8 @@ class AlphaOsc : public Plugin { uint32_t omega, lfoOmega; uint32_t phase, lfoPhase; + uint8_t notequeue[8]; + uint8_t note = 48; // last heard MIDI note float freq = 130.8; // C3, an octave below Middle C float gate = 0; // output attenuation