[PATCH 02/12] winecoreaudio: Combine MIDIIn_SendMessage into MIDIIn_ReadProc.
Andrew Eikum
aeikum at codeweavers.com
Fri Nov 26 09:01:36 CST 2021
Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>
On Thu, Nov 25, 2021 at 11:03:37AM +0000, Huw Davies wrote:
> Signed-off-by: Huw Davies <huw at codeweavers.com>
> ---
> dlls/winecoreaudio.drv/coremidi.c | 31 ++++++++++++++------
> dlls/winecoreaudio.drv/coremidi.h | 8 +++++-
> dlls/winecoreaudio.drv/midi.c | 48 ++++---------------------------
> 3 files changed, 36 insertions(+), 51 deletions(-)
>
> diff --git a/dlls/winecoreaudio.drv/coremidi.c b/dlls/winecoreaudio.drv/coremidi.c
> index 6d54d89cfac..92f52c972d3 100644
> --- a/dlls/winecoreaudio.drv/coremidi.c
> +++ b/dlls/winecoreaudio.drv/coremidi.c
> @@ -1,7 +1,11 @@
> /*
> - * Wine Midi driver for Mac OS X
> + * MIDI driver for macOS (unixlib)
> *
> - * Copyright 2006 Emmanuel Maillard
> + * Copyright 1994 Martin Ayotte
> + * Copyright 1998 Luiz Otavio L. Zorzella
> + * Copyright 1998, 1999 Eric POUECH
> + * Copyright 2005, 2006 Emmanuel Maillard
> + * Copyright 2021 Huw Davies
> *
> * This library is free software; you can redistribute it and/or
> * modify it under the terms of the GNU Lesser General Public
> @@ -56,14 +60,25 @@ void CoreMIDI_GetObjectName(MIDIObjectRef obj, char *name, int size)
> */
> void MIDIIn_ReadProc(const MIDIPacketList *pktlist, void *refCon, void *connRefCon)
> {
> - unsigned int i;
> -
> + CFMessagePortRef msg_port = CFMessagePortCreateRemote(kCFAllocatorDefault, MIDIInThreadPortName);
> MIDIPacket *packet = (MIDIPacket *)pktlist->packet;
> - for (i = 0; i < pktlist->numPackets; ++i) {
> - UInt16 devID = *((UInt16 *)connRefCon);
> -
> - MIDIIn_SendMessage(devID, packet->data, packet->length);
> + CFMutableDataRef data;
> + MIDIMessage msg;
> + unsigned int i;
>
> + for (i = 0; i < pktlist->numPackets; ++i)
> + {
> + msg.devID = *(UInt16 *)connRefCon;
> + msg.length = packet->length;
> + data = CFDataCreateMutable(kCFAllocatorDefault, sizeof(msg) + packet->length);
> + if (data)
> + {
> + CFDataAppendBytes(data, (UInt8 *)&msg, sizeof(msg));
> + CFDataAppendBytes(data, packet->data, packet->length);
> + CFMessagePortSendRequest(msg_port, 0, data, 0.0, 0.0, NULL, NULL);
> + CFRelease(data);
> + }
> packet = MIDIPacketNext(packet);
> }
> + CFRelease(msg_port);
> }
> diff --git a/dlls/winecoreaudio.drv/coremidi.h b/dlls/winecoreaudio.drv/coremidi.h
> index 3433a1d4342..47566345b54 100644
> --- a/dlls/winecoreaudio.drv/coremidi.h
> +++ b/dlls/winecoreaudio.drv/coremidi.h
> @@ -73,6 +73,12 @@ extern void MIDIIn_ReadProc(const MIDIPacketList *pktlist, void *refCon, void *c
> extern void MIDIOut_Send(MIDIPortRef port, MIDIEndpointRef dest, UInt8 *buffer, unsigned length);
>
> /* midi.c */
> -void MIDIIn_SendMessage(UInt16 devID, const void *buffer, UInt16 length);
> +extern CFStringRef MIDIInThreadPortName;
> +
> +typedef struct {
> + UInt16 devID;
> + UInt16 length;
> + Byte data[];
> +} MIDIMessage;
>
> #endif
> diff --git a/dlls/winecoreaudio.drv/midi.c b/dlls/winecoreaudio.drv/midi.c
> index 32826cb658c..2c89f32b430 100644
> --- a/dlls/winecoreaudio.drv/midi.c
> +++ b/dlls/winecoreaudio.drv/midi.c
> @@ -1,14 +1,11 @@
> /*
> - * Sample MIDI Wine Driver for Mac OS X (based on OSS midi driver)
> + * MIDI driver for macOS (PE-side)
> *
> - * Copyright 1994 Martin Ayotte
> - * Copyright 1998 Luiz Otavio L. Zorzella (init procedures)
> - * Copyright 1998/1999 Eric POUECH :
> - * 98/7 changes for making this MIDI driver work on OSS
> - * current support is limited to MIDI ports of OSS systems
> - * 98/9 rewriting MCI code for MIDI
> - * 98/11 split in midi.c and mcimidi.c
> + * Copyright 1994 Martin Ayotte
> + * Copyright 1998 Luiz Otavio L. Zorzella
> + * Copyright 1998, 1999 Eric POUECH
> * Copyright 2005, 2006 Emmanuel Maillard
> + * Copyright 2021 Huw Davies
> *
> * This library is free software; you can redistribute it and/or
> * modify it under the terms of the GNU Lesser General Public
> @@ -78,14 +75,8 @@ typedef struct tagMIDISource {
> DWORD startTime;
> } MIDISource;
>
> -typedef struct {
> - UInt16 devID;
> - UInt16 length;
> - Byte data[];
> -} MIDIMessage;
> -
> static CRITICAL_SECTION midiInLock; /* Critical section for MIDI In */
> -static CFStringRef MIDIInThreadPortName = NULL;
> +CFStringRef MIDIInThreadPortName = NULL;
>
> static DWORD WINAPI MIDIIn_MessageThread(LPVOID p);
>
> @@ -798,33 +789,6 @@ static DWORD MIDIIn_Reset(WORD wDevID)
> /*
> * MIDI In Mach message handling
> */
> -
> -/*
> - * Call from CoreMIDI IO threaded callback,
> - * we can't call Wine debug channels, critical section or anything using NtCurrentTeb here.
> - */
> -void MIDIIn_SendMessage(UInt16 devID, const void *buffer, UInt16 length)
> -{
> - MIDIMessage msg;
> - CFMutableDataRef data;
> -
> - CFMessagePortRef messagePort;
> - messagePort = CFMessagePortCreateRemote(kCFAllocatorDefault, MIDIInThreadPortName);
> -
> - msg.devID = devID;
> - msg.length = length;
> -
> - data = CFDataCreateMutable(kCFAllocatorDefault, sizeof(msg) + length);
> - if (data)
> - {
> - CFDataAppendBytes(data, (UInt8 *) &msg, sizeof(msg));
> - CFDataAppendBytes(data, buffer, length);
> - CFMessagePortSendRequest(messagePort, 0, data, 0.0, 0.0, NULL, NULL);
> - CFRelease(data);
> - }
> - CFRelease(messagePort);
> -}
> -
> static CFDataRef MIDIIn_MessageHandler(CFMessagePortRef local, SInt32 msgid, CFDataRef data, void *info)
> {
> MIDIMessage *msg = NULL;
> --
> 2.23.0
>
>
More information about the wine-devel
mailing list