fix note on sometimes not working in jam mode

This commit is contained in:
tildearrow 2022-08-27 00:37:32 -05:00
parent efd5cc0dac
commit d577755035
3 changed files with 30 additions and 13 deletions

View file

@ -3210,7 +3210,7 @@ bool DivEngine::moveSampleDown(int which) {
void DivEngine::noteOn(int chan, int ins, int note, int vol) {
if (chan<0 || chan>=chans) return;
BUSY_BEGIN;
pendingNotes.push(DivNoteEvent(chan,ins,note,vol,true));
pendingNotes.push_back(DivNoteEvent(chan,ins,note,vol,true));
if (!playing) {
reset();
freelance=true;
@ -3222,7 +3222,7 @@ void DivEngine::noteOn(int chan, int ins, int note, int vol) {
void DivEngine::noteOff(int chan) {
if (chan<0 || chan>=chans) return;
BUSY_BEGIN;
pendingNotes.push(DivNoteEvent(chan,-1,-1,-1,false));
pendingNotes.push_back(DivNoteEvent(chan,-1,-1,-1,false));
if (!playing) {
reset();
freelance=true;
@ -3274,7 +3274,7 @@ void DivEngine::autoNoteOn(int ch, int ins, int note, int vol) {
if ((!midiPoly) || (isViable[finalChan] && chan[finalChan].midiNote==-1 && (insInst->type==DIV_INS_OPL || getChannelType(finalChan)==finalChanType || notInViableChannel))) {
chan[finalChan].midiNote=note;
chan[finalChan].midiAge=midiAgeCounter++;
pendingNotes.push(DivNoteEvent(finalChan,ins,note,vol,true));
pendingNotes.push_back(DivNoteEvent(finalChan,ins,note,vol,true));
return;
}
if (++finalChan>=chans) {
@ -3295,7 +3295,7 @@ void DivEngine::autoNoteOn(int ch, int ins, int note, int vol) {
chan[candidate].midiNote=note;
chan[candidate].midiAge=midiAgeCounter++;
pendingNotes.push(DivNoteEvent(candidate,ins,note,vol,true));
pendingNotes.push_back(DivNoteEvent(candidate,ins,note,vol,true));
}
void DivEngine::autoNoteOff(int ch, int note, int vol) {
@ -3307,7 +3307,7 @@ void DivEngine::autoNoteOff(int ch, int note, int vol) {
//if (ch<0 || ch>=chans) return;
for (int i=0; i<chans; i++) {
if (chan[i].midiNote==note) {
pendingNotes.push(DivNoteEvent(i,-1,-1,-1,false));
pendingNotes.push_back(DivNoteEvent(i,-1,-1,-1,false));
chan[i].midiNote=-1;
}
}
@ -3321,7 +3321,7 @@ void DivEngine::autoNoteOffAll() {
}
for (int i=0; i<chans; i++) {
if (chan[i].midiNote!=-1) {
pendingNotes.push(DivNoteEvent(i,-1,-1,-1,false));
pendingNotes.push_back(DivNoteEvent(i,-1,-1,-1,false));
chan[i].midiNote=-1;
}
}

View file

@ -33,7 +33,7 @@
#include <mutex>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#define addWarning(x) \
if (warnings.empty()) { \
@ -357,7 +357,7 @@ class DivEngine {
DivAudioExportModes exportMode;
double exportFadeOut;
std::map<String,String> conf;
std::queue<DivNoteEvent> pendingNotes;
std::deque<DivNoteEvent> pendingNotes;
bool isMuted[DIV_MAX_CHANS];
std::mutex isBusy, saveLock;
String configPath;

View file

@ -1010,10 +1010,27 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) {
//output->midiOut->send(TAMidiMessage(TA_MIDI_CLOCK,0,0));
}
if (!pendingNotes.empty()) {
bool isOn[DIV_MAX_CHANS];
memset(isOn,0,DIV_MAX_CHANS*sizeof(bool));
for (int i=pendingNotes.size()-1; i>=0; i--) {
if (pendingNotes[i].channel<0 || pendingNotes[i].channel>=chans) continue;
if (pendingNotes[i].on) {
isOn[pendingNotes[i].channel]=true;
} else {
if (isOn[pendingNotes[i].channel]) {
logV("erasing off -> on sequence in %d",pendingNotes[i].channel);
pendingNotes.erase(pendingNotes.begin()+i);
}
}
}
}
while (!pendingNotes.empty()) {
DivNoteEvent& note=pendingNotes.front();
if (note.channel<0 || note.channel>=chans) {
pendingNotes.pop();
pendingNotes.pop_front();
continue;
}
if (note.on) {
@ -1033,7 +1050,7 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) {
dispatchCmd(DivCommand(DIV_CMD_NOTE_OFF,note.channel));
}
}
pendingNotes.pop();
pendingNotes.pop_front();
}
if (!freelance) {
@ -1245,7 +1262,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
case TA_MIDI_NOTE_OFF: {
if (chan<0 || chan>=chans) break;
if (midiIsDirect) {
pendingNotes.push(DivNoteEvent(chan,-1,-1,-1,false));
pendingNotes.push_back(DivNoteEvent(chan,-1,-1,-1,false));
} else {
autoNoteOff(msg.type&15,msg.data[0]-12,msg.data[1]);
}
@ -1260,13 +1277,13 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
if (chan<0 || chan>=chans) break;
if (msg.data[1]==0) {
if (midiIsDirect) {
pendingNotes.push(DivNoteEvent(chan,-1,-1,-1,false));
pendingNotes.push_back(DivNoteEvent(chan,-1,-1,-1,false));
} else {
autoNoteOff(msg.type&15,msg.data[0]-12,msg.data[1]);
}
} else {
if (midiIsDirect) {
pendingNotes.push(DivNoteEvent(chan,ins,msg.data[0]-12,msg.data[1],true));
pendingNotes.push_back(DivNoteEvent(chan,ins,msg.data[0]-12,msg.data[1],true));
} else {
autoNoteOn(msg.type&15,ins,msg.data[0]-12,msg.data[1]);
}