comctl32/tests: Use CRT allocation functions.
[wine.git] / dlls / winecoreaudio.drv / midi.c
blob4934923800c99d1079efa84471bb9c93199ce48b
1 /*
2 * MIDI driver for macOS (PE-side)
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1998 Luiz Otavio L. Zorzella
6 * Copyright 1998, 1999 Eric POUECH
7 * Copyright 2005, 2006 Emmanuel Maillard
8 * Copyright 2021 Huw Davies
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include <string.h>
25 #include <stdarg.h>
26 #include <stdio.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winternl.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winnls.h"
34 #include "mmddk.h"
35 #include "mmdeviceapi.h"
36 #include "audioclient.h"
37 #include "wine/debug.h"
38 #include "wine/unixlib.h"
39 #include "coreaudio.h"
40 #include "unixlib.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(midi);
44 static void notify_client(struct notify_context *notify)
46 TRACE("dev_id=%d msg=%d param1=%04IX param2=%04IX\n", notify->dev_id, notify->msg, notify->param_1, notify->param_2);
48 DriverCallback(notify->callback, notify->flags, notify->device, notify->msg,
49 notify->instance, notify->param_1, notify->param_2);
52 static DWORD WINAPI notify_thread(void *p)
54 struct midi_notify_wait_params params;
55 struct notify_context notify;
56 BOOL quit;
58 params.notify = &notify;
59 params.quit = &quit;
61 while (1)
63 UNIX_CALL(midi_notify_wait, &params);
64 if (quit) break;
65 if (notify.send_notify) notify_client(&notify);
67 return 0;
70 static LONG CoreAudio_MIDIInit(void)
72 struct midi_init_params params;
73 UINT err;
75 params.err = &err;
77 UNIX_CALL(midi_init, &params);
78 if (err != DRV_SUCCESS)
80 ERR("can't create midi client\n");
81 return err;
84 CloseHandle(CreateThread(NULL, 0, notify_thread, NULL, 0, NULL));
86 return err;
89 static LONG CoreAudio_MIDIRelease(void)
91 TRACE("\n");
93 UNIX_CALL(midi_release, NULL);
95 return DRV_SUCCESS;
98 /**************************************************************************
99 * modMessage
101 DWORD WINAPI CoreAudio_modMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
103 struct midi_out_message_params params;
104 struct notify_context notify;
105 UINT err;
107 TRACE("%d %08x %08Ix %08Ix %08Ix\n", wDevID, wMsg, dwUser, dwParam1, dwParam2);
109 params.dev_id = wDevID;
110 params.msg = wMsg;
111 params.user = dwUser;
112 params.param_1 = dwParam1;
113 params.param_2 = dwParam2;
114 params.err = &err;
115 params.notify = &notify;
117 UNIX_CALL(midi_out_message, &params);
119 if (!err && notify.send_notify) notify_client(&notify);
121 return err;
124 /**************************************************************************
125 * midMessage
127 DWORD WINAPI CoreAudio_midMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
129 struct midi_in_message_params params;
130 struct notify_context notify;
131 UINT err;
133 TRACE("%d %08x %08Ix %08Ix %08Ix\n", wDevID, wMsg, dwUser, dwParam1, dwParam2);
135 params.dev_id = wDevID;
136 params.msg = wMsg;
137 params.user = dwUser;
138 params.param_1 = dwParam1;
139 params.param_2 = dwParam2;
140 params.err = &err;
141 params.notify = &notify;
145 UNIX_CALL(midi_in_message, &params);
146 if ((!err || err == ERROR_RETRY) && notify.send_notify) notify_client(&notify);
147 } while (err == ERROR_RETRY);
149 return err;
152 /**************************************************************************
153 * CoreAudio_drvLoad [internal]
155 static LRESULT CoreAudio_drvLoad(void)
157 TRACE("()\n");
159 if (CoreAudio_MIDIInit() != DRV_SUCCESS)
160 return DRV_FAILURE;
162 return DRV_SUCCESS;
165 /**************************************************************************
166 * CoreAudio_drvFree [internal]
168 static LRESULT CoreAudio_drvFree(void)
170 TRACE("()\n");
171 CoreAudio_MIDIRelease();
172 return DRV_SUCCESS;
175 /**************************************************************************
176 * CoreAudio_drvOpen [internal]
178 static LRESULT CoreAudio_drvOpen(LPSTR str)
180 TRACE("(%s)\n", str);
181 return 1;
184 /**************************************************************************
185 * CoreAudio_drvClose [internal]
187 static DWORD CoreAudio_drvClose(DWORD dwDevID)
189 TRACE("(%08lx)\n", dwDevID);
190 return 1;
193 /**************************************************************************
194 * DriverProc (WINECOREAUDIO.1)
196 LRESULT CALLBACK CoreAudio_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
197 LPARAM dwParam1, LPARAM dwParam2)
199 TRACE("(%08IX, %p, %s (%08X), %08IX, %08IX)\n",
200 dwDevID, hDriv, wMsg == DRV_LOAD ? "DRV_LOAD" :
201 wMsg == DRV_FREE ? "DRV_FREE" :
202 wMsg == DRV_OPEN ? "DRV_OPEN" :
203 wMsg == DRV_CLOSE ? "DRV_CLOSE" :
204 wMsg == DRV_ENABLE ? "DRV_ENABLE" :
205 wMsg == DRV_DISABLE ? "DRV_DISABLE" :
206 wMsg == DRV_QUERYCONFIGURE ? "DRV_QUERYCONFIGURE" :
207 wMsg == DRV_CONFIGURE ? "DRV_CONFIGURE" :
208 wMsg == DRV_INSTALL ? "DRV_INSTALL" :
209 wMsg == DRV_REMOVE ? "DRV_REMOVE" : "UNKNOWN",
210 wMsg, dwParam1, dwParam2);
212 switch(wMsg) {
213 case DRV_LOAD: return CoreAudio_drvLoad();
214 case DRV_FREE: return CoreAudio_drvFree();
215 case DRV_OPEN: return CoreAudio_drvOpen((LPSTR)dwParam1);
216 case DRV_CLOSE: return CoreAudio_drvClose(dwDevID);
217 case DRV_ENABLE: return 1;
218 case DRV_DISABLE: return 1;
219 case DRV_QUERYCONFIGURE: return 1;
220 case DRV_CONFIGURE: MessageBoxA(0, "CoreAudio driver!", "CoreAudio driver", MB_OK); return 1;
221 case DRV_INSTALL: return DRVCNF_RESTART;
222 case DRV_REMOVE: return DRVCNF_RESTART;
223 default:
224 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);