- robusten and refactored NRPN

- increased number of midicontrollers from 128 to 1024
This commit is contained in:
2026-05-10 10:36:24 +02:00
parent cbdb18e6ba
commit 6e67193c3d
5 changed files with 54 additions and 32 deletions
+5 -2
View File
@@ -1100,7 +1100,7 @@ void JaySynth::handleMidiEvent (const MidiMessage& m)
SynthDebug("CC: controllerNumber=%d, controllerValue=%d", midiCC_info.ID, midiCC_info.value_raw); SynthDebug("CC: controllerNumber=%d, controllerValue=%d", midiCC_info.ID, midiCC_info.value_raw);
bool isNrpnProcessing = mMidiNrpn.process(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.ID = mMidiNrpn.getCommand();
midiCC_info.type = MIDI_CONTROLLER_TYPE_NRPN; 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); SynthDebug("NRPN: controllerNumber=%d, controllerValue=%d", midiCC_info.ID, midiCC_info.value_raw);
} }
handleController (midiCC_info); if (!isNrpnProcessing)
{
handleController (midiCC_info);
}
} }
if (m.isMidiMachineControlMessage()) if (m.isMidiMachineControlMessage())
+1 -1
View File
@@ -256,7 +256,7 @@ void MidiCC_PopUp::paint (Graphics& g)
void MidiCC_PopUp::resized() void MidiCC_PopUp::resized()
{ {
textButton_OK->setBounds (22, 238, 202, 22); 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_min->setBounds (103, 144, 64, 20);
label_control_max->setBounds (103, 166, 64, 20); label_control_max->setBounds (103, 166, 64, 20);
slider_test->setBounds (64, 192, 168, 26); slider_test->setBounds (64, 192, 168, 26);
+42 -24
View File
@@ -1,13 +1,11 @@
#include "MidiNrpn.h" #include "MidiNrpn.h"
#include "synth/synth_types.h"
#include <cfenv>
MidiNrpn::MidiNrpn() MidiNrpn::MidiNrpn()
: mState(0) : mState(0)
, mCommand(0) , mCommand(0)
, mValue(0) , mValue(0)
, maxValue(0) , mMaxValue(0)
, mValueIsValid(false) , mIsValid(false)
{ {
} }
@@ -19,51 +17,56 @@ MidiNrpn::~MidiNrpn()
void MidiNrpn::reset() void MidiNrpn::reset()
{ {
mIsValid = false;
mCommand = 0;
mValue = 0;
mMaxValue = 0;
mState = 0; mState = 0;
} }
int MidiNrpn::getCommand() int MidiNrpn::getCommand()
{ {
if (!mValueIsValid) if (!mIsValid)
{ {
return -1; return -1;
} }
return mCommand; return mCommand;
} }
bool MidiNrpn::isValue() bool MidiNrpn::isValid()
{ {
return mValueIsValid; return mIsValid;
} }
int MidiNrpn::consumeValue() int MidiNrpn::consumeValue()
{ {
if (!mValueIsValid) if (!mIsValid)
{ {
return -1; return -1;
} }
mValueIsValid = false; mIsValid = false;
return mValue; return mValue;
} }
int MidiNrpn::getMaxValue() int MidiNrpn::getMaxValue()
{ {
return maxValue; if (!mIsValid)
{
return 0;
}
return mMaxValue;
} }
bool MidiNrpn::process(uint8_t controllerNumber, uint8_t controllerValue) bool MidiNrpn::process(uint8_t controllerNumber, uint8_t controllerValue)
{ {
bool isNrpnProcessing = true;
int state_nxt = mState; int state_nxt = mState;
switch (mState) switch (mState)
{ {
case 0: case 0:
if (controllerNumber == 99) if (controllerNumber == 99)
{ {
state_nxt = 1; state_nxt = 1;
mCommand = (uint16_t)controllerValue & 0x00FF; mCommand = (uint16_t)controllerValue & 0x007F;
} }
break; break;
@@ -71,7 +74,11 @@ bool MidiNrpn::process(uint8_t controllerNumber, uint8_t controllerValue)
if (controllerNumber == 98) if (controllerNumber == 98)
{ {
state_nxt = 2; state_nxt = 2;
mCommand = mCommand << 8 | (uint16_t)controllerValue & 0x00FF; mCommand = mCommand << 7 | (uint16_t)controllerValue & 0x007F;
}
else
{
reset();
} }
break; break;
@@ -79,8 +86,12 @@ bool MidiNrpn::process(uint8_t controllerNumber, uint8_t controllerValue)
if (controllerNumber == 6) if (controllerNumber == 6)
{ {
state_nxt = 3; state_nxt = 3;
mValue = (uint16_t)controllerValue & 0x00FF; mValue = (uint16_t)controllerValue & 0x007F;
maxValue = 128; mMaxValue = 128;
}
else
{
reset();
} }
break; break;
@@ -88,32 +99,39 @@ bool MidiNrpn::process(uint8_t controllerNumber, uint8_t controllerValue)
if (controllerNumber == 38) if (controllerNumber == 38)
{ {
state_nxt = 4; state_nxt = 4;
mValue = mValue << 7 | (uint16_t)controllerValue & 0x00FF; mValue = mValue << 7 | (uint16_t)controllerValue & 0x007F;
maxValue *= 128; mMaxValue *= 128;
} }
else if (controllerNumber == 99) else if (controllerNumber == 99)
{ {
state_nxt = 4; state_nxt = 4;
} }
else
{
reset();
}
break; break;
case 4: case 4:
if (controllerNumber == 99) if (controllerNumber == 99)
{ {
// Do nothing
} }
else if (controllerNumber == 98) else if (controllerNumber == 98)
{ {
state_nxt = 0; state_nxt = 0;
isNrpnProcessing = false; mIsValid = true;
mValueIsValid = true; }
else
{
reset();
} }
break; break;
default: default:
break; break;
} }
mState = state_nxt; mState = state_nxt;
return isNrpnProcessing;
return mState != 0;
} }
+5 -4
View File
@@ -12,9 +12,10 @@ class MidiNrpn
~MidiNrpn(); ~MidiNrpn();
void reset(); void reset();
int getCommand();
bool isValue(); bool isValid();
int getCommand();
int consumeValue(); int consumeValue();
int getMaxValue(); int getMaxValue();
@@ -25,8 +26,8 @@ class MidiNrpn
int mState; int mState;
int mCommand; int mCommand;
int mValue; int mValue;
int maxValue; int mMaxValue;
bool mValueIsValid; bool mIsValid;
}; };
#endif //_MIDI_NRPN_H_ #endif //_MIDI_NRPN_H_
+1 -1
View File
@@ -17,7 +17,7 @@
#define NUM_PROGRAMS 64 #define NUM_PROGRAMS 64
#define NUM_FREQS 128 #define NUM_FREQS 128
#define NUM_MIDI_CONTROLLERS 128 #define NUM_MIDI_CONTROLLERS 1024
#define VOICE_NUM_OSC 2 #define VOICE_NUM_OSC 2
#define VOICE_NUM_LFO 4 #define VOICE_NUM_LFO 4