From 9607f81f363e2b74d768908dcb968cb3db3db017 Mon Sep 17 00:00:00 2001 From: Tzim Date: Fri, 30 Jun 2017 10:00:38 +0200 Subject: [PATCH] Preparation : ajout de la possibilite de plusieurs ports seq. Adaptation du MidiEventProvider --- DMX-2.0/AlsaSeqLib.Invoke.cs | 3 +++ DMX-2.0/AlsaSeqLib.cs | 52 ++++++++++++++++++++---------------- DMX-2.0/Main.cs | 6 ++++- DMX-2.0/MidiEventProvider.cs | 16 +++++++---- 4 files changed, 48 insertions(+), 29 deletions(-) diff --git a/DMX-2.0/AlsaSeqLib.Invoke.cs b/DMX-2.0/AlsaSeqLib.Invoke.cs index bdb6be1..a1b0d51 100644 --- a/DMX-2.0/AlsaSeqLib.Invoke.cs +++ b/DMX-2.0/AlsaSeqLib.Invoke.cs @@ -26,6 +26,9 @@ namespace DMX2 [DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)] public static extern int snd_seq_create_simple_port (IntPtr seq, string name, uint caps, uint type); + [DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)] + public static extern int snd_seq_delete_simple_port (IntPtr seq, int port); + [DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)] public static extern int snd_seq_event_input (IntPtr seq, out IntPtr ev); diff --git a/DMX-2.0/AlsaSeqLib.cs b/DMX-2.0/AlsaSeqLib.cs index d03e092..e76c010 100644 --- a/DMX-2.0/AlsaSeqLib.cs +++ b/DMX-2.0/AlsaSeqLib.cs @@ -9,8 +9,8 @@ namespace DMX2 { static SeqHandleWrapper seq_handle = null; static int clientId; - static int inport; - static int outport; + //static int inport; + //static int outport; public class Client @@ -123,17 +123,23 @@ namespace DMX2 seq_handle = new SeqHandleWrapper (); clientId = Invoke.snd_seq_client_id (seq_handle.Handle); + } - outport = inport = Invoke.snd_seq_create_simple_port (seq_handle.Handle, - "midi_in_out", - SND_SEQ_PORT_CAP_WRITE - //+ SND_SEQ_PORT_CAP_SUBS_WRITE - + SND_SEQ_PORT_CAP_READ - + SND_SEQ_PORT_CAP_SUBS_READ - , - SND_SEQ_PORT_TYPE_APPLICATION - ); + public static int CreatePort(string portname){ + return Invoke.snd_seq_create_simple_port (seq_handle.Handle, + portname, + SND_SEQ_PORT_CAP_WRITE + + SND_SEQ_PORT_CAP_SUBS_WRITE + + SND_SEQ_PORT_CAP_READ + + SND_SEQ_PORT_CAP_SUBS_READ + , + SND_SEQ_PORT_TYPE_APPLICATION + ); + } + public static void DeletePort(int port){ + Invoke.snd_seq_delete_simple_port (seq_handle.Handle, + port); } public static void Close () @@ -177,7 +183,7 @@ namespace DMX2 throw new InvalidOperationException (); ev.queue = SND_SEQ_QUEUE_DIRECT; ev.source.client = (byte)clientId; - ev.source.port = (byte)outport; + //ev.source.port = (byte)outport; Marshal.StructureToPtr (ev, evOutPtr.Pointer, false); Invoke.snd_seq_event_output (seq_handle.Handle, evOutPtr.Pointer); Invoke.snd_seq_drain_output (seq_handle.Handle); @@ -228,7 +234,7 @@ namespace DMX2 } } - public static bool Connect (Port port) + public static bool Connect (int localport, Port port) { if (seq_handle == null) throw new InvalidOperationException (); @@ -236,37 +242,37 @@ namespace DMX2 bool isOutput = (port.Caps & SND_SEQ_PORT_CAP_READ) == SND_SEQ_PORT_CAP_READ; if (isInput) - if (!ConnectTo (port.ClientId, port.PortId)) + if (!ConnectTo (localport,port.ClientId, port.PortId)) return false; if (isOutput) - if (!ConnectFrom (port.ClientId, port.PortId)) + if (!ConnectFrom (localport,port.ClientId, port.PortId)) return false; return true; } - public static bool ConnectTo (int client, int port) + public static bool ConnectTo (int localoutport, int client, int port) { if (seq_handle == null) throw new InvalidOperationException (); - return Invoke.snd_seq_connect_to (seq_handle.Handle, outport, client, port) == 0; + return Invoke.snd_seq_connect_to (seq_handle.Handle, localoutport, client, port) == 0; } - public static bool ConnectFrom (int client, int port) + public static bool ConnectFrom (int localinport, int client, int port) { if (seq_handle == null) throw new InvalidOperationException (); - return Invoke.snd_seq_connect_from (seq_handle.Handle, inport, client, port) == 0; + return Invoke.snd_seq_connect_from (seq_handle.Handle, localinport, client, port) == 0; } - public static void Deconnecte (int client, int port) + public static void Deconnecte (int localport, int client, int port) { if (seq_handle == null) throw new InvalidOperationException (); snd_seq_addr_t local = new snd_seq_addr_t (); local.client = (byte)clientId; - local.port = (byte)inport; + local.port = (byte)localport; snd_seq_addr_t addr; using (PointerWrapper subqueryInfo = new PointerWrapper(GetQuerySubscribeInfoSize())) @@ -286,7 +292,7 @@ namespace DMX2 if (addr.client != client || addr.port != port) continue; - Invoke.snd_seq_disconnect_from (seq_handle.Handle, inport, client, port); + Invoke.snd_seq_disconnect_from (seq_handle.Handle, localport, client, port); } @@ -305,7 +311,7 @@ namespace DMX2 if (addr.client != client || addr.port != port) continue; - Invoke.snd_seq_disconnect_to (seq_handle.Handle, outport, client, port); + Invoke.snd_seq_disconnect_to (seq_handle.Handle, localport, client, port); } } diff --git a/DMX-2.0/Main.cs b/DMX-2.0/Main.cs index e2fc5cc..2d74489 100644 --- a/DMX-2.0/Main.cs +++ b/DMX-2.0/Main.cs @@ -60,6 +60,8 @@ namespace DMX2 if (oscEn) osc = new OSCServer (); + AlsaSeqLib.Init (); + // Initialisation GTK# Application.Init (); @@ -117,9 +119,11 @@ namespace DMX2 Conduite.Courante.Dispose (); } - //if(ws!=null) ws.Dispose(); + if(ws!=null) ws.Dispose(); if(osc!=null) osc.Dispose(); + + AlsaSeqLib.Close (); } static void HandleUnhandledException (GLib.UnhandledExceptionArgs args) diff --git a/DMX-2.0/MidiEventProvider.cs b/DMX-2.0/MidiEventProvider.cs index 4301a2c..b7947f6 100644 --- a/DMX-2.0/MidiEventProvider.cs +++ b/DMX-2.0/MidiEventProvider.cs @@ -60,6 +60,8 @@ namespace DMX2 uint pageUpCC = 127; uint pageDownCC = 126; + int eventmidiport; + public uint CurrentPage { get { return page; @@ -157,7 +159,7 @@ namespace DMX2 foreach (int connectedport in dev.ConnectedPorts) { int client = connectedport >> 8; int port = connectedport & 0xFF; - AlsaSeqLib.Deconnecte (client, port); + AlsaSeqLib.Deconnecte (eventmidiport, client, port); } } @@ -183,9 +185,11 @@ namespace DMX2 knowndevices.Add(dev.Name,dev); #endif manager.RegisterProvider (this); - AlsaSeqLib.Init (); + //AlsaSeqLib.Init (); + + eventmidiport = AlsaSeqLib.CreatePort ("event_prov_in_out"); - AlsaSeqLib.ConnectFrom (AlsaSeqLib.SND_SEQ_CLIENT_SYSTEM, AlsaSeqLib.SND_SEQ_PORT_SYSTEM_ANNOUNCE); + AlsaSeqLib.ConnectFrom (eventmidiport,AlsaSeqLib.SND_SEQ_CLIENT_SYSTEM, AlsaSeqLib.SND_SEQ_PORT_SYSTEM_ANNOUNCE); AutoConnect (); } @@ -213,7 +217,7 @@ namespace DMX2 if (knowndevices [fullportname].ConnectedPorts.Contains (srcid)) return; - AlsaSeqLib.Connect (p); + AlsaSeqLib.Connect (eventmidiport,p); } } @@ -271,6 +275,7 @@ namespace DMX2 public void SendEvent (AlsaSeqLib.snd_seq_event_t ev) { + ev.source.port =(byte) eventmidiport; AlsaSeqLib.SendEventToSubscribers (ev); } @@ -594,7 +599,8 @@ namespace DMX2 if (disposed) return; disposed = true; - AlsaSeqLib.Close(); + //AlsaSeqLib.Close(); + AlsaSeqLib.DeletePort(eventmidiport); } #endregion