Basic structure of the buffer is there, but needs testing and debugging

This commit is contained in:
Oleksiy 2021-03-02 00:25:23 +02:00
parent 15e543a2e1
commit b0025406ac
1 changed files with 36 additions and 2 deletions

View File

@ -13,6 +13,8 @@ MIDI_CREATE_DEFAULT_INSTANCE();
#define MIDI_CHANNEL 3 #define MIDI_CHANNEL 3
bool gate = 0; bool gate = 0;
byte noteBuffer[8];
byte bufferIndex = 0;
// desired intensity max and min, for AutoMap, note they're inverted for reverse dynamics // desired intensity max and min, for AutoMap, note they're inverted for reverse dynamics
const int MIN_INTENSITY = 700; const int MIN_INTENSITY = 700;
@ -54,19 +56,51 @@ int carrier_freq;
void noteOn(byte channel, byte note, byte velocity) { void noteOn(byte channel, byte note, byte velocity) {
if (channel == MIDI_CHANNEL) { if (channel == MIDI_CHANNEL) {
carrier_freq = mtof((int) note);
gate = 1; gate = 1;
updateBuffer(note, gate);
//playNote(); // this is called from within buffer update
} }
} }
void noteOff(byte channel, byte note, byte velocity) { void noteOff(byte channel, byte note, byte velocity) {
if (channel == MIDI_CHANNEL) { if (channel == MIDI_CHANNEL) {
gate = 0; 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(){ 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); pinMode(LED_BUILTIN_RX,INPUT);
startMozzi(); startMozzi();