Skip to content

Commit

Permalink
Merge pull request #64 from jr0dsgarage/fixScaleCorruption
Browse files Browse the repository at this point in the history
Fix possible Scale Corruption in Midi Mode; disallow Lock and Group changes when scale is off
  • Loading branch information
okyeron authored Mar 24, 2024
2 parents fcb11bf + ca84fee commit 5eb4f91
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions OMX-27-firmware/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ struct ScaleConfig
int scaleRoot = 0;
int scalePattern = -1;
bool lockScale = false; // If Scale is locked you will be unable to play notes out of the scale.
bool lockedState = false; // for holding previous scale lock state
bool group16 = false; // If group16 is active, all notes in scale will be grouped into lower 16 notes.
bool groupedState = false; // for holding previous group16 state
bool scaleSelectHold;
bool showScaleInSeq = false;
};
Expand Down
29 changes: 27 additions & 2 deletions OMX-27-firmware/src/modes/omx_mode_midi_keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,39 @@ void OmxModeMidiKeyboard::onEncoderChanged(Encoder::Update enc)
omxDisp.displayMessage(musicScale->getScaleName(scaleConfig.scalePattern));
musicScale->calculateScale(scaleConfig.scaleRoot, scaleConfig.scalePattern);
}

if (scaleConfig.scalePattern == -1)
{ // record locked and grouped states, then set the current lockScale and group16 to off
if (prevPat != -1)
{
scaleConfig.lockedState = scaleConfig.lockScale;
scaleConfig.groupedState = scaleConfig.group16;
}
scaleConfig.lockScale = 0;
scaleConfig.group16 = 0;
}
else
{ // restore locked and grouped states if the scale was previously set to off
if (prevPat == -1)
{
scaleConfig.lockScale = scaleConfig.lockedState;
scaleConfig.group16 = scaleConfig.groupedState;
}
}
}
if (selParam == 3)
{
scaleConfig.lockScale = constrain(scaleConfig.lockScale + amt, 0, 1);
if (scaleConfig.scalePattern != -1)
{
scaleConfig.lockScale = constrain(scaleConfig.lockScale + amt, 0, 1);
}
}
if (selParam == 4)
{
scaleConfig.group16 = constrain(scaleConfig.group16 + amt, 0, 1);
if (scaleConfig.scalePattern != -1)
{
scaleConfig.group16 = constrain(scaleConfig.group16 + amt, 0, 1);
}
}
}
else if(selPage == MIPAGE_CFG)
Expand Down

0 comments on commit 5eb4f91

Please sign in to comment.