better MIDI
This commit is contained in:
parent
b32579e6e1
commit
a884d11f61
@ -32,6 +32,11 @@ void AlphaOsc::initAudioPort(bool input, uint32_t index, AudioPort &port) {
|
|||||||
if (!input && index == 0) port.name = "Osc Out";
|
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
|
// Processing function
|
||||||
void AlphaOsc::run(const float **, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount) {
|
void AlphaOsc::run(const float **, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount) {
|
||||||
bzero(outputs[0], sizeof(float) * frames);
|
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)midiEventCount;
|
||||||
//(void)midiEvents;
|
//(void)midiEvents;
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t i, j;
|
||||||
uint32_t osc;
|
uint32_t osc;
|
||||||
uint8_t lfo, pw;
|
uint8_t lfo, pw;
|
||||||
|
|
||||||
@ -53,19 +58,48 @@ void AlphaOsc::run(const float **, float **outputs, uint32_t frames, const MidiE
|
|||||||
float out, in;
|
float out, in;
|
||||||
|
|
||||||
// handle any MIDI events
|
// handle any MIDI events
|
||||||
for(i=0; i<midiEventCount; i++) {
|
for (i = 0; i < midiEventCount; i++) {
|
||||||
if (midiEvents[i].data[0] == 0x90) {
|
uint8_t val = 0;
|
||||||
|
uint8_t status = midiEvents[i].data[0];
|
||||||
|
if (midiEvents[i].size > 1) {
|
||||||
|
val = midiEvents[i].data[1];
|
||||||
|
}
|
||||||
|
if (status == 0x90) {
|
||||||
// note on
|
// note on
|
||||||
note = midiEvents[i].data[1];
|
// if (notequeue[0] != val) {
|
||||||
freq = 130.81*powf(2, (note-48)/12.0f);
|
// 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;
|
gate = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (midiEvents[i].data[0] == 0x80 && midiEvents[1].data[1] == note) {
|
if (status == 0x80) {
|
||||||
// note off for same note
|
// note off
|
||||||
gate = 0;
|
// 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
|
// steeply "logarithmic" curve similar to the Juno 106 LFO rate curve
|
||||||
|
@ -50,8 +50,10 @@ class AlphaOsc : public Plugin {
|
|||||||
|
|
||||||
// Initialisation
|
// Initialisation
|
||||||
void initAudioPort(bool input, uint32_t index, AudioPort &port) override;
|
void initAudioPort(bool input, uint32_t index, AudioPort &port) override;
|
||||||
|
|
||||||
void initParameter(uint32_t index, Parameter ¶meter) override;
|
void initParameter(uint32_t index, Parameter ¶meter) override;
|
||||||
|
|
||||||
|
void activate() override;
|
||||||
|
|
||||||
void setParameterValue(uint32_t index, float value) override;
|
void setParameterValue(uint32_t index, float value) override;
|
||||||
float getParameterValue(uint32_t index) const override;
|
float getParameterValue(uint32_t index) const override;
|
||||||
|
|
||||||
@ -63,6 +65,8 @@ class AlphaOsc : public Plugin {
|
|||||||
uint32_t omega, lfoOmega;
|
uint32_t omega, lfoOmega;
|
||||||
uint32_t phase, lfoPhase;
|
uint32_t phase, lfoPhase;
|
||||||
|
|
||||||
|
uint8_t notequeue[8];
|
||||||
|
|
||||||
uint8_t note = 48; // last heard MIDI note
|
uint8_t note = 48; // last heard MIDI note
|
||||||
float freq = 130.8; // C3, an octave below Middle C
|
float freq = 130.8; // C3, an octave below Middle C
|
||||||
float gate = 0; // output attenuation
|
float gate = 0; // output attenuation
|
||||||
|
Loading…
Reference in New Issue
Block a user