pmlinux.c (2062B)
1 /* pmlinux.c -- PortMidi os-dependent code */ 2 3 /* This file only needs to implement pm_init(), which calls various 4 routines to register the available midi devices. This file must 5 be separate from the main portmidi.c file because it is system 6 dependent, and it is separate from, pmlinuxalsa.c, because it 7 might need to register non-alsa devices as well. 8 9 NOTE: if you add non-ALSA support, you need to fix :alsa_poll() 10 in pmlinuxalsa.c, which assumes all input devices are ALSA. 11 */ 12 13 #include "stdlib.h" 14 #include "portmidi.h" 15 #include "pmutil.h" 16 #include "pminternal.h" 17 18 #ifdef PMALSA 19 #include "pmlinuxalsa.h" 20 #endif 21 22 #ifdef PMNULL 23 #include "pmlinuxnull.h" 24 #endif 25 26 PmDeviceID pm_default_input_device_id = -1; 27 PmDeviceID pm_default_output_device_id = -1; 28 29 PmDeviceID find_default_device(char *path, int input, PmDeviceID id); 30 31 void pm_init() 32 { 33 /* Note: it is not an error for PMALSA to fail to initialize. 34 * It may be a design error that the client cannot query what subsystems 35 * are working properly other than by looking at the list of available 36 * devices. 37 */ 38 #ifdef PMALSA 39 pm_linuxalsa_init(); 40 #endif 41 #ifdef PMNULL 42 pm_linuxnull_init(); 43 #endif 44 // this is set when we return to Pm_Initialize, but we need it 45 // now in order to (successfully) call Pm_CountDevices() 46 pm_initialized = TRUE; 47 pm_default_input_device_id = find_default_device( 48 "/PortMidi/PM_RECOMMENDED_INPUT_DEVICE", TRUE, 49 pm_default_input_device_id); 50 pm_default_output_device_id = find_default_device( 51 "/PortMidi/PM_RECOMMENDED_OUTPUT_DEVICE", FALSE, 52 pm_default_output_device_id); 53 } 54 55 void pm_term(void) 56 { 57 #ifdef PMALSA 58 pm_linuxalsa_term(); 59 #endif 60 } 61 62 PmDeviceID Pm_GetDefaultInputDeviceID() { 63 Pm_Initialize(); 64 return pm_default_input_device_id; 65 } 66 67 PmDeviceID Pm_GetDefaultOutputDeviceID() { 68 Pm_Initialize(); 69 return pm_default_output_device_id; 70 } 71 72 void *pm_alloc(size_t s) { return malloc(s); } 73 74 void pm_free(void *ptr) { free(ptr); } 75