From 2412275296c266505613b5c32d4ef426fcc29371 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sat, 10 Jan 2015 17:42:41 +0100 Subject: Ported changes done in previous source to make portmidi compile (nw) --- 3rdparty/portmidi/pm_common/pmutil.c | 2 +- 3rdparty/portmidi/pm_common/portmidi.c | 2 +- 3rdparty/portmidi/pm_common/portmidi.h | 8 +- 3rdparty/portmidi/pm_linux/finddefault.c | 16 ++-- 3rdparty/portmidi/pm_linux/pmlinux.c | 6 +- 3rdparty/portmidi/pm_linux/pmlinuxalsa.c | 26 +++--- 3rdparty/portmidi/pm_mac/finddefault.c | 2 +- 3rdparty/portmidi/pm_mac/osxsupport.h | 18 +++++ 3rdparty/portmidi/pm_mac/osxsupport.m | 32 ++++++++ 3rdparty/portmidi/pm_mac/pmmac.c | 4 +- 3rdparty/portmidi/pm_mac/pmmacosxcm.c | 10 +-- 3rdparty/portmidi/pm_mac/readbinaryplist.c | 58 ++++++++++--- 3rdparty/portmidi/pm_win/pmwin.c | 17 ++-- 3rdparty/portmidi/pm_win/pmwinmm.c | 126 ++++++++++++++++------------- 3rdparty/portmidi/porttime/porttime.h | 10 +-- 3rdparty/portmidi/porttime/ptmacosx_mach.c | 8 +- src/lib/lib.mak | 40 ++++----- src/osd/modules/midi/portmidi.c | 2 +- 18 files changed, 249 insertions(+), 138 deletions(-) create mode 100644 3rdparty/portmidi/pm_mac/osxsupport.h create mode 100644 3rdparty/portmidi/pm_mac/osxsupport.m diff --git a/3rdparty/portmidi/pm_common/pmutil.c b/3rdparty/portmidi/pm_common/pmutil.c index a70fe2fa1f8..7d0abe35337 100644 --- a/3rdparty/portmidi/pm_common/pmutil.c +++ b/3rdparty/portmidi/pm_common/pmutil.c @@ -8,7 +8,7 @@ #include "pmutil.h" #include "pminternal.h" -#ifdef WIN32 +#if defined(WIN32) || defined(_MSC_VER) #define bzero(addr, siz) memset(addr, 0, siz) #endif diff --git a/3rdparty/portmidi/pm_common/portmidi.c b/3rdparty/portmidi/pm_common/portmidi.c index b7161700d69..2ed9171e781 100644 --- a/3rdparty/portmidi/pm_common/portmidi.c +++ b/3rdparty/portmidi/pm_common/portmidi.c @@ -144,7 +144,7 @@ int pm_find_default_device(char *pattern, int is_input) int id = pmNoDevice; int i; /* first parse pattern into name, interf parts */ - char *interf_pref = ""; /* initially assume it is not there */ + char *interf_pref = (char *)""; /* initially assume it is not there */ char *name_pref = strstr(pattern, ", "); if (name_pref) { /* found separator, adjust the pointer */ diff --git a/3rdparty/portmidi/pm_common/portmidi.h b/3rdparty/portmidi/pm_common/portmidi.h index e07991e0d68..c57432fae12 100644 --- a/3rdparty/portmidi/pm_common/portmidi.h +++ b/3rdparty/portmidi/pm_common/portmidi.h @@ -106,11 +106,11 @@ typedef unsigned int uint32_t; #endif #endif -#ifdef _WINDLL -#define PMEXPORT __declspec(dllexport) -#else +//#ifdef _WINDLL +//#define PMEXPORT __declspec(dllexport) +//#else #define PMEXPORT -#endif +//#endif #ifndef FALSE #define FALSE 0 diff --git a/3rdparty/portmidi/pm_linux/finddefault.c b/3rdparty/portmidi/pm_linux/finddefault.c index 63403168964..1e3d332e307 100644 --- a/3rdparty/portmidi/pm_linux/finddefault.c +++ b/3rdparty/portmidi/pm_linux/finddefault.c @@ -5,8 +5,11 @@ #include #include #include +#include #include "portmidi.h" +extern int pm_find_default_device(char *pattern, int is_input); + #define STRING_MAX 256 /* skip over spaces, return first non-space */ @@ -36,8 +39,8 @@ PmDeviceID find_default_device(char *path, int input, PmDeviceID id) returns matching device id if found, otherwise id */ { - static char *pref_2 = "/.java/.userPrefs/"; - static char *pref_3 = "prefs.xml"; + static char *pref_2 = (char *)"/.java/.userPrefs/"; + static char *pref_3 = (char *)"prefs.xml"; char *pref_1 = getenv("HOME"); char *full_name, *path_ptr; FILE *inf; @@ -61,6 +64,7 @@ PmDeviceID find_default_device(char *path, int input, PmDeviceID id) } strcat(full_name, pref_3); inf = fopen(full_name, "r"); + free(full_name); if (!inf) goto nopref; // cannot open preference file // We're not going to build or link in a full XML parser. // Instead, find the path string and quoute. Then, look for @@ -71,16 +75,16 @@ PmDeviceID find_default_device(char *path, int input, PmDeviceID id) // look for quote string quote if (!match_string(inf, path_ptr)) continue; // path not found if (getc(inf) != '"') continue; // path not found, keep scanning - if (!match_string(inf, "value")) goto nopref; // value not found - if (!match_string(inf, "=")) goto nopref; // = not found - if (!match_string(inf, "\"")) goto nopref; // quote not found + if (!match_string(inf, (char *)"value")) goto nopref; // value not found + if (!match_string(inf, (char *)"=")) goto nopref; // = not found + if (!match_string(inf, (char *)"\"")) goto nopref; // quote not found // now read the value up to the close quote for (i = 0; i < STRING_MAX; i++) { if ((c = getc(inf)) == '"') break; pref_str[i] = c; } if (i == STRING_MAX) continue; // value too long, ignore - pref_str[i] == 0; + pref_str[i] = 0; i = pm_find_default_device(pref_str, input); if (i != pmNoDevice) { id = i; diff --git a/3rdparty/portmidi/pm_linux/pmlinux.c b/3rdparty/portmidi/pm_linux/pmlinux.c index 5105ecd3f3f..b05c54fccb9 100644 --- a/3rdparty/portmidi/pm_linux/pmlinux.c +++ b/3rdparty/portmidi/pm_linux/pmlinux.c @@ -26,6 +26,8 @@ PmDeviceID pm_default_input_device_id = -1; PmDeviceID pm_default_output_device_id = -1; +extern PmDeviceID find_default_device(char *path, int input, PmDeviceID id); + void pm_init() { /* Note: it is not an error for PMALSA to fail to initialize. @@ -43,10 +45,10 @@ void pm_init() // now in order to (successfully) call Pm_CountDevices() pm_initialized = TRUE; pm_default_input_device_id = find_default_device( - "/PortMidi/PM_RECOMMENDED_INPUT_DEVICE", TRUE, + (char *)"/PortMidi/PM_RECOMMENDED_INPUT_DEVICE", TRUE, pm_default_input_device_id); pm_default_output_device_id = find_default_device( - "/PortMidi/PM_RECOMMENDED_OUTPUT_DEVICE", FALSE, + (char *)"/PortMidi/PM_RECOMMENDED_OUTPUT_DEVICE", FALSE, pm_default_output_device_id); } diff --git a/3rdparty/portmidi/pm_linux/pmlinuxalsa.c b/3rdparty/portmidi/pm_linux/pmlinuxalsa.c index 8e85cfe8650..e76560d2d82 100644 --- a/3rdparty/portmidi/pm_linux/pmlinuxalsa.c +++ b/3rdparty/portmidi/pm_linux/pmlinuxalsa.c @@ -15,6 +15,7 @@ #include "string.h" #include "porttime.h" #include "pmlinux.h" +#include "osdcomm.h" #include @@ -32,9 +33,10 @@ #endif /* to store client/port in the device descriptor */ -#define MAKE_DESCRIPTOR(client, port) ((void*)(((client) << 8) | (port))) -#define GET_DESCRIPTOR_CLIENT(info) ((((int)(info)) >> 8) & 0xff) -#define GET_DESCRIPTOR_PORT(info) (((int)(info)) & 0xff) + +#define MAKE_DESCRIPTOR(client, port) ((void*)(FPTR)(((client) << 8) | (port))) +#define GET_DESCRIPTOR_CLIENT(info) ((((int)(FPTR)(info)) >> 8) & 0xff) +#define GET_DESCRIPTOR_PORT(info) (((int)(FPTR)(info)) & 0xff) #define BYTE unsigned char @@ -201,7 +203,7 @@ static PmError alsa_write_byte(PmInternal *midi, unsigned char byte, /* compute relative time of event = timestamp - now + latency */ PmTimestamp now = (midi->time_proc ? midi->time_proc(midi->time_info) : - Pt_Time(NULL)); + Pt_Time()); int when = timestamp; /* if timestamp is zero, send immediately */ /* otherwise compute time delay and use delay if positive */ @@ -242,8 +244,8 @@ static PmError alsa_out_close(PmInternal *midi) alsa_descriptor_type desc = (alsa_descriptor_type) midi->descriptor; if (!desc) return pmBadPtr; - if (pm_hosterror = snd_seq_disconnect_to(seq, desc->this_port, - desc->client, desc->port)) { + if ((pm_hosterror = snd_seq_disconnect_to(seq, desc->this_port, + desc->client, desc->port))) { // if there's an error, try to delete the port anyway, but don't // change the pm_hosterror value so we retain the first error snd_seq_delete_port(seq, desc->this_port); @@ -332,8 +334,8 @@ static PmError alsa_in_close(PmInternal *midi) { alsa_descriptor_type desc = (alsa_descriptor_type) midi->descriptor; if (!desc) return pmBadPtr; - if (pm_hosterror = snd_seq_disconnect_from(seq, desc->this_port, - desc->client, desc->port)) { + if ((pm_hosterror = snd_seq_disconnect_from(seq, desc->this_port, + desc->client, desc->port))) { snd_seq_delete_port(seq, desc->this_port); /* try to close port */ } else { pm_hosterror = snd_seq_delete_port(seq, desc->this_port); @@ -433,7 +435,7 @@ static PmError alsa_write(PmInternal *midi, PmEvent *buffer, int32_t length) static PmError alsa_write_flush(PmInternal *midi, PmTimestamp timestamp) { alsa_descriptor_type desc = (alsa_descriptor_type) midi->descriptor; - VERBOSE printf("snd_seq_drain_output: 0x%x\n", (unsigned int) seq); + VERBOSE printf("snd_seq_drain_output: 0x%x\n", (unsigned int)(FPTR) seq); desc->error = snd_seq_drain_output(seq); if (desc->error < 0) return pmHostError; @@ -744,7 +746,8 @@ PmError pm_linuxalsa_init( void ) if (caps & SND_SEQ_PORT_CAP_SUBS_WRITE) { if (pm_default_output_device_id == -1) pm_default_output_device_id = pm_descriptor_index; - pm_add_device("ALSA", + // FIXME: pm_strdup() result is leaked + pm_add_device((char *)"ALSA", pm_strdup(snd_seq_port_info_get_name(pinfo)), FALSE, MAKE_DESCRIPTOR(snd_seq_port_info_get_client(pinfo), @@ -754,7 +757,8 @@ PmError pm_linuxalsa_init( void ) if (caps & SND_SEQ_PORT_CAP_SUBS_READ) { if (pm_default_input_device_id == -1) pm_default_input_device_id = pm_descriptor_index; - pm_add_device("ALSA", + // FIXME: pm_strdup() result is leaked + pm_add_device((char *)"ALSA", pm_strdup(snd_seq_port_info_get_name(pinfo)), TRUE, MAKE_DESCRIPTOR(snd_seq_port_info_get_client(pinfo), diff --git a/3rdparty/portmidi/pm_mac/finddefault.c b/3rdparty/portmidi/pm_mac/finddefault.c index 59e02a10be5..bc95a4001a6 100644 --- a/3rdparty/portmidi/pm_mac/finddefault.c +++ b/3rdparty/portmidi/pm_mac/finddefault.c @@ -24,7 +24,7 @@ PmDeviceID find_default_device(char *path, int input, PmDeviceID id) returns matching device id if found, otherwise id */ { - static char *pref_file = "com.apple.java.util.prefs.plist"; + static char *pref_file = (char *)"com.apple.java.util.prefs.plist"; char *pref_str = NULL; // read device preferences value_ptr prefs = bplist_read_user_pref(pref_file); diff --git a/3rdparty/portmidi/pm_mac/osxsupport.h b/3rdparty/portmidi/pm_mac/osxsupport.h new file mode 100644 index 00000000000..7771868d12a --- /dev/null +++ b/3rdparty/portmidi/pm_mac/osxsupport.h @@ -0,0 +1,18 @@ +/* + osxsupport.h - Cocoa glue to emulated deprecated old Carbon path finder functions +*/ + +#ifndef _OSXSUPPORT_H_ +#define _OSXSUPPORT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +char *FindPrefsDir(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/3rdparty/portmidi/pm_mac/osxsupport.m b/3rdparty/portmidi/pm_mac/osxsupport.m new file mode 100644 index 00000000000..0fa45b874b2 --- /dev/null +++ b/3rdparty/portmidi/pm_mac/osxsupport.m @@ -0,0 +1,32 @@ +/* + osxsupport.m - Cocoa glue to emulated deprecated old Carbon path finder functions +*/ + +#import +#import +#include "osxsupport.h" + +// convert an NSString to a C string +#ifndef OSX_PPC +static char *StringToChar(NSString *str) +{ + const char *charstr = [str UTF8String]; + char *resstr = (char *)malloc(strlen(charstr)+1); + + strcpy(resstr, charstr); + return resstr; +} + +char *FindPrefsDir(void) +{ + char *resstr = NULL; + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSPreferencePanesDirectory, NSUserDomainMask, YES); + + if ([paths count] > 0) + { + resstr = StringToChar([paths objectAtIndex:0]) ; + } + return resstr; +} +#endif + diff --git a/3rdparty/portmidi/pm_mac/pmmac.c b/3rdparty/portmidi/pm_mac/pmmac.c index bcef0d1f1c1..8160fa02bb1 100644 --- a/3rdparty/portmidi/pm_mac/pmmac.c +++ b/3rdparty/portmidi/pm_mac/pmmac.c @@ -26,10 +26,10 @@ void pm_init() pm_initialized = TRUE; if (!err) { pm_default_input_device_id = find_default_device( - "/PortMidi/PM_RECOMMENDED_INPUT_DEVICE", TRUE, + (char *)"/PortMidi/PM_RECOMMENDED_INPUT_DEVICE", TRUE, pm_default_input_device_id); pm_default_output_device_id = find_default_device( - "/PortMidi/PM_RECOMMENDED_OUTPUT_DEVICE", FALSE, + (char *)"/PortMidi/PM_RECOMMENDED_OUTPUT_DEVICE", FALSE, pm_default_output_device_id); } } diff --git a/3rdparty/portmidi/pm_mac/pmmacosxcm.c b/3rdparty/portmidi/pm_mac/pmmacosxcm.c index 78513573d46..71177dded11 100644 --- a/3rdparty/portmidi/pm_mac/pmmacosxcm.c +++ b/3rdparty/portmidi/pm_mac/pmmacosxcm.c @@ -941,7 +941,7 @@ PmError pm_macosxcm_init(void) /* Initialize the client handle */ macHostError = MIDIClientCreate(CFSTR("PortMidi"), NULL, NULL, &client); if (macHostError != noErr) { - error_text = "MIDIClientCreate() in pm_macosxcm_init()"; + error_text = (char *)"MIDIClientCreate() in pm_macosxcm_init()"; goto error_return; } @@ -949,14 +949,14 @@ PmError pm_macosxcm_init(void) macHostError = MIDIInputPortCreate(client, CFSTR("Input port"), readProc, NULL, &portIn); if (macHostError != noErr) { - error_text = "MIDIInputPortCreate() in pm_macosxcm_init()"; + error_text = (char *)"MIDIInputPortCreate() in pm_macosxcm_init()"; goto error_return; } /* Create the output port */ macHostError = MIDIOutputPortCreate(client, CFSTR("Output port"), &portOut); if (macHostError != noErr) { - error_text = "MIDIOutputPortCreate() in pm_macosxcm_init()"; + error_text = (char *)"MIDIOutputPortCreate() in pm_macosxcm_init()"; goto error_return; } @@ -972,7 +972,7 @@ PmError pm_macosxcm_init(void) pm_default_input_device_id = pm_descriptor_index; /* Register this device with PortMidi */ - pm_add_device("CoreMIDI", cm_get_full_endpoint_name(endpoint), + pm_add_device((char *)"CoreMIDI", cm_get_full_endpoint_name(endpoint), TRUE, (void *) (long) endpoint, &pm_macosx_in_dictionary); } @@ -988,7 +988,7 @@ PmError pm_macosxcm_init(void) pm_default_output_device_id = pm_descriptor_index; /* Register this device with PortMidi */ - pm_add_device("CoreMIDI", cm_get_full_endpoint_name(endpoint), + pm_add_device((char *)"CoreMIDI", cm_get_full_endpoint_name(endpoint), FALSE, (void *) (long) endpoint, &pm_macosx_out_dictionary); } diff --git a/3rdparty/portmidi/pm_mac/readbinaryplist.c b/3rdparty/portmidi/pm_mac/readbinaryplist.c index d8ed8fbabc8..858dd029ec7 100644 --- a/3rdparty/portmidi/pm_mac/readbinaryplist.c +++ b/3rdparty/portmidi/pm_mac/readbinaryplist.c @@ -72,19 +72,21 @@ memory requested or calls longjmp, so callers don't have to check. */ #include +#include #include #include #include #include #include #include "readbinaryplist.h" +#include "osxsupport.h" #include #define NO 0 #define YES 1 #define BOOL int -#define MAXPATHLEN 256 +//#define MAXPATHLEN 256 /* there are 2 levels of error logging/printing: * BPLIST_LOG and BPLIST_LOG_VERBOSE @@ -97,7 +99,8 @@ memory requested or calls longjmp, so callers don't have to check. * parameters like printf but might be a no-op. */ -/* #define BPLIST_LOG_VERBOSE 1 */ +#define BPLIST_LOG_VERBOSE 0 +#define BPLIST_LOG 0 #if BPLIST_LOG_VERBOSE #ifndef BPLIST_LOG @@ -222,7 +225,7 @@ static value_ptr extract_array(bplist_info_ptr bplist, uint64_t offset); static value_ptr extract_dictionary(bplist_info_ptr bplist, uint64_t offset); -value_ptr value_create() +value_ptr value_create(void) { value_ptr value = (value_ptr) allocate(sizeof(value_node)); return value; @@ -377,7 +380,8 @@ value_ptr bplist_read_file(char *filename) return value; } - +// use old Carbon method on PPC +#ifdef OSX_PPC value_ptr bplist_read_pref(char *filename, OSType folder_type) { FSRef prefdir; @@ -398,7 +402,41 @@ value_ptr bplist_read_pref(char *filename, OSType folder_type) strlcat(cstr, filename, MAXPATHLEN); return bplist_read_file(cstr); } - +#else +value_ptr bplist_read_pref(char *filename, OSType folder_type) +{ + char cstr[MAXPATHLEN]; + char *foundstr; + + memset(cstr, 0, MAXPATHLEN); + + // for later OS X, the user preferences folder (~/Library/Preferences) is not available directly from Cocoa, + // Apple documentation suggests just using POSIX APIs like so. + if (folder_type == kPreferencesFolderType) + { + strlcpy(cstr, getenv("HOME"), MAXPATHLEN); + strlcat(cstr, "/Library/Preferences", MAXPATHLEN); + } + else // the system preferences folder (~/Library/PreferencePanes) is accessible from Cocoa however + { + foundstr = FindPrefsDir(); + + if (!foundstr) { + bplist_log("Error finding preferences folder\n"); + return NULL; + } + + strlcat(cstr, foundstr, MAXPATHLEN); + free(foundstr); + foundstr = NULL; + } + + strlcat(cstr, "/", MAXPATHLEN); + strlcat(cstr, filename, MAXPATHLEN); + + return bplist_read_file(cstr); +} +#endif value_ptr bplist_read_system_pref(char *filename) { return bplist_read_pref(filename, kSystemPreferencesFolderType); @@ -776,7 +814,7 @@ static value_ptr extract_data(bplist_info_ptr bplist, uint64_t offset) assert(bplist->data_bytes != NULL && offset < bplist->length); - if ((size = bplist_get_a_size(bplist, &offset, "data")) == UINT64_MAX) + if ((size = bplist_get_a_size(bplist, &offset, (char *)"data")) == UINT64_MAX) return NULL; value = value_create(); @@ -793,7 +831,7 @@ static value_ptr extract_ascii_string(bplist_info_ptr bplist, uint64_t offset) assert(bplist->data_bytes != NULL && offset < bplist->length); - if ((size = bplist_get_a_size(bplist, &offset, "ascii string")) == + if ((size = bplist_get_a_size(bplist, &offset, (char *)"ascii string")) == UINT64_MAX) return NULL; @@ -812,7 +850,7 @@ static value_ptr extract_unicode_string(bplist_info_ptr bplist, uint64_t offset) assert(bplist->data_bytes != NULL && offset < bplist->length); - if ((size = bplist_get_a_size(bplist, &offset, "unicode string")) == + if ((size = bplist_get_a_size(bplist, &offset, (char *)"unicode string")) == UINT64_MAX) return NULL; @@ -873,7 +911,7 @@ static value_ptr extract_array(bplist_info_ptr bplist, uint64_t offset) assert(bplist->data_bytes != NULL && offset < bplist->length); - if ((count = bplist_get_a_size(bplist, &offset, "array")) == UINT64_MAX) + if ((count = bplist_get_a_size(bplist, &offset, (char *)"array")) == UINT64_MAX) return NULL; if (count > UINT64_MAX / bplist->object_ref_size - offset) { @@ -935,7 +973,7 @@ static value_ptr extract_dictionary(bplist_info_ptr bplist, uint64_t offset) assert(bplist->data_bytes != NULL && offset < bplist->length); - if ((count = bplist_get_a_size(bplist, &offset, "array")) == UINT64_MAX) + if ((count = bplist_get_a_size(bplist, &offset, (char *)"array")) == UINT64_MAX) return NULL; if (count > UINT64_MAX / (bplist->object_ref_size * 2) - offset) { diff --git a/3rdparty/portmidi/pm_win/pmwin.c b/3rdparty/portmidi/pm_win/pmwin.c index aeed48554db..a57ed878df6 100644 --- a/3rdparty/portmidi/pm_win/pmwin.c +++ b/3rdparty/portmidi/pm_win/pmwin.c @@ -20,6 +20,7 @@ #ifdef DEBUG #include "stdio.h" #endif +#undef UNICODE #include /* pm_exit is called when the program exits. @@ -62,7 +63,7 @@ static PmDeviceID pm_get_default_device_id(int is_input, char *key) { HKEY hkey; #define PATTERN_MAX 256 char pattern[PATTERN_MAX]; - long pattern_max = PATTERN_MAX; + DWORD pattern_max = PATTERN_MAX; DWORD dwType; /* Find first input or device -- this is the default. */ PmDeviceID id = pmNoDevice; @@ -75,23 +76,23 @@ static PmDeviceID pm_get_default_device_id(int is_input, char *key) { } } /* Look in registry for a default device name pattern. */ - if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_READ, &hkey) != + if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software", 0, KEY_READ, &hkey) != ERROR_SUCCESS) { return id; } - if (RegOpenKeyEx(hkey, "JavaSoft", 0, KEY_READ, &hkey) != + if (RegOpenKeyExA(hkey, "JavaSoft", 0, KEY_READ, &hkey) != ERROR_SUCCESS) { return id; } - if (RegOpenKeyEx(hkey, "Prefs", 0, KEY_READ, &hkey) != + if (RegOpenKeyExA(hkey, "Prefs", 0, KEY_READ, &hkey) != ERROR_SUCCESS) { return id; } - if (RegOpenKeyEx(hkey, "/Port/Midi", 0, KEY_READ, &hkey) != + if (RegOpenKeyExA(hkey, "/Port/Midi", 0, KEY_READ, &hkey) != ERROR_SUCCESS) { return id; } - if (RegQueryValueEx(hkey, key, NULL, &dwType, pattern, &pattern_max) != + if (RegQueryValueExA(hkey, key, NULL, &dwType, (BYTE *)pattern, &pattern_max) != ERROR_SUCCESS) { return id; } @@ -119,13 +120,13 @@ static PmDeviceID pm_get_default_device_id(int is_input, char *key) { PmDeviceID Pm_GetDefaultInputDeviceID() { return pm_get_default_device_id(TRUE, - "/P/M_/R/E/C/O/M/M/E/N/D/E/D_/I/N/P/U/T_/D/E/V/I/C/E"); + (char *)"/P/M_/R/E/C/O/M/M/E/N/D/E/D_/I/N/P/U/T_/D/E/V/I/C/E"); } PmDeviceID Pm_GetDefaultOutputDeviceID() { return pm_get_default_device_id(FALSE, - "/P/M_/R/E/C/O/M/M/E/N/D/E/D_/O/U/T/P/U/T_/D/E/V/I/C/E"); + (char *)"/P/M_/R/E/C/O/M/M/E/N/D/E/D_/O/U/T/P/U/T_/D/E/V/I/C/E"); } diff --git a/3rdparty/portmidi/pm_win/pmwinmm.c b/3rdparty/portmidi/pm_win/pmwinmm.c index 2de8109a0a1..2b4f82911f4 100644 --- a/3rdparty/portmidi/pm_win/pmwinmm.c +++ b/3rdparty/portmidi/pm_win/pmwinmm.c @@ -10,7 +10,7 @@ */ #define _WIN32_WINNT 0x0500 #endif - +#undef UNICODE #include "windows.h" #include "mmsystem.h" #include "portmidi.h" @@ -19,6 +19,7 @@ #include "pmwinmm.h" #include #include "porttime.h" +#include "osdcomm.h" /* asserts used to verify portMidi code logic is sound; later may want something more graceful */ @@ -159,7 +160,7 @@ typedef struct midiwinmm_struct { general MIDI device queries ============================================================================= */ -static void pm_winmm_general_inputs() +static void pm_winmm_general_inputs(void) { UINT i; WORD wRtn; @@ -180,14 +181,15 @@ static void pm_winmm_general_inputs() if (wRtn == MMSYSERR_NOERROR) { /* ignore errors here -- if pm_descriptor_max is exceeded, some devices will not be accessible. */ - pm_add_device("MMSystem", midi_in_caps[i].szPname, TRUE, - (void *) i, &pm_winmm_in_dictionary); + pm_add_device((char *)"MMSystem", midi_in_caps[i].szPname, TRUE, + (void *)(FPTR)i, + &pm_winmm_in_dictionary); } } } -static void pm_winmm_mapper_input() +static void pm_winmm_mapper_input(void) { WORD wRtn; /* Note: if MIDIMAPPER opened as input (documentation implies you @@ -198,13 +200,13 @@ static void pm_winmm_mapper_input() (LPMIDIINCAPS) & midi_in_mapper_caps, sizeof(MIDIINCAPS)); if (wRtn == MMSYSERR_NOERROR) { - pm_add_device("MMSystem", midi_in_mapper_caps.szPname, TRUE, - (void *) MIDIMAPPER, &pm_winmm_in_dictionary); + pm_add_device((char *)"MMSystem", midi_in_mapper_caps.szPname, TRUE, + (void *)(FPTR)MIDIMAPPER, &pm_winmm_in_dictionary); } } -static void pm_winmm_general_outputs() +static void pm_winmm_general_outputs(void) { UINT i; DWORD wRtn; @@ -220,14 +222,15 @@ static void pm_winmm_general_outputs() wRtn = midiOutGetDevCaps(i, (LPMIDIOUTCAPS) & midi_out_caps[i], sizeof(MIDIOUTCAPS)); if (wRtn == MMSYSERR_NOERROR) { - pm_add_device("MMSystem", midi_out_caps[i].szPname, FALSE, - (void *) i, &pm_winmm_out_dictionary); + pm_add_device((char *)"MMSystem", midi_out_caps[i].szPname, FALSE, + (void *)(FPTR)i, + &pm_winmm_out_dictionary); } } } -static void pm_winmm_mapper_output() +static void pm_winmm_mapper_output(void) { WORD wRtn; /* Note: if MIDIMAPPER opened as output (pseudo MIDI device @@ -236,8 +239,8 @@ static void pm_winmm_mapper_output() wRtn = midiOutGetDevCaps((UINT) MIDIMAPPER, (LPMIDIOUTCAPS) & midi_out_mapper_caps, sizeof(MIDIOUTCAPS)); if (wRtn == MMSYSERR_NOERROR) { - pm_add_device("MMSystem", midi_out_mapper_caps.szPname, FALSE, - (void *) MIDIMAPPER, &pm_winmm_out_dictionary); + pm_add_device((char *)"MMSystem", midi_out_mapper_caps.szPname, FALSE, + (void *)(FPTR)MIDIMAPPER, &pm_winmm_out_dictionary); } } @@ -271,8 +274,8 @@ static void winmm_get_host_error(PmInternal * midi, char * msg, UINT len) { /* precondition: midi != NULL */ midiwinmm_node * m = (midiwinmm_node *) midi->descriptor; - char *hdr1 = "Host error: "; - char *hdr2 = "Host callback error: "; + char *hdr1 = (char *)"Host error: "; + //char *hdr2 = (char *)"Host callback error: "; msg[0] = 0; /* initialize result string to empty */ @@ -282,8 +285,8 @@ static void winmm_get_host_error(PmInternal * midi, char * msg, UINT len) if (m->error != MMSYSERR_NOERROR) { int n = str_copy_len(msg, hdr1, len); /* read and record host error */ - int err = midiInGetErrorText(m->error, msg + n, len - n); - assert(err == MMSYSERR_NOERROR); + midiInGetErrorText(m->error, msg + n, len - n); + //assert(err == MMSYSERR_NOERROR); m->error = MMSYSERR_NOERROR; } } @@ -291,8 +294,8 @@ static void winmm_get_host_error(PmInternal * midi, char * msg, UINT len) if (m) { if (m->error != MMSYSERR_NOERROR) { int n = str_copy_len(msg, hdr1, len); - int err = midiOutGetErrorText(m->error, msg + n, len - n); - assert(err == MMSYSERR_NOERROR); + midiOutGetErrorText(m->error, msg + n, len - n); + //assert(err == MMSYSERR_NOERROR); m->error = MMSYSERR_NOERROR; } } @@ -548,7 +551,7 @@ static PmError winmm_in_open(PmInternal *midi, void *driverInfo) int num_input_buffers = max_sysex_len / INPUT_SYSEX_LEN; midiwinmm_type m; - dwDevice = (DWORD) descriptors[i].descriptor; + dwDevice = (DWORD)(FPTR)descriptors[i].descriptor; /* create system dependent device data */ m = (midiwinmm_type) pm_alloc(sizeof(midiwinmm_node)); /* create */ @@ -614,9 +617,9 @@ free_descriptor: pm_free(m); no_memory: if (pm_hosterror) { - int err = midiInGetErrorText(pm_hosterror, (char *) pm_hosterror_text, + midiInGetErrorText(pm_hosterror, (char *) pm_hosterror_text, PM_HOST_ERROR_MSG_LEN); - assert(err == MMSYSERR_NOERROR); + //assert(err == MMSYSERR_NOERROR); return pmHostError; } /* if !pm_hosterror, then the error must be pmInsufficientMemory */ @@ -642,10 +645,10 @@ static PmError winmm_in_close(PmInternal *midi) midiwinmm_type m = (midiwinmm_type) midi->descriptor; if (!m) return pmBadPtr; /* device to close */ - if (pm_hosterror = midiInStop(m->handle.in)) { + if ((pm_hosterror = midiInStop(m->handle.in))) { midiInReset(m->handle.in); /* try to reset and close port */ midiInClose(m->handle.in); - } else if (pm_hosterror = midiInReset(m->handle.in)) { + } else if ((pm_hosterror = midiInReset(m->handle.in))) { midiInClose(m->handle.in); /* best effort to close midi port */ } else { pm_hosterror = midiInClose(m->handle.in); @@ -654,9 +657,9 @@ static PmError winmm_in_close(PmInternal *midi) DeleteCriticalSection(&m->lock); pm_free(m); /* delete */ if (pm_hosterror) { - int err = midiInGetErrorText(pm_hosterror, (char *) pm_hosterror_text, + midiInGetErrorText(pm_hosterror, (char *) pm_hosterror_text, PM_HOST_ERROR_MSG_LEN); - assert(err == MMSYSERR_NOERROR); + //assert(err == MMSYSERR_NOERROR); return pmHostError; } return pmNoError; @@ -671,8 +674,8 @@ static void FAR PASCAL winmm_in_callback( DWORD dwParam1, /* MIDI data */ DWORD dwParam2) /* device timestamp (wrt most recent midiInStart) */ { - static int entry = 0; - PmInternal *midi = (PmInternal *) dwInstance; + //static int entry = 0; + PmInternal *midi = (PmInternal *)(FPTR) dwInstance; midiwinmm_type m = (midiwinmm_type) midi->descriptor; /* NOTE: we do not just EnterCriticalSection() here because an @@ -688,7 +691,7 @@ static void FAR PASCAL winmm_in_callback( * hardware interrupt? -- but I've seen reentrant behavior * using a debugger, so it happens. */ - long new_driver_time; + //long new_driver_time; EnterCriticalSection(&m->lock); /* dwParam1 is MIDI data received, packed into DWORD w/ 1st byte of @@ -697,7 +700,7 @@ static void FAR PASCAL winmm_in_callback( in [ms] from when midiInStart called. each message is expanded to include the status byte */ - new_driver_time = dwParam2; + //new_driver_time = dwParam2; if ((dwParam1 & 0x80) == 0) { /* not a status byte -- ignore it. This happened running the @@ -717,7 +720,7 @@ static void FAR PASCAL winmm_in_callback( break; } case MIM_LONGDATA: { - MIDIHDR *lpMidiHdr = (MIDIHDR *) dwParam1; + MIDIHDR *lpMidiHdr = (MIDIHDR *)(FPTR)dwParam1; unsigned char *data = (unsigned char *) lpMidiHdr->lpData; unsigned int processed = 0; int remaining = lpMidiHdr->dwBytesRecorded; @@ -741,20 +744,20 @@ static void FAR PASCAL winmm_in_callback( case, we do not want to send them back to the interface (if we do, the interface will not close, and Windows OS may hang). */ if (lpMidiHdr->dwBytesRecorded > 0) { - MMRESULT rslt; + //MMRESULT rslt; lpMidiHdr->dwBytesRecorded = 0; lpMidiHdr->dwFlags = 0; /* note: no error checking -- can this actually fail? */ - rslt = midiInPrepareHeader(hMidiIn, lpMidiHdr, sizeof(MIDIHDR)); - assert(rslt == MMSYSERR_NOERROR); + midiInPrepareHeader(hMidiIn, lpMidiHdr, sizeof(MIDIHDR)); + //assert(rslt == MMSYSERR_NOERROR); /* note: I don't think this can fail except possibly for * MMSYSERR_NOMEM, but the pain of reporting this * unlikely but probably catastrophic error does not seem * worth it. */ - rslt = midiInAddBuffer(hMidiIn, lpMidiHdr, sizeof(MIDIHDR)); - assert(rslt == MMSYSERR_NOERROR); + midiInAddBuffer(hMidiIn, lpMidiHdr, sizeof(MIDIHDR)); + //assert(rslt == MMSYSERR_NOERROR); LeaveCriticalSection(&m->lock); } else { midiInUnprepareHeader(hMidiIn,lpMidiHdr,sizeof(MIDIHDR)); @@ -806,11 +809,11 @@ static int add_to_buffer(midiwinmm_type m, LPMIDIHDR hdr, static PmTimestamp pm_time_get(midiwinmm_type m) { MMTIME mmtime; - MMRESULT wRtn; + //MMRESULT wRtn; mmtime.wType = TIME_TICKS; mmtime.u.ticks = 0; - wRtn = midiStreamPosition(m->handle.stream, &mmtime, sizeof(mmtime)); - assert(wRtn == MMSYSERR_NOERROR); + midiStreamPosition(m->handle.stream, &mmtime, sizeof(mmtime)); + //assert(wRtn == MMSYSERR_NOERROR); return mmtime.u.ticks; } @@ -828,8 +831,7 @@ static PmError winmm_out_open(PmInternal *midi, void *driverInfo) int max_sysex_len = midi->buffer_len * 4; int output_buffer_len; int num_buffers; - dwDevice = (DWORD) descriptors[i].descriptor; - + dwDevice = (DWORD)(FPTR) descriptors[i].descriptor; /* create system dependent device data */ m = (midiwinmm_type) pm_alloc(sizeof(midiwinmm_node)); /* create */ midi->descriptor = m; @@ -891,8 +893,17 @@ static PmError winmm_out_open(PmInternal *midi, void *driverInfo) if (output_buffer_len < MIN_SIMPLE_SYSEX_LEN) output_buffer_len = MIN_SIMPLE_SYSEX_LEN; } else { - long dur = 0; - num_buffers = max(midi->buffer_len, midi->latency / 2); + //long dur = 0; + //num_buffers = (int)(double)max((double)midi->buffer_len, (double)midi->latency / 2); + if (midi->buffer_len > (midi->latency / 2)) + { + num_buffers = midi->buffer_len; + } + else + { + num_buffers = (midi->latency / 2); + } + if (num_buffers < MIN_STREAM_BUFFERS) num_buffers = MIN_STREAM_BUFFERS; output_buffer_len = STREAM_BUFFER_LEN; @@ -930,9 +941,9 @@ free_descriptor: winmm_out_delete(midi); /* frees buffers and m */ no_memory: if (pm_hosterror) { - int err = midiOutGetErrorText(pm_hosterror, (char *) pm_hosterror_text, + midiOutGetErrorText(pm_hosterror, (char *) pm_hosterror_text, PM_HOST_ERROR_MSG_LEN); - assert(err == MMSYSERR_NOERROR); + //assert(err == MMSYSERR_NOERROR); return pmHostError; } return pmInsufficientMemory; @@ -985,10 +996,10 @@ static PmError winmm_out_close(PmInternal *midi) winmm_out_delete(midi); } if (pm_hosterror) { - int err = midiOutGetErrorText(pm_hosterror, + midiOutGetErrorText(pm_hosterror, (char *) pm_hosterror_text, PM_HOST_ERROR_MSG_LEN); - assert(err == MMSYSERR_NOERROR); + //assert(err == MMSYSERR_NOERROR); return pmHostError; } return pmNoError; @@ -1207,8 +1218,9 @@ static PmError winmm_write_byte(PmInternal *midi, unsigned char byte, if (!hdr) { m->hdr = hdr = get_free_output_buffer(midi); assert(hdr); - midi->fill_base = (unsigned char *) m->hdr->lpData; - midi->fill_offset_ptr = &(hdr->dwBytesRecorded); + midi->fill_base = (unsigned char *)(FPTR) m->hdr->lpData; + midi->fill_offset_ptr = (uint32_t *)&(hdr->dwBytesRecorded); + /* when buffer fills, Pm_WriteSysEx will revert to calling * pmwin_write_byte, which expect to have space, so leave * one byte free for pmwin_write_byte. Leave another byte @@ -1330,10 +1342,10 @@ static void CALLBACK winmm_out_callback(HMIDIOUT hmo, UINT wMsg, static void CALLBACK winmm_streamout_callback(HMIDIOUT hmo, UINT wMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) { - PmInternal *midi = (PmInternal *) dwInstance; + PmInternal *midi = (PmInternal *)(FPTR) dwInstance; + LPMIDIHDR hdr = (LPMIDIHDR)(FPTR) dwParam1; midiwinmm_type m = (midiwinmm_type) midi->descriptor; - LPMIDIHDR hdr = (LPMIDIHDR) dwParam1; - int err; + //int err; /* Even if an error is pending, I think we should unprepare msgs and signal their arrival @@ -1341,13 +1353,13 @@ static void CALLBACK winmm_streamout_callback(HMIDIOUT hmo, UINT wMsg, /* printf("streamout_callback: hdr %x, wMsg %x, MOM_DONE %x\n", hdr, wMsg, MOM_DONE); */ if (wMsg == MOM_DONE) { - MMRESULT ret = midiOutUnprepareHeader(m->handle.out, hdr, + midiOutUnprepareHeader(m->handle.out, hdr, sizeof(MIDIHDR)); - assert(ret == MMSYSERR_NOERROR); + //assert(ret == MMSYSERR_NOERROR); } /* signal client in case it is blocked waiting for buffer */ - err = SetEvent(m->buffer_signal); - assert(err); /* false -> error */ + SetEvent(m->buffer_signal); + //assert(err); /* false -> error */ } @@ -1418,9 +1430,7 @@ void pm_winmm_term( void ) int i; #ifdef DEBUG char msg[PM_HOST_ERROR_MSG_LEN]; -#endif int doneAny = 0; -#ifdef DEBUG printf("pm_winmm_term called\n"); #endif for (i = 0; i < pm_descriptor_index; i++) { diff --git a/3rdparty/portmidi/porttime/porttime.h b/3rdparty/portmidi/porttime/porttime.h index ff22de9d5ab..f5ffd5c1f49 100644 --- a/3rdparty/portmidi/porttime/porttime.h +++ b/3rdparty/portmidi/porttime/porttime.h @@ -25,12 +25,8 @@ extern "C" { #endif #ifndef PMEXPORT -#ifdef _WINDLL -#define PMEXPORT __declspec(dllexport) -#else #define PMEXPORT #endif -#endif typedef enum { ptNoError = 0, /* success */ @@ -66,17 +62,17 @@ PMEXPORT PtError Pt_Start(int resolution, PtCallback *callback, void *userData); return value: Upon success, returns ptNoError. See PtError for other values. */ -PMEXPORT PtError Pt_Stop(); +PMEXPORT PtError Pt_Stop(void); /* Pt_Started() returns true iff the timer is running. */ -PMEXPORT int Pt_Started(); +PMEXPORT int Pt_Started(void); /* Pt_Time() returns the current time in ms. */ -PMEXPORT PtTimestamp Pt_Time(); +PMEXPORT PtTimestamp Pt_Time(void); /* Pt_Sleep() pauses, allowing other threads to run. diff --git a/3rdparty/portmidi/porttime/ptmacosx_mach.c b/3rdparty/portmidi/porttime/ptmacosx_mach.c index c23210e4dce..73766d194e8 100644 --- a/3rdparty/portmidi/porttime/ptmacosx_mach.c +++ b/3rdparty/portmidi/porttime/ptmacosx_mach.c @@ -14,7 +14,9 @@ #include "sys/time.h" #include "pthread.h" -#define NSEC_PER_MSEC 1000000 +#if !defined NSEC_PER_MSEC +#define NSEC_PER_MSEC 1000000ull +#endif #define THREAD_IMPORTANCE 30 static int time_started_flag = FALSE; @@ -45,7 +47,7 @@ static void *Pt_CallbackProc(void *p) (thread_policy_t)&extendedPolicy, THREAD_EXTENDED_POLICY_COUNT); if (error != KERN_SUCCESS) { - mach_error("Couldn't set thread timeshare policy", error); + mach_error((char *)"Couldn't set thread timeshare policy", error); } precedencePolicy.importance = THREAD_IMPORTANCE; @@ -53,7 +55,7 @@ static void *Pt_CallbackProc(void *p) (thread_policy_t)&precedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT); if (error != KERN_SUCCESS) { - mach_error("Couldn't set thread precedence policy", error); + mach_error((char *)"Couldn't set thread precedence policy", error); } diff --git a/src/lib/lib.mak b/src/lib/lib.mak index d6410eee9c3..d4a299dcbd6 100644 --- a/src/lib/lib.mak +++ b/src/lib/lib.mak @@ -23,6 +23,11 @@ OBJDIRS += \ $(LIBOBJ)/libflac \ $(LIBOBJ)/lib7z \ $(LIBOBJ)/portmidi \ + $(LIBOBJ)/portmidi/pm_common \ + $(LIBOBJ)/portmidi/pm_linux \ + $(LIBOBJ)/portmidi/pm_mac \ + $(LIBOBJ)/portmidi/pm_win \ + $(LIBOBJ)/portmidi/porttime \ $(LIBOBJ)/lua \ $(LIBOBJ)/lua/lsqlite3 \ $(LIBOBJ)/mongoose \ @@ -438,43 +443,42 @@ PMOPTS = # common objects LIBPMOBJS = \ - $(LIBOBJ)/portmidi/portmidi.o \ - $(LIBOBJ)/portmidi/porttime.o \ - $(LIBOBJ)/portmidi/pmutil.o + $(LIBOBJ)/portmidi/pm_common/portmidi.o \ + $(LIBOBJ)/portmidi/pm_common/pmutil.o \ + $(LIBOBJ)/portmidi/porttime/porttime.o \ ifeq ($(TARGETOS),linux) PMOPTS = -DPMALSA=1 LIBPMOBJS += \ - $(LIBOBJ)/portmidi/pmlinux.o \ - $(LIBOBJ)/portmidi/pmlinuxalsa.o \ - $(LIBOBJ)/portmidi/finddefaultlinux.o \ - $(LIBOBJ)/portmidi/ptlinux.o - + $(LIBOBJ)/portmidi/pm_linux/pmlinux.o \ + $(LIBOBJ)/portmidi/pm_linux/pmlinuxalsa.o \ + $(LIBOBJ)/portmidi/pm_linux/finddefaultlinux.o \ + $(LIBOBJ)/portmidi/porttime/ptlinux.o endif ifeq ($(TARGETOS),macosx) LIBPMOBJS += \ - $(LIBOBJ)/portmidi/pmmac.o \ - $(LIBOBJ)/portmidi/pmmacosxcm.o \ - $(LIBOBJ)/portmidi/finddefault.o \ - $(LIBOBJ)/portmidi/readbinaryplist.o \ - $(LIBOBJ)/portmidi/ptmacosx_mach.o \ - $(LIBOBJ)/portmidi/osxsupport.o + $(LIBOBJ)/portmidi/pm_mac/pmmac.o \ + $(LIBOBJ)/portmidi/pm_mac/pmmacosxcm.o \ + $(LIBOBJ)/portmidi/pm_mac/finddefault.o \ + $(LIBOBJ)/portmidi/pm_mac/readbinaryplist.o \ + $(LIBOBJ)/portmidi/pm_mac/osxsupport.o \ + $(LIBOBJ)/portmidi/porttime/ptmacosx_mach.o endif ifeq ($(TARGETOS),win32) LIBPMOBJS += \ - $(LIBOBJ)/portmidi/pmwin.o \ - $(LIBOBJ)/portmidi/pmwinmm.o \ - $(LIBOBJ)/portmidi/ptwinmm.o + $(LIBOBJ)/portmidi/pm_win/pmwin.o \ + $(LIBOBJ)/portmidi/pm_win/pmwinmm.o \ + $(LIBOBJ)/portmidi/porttime/ptwinmm.o endif $(OBJ)/libportmidi.a: $(LIBPMOBJS) $(LIBOBJ)/portmidi/%.o: $(3RDPARTY)/portmidi/%.c | $(OSPREBUILD) @echo Compiling $<... - $(CC) $(CDEFS) $(PMOPTS) $(CCOMFLAGS) $(CONLYFLAGS) -I$(LIBSRC)/portmidi/ -c $< -o $@ + $(CC) $(CDEFS) $(PMOPTS) $(CCOMFLAGS) $(CONLYFLAGS) -I$(3RDPARTY)/portmidi/pm_common -I$(3RDPARTY)/portmidi/porttime -c $< -o $@ #------------------------------------------------- # LUA library objects diff --git a/src/osd/modules/midi/portmidi.c b/src/osd/modules/midi/portmidi.c index bf94a587fd4..2e0add931a3 100644 --- a/src/osd/modules/midi/portmidi.c +++ b/src/osd/modules/midi/portmidi.c @@ -6,7 +6,7 @@ *******************************************************************c********/ -#include "portmidi/portmidi.h" +#include "portmidi/pm_common/portmidi.h" #include "osdcore.h" static const int RX_EVENT_BUF_SIZE = 512; -- cgit v1.2.3