Basic structure of the buffer is there, but needs testing and debugging
This commit is contained in:
parent
15e543a2e1
commit
b0025406ac
38
FM/FM.ino
38
FM/FM.ino
|
@ -13,6 +13,8 @@ MIDI_CREATE_DEFAULT_INSTANCE();
|
|||
#define MIDI_CHANNEL 3
|
||||
|
||||
bool gate = 0;
|
||||
byte noteBuffer[8];
|
||||
byte bufferIndex = 0;
|
||||
|
||||
// desired intensity max and min, for AutoMap, note they're inverted for reverse dynamics
|
||||
const int MIN_INTENSITY = 700;
|
||||
|
@ -54,19 +56,51 @@ int carrier_freq;
|
|||
|
||||
void noteOn(byte channel, byte note, byte velocity) {
|
||||
if (channel == MIDI_CHANNEL) {
|
||||
carrier_freq = mtof((int) note);
|
||||
gate = 1;
|
||||
updateBuffer(note, gate);
|
||||
//playNote(); // this is called from within buffer update
|
||||
}
|
||||
}
|
||||
|
||||
void noteOff(byte channel, byte note, byte velocity) {
|
||||
if (channel == MIDI_CHANNEL) {
|
||||
gate = 0;
|
||||
updateBuffer(note, gate);
|
||||
}
|
||||
}
|
||||
|
||||
void updateBuffer(byte bNote, bool bGate) {
|
||||
if (bGate == 1) {
|
||||
noteBuffer[bufferIndex] = bNote;
|
||||
playNote();
|
||||
bufferIndex++;
|
||||
}
|
||||
if (bGate == 0 && bufferIndex != 0) {
|
||||
for (int i = 0; i <= bufferIndex; i++) {
|
||||
if (noteBuffer[i] == bNote) {
|
||||
// Removing the note from the array and shifting everything to close the gap
|
||||
for (int n = i; n <= bufferIndex; n++) {
|
||||
noteBuffer[n] = noteBuffer[n + 1]; // what happens if it's the last note in buffer?
|
||||
}
|
||||
if (i == bufferIndex) {
|
||||
bufferIndex--;
|
||||
playNote();
|
||||
} else {
|
||||
bufferIndex--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void playNote() {
|
||||
byte note = noteBuffer[bufferIndex];
|
||||
carrier_freq = mtof((int) note);
|
||||
}
|
||||
|
||||
void setup(){
|
||||
pinMode(LED_BUILTIN_TX,INPUT); //switch rx and tx leds of, so they don't blink on midi
|
||||
// switch rx and tx leds of, so they don't blink on midi
|
||||
pinMode(LED_BUILTIN_TX,INPUT);
|
||||
pinMode(LED_BUILTIN_RX,INPUT);
|
||||
|
||||
startMozzi();
|
||||
|
|
Loading…
Reference in New Issue