NRPN: normalized by max value
This commit is contained in:
@@ -1105,7 +1105,7 @@ void JaySynth::handleMidiEvent (const MidiMessage& m)
|
||||
midiCC_info.ID = mMidiNrpn.getCommand();
|
||||
midiCC_info.type = MIDI_CONTROLLER_TYPE_NRPN;
|
||||
midiCC_info.value_raw = mMidiNrpn.consumeValue();
|
||||
midiCC_info.value = (synth_float_t)midiCC_info.value_raw/1000;
|
||||
midiCC_info.value = (synth_float_t)midiCC_info.value_raw/mMidiNrpn.getMaxValue();
|
||||
SynthDebug("NRPN: controllerNumber=%d, controllerValue=%d", midiCC_info.ID, midiCC_info.value_raw);
|
||||
}
|
||||
|
||||
|
||||
+43
-22
@@ -1,10 +1,13 @@
|
||||
#include "MidiNrpn.h"
|
||||
#include "synth/synth_types.h"
|
||||
#include <cfenv>
|
||||
|
||||
MidiNrpn::MidiNrpn()
|
||||
: mState(0)
|
||||
, mCommand(0)
|
||||
, mValue(0)
|
||||
, maxValue(0)
|
||||
, mValueIsValid(false)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -19,14 +22,9 @@ void MidiNrpn::reset()
|
||||
mState = 0;
|
||||
}
|
||||
|
||||
bool MidiNrpn::isCommand()
|
||||
{
|
||||
return mState >= 2;
|
||||
}
|
||||
|
||||
int MidiNrpn::getCommand()
|
||||
{
|
||||
if (!isCommand())
|
||||
if (!mValueIsValid)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -35,33 +33,45 @@ int MidiNrpn::getCommand()
|
||||
|
||||
bool MidiNrpn::isValue()
|
||||
{
|
||||
return mState == 4;
|
||||
return mValueIsValid;
|
||||
}
|
||||
|
||||
int MidiNrpn::consumeValue()
|
||||
{
|
||||
if (!isValue())
|
||||
if (!mValueIsValid)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
mState = 2;
|
||||
mValueIsValid = false;
|
||||
return mValue;
|
||||
}
|
||||
|
||||
int MidiNrpn::getMaxValue()
|
||||
{
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
bool MidiNrpn::process(uint8_t controllerNumber, uint8_t controllerValue)
|
||||
{
|
||||
bool isNrpnProcessing = false;
|
||||
bool isNrpnProcessing = true;
|
||||
|
||||
int state_nxt = mState;
|
||||
|
||||
switch (mState)
|
||||
{
|
||||
case 0:
|
||||
if (controllerNumber == 99)
|
||||
{
|
||||
state_nxt = 1;
|
||||
mCommand = (uint16_t)controllerValue & 0x00FF;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (controllerNumber == 98)
|
||||
{
|
||||
state_nxt = 2;
|
||||
mCommand |= (uint16_t)controllerValue & 0x00FF;
|
||||
isNrpnProcessing = true;
|
||||
mCommand = mCommand << 8 | (uint16_t)controllerValue & 0x00FF;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -69,8 +79,8 @@ bool MidiNrpn::process(uint8_t controllerNumber, uint8_t controllerValue)
|
||||
if (controllerNumber == 6)
|
||||
{
|
||||
state_nxt = 3;
|
||||
mValue = (uint16_t)controllerValue << 8 & 0xFF00;
|
||||
isNrpnProcessing = true;
|
||||
mValue = (uint16_t)controllerValue & 0x00FF;
|
||||
maxValue = 128;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -78,7 +88,25 @@ bool MidiNrpn::process(uint8_t controllerNumber, uint8_t controllerValue)
|
||||
if (controllerNumber == 38)
|
||||
{
|
||||
state_nxt = 4;
|
||||
mValue |= (uint16_t)controllerValue & 0x00FF;
|
||||
mValue = mValue << 7 | (uint16_t)controllerValue & 0x00FF;
|
||||
maxValue *= 128;
|
||||
|
||||
}
|
||||
else if (controllerNumber == 99)
|
||||
{
|
||||
state_nxt = 4;
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
if (controllerNumber == 99)
|
||||
{
|
||||
}
|
||||
else if (controllerNumber == 98)
|
||||
{
|
||||
state_nxt = 0;
|
||||
isNrpnProcessing = false;
|
||||
mValueIsValid = true;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -86,13 +114,6 @@ bool MidiNrpn::process(uint8_t controllerNumber, uint8_t controllerValue)
|
||||
break;
|
||||
}
|
||||
|
||||
if (controllerNumber == 99)
|
||||
{
|
||||
state_nxt = 1;
|
||||
mCommand = (uint16_t)controllerValue << 8 & 0xFF00;
|
||||
isNrpnProcessing = true;
|
||||
}
|
||||
|
||||
mState = state_nxt;
|
||||
return isNrpnProcessing;
|
||||
}
|
||||
|
||||
+3
-1
@@ -12,11 +12,11 @@ class MidiNrpn
|
||||
~MidiNrpn();
|
||||
|
||||
void reset();
|
||||
bool isCommand();
|
||||
int getCommand();
|
||||
|
||||
bool isValue();
|
||||
int consumeValue();
|
||||
int getMaxValue();
|
||||
|
||||
bool process(uint8_t controllerNumber, uint8_t controllerValue);
|
||||
|
||||
@@ -25,6 +25,8 @@ class MidiNrpn
|
||||
int mState;
|
||||
int mCommand;
|
||||
int mValue;
|
||||
int maxValue;
|
||||
bool mValueIsValid;
|
||||
};
|
||||
|
||||
#endif //_MIDI_NRPN_H_
|
||||
|
||||
Reference in New Issue
Block a user