From 90d5b8b4a064420d74678654e94ea4755b377f21 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 15 Dec 2005 00:57:02 +0000 Subject: checking in missing files on behalf of Miller (cleared it with him first). The files are from portmidi17nov04.zip svn path=/trunk/; revision=4216 --- pd/portmidi/pm_win/pmwin.c | 113 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 pd/portmidi/pm_win/pmwin.c (limited to 'pd/portmidi/pm_win/pmwin.c') diff --git a/pd/portmidi/pm_win/pmwin.c b/pd/portmidi/pm_win/pmwin.c new file mode 100644 index 00000000..b289194b --- /dev/null +++ b/pd/portmidi/pm_win/pmwin.c @@ -0,0 +1,113 @@ +/* pmwin.c -- PortMidi os-dependent code */ + +/* This file only needs to implement: + pm_init(), which calls various routines to register the + available midi devices, + Pm_GetDefaultInputDeviceID(), and + Pm_GetDefaultOutputDeviceID(). + This file must + be separate from the main portmidi.c file because it is system + dependent, and it is separate from, say, pmwinmm.c, because it + might need to register devices for winmm, directx, and others. + */ + +#include "stdlib.h" +#include "portmidi.h" +#include "pminternal.h" +#include "pmwinmm.h" +#ifdef USE_DLL_FOR_CLEANUP +#include "pmdll.h" /* used to close ports on exit */ +#endif +#ifdef DEBUG +#include "stdio.h" +#endif + +/* pm_exit is called when the program exits. + It calls pm_term to make sure PortMidi is properly closed. + If DEBUG is on, we prompt for input to avoid losing error messages. + */ +static void pm_exit(void) { + pm_term(); +#ifdef DEBUG +#define STRING_MAX 80 + { + char line[STRING_MAX]; + printf("Type ENTER...\n"); + /* note, w/o this prompting, client console application can not see one + of its errors before closing. */ + fgets(line, STRING_MAX, stdin); + } +#endif +} + + +/* pm_init is the windows-dependent initialization.*/ +void pm_init(void) +{ +#ifdef USE_DLL_FOR_CLEANUP + /* we were hoping a DLL could offer more robust cleanup after errors, + but the DLL does not seem to run after crashes. Thus, the atexit() + mechanism is just as powerful, and simpler to implement. + */ + pm_set_close_function(pm_exit); +#ifdef DEBUG + printf("registered pm_term with cleanup DLL\n"); +#endif +#else + atexit(pm_exit); +#ifdef DEBUG + printf("registered pm_exit with atexit()\n"); +#endif +#endif + pm_winmm_init(); + /* initialize other APIs (DirectX?) here */ +} + + +void pm_term(void) { + pm_winmm_term(); +} + + +PmDeviceID Pm_GetDefaultInputDeviceID() { + /* This routine should check the environment and the registry + as specified in portmidi.h, but for now, it just returns + the first device of the proper input/output flavor. + */ + int i; + Pm_Initialize(); /* make sure descriptors exist! */ + for (i = 0; i < pm_descriptor_index; i++) { + if (descriptors[i].pub.input) { + return i; + } + } + return pmNoDevice; +} + +PmDeviceID Pm_GetDefaultOutputDeviceID() { + /* This routine should check the environment and the registry + as specified in portmidi.h, but for now, it just returns + the first device of the proper input/output flavor. + */ + int i; + Pm_Initialize(); /* make sure descriptors exist! */ + for (i = 0; i < pm_descriptor_index; i++) { + if (descriptors[i].pub.output) { + return i; + } + } + return pmNoDevice; + return 0; +} + +#include "stdio.h" + +void *pm_alloc(size_t s) { + return malloc(s); +} + + +void pm_free(void *ptr) { + free(ptr); +} + -- cgit v1.2.1