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