dmime: Implement band track IDirectMusicTrack_Play.
[wine.git] / dlls / wineoss.drv / midi.c
blobca842bbdc04dcf9441d1150ff46a117d1e60208f
1 /*
2 * MIDI driver for OSS (PE-side)
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1998 Luiz Otavio L. Zorzella (init procedures)
6 * Copyright 1998, 1999 Eric POUECH
7 * Copyright 2022 Huw Davies
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 /* TODO:
25 * + use better instrument definition for OPL/2 (midiPatch.c) or
26 * use existing instrument definition (from playmidi or kmid)
27 * with a .winerc option
28 * + have a look at OPL/3 ?
29 * + implement asynchronous playback of MidiHdr
30 * + implement STREAM'ed MidiHdr (question: how shall we share the
31 * code between the midiStream functions in MMSYSTEM/WINMM and
32 * the code for the low level driver)
33 * + use a more accurate read mechanism than the one of snooping on
34 * timers (like select on fd)
37 #include <stdarg.h>
39 #include "windef.h"
40 #include "winbase.h"
41 #include "wingdi.h"
42 #include "winuser.h"
43 #include "winternl.h"
44 #include "mmddk.h"
45 #include "audioclient.h"
47 #include "wine/debug.h"
48 #include "wine/unixlib.h"
50 #include "unixlib.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(midi);
54 /*======================================================================*
55 * Low level MIDI implementation *
56 *======================================================================*/
58 static void notify_client(struct notify_context *notify)
60 TRACE("dev_id = %d msg = %d param1 = %04IX param2 = %04IX\n",
61 notify->dev_id, notify->msg, notify->param_1, notify->param_2);
63 DriverCallback(notify->callback, notify->flags, notify->device, notify->msg,
64 notify->instance, notify->param_1, notify->param_2);
67 /*======================================================================*
68 * MIDI entry points *
69 *======================================================================*/
71 /**************************************************************************
72 * midMessage (WINEOSS.@)
74 DWORD WINAPI OSS_midMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser,
75 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
77 struct midi_in_message_params params;
78 struct notify_context notify;
79 UINT err;
81 TRACE("(%04X, %04X, %08IX, %08IX, %08IX);\n",
82 wDevID, wMsg, dwUser, dwParam1, dwParam2);
84 params.dev_id = wDevID;
85 params.msg = wMsg;
86 params.user = dwUser;
87 params.param_1 = dwParam1;
88 params.param_2 = dwParam2;
89 params.err = &err;
90 params.notify = &notify;
94 OSS_CALL(midi_in_message, &params);
95 if ((!err || err == ERROR_RETRY) && notify.send_notify) notify_client(&notify);
96 } while (err == ERROR_RETRY);
98 return err;
101 /**************************************************************************
102 * modMessage (WINEOSS.@)
104 DWORD WINAPI OSS_modMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser,
105 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
107 struct midi_out_message_params params;
108 struct notify_context notify;
109 UINT err;
111 TRACE("(%04X, %04X, %08IX, %08IX, %08IX);\n",
112 wDevID, wMsg, dwUser, dwParam1, dwParam2);
114 params.dev_id = wDevID;
115 params.msg = wMsg;
116 params.user = dwUser;
117 params.param_1 = dwParam1;
118 params.param_2 = dwParam2;
119 params.err = &err;
120 params.notify = &notify;
122 OSS_CALL(midi_out_message, &params);
124 if (!err && notify.send_notify) notify_client(&notify);
126 return err;
129 static DWORD WINAPI notify_thread(void *p)
131 struct midi_notify_wait_params params;
132 struct notify_context notify;
133 BOOL quit;
135 params.notify = &notify;
136 params.quit = &quit;
138 while (1)
140 OSS_CALL(midi_notify_wait, &params);
141 if (quit) break;
142 if (notify.send_notify) notify_client(&notify);
144 return 0;
147 /**************************************************************************
148 * DriverProc (WINEOSS.1)
150 LRESULT CALLBACK OSS_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
151 LPARAM dwParam1, LPARAM dwParam2)
153 TRACE("(%08IX, %p, %08X, %08IX, %08IX)\n",
154 dwDevID, hDriv, wMsg, dwParam1, dwParam2);
156 switch(wMsg) {
157 case DRV_LOAD:
158 CloseHandle(CreateThread(NULL, 0, notify_thread, NULL, 0, NULL));
159 return 1;
160 case DRV_FREE:
161 OSS_CALL(midi_release, NULL);
162 return 1;
163 case DRV_OPEN:
164 case DRV_CLOSE:
165 case DRV_ENABLE:
166 case DRV_DISABLE:
167 case DRV_QUERYCONFIGURE:
168 case DRV_CONFIGURE:
169 return 1;
170 case DRV_INSTALL:
171 case DRV_REMOVE:
172 return DRV_SUCCESS;
173 default:
174 return 0;