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