oh yes more MIDI work

This commit is contained in:
tildearrow 2022-03-28 15:24:09 -05:00
parent d8328e91a7
commit 08910d37b2
4 changed files with 33 additions and 16 deletions

View file

@ -2621,6 +2621,10 @@ bool DivEngine::switchMaster() {
return true;
}
void DivEngine::setMidiCallback(std::function<bool(const TAMidiMessage&)> what) {
midiCallback=what;
}
void DivEngine::synchronized(const std::function<void()>& what) {
BUSY_BEGIN;
what();

View file

@ -244,6 +244,8 @@ class DivEngine {
size_t totalProcessed;
std::function<bool(const TAMidiMessage&)> midiCallback=[](const TAMidiMessage&) -> bool {return false;};
DivSystem systemFromFile(unsigned char val);
unsigned char systemToFile(DivSystem val);
int dispatchCmd(DivCommand c);
@ -635,6 +637,10 @@ class DivEngine {
// switch master
bool switchMaster();
// set MIDI input callback
// if the specified function returns true, note feedback will be inhibited.
void setMidiCallback(std::function<bool(const TAMidiMessage&)> what);
// perform secure/sync operation
void synchronized(const std::function<void()>& what);

View file

@ -1541,21 +1541,23 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
// process MIDI events (TODO: everything)
if (output->midiIn) while (!output->midiIn->queue.empty()) {
TAMidiMessage& msg=output->midiIn->queue.front();
int chan=msg.type&15;
switch (msg.type&0xf0) {
case TA_MIDI_NOTE_OFF: {
if (chan<0 || chan>=chans) break;
pendingNotes.push(DivNoteEvent(msg.type&15,-1,-1,-1,false));
break;
}
case TA_MIDI_NOTE_ON: {
if (chan<0 || chan>=chans) break;
pendingNotes.push(DivNoteEvent(msg.type&15,-1,(int)msg.data[0]-12,msg.data[1],true));
break;
}
case TA_MIDI_PROGRAM: {
// TODO: change instrument event thingy
break;
if (!midiCallback(msg)) {
int chan=msg.type&15;
switch (msg.type&0xf0) {
case TA_MIDI_NOTE_OFF: {
if (chan<0 || chan>=chans) break;
pendingNotes.push(DivNoteEvent(msg.type&15,-1,-1,-1,false));
break;
}
case TA_MIDI_NOTE_ON: {
if (chan<0 || chan>=chans) break;
pendingNotes.push(DivNoteEvent(msg.type&15,-1,(int)msg.data[0]-12,msg.data[1],true));
break;
}
case TA_MIDI_PROGRAM: {
// TODO: change instrument event thingy
break;
}
}
}
logD("%.2x\n",msg.type);

View file

@ -2628,6 +2628,11 @@ bool FurnaceGUI::init() {
firstFrame=true;
// TODO
e->setMidiCallback([this](const TAMidiMessage& msg) -> bool {
return true;
});
return true;
}