1 /* pmwin.c -- PortMidi os-dependent code */
3 /* This file only needs to implement:
4 pm_init(), which calls various routines to register the
5 available midi devices,
6 Pm_GetDefaultInputDeviceID(), and
7 Pm_GetDefaultOutputDeviceID().
9 be separate from the main portmidi.c file because it is system
10 dependent, and it is separate from, say, pmwinmm.c, because it
11 might need to register devices for winmm, directx, and others.
18 #include "pminternal.h"
25 /* pm_exit is called when the program exits.
26 It calls pm_term to make sure PortMidi is properly closed.
27 If DEBUG is on, we prompt for input to avoid losing error messages.
29 static void pm_exit(void) {
34 char line[STRING_MAX];
35 printf("Type ENTER...\n");
36 /* note, w/o this prompting, client console application can not see one
37 of its errors before closing. */
38 fgets(line, STRING_MAX, stdin);
44 /* pm_init is the windows-dependent initialization.*/
49 printf("registered pm_exit with atexit()\n");
52 /* initialize other APIs (DirectX?) here */
61 static PmDeviceID pm_get_default_device_id(int is_input, char *key) {
63 #define PATTERN_MAX 256
64 char pattern[PATTERN_MAX];
65 long pattern_max = PATTERN_MAX;
67 /* Find first input or device -- this is the default. */
68 PmDeviceID id = pmNoDevice;
70 Pm_Initialize(); /* make sure descriptors exist! */
71 for (i = 0; i < pm_descriptor_index; i++) {
72 if (descriptors[i].pub.input == is_input) {
77 /* Look in registry for a default device name pattern. */
78 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_READ, &hkey) !=
82 if (RegOpenKeyEx(hkey, "JavaSoft", 0, KEY_READ, &hkey) !=
86 if (RegOpenKeyEx(hkey, "Prefs", 0, KEY_READ, &hkey) !=
90 if (RegOpenKeyEx(hkey, "/Port/Midi", 0, KEY_READ, &hkey) !=
94 if (RegQueryValueEx(hkey, key, NULL, &dwType, pattern, &pattern_max) !=
99 /* decode pattern: upper case encoded with "/" prefix */
102 if (pattern[i] == '/' && pattern[i + 1]) {
103 pattern[j++] = toupper(pattern[++i]);
105 pattern[j++] = tolower(pattern[i]);
109 pattern[j] = 0; /* end of string */
111 /* now pattern is the string from the registry; search for match */
112 i = pm_find_default_device(pattern, is_input);
113 if (i != pmNoDevice) {
120 PmDeviceID Pm_GetDefaultInputDeviceID() {
121 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");
126 PmDeviceID Pm_GetDefaultOutputDeviceID() {
127 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");
134 void *pm_alloc(size_t s) {
139 void pm_free(void *ptr) {