[PATCH 01/10] winecoreaudio: Move midi_in_open to the unixlib.

Andrew Eikum aeikum at codeweavers.com
Mon Nov 29 09:39:57 CST 2021


Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>

On Mon, Nov 29, 2021 at 11:26:39AM +0000, Huw Davies wrote:
> Signed-off-by: Huw Davies <huw at codeweavers.com>
> ---
>  dlls/winecoreaudio.drv/coreaudio.c |  1 +
>  dlls/winecoreaudio.drv/coremidi.c  | 84 ++++++++++++++++++++++++++++++
>  dlls/winecoreaudio.drv/midi.c      | 64 +++++++----------------
>  dlls/winecoreaudio.drv/unixlib.h   | 13 +++++
>  4 files changed, 116 insertions(+), 46 deletions(-)
> 
> diff --git a/dlls/winecoreaudio.drv/coreaudio.c b/dlls/winecoreaudio.drv/coreaudio.c
> index e90c400102f..b3aa39bf485 100644
> --- a/dlls/winecoreaudio.drv/coreaudio.c
> +++ b/dlls/winecoreaudio.drv/coreaudio.c
> @@ -1632,4 +1632,5 @@ unixlib_entry_t __wine_unix_call_funcs[] =
>      midi_init,
>      midi_release,
>      midi_out_message,
> +    midi_in_message,
>  };
> diff --git a/dlls/winecoreaudio.drv/coremidi.c b/dlls/winecoreaudio.drv/coremidi.c
> index 1ca9ad6eb8e..6a8324f276e 100644
> --- a/dlls/winecoreaudio.drv/coremidi.c
> +++ b/dlls/winecoreaudio.drv/coremidi.c
> @@ -112,6 +112,20 @@ static struct midi_dest *dests;
>  static struct midi_src *srcs;
>  static CFStringRef midi_in_thread_port_name;
>  
> +static void set_in_notify(struct notify_context *notify, struct midi_src *src, 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 = src->midiDesc.dwCallback;
> +    notify->flags = src->wFlags;
> +    notify->device = src->midiDesc.hMidi;
> +    notify->instance = src->midiDesc.dwInstance;
> +}
> +
>  /*
>   *  CoreMIDI IO threaded callback,
>   *  we can't call Wine debug channels, critical section or anything using NtCurrentTeb here.
> @@ -711,6 +725,51 @@ static DWORD midi_out_reset(WORD dev_id)
>      return MMSYSERR_NOERROR;
>  }
>  
> +static DWORD midi_in_open(WORD dev_id, MIDIOPENDESC *midi_desc, DWORD flags, struct notify_context *notify)
> +{
> +    struct midi_src *src;
> +
> +    TRACE("dev_id = %d desc = %p flags = %08x\n", dev_id, midi_desc, flags);
> +
> +    if (!midi_desc)
> +    {
> +        WARN("Invalid Parameter\n");
> +        return MMSYSERR_INVALPARAM;
> +    }
> +    if (dev_id >= num_srcs)
> +    {
> +        WARN("bad device ID : %d\n", dev_id);
> +        return MMSYSERR_BADDEVICEID;
> +    }
> +    src = srcs + dev_id;
> +
> +    if (src->midiDesc.hMidi)
> +    {
> +        WARN("device already open !\n");
> +        return MMSYSERR_ALLOCATED;
> +    }
> +    if (flags & MIDI_IO_STATUS)
> +    {
> +        FIXME("No support for MIDI_IO_STATUS in flags yet, ignoring it\n");
> +        flags &= ~MIDI_IO_STATUS;
> +    }
> +    if (flags & ~CALLBACK_TYPEMASK)
> +    {
> +        FIXME("Bad flags\n");
> +        return MMSYSERR_INVALFLAG;
> +    }
> +
> +    src->wFlags = HIWORD(flags & CALLBACK_TYPEMASK);
> +    src->lpQueueHdr = NULL;
> +    src->midiDesc = *midi_desc;
> +    src->startTime = 0;
> +    src->state = 0;
> +
> +    set_in_notify(notify, src, dev_id, MIM_OPEN, 0, 0);
> +
> +    return MMSYSERR_NOERROR;
> +}
> +
>  NTSTATUS midi_out_message(void *args)
>  {
>      struct midi_out_message_params *params = args;
> @@ -765,3 +824,28 @@ NTSTATUS midi_out_message(void *args)
>  
>      return STATUS_SUCCESS;
>  }
> +
> +NTSTATUS midi_in_message(void *args)
> +{
> +    struct midi_in_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 MIDM_OPEN:
> +        *params->err = midi_in_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 f58dcc2e7a0..4063fe3c10e 100644
> --- a/dlls/winecoreaudio.drv/midi.c
> +++ b/dlls/winecoreaudio.drv/midi.c
> @@ -128,7 +128,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 MIM_OPEN:
>      case MIM_CLOSE:
>      case MIM_DATA:
>      case MIM_LONGDATA:
> @@ -148,41 +147,6 @@ static void MIDI_NotifyClient(UINT wDevID, WORD wMsg, DWORD_PTR dwParam1, DWORD_
>      DriverCallback(dwCallBack, uFlags, hDev, wMsg, dwInstance, dwParam1, dwParam2);
>  }
>  
> -static DWORD MIDIIn_Open(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
> -{
> -    TRACE("wDevID=%d lpDesc=%p dwFlags=%08x\n", wDevID, lpDesc, dwFlags);
> -
> -    if (lpDesc == NULL) {
> -	WARN("Invalid Parameter\n");
> -	return MMSYSERR_INVALPARAM;
> -    }
> -    if (wDevID >= MIDIIn_NumDevs) {
> -        WARN("bad device ID : %d\n", wDevID);
> -	return MMSYSERR_BADDEVICEID;
> -    }
> -    if (sources[wDevID].midiDesc.hMidi != 0) {
> -	WARN("device already open !\n");
> -	return MMSYSERR_ALLOCATED;
> -    }
> -    if ((dwFlags & MIDI_IO_STATUS) != 0) {
> -	WARN("No support for MIDI_IO_STATUS in dwFlags yet, ignoring it\n");
> -	dwFlags &= ~MIDI_IO_STATUS;
> -    }
> -    if ((dwFlags & ~CALLBACK_TYPEMASK) != 0) {
> -	FIXME("Bad dwFlags\n");
> -	return MMSYSERR_INVALFLAG;
> -    }
> -
> -    sources[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
> -    sources[wDevID].lpQueueHdr = NULL;
> -    sources[wDevID].midiDesc = *lpDesc;
> -    sources[wDevID].startTime = 0;
> -    sources[wDevID].state = 0;
> -
> -    MIDI_NotifyClient(wDevID, MIM_OPEN, 0L, 0L);
> -    return MMSYSERR_NOERROR;
> -}
> -
>  static DWORD MIDIIn_Close(WORD wDevID)
>  {
>      DWORD ret = MMSYSERR_NOERROR;
> @@ -520,15 +484,12 @@ DWORD WINAPI CoreAudio_modMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser, DWOR
>  */
>  DWORD WINAPI CoreAudio_midMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
>  {
> +    struct midi_in_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 MIDM_OPEN:
> -            return MIDIIn_Open(wDevID, (LPMIDIOPENDESC)dwParam1, dwParam2);
>          case MIDM_CLOSE:
>              return MIDIIn_Close(wDevID);
>          case MIDM_ADDBUFFER:
> @@ -547,10 +508,21 @@ DWORD WINAPI CoreAudio_midMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser, DWOR
>              return MIDIIn_Stop(wDevID);
>          case MIDM_RESET:
>              return MIDIIn_Reset(wDevID);
> -        default:
> -            TRACE("Unsupported message\n");
>      }
> -    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_in_message, &params);
> +
> +    if (!err && notify.send_notify) notify_client(&notify);
> +
> +    return err;
>  }
>  
>  /**************************************************************************
> diff --git a/dlls/winecoreaudio.drv/unixlib.h b/dlls/winecoreaudio.drv/unixlib.h
> index bdf38b24c88..767309bb763 100644
> --- a/dlls/winecoreaudio.drv/unixlib.h
> +++ b/dlls/winecoreaudio.drv/unixlib.h
> @@ -215,6 +215,17 @@ struct midi_out_message_params
>      struct notify_context *notify;
>  };
>  
> +struct midi_in_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,
> @@ -240,11 +251,13 @@ enum unix_funcs
>      unix_midi_init,
>      unix_midi_release,
>      unix_midi_out_message,
> +    unix_midi_in_message,
>  };
>  
>  NTSTATUS midi_init( void * ) DECLSPEC_HIDDEN;
>  NTSTATUS midi_release( void * ) DECLSPEC_HIDDEN;
>  NTSTATUS midi_out_message( void * ) DECLSPEC_HIDDEN;
> +NTSTATUS midi_in_message( void * ) DECLSPEC_HIDDEN;
>  
>  extern unixlib_handle_t coreaudio_handle;
>  
> -- 
> 2.23.0
> 
> 



More information about the wine-devel mailing list