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

View file

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

View file

@ -1010,10 +1010,27 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) {
//output->midiOut->send(TAMidiMessage(TA_MIDI_CLOCK,0,0)); //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()) { while (!pendingNotes.empty()) {
DivNoteEvent& note=pendingNotes.front(); DivNoteEvent& note=pendingNotes.front();
if (note.channel<0 || note.channel>=chans) { if (note.channel<0 || note.channel>=chans) {
pendingNotes.pop(); pendingNotes.pop_front();
continue; continue;
} }
if (note.on) { if (note.on) {
@ -1033,7 +1050,7 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) {
dispatchCmd(DivCommand(DIV_CMD_NOTE_OFF,note.channel)); dispatchCmd(DivCommand(DIV_CMD_NOTE_OFF,note.channel));
} }
} }
pendingNotes.pop(); pendingNotes.pop_front();
} }
if (!freelance) { if (!freelance) {
@ -1245,7 +1262,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
case TA_MIDI_NOTE_OFF: { case TA_MIDI_NOTE_OFF: {
if (chan<0 || chan>=chans) break; if (chan<0 || chan>=chans) break;
if (midiIsDirect) { if (midiIsDirect) {
pendingNotes.push(DivNoteEvent(chan,-1,-1,-1,false)); pendingNotes.push_back(DivNoteEvent(chan,-1,-1,-1,false));
} else { } else {
autoNoteOff(msg.type&15,msg.data[0]-12,msg.data[1]); 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 (chan<0 || chan>=chans) break;
if (msg.data[1]==0) { if (msg.data[1]==0) {
if (midiIsDirect) { if (midiIsDirect) {
pendingNotes.push(DivNoteEvent(chan,-1,-1,-1,false)); pendingNotes.push_back(DivNoteEvent(chan,-1,-1,-1,false));
} else { } else {
autoNoteOff(msg.type&15,msg.data[0]-12,msg.data[1]); autoNoteOff(msg.type&15,msg.data[0]-12,msg.data[1]);
} }
} else { } else {
if (midiIsDirect) { 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 { } else {
autoNoteOn(msg.type&15,ins,msg.data[0]-12,msg.data[1]); autoNoteOn(msg.type&15,ins,msg.data[0]-12,msg.data[1]);
} }