Signed-off-by: Huw Davies huw@codeweavers.com --- dlls/winealsa.drv/alsa.c | 1 + dlls/winealsa.drv/alsamidi.c | 51 ++++++++++++++++++++++++++++++------ dlls/winealsa.drv/midi.c | 49 ++++++++-------------------------- dlls/winealsa.drv/unixlib.h | 9 +++++++ 4 files changed, 64 insertions(+), 46 deletions(-)
diff --git a/dlls/winealsa.drv/alsa.c b/dlls/winealsa.drv/alsa.c index 76e4b98caaf..16c0c7c387d 100644 --- a/dlls/winealsa.drv/alsa.c +++ b/dlls/winealsa.drv/alsa.c @@ -2447,4 +2447,5 @@ unixlib_entry_t __wine_unix_call_funcs[] = midi_init,
midi_seq_lock, /* temporary */ + midi_seq_open, }; diff --git a/dlls/winealsa.drv/alsamidi.c b/dlls/winealsa.drv/alsamidi.c index 86e092bd977..e1fca85b3b4 100644 --- a/dlls/winealsa.drv/alsamidi.c +++ b/dlls/winealsa.drv/alsamidi.c @@ -55,6 +55,7 @@ static struct midi_dest dests[MAX_MIDIOUTDRV]; static struct midi_src srcs[MAX_MIDIINDRV]; static snd_seq_t *midi_seq; static unsigned int seq_refs; +static int port_in = -1;
static void seq_lock(void) { @@ -74,7 +75,7 @@ NTSTATUS midi_seq_lock(void *args) return STATUS_SUCCESS; }
-static int seq_open(void) +static snd_seq_t *seq_open(int *port_in_ret) { static int midi_warn;
@@ -87,12 +88,28 @@ static int seq_open(void) WARN("Error opening ALSA sequencer.\n"); midi_warn = 1; seq_unlock(); - return -1; + return NULL; } + snd_seq_set_client_name(midi_seq, "WINE midi driver"); } seq_refs++; + + if (port_in_ret) + { + if (port_in < 0) + { + port_in = snd_seq_create_simple_port(midi_seq, "WINE ALSA Input", + SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_READ | SND_SEQ_PORT_CAP_SUBS_WRITE, + SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION); + if (port_in < 0) + TRACE("Unable to create input port\n"); + else + TRACE("Input port %d created successfully\n", port_in); + } + *port_in_ret = port_in; + } seq_unlock(); - return 0; + return midi_seq; }
static void seq_close(void) @@ -100,12 +117,29 @@ static void seq_close(void) seq_lock(); if (--seq_refs == 0) { + if (port_in >= 0) + { + snd_seq_delete_simple_port(midi_seq, port_in); + port_in = -1; + } snd_seq_close(midi_seq); midi_seq = NULL; } seq_unlock(); }
+NTSTATUS midi_seq_open(void *args) +{ + struct midi_seq_open_params *params = args; + + if (!params->close) + params->seq = seq_open(params->port_in); + else + seq_close(); + + return STATUS_SUCCESS; +} + static int alsa_to_win_device_type(unsigned int type) { /* MOD_MIDIPORT output port @@ -270,6 +304,7 @@ NTSTATUS midi_init(void *args) static BOOL init_done; snd_seq_client_info_t *cinfo; snd_seq_port_info_t *pinfo; + snd_seq_t *seq;
if (init_done) { *params->err = ERROR_ALREADY_INITIALIZED; @@ -280,7 +315,7 @@ NTSTATUS midi_init(void *args) init_done = TRUE;
/* try to open device */ - if (seq_open() == -1) { + if (!(seq = seq_open(NULL))) { *params->err = ERROR_OPEN_FAILED; return STATUS_SUCCESS; } @@ -290,10 +325,10 @@ NTSTATUS midi_init(void *args)
/* First, search for all internal midi devices */ snd_seq_client_info_set_client(cinfo, -1); - while (snd_seq_query_next_client(midi_seq, cinfo) >= 0) { + while (snd_seq_query_next_client(seq, cinfo) >= 0) { snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo)); snd_seq_port_info_set_port(pinfo, -1); - while (snd_seq_query_next_port(midi_seq, pinfo) >= 0) { + while (snd_seq_query_next_port(seq, pinfo) >= 0) { unsigned int cap = snd_seq_port_info_get_capability(pinfo); unsigned int type = snd_seq_port_info_get_type(pinfo); if (!(type & SND_SEQ_PORT_TYPE_PORT)) @@ -303,10 +338,10 @@ NTSTATUS midi_init(void *args)
/* Second, search for all external ports */ snd_seq_client_info_set_client(cinfo, -1); - while (snd_seq_query_next_client(midi_seq, cinfo) >= 0) { + while (snd_seq_query_next_client(seq, cinfo) >= 0) { snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo)); snd_seq_port_info_set_port(pinfo, -1); - while (snd_seq_query_next_port(midi_seq, pinfo) >= 0) { + while (snd_seq_query_next_port(seq, pinfo) >= 0) { unsigned int cap = snd_seq_port_info_get_capability(pinfo); unsigned int type = snd_seq_port_info_get_type(pinfo); if (type & SND_SEQ_PORT_TYPE_PORT) diff --git a/dlls/winealsa.drv/midi.c b/dlls/winealsa.drv/midi.c index fae6ddf8615..535f3dbd348 100644 --- a/dlls/winealsa.drv/midi.c +++ b/dlls/winealsa.drv/midi.c @@ -55,12 +55,8 @@ static int MODM_NumDevs = 0; /* this is the total number of MIDI out devices found */ static int MIDM_NumDevs = 0;
-static snd_seq_t* midiSeq = NULL; -static int numOpenMidiSeq = 0; static int numStartedMidiIn = 0;
-static int port_in; - static CRITICAL_SECTION crit_sect; /* protects all MidiIn buffer queues */ static CRITICAL_SECTION_DEBUG critsect_debug = { @@ -152,40 +148,18 @@ static void MIDI_NotifyClient(UINT wDevID, WORD wMsg, DriverCallback(dwCallBack, uFlags, hDev, wMsg, dwInstance, dwParam1, dwParam2); }
-static BOOL midi_warn = TRUE; /************************************************************************** * midiOpenSeq [internal] */ static snd_seq_t *midiOpenSeq(int *port_in_ret) { - seq_lock(); - if (numOpenMidiSeq == 0) { - if (snd_seq_open(&midiSeq, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0) - { - if (midi_warn) - { - WARN("Error opening ALSA sequencer.\n"); - } - midi_warn = FALSE; - seq_unlock(); - return NULL; - } + struct midi_seq_open_params params;
- /* Setting the client name is the only init to do */ - snd_seq_set_client_name(midiSeq, "WINE midi driver"); + params.port_in = port_in_ret; + params.close = 0; + ALSA_CALL(midi_seq_open, ¶ms);
- port_in = snd_seq_create_simple_port(midiSeq, "WINE ALSA Input", - SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_READ|SND_SEQ_PORT_CAP_SUBS_WRITE, - SND_SEQ_PORT_TYPE_MIDI_GENERIC|SND_SEQ_PORT_TYPE_APPLICATION); - if (port_in < 0) - TRACE("Unable to create input port\n"); - else - TRACE("Input port %d created successfully\n", port_in); - } - numOpenMidiSeq++; - seq_unlock(); - if (port_in_ret) *port_in_ret = port_in; - return midiSeq; + return params.seq; }
/************************************************************************** @@ -193,13 +167,12 @@ static snd_seq_t *midiOpenSeq(int *port_in_ret) */ static int midiCloseSeq(void) { - seq_lock(); - if (--numOpenMidiSeq == 0) { - snd_seq_delete_simple_port(midiSeq, port_in); - snd_seq_close(midiSeq); - midiSeq = NULL; - } - seq_unlock(); + struct midi_seq_open_params params; + + params.port_in = NULL; + params.close = 1; + ALSA_CALL(midi_seq_open, ¶ms); + return 0; }
diff --git a/dlls/winealsa.drv/unixlib.h b/dlls/winealsa.drv/unixlib.h index e0ae16b97d9..d69ab980f42 100644 --- a/dlls/winealsa.drv/unixlib.h +++ b/dlls/winealsa.drv/unixlib.h @@ -241,6 +241,13 @@ struct midi_init_params void *dests, *srcs; };
+struct midi_seq_open_params +{ + int close; + snd_seq_t *seq; + int *port_in; +}; + enum alsa_funcs { alsa_get_endpoint_ids, @@ -269,11 +276,13 @@ enum alsa_funcs alsa_midi_init,
alsa_midi_seq_lock, /* temporary */ + alsa_midi_seq_open, };
NTSTATUS midi_init(void *args) DECLSPEC_HIDDEN;
NTSTATUS midi_seq_lock(void *args) DECLSPEC_HIDDEN; +NTSTATUS midi_seq_open(void *args) DECLSPEC_HIDDEN;
extern unixlib_handle_t alsa_handle;
Signed-off-by: Andrew Eikum aeikum@codeweavers.com
On Tue, Mar 15, 2022 at 04:19:01PM +0000, Huw Davies wrote:
Signed-off-by: Huw Davies huw@codeweavers.com
dlls/winealsa.drv/alsa.c | 1 + dlls/winealsa.drv/alsamidi.c | 51 ++++++++++++++++++++++++++++++------ dlls/winealsa.drv/midi.c | 49 ++++++++-------------------------- dlls/winealsa.drv/unixlib.h | 9 +++++++ 4 files changed, 64 insertions(+), 46 deletions(-)
diff --git a/dlls/winealsa.drv/alsa.c b/dlls/winealsa.drv/alsa.c index 76e4b98caaf..16c0c7c387d 100644 --- a/dlls/winealsa.drv/alsa.c +++ b/dlls/winealsa.drv/alsa.c @@ -2447,4 +2447,5 @@ unixlib_entry_t __wine_unix_call_funcs[] = midi_init,
midi_seq_lock, /* temporary */
- midi_seq_open,
}; diff --git a/dlls/winealsa.drv/alsamidi.c b/dlls/winealsa.drv/alsamidi.c index 86e092bd977..e1fca85b3b4 100644 --- a/dlls/winealsa.drv/alsamidi.c +++ b/dlls/winealsa.drv/alsamidi.c @@ -55,6 +55,7 @@ static struct midi_dest dests[MAX_MIDIOUTDRV]; static struct midi_src srcs[MAX_MIDIINDRV]; static snd_seq_t *midi_seq; static unsigned int seq_refs; +static int port_in = -1;
static void seq_lock(void) { @@ -74,7 +75,7 @@ NTSTATUS midi_seq_lock(void *args) return STATUS_SUCCESS; }
-static int seq_open(void) +static snd_seq_t *seq_open(int *port_in_ret) { static int midi_warn;
@@ -87,12 +88,28 @@ static int seq_open(void) WARN("Error opening ALSA sequencer.\n"); midi_warn = 1; seq_unlock();
return -1;
return NULL; }
} seq_refs++;snd_seq_set_client_name(midi_seq, "WINE midi driver");
- if (port_in_ret)
- {
if (port_in < 0)
{
port_in = snd_seq_create_simple_port(midi_seq, "WINE ALSA Input",
SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_READ | SND_SEQ_PORT_CAP_SUBS_WRITE,
SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION);
if (port_in < 0)
TRACE("Unable to create input port\n");
else
TRACE("Input port %d created successfully\n", port_in);
}
*port_in_ret = port_in;
- } seq_unlock();
- return 0;
- return midi_seq;
}
static void seq_close(void) @@ -100,12 +117,29 @@ static void seq_close(void) seq_lock(); if (--seq_refs == 0) {
if (port_in >= 0)
{
snd_seq_delete_simple_port(midi_seq, port_in);
port_in = -1;
} seq_unlock();} snd_seq_close(midi_seq); midi_seq = NULL;
}
+NTSTATUS midi_seq_open(void *args) +{
- struct midi_seq_open_params *params = args;
- if (!params->close)
params->seq = seq_open(params->port_in);
- else
seq_close();
- return STATUS_SUCCESS;
+}
static int alsa_to_win_device_type(unsigned int type) { /* MOD_MIDIPORT output port @@ -270,6 +304,7 @@ NTSTATUS midi_init(void *args) static BOOL init_done; snd_seq_client_info_t *cinfo; snd_seq_port_info_t *pinfo;
snd_seq_t *seq;
if (init_done) { *params->err = ERROR_ALREADY_INITIALIZED;
@@ -280,7 +315,7 @@ NTSTATUS midi_init(void *args) init_done = TRUE;
/* try to open device */
- if (seq_open() == -1) {
- if (!(seq = seq_open(NULL))) { *params->err = ERROR_OPEN_FAILED; return STATUS_SUCCESS; }
@@ -290,10 +325,10 @@ NTSTATUS midi_init(void *args)
/* First, search for all internal midi devices */ snd_seq_client_info_set_client(cinfo, -1);
- while (snd_seq_query_next_client(midi_seq, cinfo) >= 0) {
- while (snd_seq_query_next_client(seq, cinfo) >= 0) { snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo)); snd_seq_port_info_set_port(pinfo, -1);
while (snd_seq_query_next_port(midi_seq, pinfo) >= 0) {
while (snd_seq_query_next_port(seq, pinfo) >= 0) { unsigned int cap = snd_seq_port_info_get_capability(pinfo); unsigned int type = snd_seq_port_info_get_type(pinfo); if (!(type & SND_SEQ_PORT_TYPE_PORT))
@@ -303,10 +338,10 @@ NTSTATUS midi_init(void *args)
/* Second, search for all external ports */ snd_seq_client_info_set_client(cinfo, -1);
- while (snd_seq_query_next_client(midi_seq, cinfo) >= 0) {
- while (snd_seq_query_next_client(seq, cinfo) >= 0) { snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo)); snd_seq_port_info_set_port(pinfo, -1);
while (snd_seq_query_next_port(midi_seq, pinfo) >= 0) {
while (snd_seq_query_next_port(seq, pinfo) >= 0) { unsigned int cap = snd_seq_port_info_get_capability(pinfo); unsigned int type = snd_seq_port_info_get_type(pinfo); if (type & SND_SEQ_PORT_TYPE_PORT)
diff --git a/dlls/winealsa.drv/midi.c b/dlls/winealsa.drv/midi.c index fae6ddf8615..535f3dbd348 100644 --- a/dlls/winealsa.drv/midi.c +++ b/dlls/winealsa.drv/midi.c @@ -55,12 +55,8 @@ static int MODM_NumDevs = 0; /* this is the total number of MIDI out devices found */ static int MIDM_NumDevs = 0;
-static snd_seq_t* midiSeq = NULL; -static int numOpenMidiSeq = 0; static int numStartedMidiIn = 0;
-static int port_in;
static CRITICAL_SECTION crit_sect; /* protects all MidiIn buffer queues */ static CRITICAL_SECTION_DEBUG critsect_debug = { @@ -152,40 +148,18 @@ static void MIDI_NotifyClient(UINT wDevID, WORD wMsg, DriverCallback(dwCallBack, uFlags, hDev, wMsg, dwInstance, dwParam1, dwParam2); }
-static BOOL midi_warn = TRUE; /**************************************************************************
midiOpenSeq [internal]
*/ static snd_seq_t *midiOpenSeq(int *port_in_ret) {
- seq_lock();
- if (numOpenMidiSeq == 0) {
- if (snd_seq_open(&midiSeq, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0)
{
if (midi_warn)
{
WARN("Error opening ALSA sequencer.\n");
}
midi_warn = FALSE;
seq_unlock();
return NULL;
- }
- struct midi_seq_open_params params;
/* Setting the client name is the only init to do */
snd_seq_set_client_name(midiSeq, "WINE midi driver");
- params.port_in = port_in_ret;
- params.close = 0;
- ALSA_CALL(midi_seq_open, ¶ms);
port_in = snd_seq_create_simple_port(midiSeq, "WINE ALSA Input",
SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_READ|SND_SEQ_PORT_CAP_SUBS_WRITE,
SND_SEQ_PORT_TYPE_MIDI_GENERIC|SND_SEQ_PORT_TYPE_APPLICATION);
if (port_in < 0)
TRACE("Unable to create input port\n");
else
TRACE("Input port %d created successfully\n", port_in);
- }
- numOpenMidiSeq++;
- seq_unlock();
- if (port_in_ret) *port_in_ret = port_in;
- return midiSeq;
- return params.seq;
}
/************************************************************************** @@ -193,13 +167,12 @@ static snd_seq_t *midiOpenSeq(int *port_in_ret) */ static int midiCloseSeq(void) {
- seq_lock();
- if (--numOpenMidiSeq == 0) {
- snd_seq_delete_simple_port(midiSeq, port_in);
- snd_seq_close(midiSeq);
- midiSeq = NULL;
- }
- seq_unlock();
- struct midi_seq_open_params params;
- params.port_in = NULL;
- params.close = 1;
- ALSA_CALL(midi_seq_open, ¶ms);
- return 0;
}
diff --git a/dlls/winealsa.drv/unixlib.h b/dlls/winealsa.drv/unixlib.h index e0ae16b97d9..d69ab980f42 100644 --- a/dlls/winealsa.drv/unixlib.h +++ b/dlls/winealsa.drv/unixlib.h @@ -241,6 +241,13 @@ struct midi_init_params void *dests, *srcs; };
+struct midi_seq_open_params +{
- int close;
- snd_seq_t *seq;
- int *port_in;
+};
enum alsa_funcs { alsa_get_endpoint_ids, @@ -269,11 +276,13 @@ enum alsa_funcs alsa_midi_init,
alsa_midi_seq_lock, /* temporary */
- alsa_midi_seq_open,
};
NTSTATUS midi_init(void *args) DECLSPEC_HIDDEN;
NTSTATUS midi_seq_lock(void *args) DECLSPEC_HIDDEN; +NTSTATUS midi_seq_open(void *args) DECLSPEC_HIDDEN;
extern unixlib_handle_t alsa_handle;
-- 2.25.1