fix possible incomplete MIDI message

This commit is contained in:
tildearrow 2025-03-09 02:25:20 -05:00
parent 5a2d4662aa
commit e7df0c7b0a

View file

@ -367,7 +367,9 @@ int DivEngine::dispatchCmd(DivCommand c) {
if (chan[c.chan].curMidiNote<0) chan[c.chan].curMidiNote=0; if (chan[c.chan].curMidiNote<0) chan[c.chan].curMidiNote=0;
if (chan[c.chan].curMidiNote>127) chan[c.chan].curMidiNote=127; if (chan[c.chan].curMidiNote>127) chan[c.chan].curMidiNote=127;
} }
if (chan[c.chan].curMidiNote>=0) {
output->midiOut->send(TAMidiMessage(0x90|(c.chan&15),chan[c.chan].curMidiNote,scaledVol)); output->midiOut->send(TAMidiMessage(0x90|(c.chan&15),chan[c.chan].curMidiNote,scaledVol));
}
break; break;
case DIV_CMD_NOTE_OFF: case DIV_CMD_NOTE_OFF:
case DIV_CMD_NOTE_OFF_ENV: case DIV_CMD_NOTE_OFF_ENV:
@ -378,7 +380,7 @@ int DivEngine::dispatchCmd(DivCommand c) {
break; break;
case DIV_CMD_INSTRUMENT: case DIV_CMD_INSTRUMENT:
if (chan[c.chan].lastIns!=c.value && midiOutProgramChange) { if (chan[c.chan].lastIns!=c.value && midiOutProgramChange) {
output->midiOut->send(TAMidiMessage(0xc0|(c.chan&15),c.value,0)); output->midiOut->send(TAMidiMessage(0xc0|(c.chan&15),c.value&0x7f,0));
} }
break; break;
case DIV_CMD_VOLUME: case DIV_CMD_VOLUME:
@ -399,6 +401,8 @@ int DivEngine::dispatchCmd(DivCommand c) {
} }
case DIV_CMD_PANNING: { case DIV_CMD_PANNING: {
int pan=convertPanSplitToLinearLR(c.value,c.value2,127); int pan=convertPanSplitToLinearLR(c.value,c.value2,127);
if (pan<0) pan=0;
if (pan>127) pan=127;
output->midiOut->send(TAMidiMessage(0xb0|(c.chan&15),0x0a,pan)); output->midiOut->send(TAMidiMessage(0xb0|(c.chan&15),0x0a,pan));
break; break;
} }