more work

This commit is contained in:
tildearrow 2022-03-28 18:19:47 -05:00
parent 81319e34bc
commit 4825fe7adb
5 changed files with 57 additions and 10 deletions

View file

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

View file

@ -244,7 +244,8 @@ class DivEngine {
size_t totalProcessed;
std::function<bool(const TAMidiMessage&)> midiCallback=[](const TAMidiMessage&) -> bool {return false;};
// MIDI stuff
std::function<int(const TAMidiMessage&)> midiCallback=[](const TAMidiMessage&) -> int {return -1;};
DivSystem systemFromFile(unsigned char val);
unsigned char systemToFile(DivSystem val);
@ -638,8 +639,8 @@ class DivEngine {
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);
// if the specified function returns -2, note feedback will be inhibited.
void setMidiCallback(std::function<int(const TAMidiMessage&)> what);
// perform secure/sync operation
void synchronized(const std::function<void()>& what);

View file

@ -1541,17 +1541,32 @@ 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();
if (!midiCallback(msg)) {
int ins=-1;
if ((ins=midiCallback(msg))!=-2) {
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));
if (!playing) {
reset();
freelance=true;
playing=true;
}
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));
if (msg.data[1]==0) {
pendingNotes.push(DivNoteEvent(msg.type&15,-1,-1,-1,false));
} else {
pendingNotes.push(DivNoteEvent(msg.type&15,ins,(int)msg.data[0]-12,msg.data[1],true));
}
if (!playing) {
reset();
freelance=true;
playing=true;
}
break;
}
case TA_MIDI_PROGRAM: {

View file

@ -1874,6 +1874,24 @@ bool FurnaceGUI::loop() {
}
}
while (true) {
midiLock.lock();
if (midiQueue.empty()) {
midiLock.unlock();
break;
}
TAMidiMessage msg=midiQueue.front();
midiLock.unlock();
// parse message here
logD("message is %.2x\n",msg.type);
if (msg.type==0xb0) doAction(GUI_ACTION_PLAY_TOGGLE);
midiLock.lock();
midiQueue.pop();
midiLock.unlock();
}
ImGui_ImplSDLRenderer_NewFrame();
ImGui_ImplSDL2_NewFrame(sdlWin);
ImGui::NewFrame();
@ -2628,10 +2646,12 @@ bool FurnaceGUI::init() {
firstFrame=true;
// TODO
e->setMidiCallback([this](const TAMidiMessage& msg) -> bool {
logD("I hate macOS: %p\n",this);
return true;
// TODO: MIDI mapping time!
e->setMidiCallback([this](const TAMidiMessage& msg) -> int {
midiLock.lock();
midiQueue.push(msg);
midiLock.unlock();
return curIns;
});
return true;

View file

@ -492,6 +492,14 @@ struct UndoStep {
std::vector<UndoPatternData> pat;
};
struct MIDIBind {
int type, channel, data1, data2;
};
struct MIDIMap {
std::vector<MIDIBind> binds;
};
struct Particle {
ImU32* colors;
const char* type;
@ -562,6 +570,9 @@ class FurnaceGUI {
std::mutex backupLock;
String backupPath;
std::mutex midiLock;
std::queue<TAMidiMessage> midiQueue;
ImFont* mainFont;
ImFont* iconFont;
ImFont* patFont;