commit d12b46edaf5d9ee0b82d8144439255cfa0fc4cd9
parent 743270e2075b65e2ab227ce6bf0358ad1a73cb46
Author: Olav Sørensen <olav.sorensen@live.no>
Date: Tue, 9 Apr 2024 22:24:33 +0200
More MIDI stuff
Diffstat:
3 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/src/ft2_main.c b/src/ft2_main.c
@@ -96,7 +96,9 @@ int main(int argc, char *argv[])
#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;
diff --git a/src/ft2_midi.c b/src/ft2_midi.c
@@ -29,7 +29,7 @@ midi_t midi; // globalized
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 @@ bool initMidiIn(void)
if (!midiInDev->ok)
{
rtmidi_in_free(midiInDev);
+ midiInDev = NULL;
return false;
}
@@ -188,16 +189,14 @@ bool initMidiIn(void)
bool openMidiInDevice(uint32_t deviceID)
{
- if (midiDeviceOpened)
- return false;
-
- if (midiInDev == NULL || getNumMidiInDevices() == 0)
+ if (midiDeviceOpened || midiInDev == NULL || midi.numInputDevices == 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 @@ bool openMidiInDevice(uint32_t deviceID)
}
rtmidi_in_ignore_types(midiInDev, true, true, true);
+ */
midiDeviceOpened = true;
return true;
@@ -281,9 +281,7 @@ bool setMidiInputDeviceFromConfig(void)
{
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 @@ setDefMidiInputDev:
}
midi.inputDevice = 0;
- midi.inputDeviceName = strdup("RtMidi");
+ midi.inputDeviceName = strdup("Error configuring MIDI...");
midi.numInputDevices = 1;
return false;
@@ -497,16 +495,15 @@ bool testMidiInputDeviceListMouseDown(void)
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;
}
diff --git a/src/ft2_midi.h b/src/ft2_midi.h
@@ -35,6 +35,6 @@ void scrollMidiInputDevListUp(void);
void scrollMidiInputDevListDown(void);
void sbMidiInputSetPos(uint32_t pos);
bool testMidiInputDeviceListMouseDown(void);
-int32_t SDLCALL initMidiFunc(void *ptr);
+int32_t initMidiFunc(void *ptr);
#endif