commit f4513abd5e8b55041a2aaafb44f0aa77a742b8b3
parent d12b46edaf5d9ee0b82d8144439255cfa0fc4cd9
Author: Olav Sørensen <olav.sorensen@live.no>
Date: Fri, 12 Apr 2024 14:36:58 +0200
More MIDI fixes (ugh)
Diffstat:
7 files changed, 56 insertions(+), 91 deletions(-)
diff --git a/src/ft2_config.c b/src/ft2_config.c
@@ -44,7 +44,7 @@ static uint8_t configBuffer[CONFIG_FILE_SIZE];
static void xorConfigBuffer(uint8_t *ptr8)
{
for (int32_t i = 0; i < CONFIG_FILE_SIZE; i++)
- ptr8[i] ^= i*7;
+ ptr8[i] ^= (uint8_t)(i*7);
}
static int32_t calcChecksum(const uint8_t *p, uint16_t len) // for Nibbles highscore data
@@ -290,7 +290,7 @@ bool loadConfig(bool showErrorFlag)
audio.currInputDevice = getAudioInputDeviceFromConfig();
#ifdef HAS_MIDI
- if (midi.supported && midi.initThreadDone)
+ if (midi.initThreadDone)
{
setMidiInputDeviceFromConfig();
if (ui.configScreenShown && editor.currConfigScreen == CONFIG_SCREEN_MIDI_INPUT)
@@ -390,8 +390,7 @@ bool saveConfig(bool showErrorFlag)
saveAudioDevicesToConfig(audio.currOutputDevice, audio.currInputDevice);
#ifdef HAS_MIDI
- if (midi.supported)
- saveMidiInputDeviceToConfig();
+ saveMidiInputDeviceToConfig();
#endif
FILE *f = UNICHAR_FOPEN(editor.configFileLocationU, "wb");
@@ -470,6 +469,7 @@ static UNICHAR *getFullAudDevConfigPathU(void) // kinda hackish
return filePathU;
}
+#ifdef HAS_MIDI
static UNICHAR *getFullMidiDevConfigPathU(void) // kinda hackish
{
int32_t mididevDotIniStrLen, ft2DotCfgStrLen;
@@ -501,6 +501,7 @@ static UNICHAR *getFullMidiDevConfigPathU(void) // kinda hackish
return filePathU;
}
+#endif
static void setConfigFileLocation(void) // kinda hackish
{
@@ -523,8 +524,7 @@ static void setConfigFileLocation(void) // kinda hackish
return;
}
- oldPathU[0] = 0;
- tmpPathU[0] = 0;
+ oldPathU[0] = tmpPathU[0] = (UNICHAR)0;
if (GetCurrentDirectoryW(PATH_MAX - ft2DotCfgStrLen - 1, oldPathU) == 0)
{
@@ -674,9 +674,9 @@ static void setConfigFileLocation(void) // kinda hackish
strcat(editor.configFileLocationU, "/FT2.CFG");
#endif
- if (midi.supported)
- editor.midiConfigFileLocationU = getFullMidiDevConfigPathU();
-
+#ifdef HAS_MIDI
+ editor.midiConfigFileLocationU = getFullMidiDevConfigPathU();
+#endif
editor.audioDevConfigFileLocationU = getFullAudDevConfigPathU();
}
@@ -800,14 +800,6 @@ static void setConfigRadioButtonStates(void)
radioButtons[tmpID].state = RADIOBUTTON_CHECKED;
showRadioButtonGroup(RB_GROUP_CONFIG_SELECT);
-
- // hide MIDI radio button if MIDI is not supported (hackish)
- if (!midi.supported)
- {
- radioButton_t *t = &radioButtons[RB_CONFIG_MIDI_INPUT];
- hideRadioButton(RB_CONFIG_MIDI_INPUT);
- fillRect(t->x, t->y, RADIOBUTTON_W, RADIOBUTTON_H, PAL_DESKTOP);
- }
}
void setConfigAudioRadioButtonStates(void) // accessed by other .c files
@@ -1031,10 +1023,7 @@ static void setConfigMiscCheckButtonStates(void)
checkBoxes[CB_CONF_CHANGE_PATTLEN_INS_DEL].checked = config.recTrueInsert;
checkBoxes[CB_CONF_MIDI_ALLOW_PC].checked = config.recMIDIAllowPC;
#ifdef HAS_MIDI
- if (midi.supported)
- checkBoxes[CB_CONF_MIDI_ENABLE].checked = midi.enable;
- else
- checkBoxes[CB_CONF_MIDI_ENABLE].checked = false;
+ checkBoxes[CB_CONF_MIDI_ENABLE].checked = midi.enable;
#else
checkBoxes[CB_CONF_MIDI_ENABLE].checked = false;
#endif
@@ -1125,8 +1114,7 @@ void showConfigScreen(void)
textOutShadow(21, 35, PAL_FORGRND, PAL_DSKTOP2, "Layout");
textOutShadow(21, 51, PAL_FORGRND, PAL_DSKTOP2, "Miscellaneous");
#ifdef HAS_MIDI
- if (midi.supported)
- textOutShadow(21, 67, PAL_FORGRND, PAL_DSKTOP2, "MIDI input");
+ textOutShadow(21, 67, PAL_FORGRND, PAL_DSKTOP2, "MIDI input");
#endif
textOutShadow(20, 93, PAL_FORGRND, PAL_DSKTOP2, "Auto save");
@@ -2089,17 +2077,7 @@ void cbMIDIAllowPC(void)
void cbMIDIEnable(void)
{
#ifdef HAS_MIDI
- if (midi.supported)
- {
- midi.enable ^= 1;
- }
- else
- {
- checkBoxes[CB_CONF_MIDI_ENABLE].checked = false;
- drawCheckBox(CB_CONF_MIDI_ENABLE);
-
- okBox(0, "System message", "MIDI support is disabled for Windows XP as it is buggy!", NULL);
- }
+ midi.enable ^= 1;
#else
checkBoxes[CB_CONF_MIDI_ENABLE].checked = false;
drawCheckBox(CB_CONF_MIDI_ENABLE);
diff --git a/src/ft2_header.h b/src/ft2_header.h
@@ -12,7 +12,7 @@
#endif
#include "ft2_replayer.h"
-#define PROG_VER_STR "1.81"
+#define PROG_VER_STR "1.82"
// do NOT change these! It will only mess things up...
diff --git a/src/ft2_keyboard.c b/src/ft2_keyboard.c
@@ -1284,12 +1284,9 @@ static bool checkModifiedKeys(SDL_Keycode keycode)
else if (keyb.leftCtrlPressed)
{
#ifdef HAS_MIDI
- if (midi.supported)
- {
- editor.currConfigScreen = 3;
- showConfigScreen();
- checkRadioButton(RB_CONFIG_MIDI_INPUT);
- }
+ editor.currConfigScreen = 3;
+ showConfigScreen();
+ checkRadioButton(RB_CONFIG_MIDI_INPUT);
#endif
return true;
}
diff --git a/src/ft2_main.c b/src/ft2_main.c
@@ -9,7 +9,6 @@
#ifdef _WIN32
#define WIN32_MEAN_AND_LEAN
#include <windows.h>
-#include <versionhelpers.h>
#include <SDL2/SDL_syswm.h>
#else
#include <unistd.h> // chdir()
@@ -96,12 +95,6 @@ int main(int argc, char *argv[])
#endif
#ifdef _WIN32
- /* Disable MIDI support if using Windows XP,
- ** as it is unstable when initialized in an own thread.
- */
- if (!IsWindowsVistaOrGreater())
- midi.supported = false;
-
#ifndef _MSC_VER
SetProcessDPIAware();
#endif
@@ -153,19 +146,14 @@ int main(int argc, char *argv[])
#ifdef __APPLE__
osxSetDirToProgramDirFromArgs(argv);
#endif
- if (!setupExecutablePath() || !loadBMPs())
+ if (!setupExecutablePath() || !loadBMPs() || !calcCubicSplineTable() || !calcWindowedSincTables())
{
cleanUpAndExit();
return 1;
}
- if (!calcCubicSplineTable() || !calcWindowedSincTables()) // must be called before config is loaded
- {
- cleanUpAndExit();
- return false;
- }
+ loadConfigOrSetDefaults(); // config must be loaded at this exact point
- loadConfigOrSetDefaults();
if (!setupWindow() || !setupRenderer())
{
// error message was shown in the functions above
@@ -233,17 +221,18 @@ int main(int argc, char *argv[])
}
#ifdef HAS_MIDI
- // set up MIDI input (in a thread because it can take quite a while on f.ex. macOS)
- if (midi.supported)
+#ifdef __APPLE__
+ // MIDI init can take several seconds on Mac, use thread
+ midi.initMidiThread = SDL_CreateThread(initMidiFunc, NULL, NULL);
+ if (midi.initMidiThread == NULL)
{
- midi.initMidiThread = SDL_CreateThread(initMidiFunc, NULL, NULL);
- if (midi.initMidiThread == NULL)
- {
- showErrorMsgBox("Couldn't create MIDI initialization thread!");
- cleanUpAndExit();
- return 1;
- }
+ showErrorMsgBox("Couldn't create MIDI initialization thread!");
+ cleanUpAndExit();
+ return 1;
}
+#else
+ initMidiFunc(NULL);
+#endif
#endif
hpc_ResetCounters(&video.vblankHpc); // quirk: this is needed for potential okBox() calls in handleModuleLoadFromArg()
@@ -278,7 +267,6 @@ static void initializeVars(void)
// clear common structs
#ifdef HAS_MIDI
memset(&midi, 0, sizeof (midi));
- midi.supported = true;
#endif
memset(&video, 0, sizeof (video));
memset(&keyb, 0, sizeof (keyb));
@@ -340,26 +328,31 @@ static void initializeVars(void)
static void cleanUpAndExit(void) // never call this inside the main loop!
{
#ifdef HAS_MIDI
- if (midi.supported)
+#ifdef __APPLE__
+ // on Mac we used a thread to init MIDI (as it could take several seconds)
+ if (midi.initMidiThread != NULL)
{
- if (midi.initMidiThread != NULL)
- {
- SDL_WaitThread(midi.initMidiThread, NULL);
- midi.initMidiThread = NULL;
- }
+ SDL_WaitThread(midi.initMidiThread, NULL);
+ midi.initMidiThread = NULL;
+ }
+#endif
+ midi.enable = false; // stop MIDI callback from doing things
+ while (midi.callbackBusy) SDL_Delay(1); // wait for MIDI callback to finish
- midi.enable = false; // stop MIDI callback from doing things
- while (midi.callbackBusy) SDL_Delay(1); // wait for MIDI callback to finish
+ closeMidiInDevice();
+ freeMidiIn();
+ freeMidiInputDeviceList();
- closeMidiInDevice();
- freeMidiIn();
- freeMidiInputDeviceList();
+ if (midi.inputDeviceName != NULL)
+ {
+ free(midi.inputDeviceName);
+ midi.inputDeviceName = NULL;
+ }
- if (midi.inputDeviceName != NULL)
- {
- free(midi.inputDeviceName);
- midi.inputDeviceName = NULL;
- }
+ if (editor.midiConfigFileLocationU != NULL)
+ {
+ free(editor.midiConfigFileLocationU);
+ editor.midiConfigFileLocationU = NULL;
}
#endif
@@ -387,12 +380,6 @@ static void cleanUpAndExit(void) // never call this inside the main loop!
editor.configFileLocationU = NULL;
}
- if (editor.midiConfigFileLocationU != NULL)
- {
- free(editor.midiConfigFileLocationU);
- editor.midiConfigFileLocationU = NULL;
- }
-
if (editor.binaryPathU != NULL)
{
free(editor.binaryPathU);
diff --git a/src/ft2_midi.c b/src/ft2_midi.c
@@ -196,7 +196,6 @@ bool openMidiInDevice(uint32_t deviceID)
if (!midiInDev->ok)
return false;
- /*
rtmidi_in_set_callback(midiInDev, midiInCallback, NULL);
if (!midiInDev->ok)
{
@@ -205,7 +204,6 @@ bool openMidiInDevice(uint32_t deviceID)
}
rtmidi_in_ignore_types(midiInDev, true, true, true);
- */
midiDeviceOpened = true;
return true;
diff --git a/src/ft2_midi.h b/src/ft2_midi.h
@@ -12,11 +12,13 @@
typedef struct midi_t
{
char *inputDeviceName, *inputDeviceNames[MAX_MIDI_DEVICES];
- volatile bool supported, initThreadDone, callbackBusy, enable;
+ volatile bool initThreadDone, callbackBusy, enable;
bool rescanDevicesFlag;
uint32_t inputDevice, numInputDevices;
int16_t currMIDIVibDepth, currMIDIPitch;
+#ifdef __APPLE__
SDL_Thread *initMidiThread;
+#endif
} midi_t;
extern midi_t midi; // ft2_midi.c
diff --git a/src/ft2_structs.h b/src/ft2_structs.h
@@ -12,7 +12,10 @@ typedef struct cpu_t
typedef struct editor_t
{
UNICHAR *binaryPathU, *tmpFilenameU, *tmpInstrFilenameU; // used by saving/loading threads
- UNICHAR *configFileLocationU, *audioDevConfigFileLocationU, *midiConfigFileLocationU;
+ UNICHAR *configFileLocationU, *audioDevConfigFileLocationU;
+#ifdef HAS_MIDI
+ UNICHAR *midiConfigFileLocationU;
+#endif
volatile bool mainLoopOngoing;
volatile bool busy, scopeThreadBusy, programRunning, wavIsRendering, wavReachedEndFlag;