From ea9690d72b1c51371b488bd93655d9023991272b Mon Sep 17 00:00:00 2001 From: Ken Cooke Date: Mon, 6 May 2019 10:46:54 -0700 Subject: [PATCH 1/3] Disable MIDI rescan after devicechange, to avoid deadlock --- interface/src/Application.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 59f4934dca..6b956e7f55 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -557,7 +557,10 @@ public: return true; } } - + // Attempting to close MIDI interfaces of a hot-unplugged device can result in audio-driver deadlock. + // Detecting MIDI devices that have been added/removed after starting Inteface has been disabled. + // https://support.microsoft.com/en-us/help/4460006/midi-device-app-hangs-when-former-midi-api-is-used +#if 0 if (message->message == WM_DEVICECHANGE) { const float MIN_DELTA_SECONDS = 2.0f; // de-bounce signal static float lastTriggerTime = 0.0f; @@ -567,6 +570,7 @@ public: Midi::USBchanged(); // re-scan the MIDI bus } } +#endif } return false; } From f133ab65e4adb138413c2ecee84932fc158dff45 Mon Sep 17 00:00:00 2001 From: Ken Cooke Date: Mon, 6 May 2019 10:48:53 -0700 Subject: [PATCH 2/3] MIDI bugfix --- libraries/midi/src/Midi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/midi/src/Midi.cpp b/libraries/midi/src/Midi.cpp index 1f190111f2..06c370761e 100644 --- a/libraries/midi/src/Midi.cpp +++ b/libraries/midi/src/Midi.cpp @@ -206,7 +206,7 @@ void Midi::MidiSetup() { MIDIOUTCAPS outcaps; for (unsigned int i = 0; i < midiOutGetNumDevs(); i++) { - midiOutGetDevCaps(i, &outcaps, sizeof(MIDIINCAPS)); + midiOutGetDevCaps(i, &outcaps, sizeof(MIDIOUTCAPS)); bool found = false; for (int j = 0; j < midiOutExclude.size(); j++) { From 408fb56d57d5b89f3351e99ee2f2554aebb176f1 Mon Sep 17 00:00:00 2001 From: Ken Cooke Date: Mon, 6 May 2019 10:53:58 -0700 Subject: [PATCH 3/3] MIDI error checking --- libraries/midi/src/Midi.cpp | 51 ++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/libraries/midi/src/Midi.cpp b/libraries/midi/src/Midi.cpp index 06c370761e..1b58148e98 100644 --- a/libraries/midi/src/Midi.cpp +++ b/libraries/midi/src/Midi.cpp @@ -187,38 +187,43 @@ void Midi::MidiSetup() { MIDIINCAPS incaps; for (unsigned int i = 0; i < midiInGetNumDevs(); i++) { - midiInGetDevCaps(i, &incaps, sizeof(MIDIINCAPS)); + if (MMSYSERR_NOERROR == midiInGetDevCaps(i, &incaps, sizeof(MIDIINCAPS))) { - bool found = false; - for (int j = 0; j < midiInExclude.size(); j++) { - if (midiInExclude[j].toStdString().compare(incaps.szPname) == 0) { - found = true; - break; + bool found = false; + for (int j = 0; j < midiInExclude.size(); j++) { + if (midiInExclude[j].toStdString().compare(incaps.szPname) == 0) { + found = true; + break; + } + } + if (!found) { // EXCLUDE AN INPUT BY NAME + HMIDIIN tmphin; + if (MMSYSERR_NOERROR == midiInOpen(&tmphin, i, (DWORD_PTR)MidiInProc, NULL, CALLBACK_FUNCTION)) { + if (MMSYSERR_NOERROR == midiInStart(tmphin)) { + midihin.push_back(tmphin); + } + } } - } - if (!found) { // EXCLUDE AN INPUT BY NAME - HMIDIIN tmphin; - midiInOpen(&tmphin, i, (DWORD_PTR)MidiInProc, NULL, CALLBACK_FUNCTION); - midiInStart(tmphin); - midihin.push_back(tmphin); } } MIDIOUTCAPS outcaps; for (unsigned int i = 0; i < midiOutGetNumDevs(); i++) { - midiOutGetDevCaps(i, &outcaps, sizeof(MIDIOUTCAPS)); + if (MMSYSERR_NOERROR == midiOutGetDevCaps(i, &outcaps, sizeof(MIDIOUTCAPS))) { - bool found = false; - for (int j = 0; j < midiOutExclude.size(); j++) { - if (midiOutExclude[j].toStdString().compare(outcaps.szPname) == 0) { - found = true; - break; + bool found = false; + for (int j = 0; j < midiOutExclude.size(); j++) { + if (midiOutExclude[j].toStdString().compare(outcaps.szPname) == 0) { + found = true; + break; + } + } + if (!found) { // EXCLUDE AN OUTPUT BY NAME + HMIDIOUT tmphout; + if (MMSYSERR_NOERROR == midiOutOpen(&tmphout, i, (DWORD_PTR)MidiOutProc, NULL, CALLBACK_FUNCTION)) { + midihout.push_back(tmphout); + } } - } - if (!found) { // EXCLUDE AN OUTPUT BY NAME - HMIDIOUT tmphout; - midiOutOpen(&tmphout, i, (DWORD_PTR)MidiOutProc, NULL, CALLBACK_FUNCTION); - midihout.push_back(tmphout); } }