From c016f996b8f61bb82e11584844beea9eaa20373f Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 21 Jul 2019 16:19:51 +0200 Subject: [PATCH] Now the MIDI library handles the clock signals --- cvkeyboard.ino | 55 +++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/cvkeyboard.ino b/cvkeyboard.ino index 1d1dba2..32f4331 100644 --- a/cvkeyboard.ino +++ b/cvkeyboard.ino @@ -107,8 +107,9 @@ void setup() { pinMode(OW, INPUT_PULLUP); // Used for overwrite switch pinMode(NEXT, INPUT_PULLUP); display(loadingDisplay[1]); - MIDI.begin(MIDI_CHANNEL_OFF); - Serial.begin(115200); // Uncomment this if you use Hairless and set baud rate + MIDI.begin(1); // was using MIDI_CHANNEL_OFF + MIDI.setHandleClock(clocksync); + MIDI.setHandleControlChange(midisettings); display(loadingDisplay[2]); for (int i = 0; i < 6; i++){ current[i] = NULL; @@ -133,10 +134,17 @@ void setup() { } void loop() { - sync(); cap_read = cap.touched(); + MIDI.read(); - if ((cap_read >> 8) & 1) { // Only for now! + if (next_step != (bool) !digitalRead(NEXT)) { // Manual step control + next_step = (bool) !digitalRead(NEXT); + if (millis() > last_next+DEBOUNCE && next_step == HIGH) { + last_next = millis(); + sem_beat++; + } + } + if ((cap_read >> 8) & 1) { // Only for now! Needed to change channel for (int i=0; idpad_s = current[channel-1]->dpad_s | dpad; // Drum hits aren't exclusive! } + + if (millis() > last_save + (unsigned long) MINUTE*INTERVAL) { + saveAll(); + last_save = millis(); + } } // Hardware specific functions @@ -330,32 +343,18 @@ void playDrum(int c, bool status, byte chan) { } } -// Sync functions +// MIDI callback functions -void sync() { +void clocksync(){ + midiclock++; + if (midiclock == BPQN) { + midiclock = 0; + sem_beat++; + } +} - if (millis() > last_save + (unsigned long) MINUTE*INTERVAL) { - saveAll(); - last_save = millis(); - } - - if (next_step != (bool) !digitalRead(NEXT)) { // Used to increase channel with a button because I don't have a rotary switch (yet!) - next_step = (bool) !digitalRead(NEXT); - if (millis() > last_next+DEBOUNCE && next_step == HIGH) { - last_next = millis(); - sem_beat++; - } - } - if (Serial.available()) { - if (Serial.read() == MIDICLOCK) { - //sem_beat++; - midiclock++; - if (midiclock == BPQN) { - midiclock = 0; - sem_beat++; - } - } - } +void midisettings(byte channel, byte number, byte value) { + return; } // List management functions