diff --git a/src/plug/JaySynth.cpp b/src/plug/JaySynth.cpp index 2425d4c..ee686e3 100644 --- a/src/plug/JaySynth.cpp +++ b/src/plug/JaySynth.cpp @@ -1100,7 +1100,7 @@ void JaySynth::handleMidiEvent (const MidiMessage& m) SynthDebug("CC: controllerNumber=%d, controllerValue=%d", midiCC_info.ID, midiCC_info.value_raw); bool isNrpnProcessing = mMidiNrpn.process(midiCC_info.ID, midiCC_info.value_raw); - if (mMidiNrpn.isValue()) + if (mMidiNrpn.isValid()) { midiCC_info.ID = mMidiNrpn.getCommand(); midiCC_info.type = MIDI_CONTROLLER_TYPE_NRPN; @@ -1109,7 +1109,10 @@ void JaySynth::handleMidiEvent (const MidiMessage& m) SynthDebug("NRPN: controllerNumber=%d, controllerValue=%d", midiCC_info.ID, midiCC_info.value_raw); } - handleController (midiCC_info); + if (!isNrpnProcessing) + { + handleController (midiCC_info); + } } if (m.isMidiMachineControlMessage()) diff --git a/src/plug/MidiCC_PopUp.cpp b/src/plug/MidiCC_PopUp.cpp index 4ff32af..453db7b 100644 --- a/src/plug/MidiCC_PopUp.cpp +++ b/src/plug/MidiCC_PopUp.cpp @@ -256,7 +256,7 @@ void MidiCC_PopUp::paint (Graphics& g) void MidiCC_PopUp::resized() { textButton_OK->setBounds (22, 238, 202, 22); - label_MidiCC_ID->setBounds (135, 122, 32, 20); + label_MidiCC_ID->setBounds (119, 122, 48, 20); label_control_min->setBounds (103, 144, 64, 20); label_control_max->setBounds (103, 166, 64, 20); slider_test->setBounds (64, 192, 168, 26); diff --git a/src/plug/MidiNrpn.cpp b/src/plug/MidiNrpn.cpp index 51c539a..2f37bd2 100644 --- a/src/plug/MidiNrpn.cpp +++ b/src/plug/MidiNrpn.cpp @@ -1,13 +1,11 @@ #include "MidiNrpn.h" -#include "synth/synth_types.h" -#include MidiNrpn::MidiNrpn() : mState(0) , mCommand(0) , mValue(0) -, maxValue(0) -, mValueIsValid(false) +, mMaxValue(0) +, mIsValid(false) { } @@ -19,51 +17,56 @@ MidiNrpn::~MidiNrpn() void MidiNrpn::reset() { + mIsValid = false; + mCommand = 0; + mValue = 0; + mMaxValue = 0; mState = 0; } int MidiNrpn::getCommand() { - if (!mValueIsValid) + if (!mIsValid) { return -1; } return mCommand; } -bool MidiNrpn::isValue() +bool MidiNrpn::isValid() { - return mValueIsValid; + return mIsValid; } int MidiNrpn::consumeValue() { - if (!mValueIsValid) + if (!mIsValid) { return -1; } - mValueIsValid = false; + mIsValid = false; return mValue; } int MidiNrpn::getMaxValue() { - return maxValue; + if (!mIsValid) + { + return 0; + } + return mMaxValue; } bool MidiNrpn::process(uint8_t controllerNumber, uint8_t controllerValue) { - bool isNrpnProcessing = true; - int state_nxt = mState; - switch (mState) { case 0: if (controllerNumber == 99) { state_nxt = 1; - mCommand = (uint16_t)controllerValue & 0x00FF; + mCommand = (uint16_t)controllerValue & 0x007F; } break; @@ -71,7 +74,11 @@ bool MidiNrpn::process(uint8_t controllerNumber, uint8_t controllerValue) if (controllerNumber == 98) { state_nxt = 2; - mCommand = mCommand << 8 | (uint16_t)controllerValue & 0x00FF; + mCommand = mCommand << 7 | (uint16_t)controllerValue & 0x007F; + } + else + { + reset(); } break; @@ -79,8 +86,12 @@ bool MidiNrpn::process(uint8_t controllerNumber, uint8_t controllerValue) if (controllerNumber == 6) { state_nxt = 3; - mValue = (uint16_t)controllerValue & 0x00FF; - maxValue = 128; + mValue = (uint16_t)controllerValue & 0x007F; + mMaxValue = 128; + } + else + { + reset(); } break; @@ -88,32 +99,39 @@ bool MidiNrpn::process(uint8_t controllerNumber, uint8_t controllerValue) if (controllerNumber == 38) { state_nxt = 4; - mValue = mValue << 7 | (uint16_t)controllerValue & 0x00FF; - maxValue *= 128; - + mValue = mValue << 7 | (uint16_t)controllerValue & 0x007F; + mMaxValue *= 128; } else if (controllerNumber == 99) { state_nxt = 4; } + else + { + reset(); + } break; case 4: if (controllerNumber == 99) { + // Do nothing } else if (controllerNumber == 98) { state_nxt = 0; - isNrpnProcessing = false; - mValueIsValid = true; + mIsValid = true; + } + else + { + reset(); } break; default: break; } - mState = state_nxt; - return isNrpnProcessing; + + return mState != 0; } diff --git a/src/plug/MidiNrpn.h b/src/plug/MidiNrpn.h index cfe191a..92ffe15 100644 --- a/src/plug/MidiNrpn.h +++ b/src/plug/MidiNrpn.h @@ -12,9 +12,10 @@ class MidiNrpn ~MidiNrpn(); void reset(); - int getCommand(); - bool isValue(); + bool isValid(); + + int getCommand(); int consumeValue(); int getMaxValue(); @@ -25,8 +26,8 @@ class MidiNrpn int mState; int mCommand; int mValue; - int maxValue; - bool mValueIsValid; + int mMaxValue; + bool mIsValid; }; #endif //_MIDI_NRPN_H_ diff --git a/src/synth/synth_defs.h b/src/synth/synth_defs.h index 70d7df6..2e39060 100644 --- a/src/synth/synth_defs.h +++ b/src/synth/synth_defs.h @@ -17,7 +17,7 @@ #define NUM_PROGRAMS 64 #define NUM_FREQS 128 -#define NUM_MIDI_CONTROLLERS 128 +#define NUM_MIDI_CONTROLLERS 1024 #define VOICE_NUM_OSC 2 #define VOICE_NUM_LFO 4