3rdparty/portmidi: Try to get PortMidi into a state where it will build with sane compiler settings.

This commit is contained in:
Vas Crabb 2025-04-20 08:18:21 +10:00
parent 844af3a173
commit cfec4a0ec0
11 changed files with 38 additions and 37 deletions

View File

@ -162,7 +162,7 @@ PmError pm_fail_timestamp_fn(PmInternal *midi, PmTimestamp timestamp);
PmError pm_success_fn(PmInternal *midi); PmError pm_success_fn(PmInternal *midi);
PmError pm_add_interf(char *interf, pm_create_fn create_fn, PmError pm_add_interf(char *interf, pm_create_fn create_fn,
pm_delete_fn delete_fn); pm_delete_fn delete_fn);
PmError pm_add_device(char *interf, const char *name, int is_input, PmError pm_add_device(const char *interf, const char *name, int is_input,
int is_virtual, void *descriptor, pm_fns_type dictionary); int is_virtual, void *descriptor, pm_fns_type dictionary);
void pm_undo_add_device(int id); void pm_undo_add_device(int id);
uint32_t pm_read_bytes(PmInternal *midi, const unsigned char *data, int len, uint32_t pm_read_bytes(PmInternal *midi, const unsigned char *data, int len,

View File

@ -179,7 +179,7 @@ PmError pm_create_virtual(PmInternal *midi, int is_input, const char *interf,
* device would take the name of an existing device. * device would take the name of an existing device.
* otherwise returns index (portmidi device_id) of the added device * otherwise returns index (portmidi device_id) of the added device
*/ */
PmError pm_add_device(char *interf, const char *name, int is_input, PmError pm_add_device(const char *interf, const char *name, int is_input,
int is_virtual, void *descriptor, pm_fns_type dictionary) { int is_virtual, void *descriptor, pm_fns_type dictionary) {
/* printf("pm_add_device: %s %s %d %p %p\n", /* printf("pm_add_device: %s %s %d %p %p\n",
interf, name, is_input, descriptor, dictionary); */ interf, name, is_input, descriptor, dictionary); */
@ -293,7 +293,7 @@ int pm_find_default_device(char *pattern, int is_input)
int id = pmNoDevice; int id = pmNoDevice;
int i; int i;
/* first parse pattern into name, interf parts */ /* first parse pattern into name, interf parts */
char *interf_pref = ""; /* initially assume it is not there */ char const *interf_pref = ""; /* initially assume it is not there */
char *name_pref = strstr(pattern, ", "); char *name_pref = strstr(pattern, ", ");
if (name_pref) { /* found separator, adjust the pointer */ if (name_pref) { /* found separator, adjust the pointer */
@ -909,7 +909,7 @@ PMEXPORT PmError Pm_OpenInput(PortMidiStream** stream,
PmTimeProcPtr time_proc, PmTimeProcPtr time_proc,
void *time_info) void *time_info)
{ {
PmInternal *midi; PmInternal *midi = NULL;
PmError err = pmNoError; PmError err = pmNoError;
pm_hosterror = FALSE; pm_hosterror = FALSE;
*stream = NULL; /* invariant: *stream == midi */ *stream = NULL; /* invariant: *stream == midi */

View File

@ -22,7 +22,7 @@ void skip_spaces(FILE *inf)
} }
/* trim leading spaces and match a string */ /* trim leading spaces and match a string */
int match_string(FILE *inf, char *s) int match_string(FILE *inf, const char *s)
{ {
skip_spaces(inf); skip_spaces(inf);
while (*s && *s == getc(inf)) s++; while (*s && *s == getc(inf)) s++;
@ -33,17 +33,18 @@ int match_string(FILE *inf, char *s)
/* /*
/* Parse preference files, find default device, search devices -- /* Parse preference files, find default device, search devices --
*/ */
PmDeviceID find_default_device(char *path, int input, PmDeviceID id) PmDeviceID find_default_device(const char *path, int input, PmDeviceID id)
/* path -- the name of the preference we are searching for /* path -- the name of the preference we are searching for
input -- true iff this is an input device input -- true iff this is an input device
id -- current default device id id -- current default device id
returns matching device id if found, otherwise id returns matching device id if found, otherwise id
*/ */
{ {
static char *pref_2 = "/.java/.userPrefs/"; static char const *const pref_2 = "/.java/.userPrefs/";
static char *pref_3 = "prefs.xml"; static char const *const pref_3 = "prefs.xml";
char *pref_1 = getenv("HOME"); const char *pref_1 = getenv("HOME");
char *full_name, *path_ptr; const char *path_ptr;
char *full_name;
FILE *inf; FILE *inf;
int c, i; int c, i;
if (!pref_1) goto nopref; // cannot find preference file if (!pref_1) goto nopref; // cannot find preference file

View File

@ -2,4 +2,4 @@
Roger Dannenberg, Jan 2021 Roger Dannenberg, Jan 2021
*/ */
PmDeviceID find_default_device(char *path, int input, PmDeviceID id); PmDeviceID find_default_device(const char *path, int input, PmDeviceID id);

View File

@ -31,7 +31,7 @@
PmDeviceID pm_default_input_device_id = -1; PmDeviceID pm_default_input_device_id = -1;
PmDeviceID pm_default_output_device_id = -1; PmDeviceID pm_default_output_device_id = -1;
void pm_init() void pm_init(void)
{ {
/* Note: it is not an error for PMALSA to fail to initialize. /* Note: it is not an error for PMALSA to fail to initialize.
* It may be a design error that the client cannot query what subsystems * It may be a design error that the client cannot query what subsystems
@ -65,12 +65,12 @@ void pm_term(void)
#endif #endif
} }
PmDeviceID Pm_GetDefaultInputDeviceID() { PmDeviceID Pm_GetDefaultInputDeviceID(void) {
Pm_Initialize(); Pm_Initialize();
return pm_default_input_device_id; return pm_default_input_device_id;
} }
PmDeviceID Pm_GetDefaultOutputDeviceID() { PmDeviceID Pm_GetDefaultOutputDeviceID(void) {
Pm_Initialize(); Pm_Initialize();
return pm_default_output_device_id; return pm_default_output_device_id;
} }

View File

@ -24,7 +24,7 @@ PmDeviceID find_default_device(char *path, int input, PmDeviceID id)
returns matching device id if found, otherwise id returns matching device id if found, otherwise id
*/ */
{ {
static char *pref_file = "com.apple.java.util.prefs.plist"; static char const *const pref_file = "com.apple.java.util.prefs.plist";
char *pref_str = NULL; char *pref_str = NULL;
// read device preferences // read device preferences
value_ptr prefs = bplist_read_user_pref(pref_file); value_ptr prefs = bplist_read_user_pref(pref_file);

View File

@ -18,7 +18,7 @@ non-CoreMIDI devices.
PmDeviceID pm_default_input_device_id = -1; PmDeviceID pm_default_input_device_id = -1;
PmDeviceID pm_default_output_device_id = -1; PmDeviceID pm_default_output_device_id = -1;
void pm_init() void pm_init(void)
{ {
PmError err = pm_macosxcm_init(); PmError err = pm_macosxcm_init();
// this is set when we return to Pm_Initialize, but we need it // this is set when we return to Pm_Initialize, but we need it
@ -41,13 +41,13 @@ void pm_term(void)
} }
PmDeviceID Pm_GetDefaultInputDeviceID() PmDeviceID Pm_GetDefaultInputDeviceID(void)
{ {
Pm_Initialize(); Pm_Initialize();
return pm_default_input_device_id; return pm_default_input_device_id;
} }
PmDeviceID Pm_GetDefaultOutputDeviceID() PmDeviceID Pm_GetDefaultOutputDeviceID(void)
{ {
Pm_Initialize(); Pm_Initialize();
return pm_default_output_device_id; return pm_default_output_device_id;

View File

@ -155,7 +155,7 @@ static void *allocate(size_t size)
return result; return result;
} }
void bplist_free_data() void bplist_free_data(void)
{ {
while (block_list) { while (block_list) {
void *next = *(void **)block_list; void *next = *(void **)block_list;
@ -206,7 +206,7 @@ typedef struct bplist_info
static value_ptr bplist_read_pldata(pldata_ptr data); static value_ptr bplist_read_pldata(pldata_ptr data);
static value_ptr bplist_read_pref(char *filename, OSType folder_type); static value_ptr bplist_read_pref(const char *filename, OSType folder_type);
static uint64_t read_sized_int(bplist_info_ptr bplist, uint64_t offset, static uint64_t read_sized_int(bplist_info_ptr bplist, uint64_t offset,
uint8_t size); uint8_t size);
static uint64_t read_offset(bplist_info_ptr bplist, uint64_t index); static uint64_t read_offset(bplist_info_ptr bplist, uint64_t index);
@ -344,7 +344,7 @@ BOOL is_binary_plist(pldata_ptr data)
} }
value_ptr bplist_read_file(char *filename) value_ptr bplist_read_file(const char *filename)
{ {
struct stat stbuf; struct stat stbuf;
pldata_node pldata; pldata_node pldata;
@ -391,7 +391,7 @@ value_ptr bplist_read_file(char *filename)
} }
value_ptr bplist_read_pref(char *filename, OSType folder_type) value_ptr bplist_read_pref(const char *filename, OSType folder_type)
{ {
FSRef prefdir; FSRef prefdir;
char cstr[MAX_PATH_LEN]; char cstr[MAX_PATH_LEN];
@ -413,12 +413,12 @@ value_ptr bplist_read_pref(char *filename, OSType folder_type)
} }
value_ptr bplist_read_system_pref(char *filename) { value_ptr bplist_read_system_pref(const char *filename) {
return bplist_read_pref(filename, kSystemPreferencesFolderType); return bplist_read_pref(filename, kSystemPreferencesFolderType);
} }
value_ptr bplist_read_user_pref(char *filename) { value_ptr bplist_read_user_pref(const char *filename) {
return bplist_read_pref(filename, kPreferencesFolderType); return bplist_read_pref(filename, kPreferencesFolderType);
} }

View File

@ -71,10 +71,10 @@ typedef struct value_struct {
} value_node, *value_ptr; } value_node, *value_ptr;
value_ptr bplist_read_file(char *filename); value_ptr bplist_read_file(const char *filename);
value_ptr bplist_read_user_pref(char *filename); value_ptr bplist_read_user_pref(const char *filename);
value_ptr bplist_read_system_pref(char *filename); value_ptr bplist_read_system_pref(const char *filename);
void bplist_free_data(); void bplist_free_data(void);
/*************** functions for accessing values ****************/ /*************** functions for accessing values ****************/

View File

@ -56,7 +56,7 @@ void pm_term(void) {
} }
static PmDeviceID pm_get_default_device_id(int is_input, char *key) { static PmDeviceID pm_get_default_device_id(int is_input, const char *key) {
HKEY hkey; HKEY hkey;
#define PATTERN_MAX 256 #define PATTERN_MAX 256
char pattern[PATTERN_MAX]; char pattern[PATTERN_MAX];

View File

@ -139,7 +139,7 @@ typedef struct winmm_info_struct {
general MIDI device queries general MIDI device queries
============================================================================= =============================================================================
*/ */
static void pm_winmm_general_inputs() static void pm_winmm_general_inputs(void)
{ {
UINT i; UINT i;
WORD wRtn; WORD wRtn;
@ -168,7 +168,7 @@ static void pm_winmm_general_inputs()
} }
static void pm_winmm_mapper_input() static void pm_winmm_mapper_input(void)
{ {
WORD wRtn; WORD wRtn;
/* Note: if MIDIMAPPER opened as input (documentation implies you /* Note: if MIDIMAPPER opened as input (documentation implies you
@ -186,7 +186,7 @@ static void pm_winmm_mapper_input()
} }
static void pm_winmm_general_outputs() static void pm_winmm_general_outputs(void)
{ {
UINT i; UINT i;
DWORD wRtn; DWORD wRtn;
@ -210,7 +210,7 @@ static void pm_winmm_general_outputs()
} }
static void pm_winmm_mapper_output() static void pm_winmm_mapper_output(void)
{ {
WORD wRtn; WORD wRtn;
/* Note: if MIDIMAPPER opened as output (pseudo MIDI device /* Note: if MIDIMAPPER opened as output (pseudo MIDI device
@ -400,7 +400,7 @@ static unsigned int allocate_input_buffer(HMIDIIN h, long buffer_len)
} }
static winmm_info_type winmm_info_create() static winmm_info_type winmm_info_create(void)
{ {
winmm_info_type info = (winmm_info_type) pm_alloc(sizeof(winmm_info_node)); winmm_info_type info = (winmm_info_type) pm_alloc(sizeof(winmm_info_node));
info->handle.in = NULL; info->handle.in = NULL;
@ -501,10 +501,10 @@ static PmError winmm_in_close(PmInternal *midi)
winmm_info_type info = (winmm_info_type) midi->api_info; winmm_info_type info = (winmm_info_type) midi->api_info;
if (!info) return pmBadPtr; if (!info) return pmBadPtr;
/* device to close */ /* device to close */
if (pm_hosterror = midiInStop(info->handle.in)) { if ((pm_hosterror = midiInStop(info->handle.in))) {
midiInReset(info->handle.in); /* try to reset and close port */ midiInReset(info->handle.in); /* try to reset and close port */
midiInClose(info->handle.in); midiInClose(info->handle.in);
} else if (pm_hosterror = midiInReset(info->handle.in)) { } else if ((pm_hosterror = midiInReset(info->handle.in))) {
midiInClose(info->handle.in); /* best effort to close midi port */ midiInClose(info->handle.in); /* best effort to close midi port */
} else { } else {
pm_hosterror = midiInClose(info->handle.in); pm_hosterror = midiInClose(info->handle.in);
@ -988,7 +988,7 @@ static PmError winmm_write_byte(PmInternal *midi, unsigned char byte,
info->hdr = hdr = get_free_output_buffer(midi); info->hdr = hdr = get_free_output_buffer(midi);
assert(hdr); assert(hdr);
midi->fill_base = (unsigned char *) info->hdr->lpData; midi->fill_base = (unsigned char *) info->hdr->lpData;
midi->fill_offset_ptr = &(hdr->dwBytesRecorded); midi->fill_offset_ptr = (unsigned int *) &(hdr->dwBytesRecorded);
/* when buffer fills, Pm_WriteSysEx will revert to calling /* when buffer fills, Pm_WriteSysEx will revert to calling
* pmwin_write_byte, which expect to have space, so leave * pmwin_write_byte, which expect to have space, so leave
* one byte free for pmwin_write_byte. Leave another byte * one byte free for pmwin_write_byte. Leave another byte