From c1c2b52ba7656c9d1eae6c1c127bc8ae3496655f Mon Sep 17 00:00:00 2001 From: Daniel Konar Date: Wed, 27 Dec 2023 08:53:09 +0100 Subject: [PATCH] Add button in midi settings to refresh midi devices Deletes and creates a new RT midi instance allowing for midi devices to be plugged in without restarting --- src/audio/midi.cpp | 5 +++++ src/audio/taAudio.h | 2 ++ src/engine/engine.cpp | 9 +++++++++ src/engine/engine.h | 3 +++ src/gui/settings.cpp | 7 +++++++ 5 files changed, 26 insertions(+) diff --git a/src/audio/midi.cpp b/src/audio/midi.cpp index fa3faf1f4..ea46cc20e 100644 --- a/src/audio/midi.cpp +++ b/src/audio/midi.cpp @@ -58,4 +58,9 @@ void TAAudio::quitMidi() { delete midiOut; midiOut=NULL; } +} + +bool TAAudio::reinitMidi(bool jack) { + quitMidi(); + initMidi(jack); } \ No newline at end of file diff --git a/src/audio/taAudio.h b/src/audio/taAudio.h index 0b6f530c6..3d21cbaff 100644 --- a/src/audio/taAudio.h +++ b/src/audio/taAudio.h @@ -178,6 +178,8 @@ class TAAudio { virtual std::vector listAudioDevices(); bool initMidi(bool jack); void quitMidi(); + /** remove and reload midi to allow hotswaping midi devices */ + bool reinitMidi(bool jack); virtual bool init(TAAudioDesc& request, TAAudioDesc& response); TAAudio(): diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index b425f5dc1..76c56cb16 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -3473,6 +3473,15 @@ void DivEngine::rescanAudioDevices() { } } + +void DivEngine::rescanMidiDevices() { + if (output!=NULL) { + logV("reloading midi..."); + output->reinitMidi(false); + rescanAudioDevices(); + } +} + void DivEngine::initDispatch(bool isRender) { BUSY_BEGIN; logV("initializing dispatch..."); diff --git a/src/engine/engine.h b/src/engine/engine.h index eb4bc5bbb..a5b73b2ba 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -1077,6 +1077,9 @@ class DivEngine { // rescan audio devices void rescanAudioDevices(); + /** rescan midi devices */ + void rescanMidiDevices(); + // set the console mode. void setConsoleMode(bool enable); diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index 8c503d72b..df0ca64eb 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -1129,6 +1129,13 @@ void FurnaceGUI::drawSettings() { ImGui::EndCombo(); } + ImGui::SameLine(); + if (ImGui::Button("Reload MIDI devices")) { + e->rescanMidiDevices(); + audioEngineChanged=true; + settingsChanged=false; + } + if (hasToReloadMidi) { midiMap.read(e->getConfigPath()+DIR_SEPARATOR_STR+"midiIn_"+stripName(settings.midiInDevice)+".cfg"); midiMap.compile();