more work
This commit is contained in:
parent
81319e34bc
commit
4825fe7adb
|
@ -2621,7 +2621,7 @@ bool DivEngine::switchMaster() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DivEngine::setMidiCallback(std::function<bool(const TAMidiMessage&)> what) {
|
void DivEngine::setMidiCallback(std::function<int(const TAMidiMessage&)> what) {
|
||||||
midiCallback=what;
|
midiCallback=what;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -244,7 +244,8 @@ class DivEngine {
|
||||||
|
|
||||||
size_t totalProcessed;
|
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);
|
DivSystem systemFromFile(unsigned char val);
|
||||||
unsigned char systemToFile(DivSystem val);
|
unsigned char systemToFile(DivSystem val);
|
||||||
|
@ -638,8 +639,8 @@ class DivEngine {
|
||||||
bool switchMaster();
|
bool switchMaster();
|
||||||
|
|
||||||
// set MIDI input callback
|
// set MIDI input callback
|
||||||
// if the specified function returns true, note feedback will be inhibited.
|
// if the specified function returns -2, note feedback will be inhibited.
|
||||||
void setMidiCallback(std::function<bool(const TAMidiMessage&)> what);
|
void setMidiCallback(std::function<int(const TAMidiMessage&)> what);
|
||||||
|
|
||||||
// perform secure/sync operation
|
// perform secure/sync operation
|
||||||
void synchronized(const std::function<void()>& what);
|
void synchronized(const std::function<void()>& what);
|
||||||
|
|
|
@ -1541,17 +1541,32 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
||||||
// process MIDI events (TODO: everything)
|
// process MIDI events (TODO: everything)
|
||||||
if (output->midiIn) while (!output->midiIn->queue.empty()) {
|
if (output->midiIn) while (!output->midiIn->queue.empty()) {
|
||||||
TAMidiMessage& msg=output->midiIn->queue.front();
|
TAMidiMessage& msg=output->midiIn->queue.front();
|
||||||
if (!midiCallback(msg)) {
|
int ins=-1;
|
||||||
|
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;
|
||||||
pendingNotes.push(DivNoteEvent(msg.type&15,-1,-1,-1,false));
|
pendingNotes.push(DivNoteEvent(msg.type&15,-1,-1,-1,false));
|
||||||
|
if (!playing) {
|
||||||
|
reset();
|
||||||
|
freelance=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;
|
||||||
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;
|
break;
|
||||||
}
|
}
|
||||||
case TA_MIDI_PROGRAM: {
|
case TA_MIDI_PROGRAM: {
|
||||||
|
|
|
@ -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_ImplSDLRenderer_NewFrame();
|
||||||
ImGui_ImplSDL2_NewFrame(sdlWin);
|
ImGui_ImplSDL2_NewFrame(sdlWin);
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
@ -2628,10 +2646,12 @@ bool FurnaceGUI::init() {
|
||||||
|
|
||||||
firstFrame=true;
|
firstFrame=true;
|
||||||
|
|
||||||
// TODO
|
// TODO: MIDI mapping time!
|
||||||
e->setMidiCallback([this](const TAMidiMessage& msg) -> bool {
|
e->setMidiCallback([this](const TAMidiMessage& msg) -> int {
|
||||||
logD("I hate macOS: %p\n",this);
|
midiLock.lock();
|
||||||
return true;
|
midiQueue.push(msg);
|
||||||
|
midiLock.unlock();
|
||||||
|
return curIns;
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -492,6 +492,14 @@ struct UndoStep {
|
||||||
std::vector<UndoPatternData> pat;
|
std::vector<UndoPatternData> pat;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct MIDIBind {
|
||||||
|
int type, channel, data1, data2;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MIDIMap {
|
||||||
|
std::vector<MIDIBind> binds;
|
||||||
|
};
|
||||||
|
|
||||||
struct Particle {
|
struct Particle {
|
||||||
ImU32* colors;
|
ImU32* colors;
|
||||||
const char* type;
|
const char* type;
|
||||||
|
@ -562,6 +570,9 @@ class FurnaceGUI {
|
||||||
std::mutex backupLock;
|
std::mutex backupLock;
|
||||||
String backupPath;
|
String backupPath;
|
||||||
|
|
||||||
|
std::mutex midiLock;
|
||||||
|
std::queue<TAMidiMessage> midiQueue;
|
||||||
|
|
||||||
ImFont* mainFont;
|
ImFont* mainFont;
|
||||||
ImFont* iconFont;
|
ImFont* iconFont;
|
||||||
ImFont* patFont;
|
ImFont* patFont;
|
||||||
|
|
Loading…
Reference in a new issue