[PATCH 1/6] winealsa: Combine two loops into one.

Huw Davies huw at codeweavers.com
Tue Mar 15 04:30:40 CDT 2022


Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 dlls/winealsa.drv/midi.c | 38 ++++++++++++++------------------------
 1 file changed, 14 insertions(+), 24 deletions(-)

diff --git a/dlls/winealsa.drv/midi.c b/dlls/winealsa.drv/midi.c
index dff77ce88d8..c90b061da64 100644
--- a/dlls/winealsa.drv/midi.c
+++ b/dlls/winealsa.drv/midi.c
@@ -1263,6 +1263,7 @@ static BOOL ALSA_MidiInit(void)
     static	BOOL	bInitDone = FALSE;
     snd_seq_client_info_t *cinfo;
     snd_seq_port_info_t *pinfo;
+    int external;
 
     if (bInitDone)
 	return TRUE;
@@ -1281,30 +1282,19 @@ static BOOL ALSA_MidiInit(void)
     cinfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, snd_seq_client_info_sizeof() );
     pinfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, snd_seq_port_info_sizeof() );
 
-    /* First, search for all internal midi devices */
-    snd_seq_client_info_set_client(cinfo, -1);
-    while(snd_seq_query_next_client(midiSeq, 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(midiSeq, 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))
-	        ALSA_AddMidiPort(cinfo, pinfo, cap, type);
-	}
-    }
-
-    /* Second, search for all external ports */
-    snd_seq_client_info_set_client(cinfo, -1);
-    while(snd_seq_query_next_client(midiSeq, 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(midiSeq, 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)
-	        ALSA_AddMidiPort(cinfo, pinfo, cap, type);
-	}
+    /* Add internal ports first, followed by external */
+    for (external = 0; external < 2; external++) {
+        snd_seq_client_info_set_client(cinfo, -1);
+        while (snd_seq_query_next_client(midiSeq, 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(midiSeq, pinfo) >= 0) {
+                unsigned int cap = snd_seq_port_info_get_capability(pinfo);
+                unsigned int type = snd_seq_port_info_get_type(pinfo);
+                if (!external == !(type & SND_SEQ_PORT_TYPE_PORT))
+                    ALSA_AddMidiPort(cinfo, pinfo, cap, type);
+            }
+        }
     }
 
     /* close file and exit */
-- 
2.25.1




More information about the wine-devel mailing list