Use a helper function to check valid MIDI controller inputs

This commit is contained in:
Chris Robinson 2014-07-04 11:18:32 -07:00
parent f667782df2
commit 5afc29f65d
4 changed files with 19 additions and 9 deletions

View File

@ -16,6 +16,8 @@
#include "alu.h"
extern inline ALboolean IsValidCtrlInput(int cc);
extern inline size_t Reader_read(Reader *self, void *buf, size_t len);

View File

@ -614,11 +614,8 @@ static ALenum getModSrcInput(int input)
if(input == 16) return AL_PITCHBEND_SENSITIVITY_SOFT;
if((input&0x80))
{
input ^= 0x80;
if(input > 0 && input < 120 && !(input == 6 || (input >= 32 && input <= 63) ||
(input >= 98 && input <= 101)))
return input;
input ^= 0x80;
if(IsValidCtrlInput(input^0x80))
return input^0x80;
}
ERR("Unhandled modulator source input: 0x%02x\n", input);
return AL_INVALID;

View File

@ -157,6 +157,20 @@ inline struct ALsoundfont *RemoveSfont(ALCdevice *device, ALuint id)
void ReleaseALSoundfonts(ALCdevice *device);
inline ALboolean IsValidCtrlInput(int cc)
{
/* These correspond to MIDI functions, not real controller values. */
if(cc == 0 || cc == 6 || cc == 32 || cc == 38 || (cc >= 98 && cc <= 101) || cc >= 120)
return AL_FALSE;
/* These are the LSB components of CC0...CC31, which are automatically used when
* reading the MSB controller value. */
if(cc >= 32 && cc <= 63)
return AL_FALSE;
/* All the rest are okay! */
return AL_TRUE;
}
#ifdef __cplusplus
}
#endif

View File

@ -871,10 +871,7 @@ void ALfontsound_setModStagei(ALfontsound *self, ALCcontext *context, ALsizei st
value == AL_NOTEON_KEY_SOFT || value == AL_KEYPRESSURE_SOFT ||
value == AL_CHANNELPRESSURE_SOFT || value == AL_PITCHBEND_SOFT ||
value == AL_PITCHBEND_SENSITIVITY_SOFT ||
(value > 0 && value < 120 && !(value == 6 || (value >= 32 && value <= 63) ||
(value >= 98 && value <= 101))
)
))
IsValidCtrlInput(value)))
SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
ALfontsound_getModStage(self, stage)->Source[srcidx].Input = value;
break;