ref: d12b46edaf5d9ee0b82d8144439255cfa0fc4cd9
parent: 743270e2075b65e2ab227ce6bf0358ad1a73cb46
author: Olav Sørensen <olav.sorensen@live.no>
date: Tue Apr 9 18:25:00 EDT 2024
More MIDI stuff
--- a/src/ft2_main.c
+++ b/src/ft2_main.c
@@ -96,7 +96,9 @@
#endif
#ifdef _WIN32
- // disable MIDI support if using Windows XP, as it is unstable
+ /* Disable MIDI support if using Windows XP,
+ ** as it is unstable when initialized in an own thread.
+ */
if (!IsWindowsVistaOrGreater())
midi.supported = false;
--- a/src/ft2_midi.c
+++ b/src/ft2_midi.c
@@ -29,7 +29,7 @@
static volatile bool midiDeviceOpened;
static bool recMIDIValidChn = true;
-static RtMidiPtr midiInDev;
+static volatile RtMidiPtr midiInDev;
static inline void midiInSetChannel(uint8_t status)
{
@@ -180,6 +180,7 @@
if (!midiInDev->ok)
{
rtmidi_in_free(midiInDev);
+ midiInDev = NULL;
return false;
}
@@ -188,16 +189,14 @@
bool openMidiInDevice(uint32_t deviceID)
{
- if (midiDeviceOpened)
+ if (midiDeviceOpened || midiInDev == NULL || midi.numInputDevices == 0)
return false;
- if (midiInDev == NULL || getNumMidiInDevices() == 0)
- return false;
-
rtmidi_open_port(midiInDev, deviceID, "FT2 Clone MIDI Port");
if (!midiInDev->ok)
return false;
+ /*
rtmidi_in_set_callback(midiInDev, midiInCallback, NULL);
if (!midiInDev->ok)
{
@@ -206,6 +205,7 @@
}
rtmidi_in_ignore_types(midiInDev, true, true, true);
+ */
midiDeviceOpened = true;
return true;
@@ -281,9 +281,7 @@
{
uint32_t i;
- // XXX: Something in here is corrupting!
-
- if (editor.midiConfigFileLocationU == NULL)
+ if (midiInDev == NULL || editor.midiConfigFileLocationU == NULL)
goto setDefMidiInputDev;
const uint32_t numDevices = getNumMidiInDevices();
@@ -353,7 +351,7 @@
}
midi.inputDevice = 0;
- midi.inputDeviceName = strdup("RtMidi");
+ midi.inputDeviceName = strdup("Error configuring MIDI...");
midi.numInputDevices = 1;
return false;
@@ -497,16 +495,15 @@
return true;
}
-int32_t SDLCALL initMidiFunc(void *ptr)
+int32_t initMidiFunc(void *ptr)
{
- midi.initThreadDone = false;
initMidiIn();
setMidiInputDeviceFromConfig();
openMidiInDevice(midi.inputDevice);
midi.rescanDevicesFlag = true;
midi.initThreadDone = true;
- return true;
+ return true;
(void)ptr;
}
--- a/src/ft2_midi.h
+++ b/src/ft2_midi.h
@@ -35,6 +35,6 @@
void scrollMidiInputDevListDown(void);
void sbMidiInputSetPos(uint32_t pos);
bool testMidiInputDeviceListMouseDown(void);
-int32_t SDLCALL initMidiFunc(void *ptr);
+int32_t initMidiFunc(void *ptr);
#endif
--
⑨