Stability fix
This commit is contained in:
+12
-5
@@ -4,12 +4,15 @@
|
||||
#include "config.h"
|
||||
#include "SharedState.h"
|
||||
|
||||
static Step local_sequence[NUM_TRACKS][NUM_STEPS];
|
||||
static Step local_nextSequence[NUM_TRACKS][NUM_STEPS];
|
||||
|
||||
bool wasPlaying = false;
|
||||
|
||||
static void handlePlayback() {
|
||||
bool nowPlaying = isPlaying;
|
||||
int tracksToPlay = (playMode == MODE_POLY) ? NUM_TRACKS : 1;
|
||||
if (!wasPlaying && !nowPlaying) {
|
||||
if (!wasPlaying && nowPlaying) {
|
||||
midi.sendRealtime(0xFA); // MIDI Start
|
||||
} else if (wasPlaying && !nowPlaying) {
|
||||
midi.sendRealtime(0xFC); // MIDI Stop
|
||||
@@ -17,12 +20,18 @@ static void handlePlayback() {
|
||||
}
|
||||
wasPlaying = nowPlaying;
|
||||
|
||||
if (!nowPlaying) return;
|
||||
if (!nowPlaying) {
|
||||
delay(1); // yield
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned long currentMicros = micros();
|
||||
unsigned long clockInterval = 2500000 / tempo; // 60s * 1000000us / (tempo * 24ppqn)
|
||||
|
||||
if (currentMicros - lastClockTime >= clockInterval) {
|
||||
if (currentMicros - lastClockTime < clockInterval) {
|
||||
delay(1); // yield
|
||||
return;
|
||||
} else {
|
||||
lastClockTime += clockInterval;
|
||||
|
||||
midi.sendRealtime(0xF8); // MIDI Clock
|
||||
@@ -32,9 +41,7 @@ static void handlePlayback() {
|
||||
clockCount = 0;
|
||||
|
||||
midi.lock();
|
||||
Step local_sequence[NUM_TRACKS][NUM_STEPS];
|
||||
memcpy(local_sequence, sequence, sizeof(local_sequence));
|
||||
Step local_nextSequence[NUM_TRACKS][NUM_STEPS];
|
||||
memcpy(local_nextSequence, nextSequence, sizeof(local_nextSequence));
|
||||
midi.unlock();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user