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
35 #include "mmdeviceapi.h"
36 #include "audioclient.h"
37 #include "wine/debug.h"
38 #include "wine/unixlib.h"
39 #include "coreaudio.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
;
58 params
.notify
= ¬ify
;
63 UNIX_CALL(midi_notify_wait
, ¶ms
);
65 if (notify
.send_notify
) notify_client(¬ify
);
70 static LONG
CoreAudio_MIDIInit(void)
72 struct midi_init_params params
;
77 UNIX_CALL(midi_init
, ¶ms
);
78 if (err
!= DRV_SUCCESS
)
80 ERR("can't create midi client\n");
84 CloseHandle(CreateThread(NULL
, 0, notify_thread
, NULL
, 0, NULL
));
89 static LONG
CoreAudio_MIDIRelease(void)
93 UNIX_CALL(midi_release
, NULL
);
98 /**************************************************************************
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
;
107 TRACE("%d %08x %08Ix %08Ix %08Ix\n", wDevID
, wMsg
, dwUser
, dwParam1
, dwParam2
);
109 params
.dev_id
= wDevID
;
111 params
.user
= dwUser
;
112 params
.param_1
= dwParam1
;
113 params
.param_2
= dwParam2
;
115 params
.notify
= ¬ify
;
117 UNIX_CALL(midi_out_message
, ¶ms
);
119 if (!err
&& notify
.send_notify
) notify_client(¬ify
);
124 /**************************************************************************
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
;
133 TRACE("%d %08x %08Ix %08Ix %08Ix\n", wDevID
, wMsg
, dwUser
, dwParam1
, dwParam2
);
135 params
.dev_id
= wDevID
;
137 params
.user
= dwUser
;
138 params
.param_1
= dwParam1
;
139 params
.param_2
= dwParam2
;
141 params
.notify
= ¬ify
;
145 UNIX_CALL(midi_in_message
, ¶ms
);
146 if ((!err
|| err
== ERROR_RETRY
) && notify
.send_notify
) notify_client(¬ify
);
147 } while (err
== ERROR_RETRY
);
152 /**************************************************************************
153 * CoreAudio_drvLoad [internal]
155 static LRESULT
CoreAudio_drvLoad(void)
159 if (CoreAudio_MIDIInit() != DRV_SUCCESS
)
165 /**************************************************************************
166 * CoreAudio_drvFree [internal]
168 static LRESULT
CoreAudio_drvFree(void)
171 CoreAudio_MIDIRelease();
175 /**************************************************************************
176 * CoreAudio_drvOpen [internal]
178 static LRESULT
CoreAudio_drvOpen(LPSTR str
)
180 TRACE("(%s)\n", str
);
184 /**************************************************************************
185 * CoreAudio_drvClose [internal]
187 static DWORD
CoreAudio_drvClose(DWORD dwDevID
)
189 TRACE("(%08lx)\n", dwDevID
);
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
);
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
;
224 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);