[PATCH 04/12] winecoreaudio: Move midi_out_open to the unixlib.
Huw Davies
huw at codeweavers.com
Thu Nov 25 05:03:39 CST 2021
Notifications are filled out by the unixlib and returned to
the user-side for dispatch.
Signed-off-by: Huw Davies <huw at codeweavers.com>
---
dlls/winecoreaudio.drv/audiounit.c | 90 ---------------
dlls/winecoreaudio.drv/coreaudio.c | 1 +
dlls/winecoreaudio.drv/coremidi.c | 177 +++++++++++++++++++++++++++++
dlls/winecoreaudio.drv/midi.c | 87 +++++---------
dlls/winecoreaudio.drv/unixlib.h | 27 +++++
5 files changed, 231 insertions(+), 151 deletions(-)
diff --git a/dlls/winecoreaudio.drv/audiounit.c b/dlls/winecoreaudio.drv/audiounit.c
index c91fec216bd..d155bda7be3 100644
--- a/dlls/winecoreaudio.drv/audiounit.c
+++ b/dlls/winecoreaudio.drv/audiounit.c
@@ -86,96 +86,6 @@ int AudioUnit_GetVolume(AudioUnit au, float *left, float *right)
}
-/*
- * MIDI Synth Unit
- */
-int SynthUnit_CreateDefaultSynthUnit(AUGraph *graph, AudioUnit *synth)
-{
- OSStatus err;
- AudioComponentDescription desc;
- AUNode synthNode;
- AUNode outNode;
-
- err = NewAUGraph(graph);
- if (err != noErr)
- {
- ERR_(midi)("NewAUGraph return %s\n", wine_dbgstr_fourcc(err));
- return 0;
- }
-
- desc.componentManufacturer = kAudioUnitManufacturer_Apple;
- desc.componentFlags = 0;
- desc.componentFlagsMask = 0;
-
- /* create synth node */
- desc.componentType = kAudioUnitType_MusicDevice;
- desc.componentSubType = kAudioUnitSubType_DLSSynth;
-
- err = AUGraphAddNode(*graph, &desc, &synthNode);
- if (err != noErr)
- {
- ERR_(midi)("AUGraphAddNode cannot create synthNode : %s\n", wine_dbgstr_fourcc(err));
- return 0;
- }
-
- /* create out node */
- desc.componentType = kAudioUnitType_Output;
- desc.componentSubType = kAudioUnitSubType_DefaultOutput;
-
- err = AUGraphAddNode(*graph, &desc, &outNode);
- if (err != noErr)
- {
- ERR_(midi)("AUGraphAddNode cannot create outNode %s\n", wine_dbgstr_fourcc(err));
- return 0;
- }
-
- err = AUGraphOpen(*graph);
- if (err != noErr)
- {
- ERR_(midi)("AUGraphOpen return %s\n", wine_dbgstr_fourcc(err));
- return 0;
- }
-
- /* connecting the nodes */
- err = AUGraphConnectNodeInput(*graph, synthNode, 0, outNode, 0);
- if (err != noErr)
- {
- ERR_(midi)("AUGraphConnectNodeInput cannot connect synthNode to outNode : %s\n", wine_dbgstr_fourcc(err));
- return 0;
- }
-
- /* Get the synth unit */
- err = AUGraphNodeInfo(*graph, synthNode, 0, synth);
- if (err != noErr)
- {
- ERR_(midi)("AUGraphNodeInfo return %s\n", wine_dbgstr_fourcc(err));
- return 0;
- }
-
- return 1;
-}
-
-int SynthUnit_Initialize(AudioUnit synth, AUGraph graph)
-{
- OSStatus err = noErr;
-
- err = AUGraphInitialize(graph);
- if (err != noErr)
- {
- ERR_(midi)("AUGraphInitialize(%p) return %s\n", graph, wine_dbgstr_fourcc(err));
- return 0;
- }
-
- err = AUGraphStart(graph);
- if (err != noErr)
- {
- ERR_(midi)("AUGraphStart(%p) return %s\n", graph, wine_dbgstr_fourcc(err));
- return 0;
- }
-
- return 1;
-}
-
int SynthUnit_Close(AUGraph graph)
{
OSStatus err = noErr;
diff --git a/dlls/winecoreaudio.drv/coreaudio.c b/dlls/winecoreaudio.drv/coreaudio.c
index 9476b6baf6f..e90c400102f 100644
--- a/dlls/winecoreaudio.drv/coreaudio.c
+++ b/dlls/winecoreaudio.drv/coreaudio.c
@@ -1631,4 +1631,5 @@ unixlib_entry_t __wine_unix_call_funcs[] =
set_volumes,
midi_init,
midi_release,
+ midi_out_message,
};
diff --git a/dlls/winecoreaudio.drv/coremidi.c b/dlls/winecoreaudio.drv/coremidi.c
index dedfa0aa9ee..a7b84f0a41e 100644
--- a/dlls/winecoreaudio.drv/coremidi.c
+++ b/dlls/winecoreaudio.drv/coremidi.c
@@ -86,6 +86,7 @@
#include "wine/unicode.h"
#include "wine/unixlib.h"
+#include "coreaudio.h"
#include "coremidi.h"
#include "unixlib.h"
@@ -263,3 +264,179 @@ NTSTATUS midi_release(void *args)
return STATUS_SUCCESS;
}
+
+/*
+ * MIDI Synth Unit
+ */
+static BOOL synth_unit_create_default(AUGraph *graph, AudioUnit *synth)
+{
+ AudioComponentDescription desc;
+ AUNode synth_node;
+ AUNode out_node;
+ OSStatus sc;
+
+ sc = NewAUGraph(graph);
+ if (sc != noErr)
+ {
+ ERR("NewAUGraph return %s\n", wine_dbgstr_fourcc(sc));
+ return FALSE;
+ }
+
+ desc.componentManufacturer = kAudioUnitManufacturer_Apple;
+ desc.componentFlags = 0;
+ desc.componentFlagsMask = 0;
+
+ /* create synth node */
+ desc.componentType = kAudioUnitType_MusicDevice;
+ desc.componentSubType = kAudioUnitSubType_DLSSynth;
+
+ sc = AUGraphAddNode(*graph, &desc, &synth_node);
+ if (sc != noErr)
+ {
+ ERR("AUGraphAddNode cannot create synthNode : %s\n", wine_dbgstr_fourcc(sc));
+ return FALSE;
+ }
+
+ /* create out node */
+ desc.componentType = kAudioUnitType_Output;
+ desc.componentSubType = kAudioUnitSubType_DefaultOutput;
+
+ sc = AUGraphAddNode(*graph, &desc, &out_node);
+ if (sc != noErr)
+ {
+ ERR("AUGraphAddNode cannot create outNode %s\n", wine_dbgstr_fourcc(sc));
+ return FALSE;
+ }
+
+ sc = AUGraphOpen(*graph);
+ if (sc != noErr)
+ {
+ ERR("AUGraphOpen returns %s\n", wine_dbgstr_fourcc(sc));
+ return FALSE;
+ }
+
+ /* connecting the nodes */
+ sc = AUGraphConnectNodeInput(*graph, synth_node, 0, out_node, 0);
+ if (sc != noErr)
+ {
+ ERR("AUGraphConnectNodeInput cannot connect synthNode to outNode : %s\n",
+ wine_dbgstr_fourcc(sc));
+ return FALSE;
+ }
+
+ /* Get the synth unit */
+ sc = AUGraphNodeInfo(*graph, synth_node, 0, synth);
+ if (sc != noErr)
+ {
+ ERR("AUGraphNodeInfo return %s\n", wine_dbgstr_fourcc(sc));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static BOOL synth_unit_init(AudioUnit synth, AUGraph graph)
+{
+ OSStatus sc;
+
+ sc = AUGraphInitialize(graph);
+ if (sc != noErr)
+ {
+ ERR("AUGraphInitialize(%p) returns %s\n", graph, wine_dbgstr_fourcc(sc));
+ return FALSE;
+ }
+
+ sc = AUGraphStart(graph);
+ if (sc != noErr)
+ {
+ ERR("AUGraphStart(%p) returns %s\n", graph, wine_dbgstr_fourcc(sc));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void set_out_notify(struct notify_context *notify, struct midi_dest *dest, WORD dev_id, WORD msg,
+ DWORD_PTR param_1, DWORD_PTR param_2)
+{
+ notify->send_notify = TRUE;
+ notify->dev_id = dev_id;
+ notify->msg = msg;
+ notify->param_1 = param_1;
+ notify->param_2 = param_2;
+ notify->callback = dest->midiDesc.dwCallback;
+ notify->flags = dest->wFlags;
+ notify->device = dest->midiDesc.hMidi;
+ notify->instance = dest->midiDesc.dwInstance;
+}
+
+static DWORD midi_out_open(WORD dev_id, MIDIOPENDESC *midi_desc, DWORD flags, struct notify_context *notify)
+{
+ struct midi_dest *dest;
+
+ TRACE("dev_id = %d desc = %p flags = %08x\n", dev_id, midi_desc, flags);
+
+ if (!midi_desc) return MMSYSERR_INVALPARAM;
+
+ if (dev_id >= num_dests)
+ {
+ WARN("bad device ID : %d\n", dev_id);
+ return MMSYSERR_BADDEVICEID;
+ }
+ if (dests[dev_id].midiDesc.hMidi != 0)
+ {
+ WARN("device already open!\n");
+ return MMSYSERR_ALLOCATED;
+ }
+ if ((flags & ~CALLBACK_TYPEMASK) != 0)
+ {
+ WARN("bad flags\n");
+ return MMSYSERR_INVALFLAG;
+ }
+
+ dest = dests + dev_id;
+ if (dest->caps.wTechnology == MOD_SYNTH)
+ {
+ if (!synth_unit_create_default(&dest->graph, &dest->synth))
+ {
+ ERR("SynthUnit_CreateDefaultSynthUnit dest=%p failed\n", dest);
+ return MMSYSERR_ERROR;
+ }
+ if (!synth_unit_init(dest->synth, dest->graph))
+ {
+ ERR("SynthUnit_Initialise dest=%p failed\n", dest);
+ return MMSYSERR_ERROR;
+ }
+ }
+ dest->wFlags = HIWORD(flags & CALLBACK_TYPEMASK);
+ dest->midiDesc = *midi_desc;
+
+ set_out_notify(notify, dest, dev_id, MOM_OPEN, 0, 0);
+
+ return MMSYSERR_NOERROR;
+}
+
+NTSTATUS midi_out_message(void *args)
+{
+ struct midi_out_message_params *params = args;
+
+ params->notify->send_notify = FALSE;
+
+ switch (params->msg)
+ {
+ case DRVM_INIT:
+ case DRVM_EXIT:
+ case DRVM_ENABLE:
+ case DRVM_DISABLE:
+ *params->err = MMSYSERR_NOERROR;
+ break;
+ case MODM_OPEN:
+ *params->err = midi_out_open(params->dev_id, (MIDIOPENDESC *)params->param_1, params->param_2, params->notify);
+ break;
+ default:
+ TRACE("Unsupported message\n");
+ *params->err = MMSYSERR_NOTSUPPORTED;
+ }
+
+ return STATUS_SUCCESS;
+}
diff --git a/dlls/winecoreaudio.drv/midi.c b/dlls/winecoreaudio.drv/midi.c
index 000c57ad98d..575a8bf6813 100644
--- a/dlls/winecoreaudio.drv/midi.c
+++ b/dlls/winecoreaudio.drv/midi.c
@@ -64,10 +64,16 @@ static MIDIPortRef MIDIOutPort = NULL;
MIDIDestination *destinations;
MIDISource *sources;
-extern int SynthUnit_CreateDefaultSynthUnit(AUGraph *graph, AudioUnit *synth);
-extern int SynthUnit_Initialize(AudioUnit synth, AUGraph graph);
extern int SynthUnit_Close(AUGraph graph);
+static void notify_client(struct notify_context *notify)
+{
+ TRACE("dev_id=%d msg=%d param1=%04lX param2=%04lX\n", notify->dev_id, notify->msg, notify->param_1, notify->param_2);
+
+ DriverCallback(notify->callback, notify->flags, notify->device, notify->msg,
+ notify->instance, notify->param_1, notify->param_2);
+}
+
static LONG CoreAudio_MIDIInit(void)
{
struct midi_init_params params;
@@ -131,7 +137,6 @@ static void MIDI_NotifyClient(UINT wDevID, WORD wMsg, DWORD_PTR dwParam1, DWORD_
TRACE("wDevID=%d wMsg=%d dwParm1=%04lX dwParam2=%04lX\n", wDevID, wMsg, dwParam1, dwParam2);
switch (wMsg) {
- case MOM_OPEN:
case MOM_CLOSE:
case MOM_DONE:
case MOM_POSITIONCB:
@@ -161,54 +166,6 @@ static void MIDI_NotifyClient(UINT wDevID, WORD wMsg, DWORD_PTR dwParam1, DWORD_
DriverCallback(dwCallBack, uFlags, hDev, wMsg, dwInstance, dwParam1, dwParam2);
}
-static DWORD MIDIOut_Open(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
-{
- MIDIDestination *dest;
-
- TRACE("wDevID=%d lpDesc=%p dwFlags=%08x\n", wDevID, lpDesc, dwFlags);
-
- if (lpDesc == NULL) {
- WARN("Invalid Parameter\n");
- return MMSYSERR_INVALPARAM;
- }
-
- if (wDevID >= MIDIOut_NumDevs) {
- WARN("bad device ID : %d\n", wDevID);
- return MMSYSERR_BADDEVICEID;
- }
-
- if (destinations[wDevID].midiDesc.hMidi != 0) {
- WARN("device already open !\n");
- return MMSYSERR_ALLOCATED;
- }
-
- if ((dwFlags & ~CALLBACK_TYPEMASK) != 0) {
- WARN("bad dwFlags\n");
- return MMSYSERR_INVALFLAG;
- }
- dest = &destinations[wDevID];
-
- if (dest->caps.wTechnology == MOD_SYNTH)
- {
- if (!SynthUnit_CreateDefaultSynthUnit(&dest->graph, &dest->synth))
- {
- ERR("SynthUnit_CreateDefaultSynthUnit dest=%p failed\n", dest);
- return MMSYSERR_ERROR;
- }
-
- if (!SynthUnit_Initialize(dest->synth, dest->graph))
- {
- ERR("SynthUnit_Initialise dest=%p failed\n", dest);
- return MMSYSERR_ERROR;
- }
- }
- dest->wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
- dest->midiDesc = *lpDesc;
-
- MIDI_NotifyClient(wDevID, MOM_OPEN, 0L, 0L);
- return MMSYSERR_NOERROR;
-}
-
static DWORD MIDIOut_Close(WORD wDevID)
{
DWORD ret = MMSYSERR_NOERROR;
@@ -825,16 +782,13 @@ static DWORD WINAPI MIDIIn_MessageThread(LPVOID p)
*/
DWORD WINAPI CoreAudio_modMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
{
+ struct midi_out_message_params params;
+ struct notify_context notify;
+ DWORD err;
+
TRACE("%d %08x %08lx %08lx %08lx\n", wDevID, wMsg, dwUser, dwParam1, dwParam2);
switch (wMsg) {
- case DRVM_INIT:
- case DRVM_EXIT:
- case DRVM_ENABLE:
- case DRVM_DISABLE:
- return 0;
- case MODM_OPEN:
- return MIDIOut_Open(wDevID, (LPMIDIOPENDESC)dwParam1, dwParam2);
case MODM_CLOSE:
return MIDIOut_Close(wDevID);
case MODM_DATA:
@@ -855,10 +809,21 @@ DWORD WINAPI CoreAudio_modMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser, DWOR
return MIDIOut_SetVolume(wDevID, dwParam1);
case MODM_RESET:
return MIDIOut_Reset(wDevID);
- default:
- TRACE("Unsupported message (08%x)\n", wMsg);
}
- return MMSYSERR_NOTSUPPORTED;
+
+ params.dev_id = wDevID;
+ params.msg = wMsg;
+ params.user = dwUser;
+ params.param_1 = dwParam1;
+ params.param_2 = dwParam2;
+ params.err = &err;
+ params.notify = ¬ify;
+
+ UNIX_CALL(midi_out_message, ¶ms);
+
+ if (!err && notify.send_notify) notify_client(¬ify);
+
+ return err;
}
/**************************************************************************
diff --git a/dlls/winecoreaudio.drv/unixlib.h b/dlls/winecoreaudio.drv/unixlib.h
index 6dfb68d202f..6afb9eb287d 100644
--- a/dlls/winecoreaudio.drv/unixlib.h
+++ b/dlls/winecoreaudio.drv/unixlib.h
@@ -17,6 +17,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
+#include "mmddk.h"
struct coreaudio_stream;
@@ -190,6 +191,30 @@ struct midi_init_params
void *midi_out_port, *midi_in_port;
};
+struct notify_context
+{
+ BOOL send_notify;
+ WORD dev_id;
+ WORD msg;
+ DWORD_PTR param_1;
+ DWORD_PTR param_2;
+ DWORD_PTR callback;
+ DWORD flags;
+ HANDLE device;
+ DWORD_PTR instance;
+};
+
+struct midi_out_message_params
+{
+ UINT dev_id;
+ UINT msg;
+ DWORD_PTR user;
+ DWORD_PTR param_1;
+ DWORD_PTR param_2;
+ DWORD *err;
+ struct notify_context *notify;
+};
+
enum unix_funcs
{
unix_get_endpoint_ids,
@@ -214,10 +239,12 @@ enum unix_funcs
unix_set_volumes,
unix_midi_init,
unix_midi_release,
+ unix_midi_out_message,
};
NTSTATUS midi_init( void * ) DECLSPEC_HIDDEN;
NTSTATUS midi_release( void * ) DECLSPEC_HIDDEN;
+NTSTATUS midi_out_message( void * ) DECLSPEC_HIDDEN;
extern unixlib_handle_t coreaudio_handle;
--
2.23.0
More information about the wine-devel
mailing list