Skip to content

Commit

Permalink
fix arp resync
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed Apr 26, 2024
1 parent d7d39da commit 3c07776
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion include/midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void midiOut(byte note);
void pedalUp();
void pedalDown();
void dumpPreset();

void resyncArpLfo();
void sendControlChange(byte number, byte value, byte channel);
void sendNoteOff(byte note, byte velocity, byte channel);
void sendTool(byte note, byte velocity);
Expand Down
2 changes: 1 addition & 1 deletion src/MEGAfm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void enterSetup() {

void setup() {

arpMidiSpeedPending=1;
arpMidiSpeedPending = 1;
lastSentCC[0] = 255;

fillAllLfoTables();
Expand Down
41 changes: 22 additions & 19 deletions src/midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ static byte syncLfoCounter;

static bool arpClearFlag = false;

void resyncArpLfo() {
if (arpClockEnable) {
if (arpMidiSpeed != arpMidiSpeedPending || resyncArp) {
arpMidiSpeed = arpMidiSpeedPending;
arpClockCounter = 0;
resyncArp = false;
}
}

for (int i = 0; i < 3; i++) {
if (lfoClockEnable[i]) {
if (lfoClockSpeedPending[i] != lfoClockSpeedPendingLast[i]) {
lfoClockSpeed[i] = lfoClockSpeedPending[i];
lfoClockSpeedPendingLast[i] = lfoClockSpeedPending[i];
lfoStepF[i] = 0;
}
}
}
}
void handleAftertouch(byte channel, byte val) {
leftDot();
if (mpe) {
Expand Down Expand Up @@ -74,27 +93,11 @@ void handleClock() {
}

absoluteClockCounter++;
if (absoluteClockCounter >= 96) {
if (absoluteClockCounter >= 48) {
leftDot();
absoluteClockCounter = 0;

if (arpClockEnable) {
if (arpMidiSpeed != arpMidiSpeedPending || resyncArp) {
arpMidiSpeed = arpMidiSpeedPending;
arpClockCounter = 0;
resyncArp = false;
}
}

for (int i = 0; i < 3; i++) {
if (lfoClockEnable[i]) {
if (lfoClockSpeedPending[i] != lfoClockSpeedPendingLast[i]) {
lfoClockSpeed[i] = lfoClockSpeedPending[i];
lfoClockSpeedPendingLast[i] = lfoClockSpeedPending[i];
lfoStepF[i] = 0;
}
}
}
resyncArpLfo();
}

////////////////////////////////////
Expand Down Expand Up @@ -195,7 +198,7 @@ void handleStop() { sync = false; }
void handleStart() {
if (vibratoClockEnable)
vibIndex = 0;

resyncArpLfo();
absoluteClockCounter = 0;
seqStep = 0;
arpClockCounter = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ void loadPreset() {
displayFreeze = 0;
ledNumber(preset);
displayFreeze = 12000;

arpMidiSpeedPending = map(fmBase[46], 0, 255, 0, 10);
}

void savePreset() {
Expand Down

0 comments on commit 3c07776

Please sign in to comment.