Move midi input processing from playback to gui to allow correct input volume playback

This commit is contained in:
Daniel Konar 2023-12-12 21:05:30 +01:00
parent 7d1d02f81c
commit 6f8f6ccde3
2 changed files with 67 additions and 33 deletions

View file

@ -1825,37 +1825,37 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
if ((ins=midiCallback(msg))!=-2) { if ((ins=midiCallback(msg))!=-2) {
int chan=msg.type&15; int chan=msg.type&15;
switch (msg.type&0xf0) { switch (msg.type&0xf0) {
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_back(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]);
} // }
if (!playing) { // if (!playing) {
reset(); // reset();
freelance=true; // freelance=true;
playing=true; // playing=true;
} // }
break; // break;
} // }
case TA_MIDI_NOTE_ON: { // case TA_MIDI_NOTE_ON: {
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_back(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_back(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]);
} // }
} // }
break; // break;
} // }
case TA_MIDI_PROGRAM: { case TA_MIDI_PROGRAM: {
// TODO: change instrument event thingy // TODO: change instrument event thingy
break; break;

View file

@ -3767,6 +3767,10 @@ bool FurnaceGUI::loop() {
learning=-1; learning=-1;
} else { } else {
int action=midiMap.at(msg); int action=midiMap.at(msg);
int chan=msg.type&15;
int ins=-1;
int vol = midiMap.volInput?((int)(pow((double)msg.data[1]/127.0,midiMap.volExp)*127.0)):-1;
int note = msg.data[0]-12;
if (action!=0) { if (action!=0) {
doAction(action); doAction(action);
} else switch (msg.type&0xf0) { } else switch (msg.type&0xf0) {
@ -3774,10 +3778,33 @@ bool FurnaceGUI::loop() {
if (midiMap.valueInputStyle==0 || midiMap.valueInputStyle>3 || cursor.xFine==0) { if (midiMap.valueInputStyle==0 || midiMap.valueInputStyle>3 || cursor.xFine==0) {
if (midiMap.noteInput && edit && msg.data[1]!=0) { if (midiMap.noteInput && edit && msg.data[1]!=0) {
noteInput( noteInput(
msg.data[0]-12, note,
0, 0,
midiMap.volInput?((int)(pow((double)msg.data[1]/127.0,midiMap.volExp)*127.0)):-1 vol
); );
// Preview note input with velocity sensitivity
if (midiMap.directChannel) {
e->noteOn(
chan,
ins,
note,
vol
);
} else {
e->autoNoteOn(
chan,
ins,
note,
vol
);
}
} else if (msg.data[1]==0) {
// Velocity 0 note offs
if (midiMap.directChannel) {
e->noteOff(chan);
} else {
e->autoNoteOff(chan, note);
}
} }
} else { } else {
if (edit && msg.data[1]!=0) { if (edit && msg.data[1]!=0) {
@ -3802,6 +3829,13 @@ bool FurnaceGUI::loop() {
} }
} }
break; break;
case TA_MIDI_NOTE_OFF:
if (midiMap.directChannel) {
e->noteOff(msg.type&15);
} else {
e->autoNoteOff(msg.type&15, msg.data[0]-12);
}
break;
case TA_MIDI_PROGRAM: case TA_MIDI_PROGRAM:
if (midiMap.programChange) { if (midiMap.programChange) {
curIns=msg.data[0]; curIns=msg.data[0];