Previous 199869 Revisions Next

r34329 Saturday 10th January, 2015 at 16:42:41 UTC by Miodrag Milanović
Ported changes done in previous source to make portmidi compile (nw)
[3rdparty/portmidi/pm_common]pmutil.c portmidi.c portmidi.h
[3rdparty/portmidi/pm_linux]finddefault.c pmlinux.c pmlinuxalsa.c
[3rdparty/portmidi/pm_mac]finddefault.c osxsupport.h* osxsupport.m* pmmac.c pmmacosxcm.c readbinaryplist.c
[3rdparty/portmidi/pm_win]pmwin.c pmwinmm.c
[3rdparty/portmidi/porttime]porttime.h ptmacosx_mach.c
[src/lib]lib.mak
[src/osd/modules/midi]portmidi.c

trunk/3rdparty/portmidi/pm_common/pmutil.c
r242840r242841
88#include "pmutil.h"
99#include "pminternal.h"
1010
11#ifdef WIN32
11#if defined(WIN32) || defined(_MSC_VER)
1212#define bzero(addr, siz) memset(addr, 0, siz)
1313#endif
1414
trunk/3rdparty/portmidi/pm_common/portmidi.c
r242840r242841
144144    int id = pmNoDevice;
145145    int i;
146146    /* first parse pattern into name, interf parts */
147    char *interf_pref = ""; /* initially assume it is not there */
147    char *interf_pref = (char *)""; /* initially assume it is not there */
148148    char *name_pref = strstr(pattern, ", ");
149149
150150    if (name_pref) { /* found separator, adjust the pointer */
trunk/3rdparty/portmidi/pm_common/portmidi.h
r242840r242841
106106#endif
107107#endif
108108
109#ifdef _WINDLL
110#define PMEXPORT __declspec(dllexport)
111#else
109//#ifdef _WINDLL
110//#define PMEXPORT __declspec(dllexport)
111//#else
112112#define PMEXPORT
113#endif
113//#endif
114114
115115#ifndef FALSE
116116    #define FALSE 0
trunk/3rdparty/portmidi/pm_linux/finddefault.c
r242840r242841
55#include <stdlib.h>
66#include <stdio.h>
77#include <string.h>
8#include <ctype.h>
89#include "portmidi.h"
910
11extern int pm_find_default_device(char *pattern, int is_input);
12
1013#define STRING_MAX 256
1114
1215/* skip over spaces, return first non-space */
r242840r242841
3639   returns matching device id if found, otherwise id
3740*/
3841{
39    static char *pref_2 = "/.java/.userPrefs/";
40    static char *pref_3 = "prefs.xml";
42    static char *pref_2 = (char *)"/.java/.userPrefs/";
43    static char *pref_3 = (char *)"prefs.xml";
4144    char *pref_1 = getenv("HOME");
4245    char *full_name, *path_ptr;
4346    FILE *inf;
r242840r242841
6164    }
6265    strcat(full_name, pref_3);
6366    inf = fopen(full_name, "r");
67   free(full_name);
6468    if (!inf) goto nopref; // cannot open preference file
6569    // We're not going to build or link in a full XML parser.
6670    // Instead, find the path string and quoute. Then, look for
r242840r242841
7175        // look for quote string quote
7276        if (!match_string(inf, path_ptr)) continue; // path not found
7377        if (getc(inf) != '"') continue; // path not found, keep scanning
74        if (!match_string(inf, "value")) goto nopref; // value not found
75        if (!match_string(inf, "=")) goto nopref; // = not found
76        if (!match_string(inf, "\"")) goto nopref; // quote not found
78        if (!match_string(inf, (char *)"value")) goto nopref; // value not found
79        if (!match_string(inf, (char *)"=")) goto nopref; // = not found
80        if (!match_string(inf, (char *)"\"")) goto nopref; // quote not found
7781        // now read the value up to the close quote
7882        for (i = 0; i < STRING_MAX; i++) {
7983            if ((c = getc(inf)) == '"') break;
8084            pref_str[i] = c;
8185        }
8286        if (i == STRING_MAX) continue; // value too long, ignore
83        pref_str[i] == 0;
87        pref_str[i] = 0;
8488        i = pm_find_default_device(pref_str, input);
8589        if (i != pmNoDevice) {
8690            id = i;
trunk/3rdparty/portmidi/pm_linux/pmlinux.c
r242840r242841
2626PmDeviceID pm_default_input_device_id = -1;
2727PmDeviceID pm_default_output_device_id = -1;
2828
29extern PmDeviceID find_default_device(char *path, int input, PmDeviceID id);
30
2931void pm_init()
3032{
3133    /* Note: it is not an error for PMALSA to fail to initialize.
r242840r242841
4345    // now in order to (successfully) call Pm_CountDevices()
4446    pm_initialized = TRUE;     
4547    pm_default_input_device_id = find_default_device(
46        "/PortMidi/PM_RECOMMENDED_INPUT_DEVICE", TRUE,
48        (char *)"/PortMidi/PM_RECOMMENDED_INPUT_DEVICE", TRUE,
4749        pm_default_input_device_id);
4850    pm_default_output_device_id = find_default_device(
49        "/PortMidi/PM_RECOMMENDED_OUTPUT_DEVICE", FALSE,
51        (char *)"/PortMidi/PM_RECOMMENDED_OUTPUT_DEVICE", FALSE,
5052        pm_default_output_device_id);
5153}
5254
trunk/3rdparty/portmidi/pm_linux/pmlinuxalsa.c
r242840r242841
1515#include "string.h"
1616#include "porttime.h"
1717#include "pmlinux.h"
18#include "osdcomm.h"
1819
1920#include <alsa/asoundlib.h>
2021
r242840r242841
3233#endif
3334
3435/* to store client/port in the device descriptor */
35#define MAKE_DESCRIPTOR(client, port) ((void*)(((client) << 8) | (port)))
36#define GET_DESCRIPTOR_CLIENT(info) ((((int)(info)) >> 8) & 0xff)
37#define GET_DESCRIPTOR_PORT(info) (((int)(info)) & 0xff)
3836
37#define MAKE_DESCRIPTOR(client, port) ((void*)(FPTR)(((client) << 8) | (port)))
38#define GET_DESCRIPTOR_CLIENT(info) ((((int)(FPTR)(info)) >> 8) & 0xff)
39#define GET_DESCRIPTOR_PORT(info) (((int)(FPTR)(info)) & 0xff)
40
3941#define BYTE unsigned char
4042
4143extern pm_fns_node pm_linuxalsa_in_dictionary;
r242840r242841
201203            /* compute relative time of event = timestamp - now + latency */
202204            PmTimestamp now = (midi->time_proc ?
203205                               midi->time_proc(midi->time_info) :
204                               Pt_Time(NULL));
206                               Pt_Time());
205207            int when = timestamp;
206208            /* if timestamp is zero, send immediately */
207209            /* otherwise compute time delay and use delay if positive */
r242840r242841
242244    alsa_descriptor_type desc = (alsa_descriptor_type) midi->descriptor;
243245    if (!desc) return pmBadPtr;
244246
245    if (pm_hosterror = snd_seq_disconnect_to(seq, desc->this_port,
246                                             desc->client, desc->port)) {
247    if ((pm_hosterror = snd_seq_disconnect_to(seq, desc->this_port,
248                                             desc->client, desc->port))) {
247249        // if there's an error, try to delete the port anyway, but don't
248250        // change the pm_hosterror value so we retain the first error
249251        snd_seq_delete_port(seq, desc->this_port);
r242840r242841
332334{
333335    alsa_descriptor_type desc = (alsa_descriptor_type) midi->descriptor;
334336    if (!desc) return pmBadPtr;
335    if (pm_hosterror = snd_seq_disconnect_from(seq, desc->this_port,
336                                               desc->client, desc->port)) {
337    if ((pm_hosterror = snd_seq_disconnect_from(seq, desc->this_port,
338                                               desc->client, desc->port))) {
337339        snd_seq_delete_port(seq, desc->this_port); /* try to close port */
338340    } else {
339341        pm_hosterror = snd_seq_delete_port(seq, desc->this_port);
r242840r242841
433435static PmError alsa_write_flush(PmInternal *midi, PmTimestamp timestamp)
434436{
435437    alsa_descriptor_type desc = (alsa_descriptor_type) midi->descriptor;
436    VERBOSE printf("snd_seq_drain_output: 0x%x\n", (unsigned int) seq);
438    VERBOSE printf("snd_seq_drain_output: 0x%x\n", (unsigned int)(FPTR) seq);
437439    desc->error = snd_seq_drain_output(seq);
438440    if (desc->error < 0) return pmHostError;
439441
r242840r242841
744746            if (caps & SND_SEQ_PORT_CAP_SUBS_WRITE) {
745747                if (pm_default_output_device_id == -1)
746748                    pm_default_output_device_id = pm_descriptor_index;
747                pm_add_device("ALSA",
749            // FIXME: pm_strdup() result is leaked
750                pm_add_device((char *)"ALSA",
748751                              pm_strdup(snd_seq_port_info_get_name(pinfo)),
749752                              FALSE,
750753                              MAKE_DESCRIPTOR(snd_seq_port_info_get_client(pinfo),
r242840r242841
754757            if (caps & SND_SEQ_PORT_CAP_SUBS_READ) {
755758                if (pm_default_input_device_id == -1)
756759                    pm_default_input_device_id = pm_descriptor_index;
757                pm_add_device("ALSA",
760            // FIXME: pm_strdup() result is leaked
761                pm_add_device((char *)"ALSA",
758762                              pm_strdup(snd_seq_port_info_get_name(pinfo)),
759763                              TRUE,
760764                              MAKE_DESCRIPTOR(snd_seq_port_info_get_client(pinfo),
trunk/3rdparty/portmidi/pm_mac/finddefault.c
r242840r242841
2424   returns matching device id if found, otherwise id
2525*/
2626{
27    static char *pref_file = "com.apple.java.util.prefs.plist";
27    static char *pref_file = (char *)"com.apple.java.util.prefs.plist";
2828    char *pref_str = NULL;
2929    // read device preferences
3030    value_ptr prefs = bplist_read_user_pref(pref_file);
trunk/3rdparty/portmidi/pm_mac/osxsupport.h
r0r242841
1/*
2    osxsupport.h - Cocoa glue to emulated deprecated old Carbon path finder functions
3*/
4
5#ifndef _OSXSUPPORT_H_
6#define _OSXSUPPORT_H_
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12char *FindPrefsDir(void);
13
14#ifdef __cplusplus
15}
16#endif
17
18#endif
trunk/3rdparty/portmidi/pm_mac/osxsupport.m
r0r242841
1/*
2    osxsupport.m - Cocoa glue to emulated deprecated old Carbon path finder functions
3*/
4
5#import <Cocoa/Cocoa.h>
6#import <AvailabilityMacros.h>
7#include "osxsupport.h"
8
9// convert an NSString to a C string
10#ifndef OSX_PPC
11static char *StringToChar(NSString *str)
12{
13   const char *charstr = [str UTF8String];
14   char *resstr = (char *)malloc(strlen(charstr)+1);
15
16   strcpy(resstr, charstr);
17   return resstr;
18}
19
20char *FindPrefsDir(void)
21{
22   char *resstr = NULL;
23   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSPreferencePanesDirectory, NSUserDomainMask, YES);
24
25   if ([paths count] > 0)
26   {
27      resstr = StringToChar([paths objectAtIndex:0]) ;
28   }
29   return resstr;
30}
31#endif
32
trunk/3rdparty/portmidi/pm_mac/pmmac.c
r242840r242841
2626    pm_initialized = TRUE;
2727    if (!err) {
2828        pm_default_input_device_id = find_default_device(
29                "/PortMidi/PM_RECOMMENDED_INPUT_DEVICE", TRUE,
29                (char *)"/PortMidi/PM_RECOMMENDED_INPUT_DEVICE", TRUE,
3030                pm_default_input_device_id);
3131        pm_default_output_device_id = find_default_device(
32                "/PortMidi/PM_RECOMMENDED_OUTPUT_DEVICE", FALSE,
32                (char *)"/PortMidi/PM_RECOMMENDED_OUTPUT_DEVICE", FALSE,
3333                pm_default_output_device_id);
3434    }
3535}
trunk/3rdparty/portmidi/pm_mac/pmmacosxcm.c
r242840r242841
941941    /* Initialize the client handle */
942942    macHostError = MIDIClientCreate(CFSTR("PortMidi"), NULL, NULL, &client);
943943    if (macHostError != noErr) {
944        error_text = "MIDIClientCreate() in pm_macosxcm_init()";
944        error_text = (char *)"MIDIClientCreate() in pm_macosxcm_init()";
945945        goto error_return;
946946    }
947947
r242840r242841
949949    macHostError = MIDIInputPortCreate(client, CFSTR("Input port"), readProc,
950950                                          NULL, &portIn);
951951    if (macHostError != noErr) {
952        error_text = "MIDIInputPortCreate() in pm_macosxcm_init()";
952        error_text = (char *)"MIDIInputPortCreate() in pm_macosxcm_init()";
953953        goto error_return;
954954    }
955955       
956956    /* Create the output port */
957957    macHostError = MIDIOutputPortCreate(client, CFSTR("Output port"), &portOut);
958958    if (macHostError != noErr) {
959        error_text = "MIDIOutputPortCreate() in pm_macosxcm_init()";
959        error_text = (char *)"MIDIOutputPortCreate() in pm_macosxcm_init()";
960960        goto error_return;
961961    }
962962
r242840r242841
972972            pm_default_input_device_id = pm_descriptor_index;
973973       
974974        /* Register this device with PortMidi */
975        pm_add_device("CoreMIDI", cm_get_full_endpoint_name(endpoint),
975        pm_add_device((char *)"CoreMIDI", cm_get_full_endpoint_name(endpoint),
976976                      TRUE, (void *) (long) endpoint, &pm_macosx_in_dictionary);
977977    }
978978
r242840r242841
988988            pm_default_output_device_id = pm_descriptor_index;
989989
990990        /* Register this device with PortMidi */
991        pm_add_device("CoreMIDI", cm_get_full_endpoint_name(endpoint),
991        pm_add_device((char *)"CoreMIDI", cm_get_full_endpoint_name(endpoint),
992992                      FALSE, (void *) (long) endpoint,
993993                      &pm_macosx_out_dictionary);
994994    }
trunk/3rdparty/portmidi/pm_mac/readbinaryplist.c
r242840r242841
7272*/
7373
7474#include <sys/types.h>
75#include <sys/param.h>
7576#include <stdlib.h>
7677#include <string.h>
7778#include <assert.h>
7879#include <stdio.h>
7980#include <sys/stat.h>
8081#include "readbinaryplist.h"
82#include "osxsupport.h"
8183#include <Carbon/Carbon.h>
8284
8385#define NO 0
8486#define YES 1
8587#define BOOL int
8688
87#define MAXPATHLEN 256
89//#define MAXPATHLEN 256
8890
8991/* there are 2 levels of error logging/printing:
9092 *   BPLIST_LOG and BPLIST_LOG_VERBOSE
r242840r242841
9799 * parameters like printf but might be a no-op.
98100 */
99101 
100/* #define BPLIST_LOG_VERBOSE 1 */
102#define BPLIST_LOG_VERBOSE 0
103#define BPLIST_LOG 0
101104
102105#if BPLIST_LOG_VERBOSE
103106    #ifndef BPLIST_LOG
r242840r242841
222225static value_ptr extract_dictionary(bplist_info_ptr bplist, uint64_t offset);
223226
224227
225value_ptr value_create()
228value_ptr value_create(void)
226229{
227230    value_ptr value = (value_ptr) allocate(sizeof(value_node));
228231    return value;
r242840r242841
377380    return value;
378381}
379382
380
383// use old Carbon method on PPC
384#ifdef OSX_PPC
381385value_ptr bplist_read_pref(char *filename, OSType folder_type)
382386{
383387    FSRef prefdir;
r242840r242841
398402    strlcat(cstr, filename, MAXPATHLEN);
399403    return bplist_read_file(cstr);
400404}
405#else
406value_ptr bplist_read_pref(char *filename, OSType folder_type)
407{
408   char cstr[MAXPATHLEN];
409   char *foundstr;
401410
411   memset(cstr, 0, MAXPATHLEN);
402412
413   // for later OS X, the user preferences folder (~/Library/Preferences) is not available directly from Cocoa,
414   // Apple documentation suggests just using POSIX APIs like so.
415   if (folder_type == kPreferencesFolderType)
416   {
417      strlcpy(cstr, getenv("HOME"), MAXPATHLEN);
418      strlcat(cstr, "/Library/Preferences", MAXPATHLEN);
419   }
420   else // the system preferences folder (~/Library/PreferencePanes) is accessible from Cocoa however
421   {
422      foundstr = FindPrefsDir();
423
424      if (!foundstr) {
425         bplist_log("Error finding preferences folder\n");
426         return NULL;
427      }
428
429      strlcat(cstr, foundstr, MAXPATHLEN);
430      free(foundstr);
431      foundstr = NULL;
432   }
433
434   strlcat(cstr, "/", MAXPATHLEN);
435   strlcat(cstr, filename, MAXPATHLEN);
436
437   return bplist_read_file(cstr);
438}
439#endif
440
403441value_ptr bplist_read_system_pref(char *filename) {
404442    return bplist_read_pref(filename, kSystemPreferencesFolderType);
405443}
r242840r242841
776814       
777815    assert(bplist->data_bytes != NULL && offset < bplist->length);
778816       
779    if ((size = bplist_get_a_size(bplist, &offset, "data")) == UINT64_MAX)
817    if ((size = bplist_get_a_size(bplist, &offset, (char *)"data")) == UINT64_MAX)
780818        return NULL;
781819       
782820    value = value_create();
r242840r242841
793831       
794832    assert(bplist->data_bytes != NULL && offset < bplist->length);
795833       
796    if ((size = bplist_get_a_size(bplist, &offset, "ascii string")) ==
834    if ((size = bplist_get_a_size(bplist, &offset, (char *)"ascii string")) ==
797835        UINT64_MAX)
798836        return NULL;
799837
r242840r242841
812850       
813851    assert(bplist->data_bytes != NULL && offset < bplist->length);
814852       
815    if ((size = bplist_get_a_size(bplist, &offset, "unicode string")) ==
853    if ((size = bplist_get_a_size(bplist, &offset, (char *)"unicode string")) ==
816854        UINT64_MAX)
817855        return NULL;
818856       
r242840r242841
873911       
874912    assert(bplist->data_bytes != NULL && offset < bplist->length);
875913       
876    if ((count = bplist_get_a_size(bplist, &offset, "array")) == UINT64_MAX)
914    if ((count = bplist_get_a_size(bplist, &offset, (char *)"array")) == UINT64_MAX)
877915        return NULL;
878916       
879917    if (count > UINT64_MAX / bplist->object_ref_size - offset) {
r242840r242841
935973    assert(bplist->data_bytes != NULL && offset < bplist->length);
936974       
937975       
938    if ((count = bplist_get_a_size(bplist, &offset, "array")) == UINT64_MAX)
976    if ((count = bplist_get_a_size(bplist, &offset, (char *)"array")) == UINT64_MAX)
939977        return NULL;
940978
941979    if (count > UINT64_MAX / (bplist->object_ref_size * 2) - offset) {
trunk/3rdparty/portmidi/pm_win/pmwin.c
r242840r242841
2020#ifdef DEBUG
2121#include "stdio.h"
2222#endif
23#undef UNICODE
2324#include <windows.h>
2425
2526/* pm_exit is called when the program exits.
r242840r242841
6263    HKEY hkey;
6364#define PATTERN_MAX 256
6465    char pattern[PATTERN_MAX];
65    long pattern_max = PATTERN_MAX;
66    DWORD pattern_max = PATTERN_MAX;
6667    DWORD dwType;
6768    /* Find first input or device -- this is the default. */
6869    PmDeviceID id = pmNoDevice;
r242840r242841
7576        }
7677    }
7778    /* Look in registry for a default device name pattern. */
78    if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_READ, &hkey) !=
79    if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software", 0, KEY_READ, &hkey) !=
7980        ERROR_SUCCESS) {
8081        return id;
8182    }
82    if (RegOpenKeyEx(hkey, "JavaSoft", 0, KEY_READ, &hkey) !=
83    if (RegOpenKeyExA(hkey, "JavaSoft", 0, KEY_READ, &hkey) !=
8384        ERROR_SUCCESS) {
8485        return id;
8586    }
86    if (RegOpenKeyEx(hkey, "Prefs", 0, KEY_READ, &hkey) !=
87    if (RegOpenKeyExA(hkey, "Prefs", 0, KEY_READ, &hkey) !=
8788        ERROR_SUCCESS) {
8889        return id;
8990    }
90    if (RegOpenKeyEx(hkey, "/Port/Midi", 0, KEY_READ, &hkey) !=
91    if (RegOpenKeyExA(hkey, "/Port/Midi", 0, KEY_READ, &hkey) !=
9192        ERROR_SUCCESS) {
9293        return id;
9394    }
94    if (RegQueryValueEx(hkey, key, NULL, &dwType, pattern, &pattern_max) !=
95    if (RegQueryValueExA(hkey, key, NULL, &dwType, (BYTE *)pattern, &pattern_max) !=
9596   ERROR_SUCCESS) {
9697        return id;
9798    }
r242840r242841
119120
120121PmDeviceID Pm_GetDefaultInputDeviceID() {
121122    return pm_get_default_device_id(TRUE,
122           "/P/M_/R/E/C/O/M/M/E/N/D/E/D_/I/N/P/U/T_/D/E/V/I/C/E");
123           (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");
123124}
124125
125126
126127PmDeviceID Pm_GetDefaultOutputDeviceID() {
127128  return pm_get_default_device_id(FALSE,
128          "/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");
129          (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");
129130}
130131
131132
trunk/3rdparty/portmidi/pm_win/pmwinmm.c
r242840r242841
1010     */
1111    #define _WIN32_WINNT 0x0500
1212#endif
13
13#undef UNICODE
1414#include "windows.h"
1515#include "mmsystem.h"
1616#include "portmidi.h"
r242840r242841
1919#include "pmwinmm.h"
2020#include <string.h>
2121#include "porttime.h"
22#include "osdcomm.h"
2223
2324/* asserts used to verify portMidi code logic is sound; later may want
2425    something more graceful */
r242840r242841
159160general MIDI device queries
160161=============================================================================
161162*/
162static void pm_winmm_general_inputs()
163static void pm_winmm_general_inputs(void)
163164{
164165    UINT i;
165166    WORD wRtn;
r242840r242841
180181        if (wRtn == MMSYSERR_NOERROR) {
181182            /* ignore errors here -- if pm_descriptor_max is exceeded, some
182183               devices will not be accessible. */
183            pm_add_device("MMSystem", midi_in_caps[i].szPname, TRUE,
184                          (void *) i, &pm_winmm_in_dictionary);
184            pm_add_device((char *)"MMSystem", midi_in_caps[i].szPname, TRUE,
185                          (void *)(FPTR)i,
186                    &pm_winmm_in_dictionary);
185187        }
186188    }
187189}
188190
189191
190static void pm_winmm_mapper_input()
192static void pm_winmm_mapper_input(void)
191193{
192194    WORD wRtn;
193195    /* Note: if MIDIMAPPER opened as input (documentation implies you
r242840r242841
198200                            (LPMIDIINCAPS) & midi_in_mapper_caps,
199201                            sizeof(MIDIINCAPS));
200202    if (wRtn == MMSYSERR_NOERROR) {
201        pm_add_device("MMSystem", midi_in_mapper_caps.szPname, TRUE,
202                      (void *) MIDIMAPPER, &pm_winmm_in_dictionary);
203        pm_add_device((char *)"MMSystem", midi_in_mapper_caps.szPname, TRUE,
204                      (void *)(FPTR)MIDIMAPPER, &pm_winmm_in_dictionary);
203205    }
204206}
205207
206208
207static void pm_winmm_general_outputs()
209static void pm_winmm_general_outputs(void)
208210{
209211    UINT i;
210212    DWORD wRtn;
r242840r242841
220222        wRtn = midiOutGetDevCaps(i, (LPMIDIOUTCAPS) & midi_out_caps[i],
221223                                 sizeof(MIDIOUTCAPS));
222224        if (wRtn == MMSYSERR_NOERROR) {
223            pm_add_device("MMSystem", midi_out_caps[i].szPname, FALSE,
224                          (void *) i, &pm_winmm_out_dictionary);
225            pm_add_device((char *)"MMSystem", midi_out_caps[i].szPname, FALSE,
226                          (void *)(FPTR)i,
227                    &pm_winmm_out_dictionary);
225228        }
226229    }
227230}
228231
229232
230static void pm_winmm_mapper_output()
233static void pm_winmm_mapper_output(void)
231234{
232235    WORD wRtn;
233236    /* Note: if MIDIMAPPER opened as output (pseudo MIDI device
r242840r242841
236239    wRtn = midiOutGetDevCaps((UINT) MIDIMAPPER, (LPMIDIOUTCAPS)
237240                             & midi_out_mapper_caps, sizeof(MIDIOUTCAPS));
238241    if (wRtn == MMSYSERR_NOERROR) {
239        pm_add_device("MMSystem", midi_out_mapper_caps.szPname, FALSE,
240                      (void *) MIDIMAPPER, &pm_winmm_out_dictionary);
242        pm_add_device((char *)"MMSystem", midi_out_mapper_caps.szPname, FALSE,
243                      (void *)(FPTR)MIDIMAPPER, &pm_winmm_out_dictionary);
241244    }
242245}
243246
r242840r242841
271274{
272275    /* precondition: midi != NULL */
273276    midiwinmm_node * m = (midiwinmm_node *) midi->descriptor;
274    char *hdr1 = "Host error: ";
275    char *hdr2 = "Host callback error: ";
277    char *hdr1 = (char *)"Host error: ";
278    //char *hdr2 = (char *)"Host callback error: ";
276279
277280    msg[0] = 0; /* initialize result string to empty */
278281
r242840r242841
282285            if (m->error != MMSYSERR_NOERROR) {
283286                int n = str_copy_len(msg, hdr1, len);
284287                /* read and record host error */
285                int err = midiInGetErrorText(m->error, msg + n, len - n);
286                assert(err == MMSYSERR_NOERROR);
288                midiInGetErrorText(m->error, msg + n, len - n);
289                //assert(err == MMSYSERR_NOERROR);
287290                m->error = MMSYSERR_NOERROR;
288291            }
289292        }
r242840r242841
291294        if (m) {
292295            if (m->error != MMSYSERR_NOERROR) {
293296                int n = str_copy_len(msg, hdr1, len);
294                int err = midiOutGetErrorText(m->error, msg + n, len - n);
295                assert(err == MMSYSERR_NOERROR);
297                midiOutGetErrorText(m->error, msg + n, len - n);
298                //assert(err == MMSYSERR_NOERROR);
296299                m->error = MMSYSERR_NOERROR;
297300            }
298301        }
r242840r242841
548551    int num_input_buffers = max_sysex_len / INPUT_SYSEX_LEN;
549552    midiwinmm_type m;
550553
551    dwDevice = (DWORD) descriptors[i].descriptor;
554    dwDevice = (DWORD)(FPTR)descriptors[i].descriptor;
552555
553556    /* create system dependent device data */
554557    m = (midiwinmm_type) pm_alloc(sizeof(midiwinmm_node)); /* create */
r242840r242841
614617    pm_free(m);
615618no_memory:
616619    if (pm_hosterror) {
617        int err = midiInGetErrorText(pm_hosterror, (char *) pm_hosterror_text,
620        midiInGetErrorText(pm_hosterror, (char *) pm_hosterror_text,
618621                                     PM_HOST_ERROR_MSG_LEN);
619        assert(err == MMSYSERR_NOERROR);
622        //assert(err == MMSYSERR_NOERROR);
620623        return pmHostError;
621624    }
622625    /* if !pm_hosterror, then the error must be pmInsufficientMemory */
r242840r242841
642645    midiwinmm_type m = (midiwinmm_type) midi->descriptor;
643646    if (!m) return pmBadPtr;
644647    /* device to close */
645    if (pm_hosterror = midiInStop(m->handle.in)) {
648    if ((pm_hosterror = midiInStop(m->handle.in))) {
646649        midiInReset(m->handle.in); /* try to reset and close port */
647650        midiInClose(m->handle.in);
648    } else if (pm_hosterror = midiInReset(m->handle.in)) {
651    } else if ((pm_hosterror = midiInReset(m->handle.in))) {
649652        midiInClose(m->handle.in); /* best effort to close midi port */
650653    } else {
651654        pm_hosterror = midiInClose(m->handle.in);
r242840r242841
654657    DeleteCriticalSection(&m->lock);
655658    pm_free(m); /* delete */
656659    if (pm_hosterror) {
657        int err = midiInGetErrorText(pm_hosterror, (char *) pm_hosterror_text,
660        midiInGetErrorText(pm_hosterror, (char *) pm_hosterror_text,
658661                                     PM_HOST_ERROR_MSG_LEN);
659        assert(err == MMSYSERR_NOERROR);
662        //assert(err == MMSYSERR_NOERROR);
660663        return pmHostError;
661664    }
662665    return pmNoError;
r242840r242841
671674    DWORD dwParam1,     /* MIDI data */
672675    DWORD dwParam2)    /* device timestamp (wrt most recent midiInStart) */
673676{
674    static int entry = 0;
675    PmInternal *midi = (PmInternal *) dwInstance;
677    //static int entry = 0;
678    PmInternal *midi = (PmInternal *)(FPTR) dwInstance;
676679    midiwinmm_type m = (midiwinmm_type) midi->descriptor;
677680
678681    /* NOTE: we do not just EnterCriticalSection() here because an
r242840r242841
688691         * hardware interrupt? -- but I've seen reentrant behavior
689692         * using a debugger, so it happens.
690693         */
691        long new_driver_time;
694        //long new_driver_time;
692695        EnterCriticalSection(&m->lock);
693696
694697        /* dwParam1 is MIDI data received, packed into DWORD w/ 1st byte of
r242840r242841
697700            in [ms] from when midiInStart called.
698701           each message is expanded to include the status byte */
699702
700        new_driver_time = dwParam2;
703        //new_driver_time = dwParam2;
701704
702705        if ((dwParam1 & 0x80) == 0) {
703706            /* not a status byte -- ignore it. This happened running the
r242840r242841
717720        break;
718721    }
719722    case MIM_LONGDATA: {
720        MIDIHDR *lpMidiHdr = (MIDIHDR *) dwParam1;
723        MIDIHDR *lpMidiHdr = (MIDIHDR *)(FPTR)dwParam1;
721724        unsigned char *data = (unsigned char *) lpMidiHdr->lpData;
722725        unsigned int processed = 0;
723726        int remaining = lpMidiHdr->dwBytesRecorded;
r242840r242841
741744           case, we do not want to send them back to the interface (if
742745           we do, the interface will not close, and Windows OS may hang). */
743746        if (lpMidiHdr->dwBytesRecorded > 0) {
744            MMRESULT rslt;
747            //MMRESULT rslt;
745748            lpMidiHdr->dwBytesRecorded = 0;
746749            lpMidiHdr->dwFlags = 0;
747750         
748751            /* note: no error checking -- can this actually fail? */
749            rslt = midiInPrepareHeader(hMidiIn, lpMidiHdr, sizeof(MIDIHDR));
750            assert(rslt == MMSYSERR_NOERROR);
752            midiInPrepareHeader(hMidiIn, lpMidiHdr, sizeof(MIDIHDR));
753            //assert(rslt == MMSYSERR_NOERROR);
751754            /* note: I don't think this can fail except possibly for
752755             * MMSYSERR_NOMEM, but the pain of reporting this
753756             * unlikely but probably catastrophic error does not seem
754757             * worth it.
755758             */
756            rslt = midiInAddBuffer(hMidiIn, lpMidiHdr, sizeof(MIDIHDR));
757            assert(rslt == MMSYSERR_NOERROR);
759            midiInAddBuffer(hMidiIn, lpMidiHdr, sizeof(MIDIHDR));
760            //assert(rslt == MMSYSERR_NOERROR);
758761            LeaveCriticalSection(&m->lock);
759762        } else {
760763            midiInUnprepareHeader(hMidiIn,lpMidiHdr,sizeof(MIDIHDR));
r242840r242841
806809static PmTimestamp pm_time_get(midiwinmm_type m)
807810{
808811    MMTIME mmtime;
809    MMRESULT wRtn;
812    //MMRESULT wRtn;
810813    mmtime.wType = TIME_TICKS;
811814    mmtime.u.ticks = 0;
812    wRtn = midiStreamPosition(m->handle.stream, &mmtime, sizeof(mmtime));
813    assert(wRtn == MMSYSERR_NOERROR);
815    midiStreamPosition(m->handle.stream, &mmtime, sizeof(mmtime));
816    //assert(wRtn == MMSYSERR_NOERROR);
814817    return mmtime.u.ticks;
815818}
816819
r242840r242841
828831    int max_sysex_len = midi->buffer_len * 4;
829832    int output_buffer_len;
830833    int num_buffers;
831    dwDevice = (DWORD) descriptors[i].descriptor;
832
834    dwDevice = (DWORD)(FPTR) descriptors[i].descriptor;
833835    /* create system dependent device data */
834836    m = (midiwinmm_type) pm_alloc(sizeof(midiwinmm_node)); /* create */
835837    midi->descriptor = m;
r242840r242841
891893        if (output_buffer_len < MIN_SIMPLE_SYSEX_LEN)
892894            output_buffer_len = MIN_SIMPLE_SYSEX_LEN;
893895    } else {
894        long dur = 0;
895        num_buffers = max(midi->buffer_len, midi->latency / 2);
896      //long dur = 0;
897      //num_buffers = (int)(double)max((double)midi->buffer_len, (double)midi->latency / 2);
898      if (midi->buffer_len > (midi->latency / 2))
899      {
900         num_buffers = midi->buffer_len;
901      }
902      else
903      {
904         num_buffers = (midi->latency / 2);
905      }
906
896907        if (num_buffers < MIN_STREAM_BUFFERS)
897908            num_buffers = MIN_STREAM_BUFFERS;
898909        output_buffer_len = STREAM_BUFFER_LEN;
r242840r242841
930941    winmm_out_delete(midi); /* frees buffers and m */
931942no_memory:
932943    if (pm_hosterror) {
933        int err = midiOutGetErrorText(pm_hosterror, (char *) pm_hosterror_text,
944        midiOutGetErrorText(pm_hosterror, (char *) pm_hosterror_text,
934945                                      PM_HOST_ERROR_MSG_LEN);
935        assert(err == MMSYSERR_NOERROR);
946        //assert(err == MMSYSERR_NOERROR);
936947        return pmHostError;
937948    }
938949    return pmInsufficientMemory;
r242840r242841
985996        winmm_out_delete(midi);
986997    }
987998    if (pm_hosterror) {
988        int err = midiOutGetErrorText(pm_hosterror,
999        midiOutGetErrorText(pm_hosterror,
9891000                                      (char *) pm_hosterror_text,
9901001                                      PM_HOST_ERROR_MSG_LEN);
991        assert(err == MMSYSERR_NOERROR);
1002        //assert(err == MMSYSERR_NOERROR);
9921003        return pmHostError;
9931004    }
9941005    return pmNoError;
r242840r242841
12071218    if (!hdr) {
12081219        m->hdr = hdr = get_free_output_buffer(midi);
12091220        assert(hdr);
1210        midi->fill_base = (unsigned char *) m->hdr->lpData;
1211        midi->fill_offset_ptr = &(hdr->dwBytesRecorded);
1221        midi->fill_base = (unsigned char *)(FPTR) m->hdr->lpData;
1222        midi->fill_offset_ptr = (uint32_t *)&(hdr->dwBytesRecorded);
1223
12121224        /* when buffer fills, Pm_WriteSysEx will revert to calling
12131225         * pmwin_write_byte, which expect to have space, so leave
12141226         * one byte free for pmwin_write_byte. Leave another byte
r242840r242841
13301342static void CALLBACK winmm_streamout_callback(HMIDIOUT hmo, UINT wMsg,
13311343        DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
13321344{
1333    PmInternal *midi = (PmInternal *) dwInstance;
1345    PmInternal *midi = (PmInternal *)(FPTR) dwInstance;
1346    LPMIDIHDR hdr = (LPMIDIHDR)(FPTR) dwParam1;
13341347    midiwinmm_type m = (midiwinmm_type) midi->descriptor;
1335    LPMIDIHDR hdr = (LPMIDIHDR) dwParam1;
1336    int err;
1348    //int err;
13371349
13381350    /* Even if an error is pending, I think we should unprepare msgs and
13391351       signal their arrival
r242840r242841
13411353    /* printf("streamout_callback: hdr %x, wMsg %x, MOM_DONE %x\n",
13421354           hdr, wMsg, MOM_DONE); */
13431355    if (wMsg == MOM_DONE) {
1344        MMRESULT ret = midiOutUnprepareHeader(m->handle.out, hdr,
1356        midiOutUnprepareHeader(m->handle.out, hdr,
13451357                                              sizeof(MIDIHDR));
1346        assert(ret == MMSYSERR_NOERROR);
1358        //assert(ret == MMSYSERR_NOERROR);
13471359    }
13481360    /* signal client in case it is blocked waiting for buffer */
1349    err = SetEvent(m->buffer_signal);
1350    assert(err); /* false -> error */
1361    SetEvent(m->buffer_signal);
1362    //assert(err); /* false -> error */
13511363}
13521364
13531365
r242840r242841
14181430    int i;
14191431#ifdef DEBUG
14201432    char msg[PM_HOST_ERROR_MSG_LEN];
1421#endif
14221433    int doneAny = 0;
1423#ifdef DEBUG
14241434    printf("pm_winmm_term called\n");
14251435#endif
14261436    for (i = 0; i < pm_descriptor_index; i++) {
trunk/3rdparty/portmidi/porttime/porttime.h
r242840r242841
2525#endif
2626
2727#ifndef PMEXPORT
28#ifdef _WINDLL
29#define PMEXPORT __declspec(dllexport)
30#else
3128#define PMEXPORT
3229#endif
33#endif
3430
3531typedef enum {
3632    ptNoError = 0,         /* success */
r242840r242841
6662    return value:
6763    Upon success, returns ptNoError. See PtError for other values.
6864*/
69PMEXPORT PtError Pt_Stop();
65PMEXPORT PtError Pt_Stop(void);
7066
7167/*
7268    Pt_Started() returns true iff the timer is running.
7369*/
74PMEXPORT int Pt_Started();
70PMEXPORT int Pt_Started(void);
7571
7672/*
7773    Pt_Time() returns the current time in ms.
7874*/
79PMEXPORT PtTimestamp Pt_Time();
75PMEXPORT PtTimestamp Pt_Time(void);
8076
8177/*
8278    Pt_Sleep() pauses, allowing other threads to run.
trunk/3rdparty/portmidi/porttime/ptmacosx_mach.c
r242840r242841
1414#include "sys/time.h"
1515#include "pthread.h"
1616
17#define NSEC_PER_MSEC 1000000
17#if !defined NSEC_PER_MSEC
18#define NSEC_PER_MSEC 1000000ull
19#endif
1820#define THREAD_IMPORTANCE 30
1921
2022static int time_started_flag = FALSE;
r242840r242841
4547                              (thread_policy_t)&extendedPolicy,
4648                              THREAD_EXTENDED_POLICY_COUNT);
4749    if (error != KERN_SUCCESS) {
48        mach_error("Couldn't set thread timeshare policy", error);
50        mach_error((char *)"Couldn't set thread timeshare policy", error);
4951    }
5052
5153    precedencePolicy.importance = THREAD_IMPORTANCE;
r242840r242841
5355                              (thread_policy_t)&precedencePolicy,
5456                              THREAD_PRECEDENCE_POLICY_COUNT);
5557    if (error != KERN_SUCCESS) {
56        mach_error("Couldn't set thread precedence policy", error);
58        mach_error((char *)"Couldn't set thread precedence policy", error);
5759    }
5860   
5961   
trunk/src/lib/lib.mak
r242840r242841
2323   $(LIBOBJ)/libflac \
2424   $(LIBOBJ)/lib7z \
2525   $(LIBOBJ)/portmidi \
26   $(LIBOBJ)/portmidi/pm_common \
27   $(LIBOBJ)/portmidi/pm_linux \
28   $(LIBOBJ)/portmidi/pm_mac \
29   $(LIBOBJ)/portmidi/pm_win \
30   $(LIBOBJ)/portmidi/porttime \
2631   $(LIBOBJ)/lua \
2732   $(LIBOBJ)/lua/lsqlite3 \
2833   $(LIBOBJ)/mongoose \
r242840r242841
438443
439444# common objects
440445LIBPMOBJS = \
441   $(LIBOBJ)/portmidi/portmidi.o \
442   $(LIBOBJ)/portmidi/porttime.o \
443   $(LIBOBJ)/portmidi/pmutil.o
446   $(LIBOBJ)/portmidi/pm_common/portmidi.o \
447   $(LIBOBJ)/portmidi/pm_common/pmutil.o \
448   $(LIBOBJ)/portmidi/porttime/porttime.o \
444449
445450ifeq ($(TARGETOS),linux)
446451PMOPTS = -DPMALSA=1
447452
448453LIBPMOBJS += \
449   $(LIBOBJ)/portmidi/pmlinux.o \
450   $(LIBOBJ)/portmidi/pmlinuxalsa.o \
451   $(LIBOBJ)/portmidi/finddefaultlinux.o \
452   $(LIBOBJ)/portmidi/ptlinux.o
453
454   $(LIBOBJ)/portmidi/pm_linux/pmlinux.o \
455   $(LIBOBJ)/portmidi/pm_linux/pmlinuxalsa.o \
456   $(LIBOBJ)/portmidi/pm_linux/finddefaultlinux.o \
457   $(LIBOBJ)/portmidi/porttime/ptlinux.o
454458endif
455459
456460ifeq ($(TARGETOS),macosx)
457461LIBPMOBJS += \
458   $(LIBOBJ)/portmidi/pmmac.o \
459   $(LIBOBJ)/portmidi/pmmacosxcm.o \
460   $(LIBOBJ)/portmidi/finddefault.o \
461   $(LIBOBJ)/portmidi/readbinaryplist.o \
462   $(LIBOBJ)/portmidi/ptmacosx_mach.o \
463   $(LIBOBJ)/portmidi/osxsupport.o
462   $(LIBOBJ)/portmidi/pm_mac/pmmac.o \
463   $(LIBOBJ)/portmidi/pm_mac/pmmacosxcm.o \
464   $(LIBOBJ)/portmidi/pm_mac/finddefault.o \
465   $(LIBOBJ)/portmidi/pm_mac/readbinaryplist.o \
466   $(LIBOBJ)/portmidi/pm_mac/osxsupport.o \
467   $(LIBOBJ)/portmidi/porttime/ptmacosx_mach.o
464468endif
465469
466470ifeq ($(TARGETOS),win32)
467471LIBPMOBJS += \
468   $(LIBOBJ)/portmidi/pmwin.o \
469   $(LIBOBJ)/portmidi/pmwinmm.o \
470   $(LIBOBJ)/portmidi/ptwinmm.o
472   $(LIBOBJ)/portmidi/pm_win/pmwin.o \
473   $(LIBOBJ)/portmidi/pm_win/pmwinmm.o \
474   $(LIBOBJ)/portmidi/porttime/ptwinmm.o
471475endif
472476
473477$(OBJ)/libportmidi.a: $(LIBPMOBJS)
474478
475479$(LIBOBJ)/portmidi/%.o: $(3RDPARTY)/portmidi/%.c | $(OSPREBUILD)
476480   @echo Compiling $<...
477   $(CC) $(CDEFS) $(PMOPTS) $(CCOMFLAGS) $(CONLYFLAGS) -I$(LIBSRC)/portmidi/ -c $< -o $@
481   $(CC) $(CDEFS) $(PMOPTS) $(CCOMFLAGS) $(CONLYFLAGS) -I$(3RDPARTY)/portmidi/pm_common -I$(3RDPARTY)/portmidi/porttime -c $< -o $@
478482
479483#-------------------------------------------------
480484# LUA library objects
trunk/src/osd/modules/midi/portmidi.c
r242840r242841
66
77*******************************************************************c********/
88
9#include "portmidi/portmidi.h"
9#include "portmidi/pm_common/portmidi.h"
1010#include "osdcore.h"
1111
1212static const int RX_EVENT_BUF_SIZE = 512;


Previous 199869 Revisions Next


© 1997-2024 The MAME Team