From 404f9685871df5400fb4cd940b22ed8292a03689 Mon Sep 17 00:00:00 2001 From: Tzim Date: Wed, 5 Jul 2017 17:02:31 +0200 Subject: [PATCH] Ajout MidiPort --- DMX-2.0/AlsaSeqLib.MidiPort.cs | 129 ++++++++++++++++++++++ DMX-2.0/AlsaSeqLib.Wrappers.cs | 4 +- DMX-2.0/AlsaSeqLib.cs | 191 ++++++++------------------------- DMX-2.0/DMX-2.0.csproj | 1 + DMX-2.0/GestionMidiUI.cs | 10 +- DMX-2.0/Main.cs | 2 +- DMX-2.0/MidiEventProvider.cs | 41 +++---- DMX-2.0/SequenceurMidi.cs | 18 ++-- 8 files changed, 208 insertions(+), 188 deletions(-) create mode 100644 DMX-2.0/AlsaSeqLib.MidiPort.cs diff --git a/DMX-2.0/AlsaSeqLib.MidiPort.cs b/DMX-2.0/AlsaSeqLib.MidiPort.cs new file mode 100644 index 0000000..db700d1 --- /dev/null +++ b/DMX-2.0/AlsaSeqLib.MidiPort.cs @@ -0,0 +1,129 @@ +using System; +using System.Runtime.InteropServices; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Collections.Concurrent; + +namespace DMX2 +{ + public static partial class AlsaSeqLib + { public class MidiPort : IDisposable + { + internal ConcurrentQueue eventqueue = new ConcurrentQueue (); + + internal int portid; + public MidiPort(string portname){ + portid=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 + ); + openports[portid]=this; + } + + bool closed = false; + public void Close() + { + if (closed) + return; + closed = true; + + Invoke.snd_seq_delete_simple_port (seq_handle.Handle, + portid); + + if(openports.ContainsKey(portid)) + if (openports [portid] == this) + openports.Remove (portid); + } + + void IDisposable.Dispose(){ + Close (); + } + + public void SendEvent(snd_seq_event_t ev){ + if (seq_handle == null) + throw new InvalidOperationException (); + + ev.source.client = (byte)clientId; + ev.source.port = (byte)portid; + ev.dest.client = SND_SEQ_ADDRESS_SUBSCRIBERS; + ev.dest.port = SND_SEQ_ADDRESS_UNKNOWN; + ev.queue = SND_SEQ_QUEUE_DIRECT; + + Marshal.StructureToPtr (ev, evOutPtr.Pointer, false); + Invoke.snd_seq_event_output (seq_handle.Handle, evOutPtr.Pointer); + Invoke.snd_seq_drain_output (seq_handle.Handle); + + } + + public bool GetEvent(out snd_seq_event_t ev){ + return eventqueue.TryDequeue (out ev); + } + + public bool ConnectTo(Port p){ + if (seq_handle == null) + throw new InvalidOperationException (); + return Invoke.snd_seq_connect_to (seq_handle.Handle, portid, p.ClientId, p.PortId) == 0; + } + + internal bool ConnectTo(int client, int port){ + if (seq_handle == null) + throw new InvalidOperationException (); + return Invoke.snd_seq_connect_to (seq_handle.Handle, portid, client, port) == 0; + } + + public bool ConnectFrom(Port p){ + if (seq_handle == null) + throw new InvalidOperationException (); + return Invoke.snd_seq_connect_from (seq_handle.Handle, portid, p.ClientId, p.PortId) == 0; + } + + public void Deconnecte(Port p){ + if (seq_handle == null) + throw new InvalidOperationException (); + snd_seq_addr_t local = new snd_seq_addr_t (); + local.client = (byte)clientId; + local.port = (byte)portid; + + snd_seq_addr_t addr; + using (PointerWrapper subqueryInfo = new PointerWrapper(GetQuerySubscribeInfoSize())) + using (PointerWrapper localAddr =new PointerWrapper(local.SndSeqAddrToPtr())) { + Invoke.snd_seq_query_subscribe_set_root (subqueryInfo.Pointer, localAddr.Pointer); + Invoke.snd_seq_query_subscribe_set_type (subqueryInfo.Pointer, SND_SEQ_QUERY_SUBS_WRITE); + + for (Invoke.snd_seq_query_subscribe_set_index(subqueryInfo.Pointer,0); + Invoke.snd_seq_query_port_subscribers (seq_handle.Handle,subqueryInfo.Pointer)>=0; + Invoke.snd_seq_query_subscribe_set_index(subqueryInfo.Pointer, + Invoke.snd_seq_query_subscribe_get_index(subqueryInfo.Pointer) +1) + ) { + addr = Invoke.snd_seq_query_subscribe_get_addr (subqueryInfo.Pointer).PtrToSndSeqAddr (); + + if (addr.client != p.ClientId || addr.port != p.PortId) + continue; + + Invoke.snd_seq_disconnect_from (seq_handle.Handle, portid, p.ClientId, p.PortId); + } + + Invoke.snd_seq_query_subscribe_set_type (subqueryInfo.Pointer, SND_SEQ_QUERY_SUBS_READ); + + for (Invoke.snd_seq_query_subscribe_set_index(subqueryInfo.Pointer,0); + Invoke.snd_seq_query_port_subscribers (seq_handle.Handle,subqueryInfo.Pointer)>=0; + Invoke.snd_seq_query_subscribe_set_index(subqueryInfo.Pointer, + Invoke.snd_seq_query_subscribe_get_index(subqueryInfo.Pointer) +1) + ) { + addr = Invoke.snd_seq_query_subscribe_get_addr (subqueryInfo.Pointer).PtrToSndSeqAddr (); + if (addr.client != p.ClientId || addr.port != p.PortId) + continue; + Invoke.snd_seq_disconnect_to (seq_handle.Handle, portid, p.ClientId, p.PortId); + } + } + } + + + } + } +} diff --git a/DMX-2.0/AlsaSeqLib.Wrappers.cs b/DMX-2.0/AlsaSeqLib.Wrappers.cs index 58e145d..eb396e8 100644 --- a/DMX-2.0/AlsaSeqLib.Wrappers.cs +++ b/DMX-2.0/AlsaSeqLib.Wrappers.cs @@ -15,10 +15,10 @@ namespace DMX2 } } - public SeqHandleWrapper () + public SeqHandleWrapper (string appname) { Invoke.snd_seq_open (out _seq, "default", SND_SEQ_OPEN_DUPLEX, 0); - Invoke.snd_seq_set_client_name (_seq, "Loupiottes"); + Invoke.snd_seq_set_client_name (_seq, appname); } ~SeqHandleWrapper () diff --git a/DMX-2.0/AlsaSeqLib.cs b/DMX-2.0/AlsaSeqLib.cs index e76c010..c3fa9e1 100644 --- a/DMX-2.0/AlsaSeqLib.cs +++ b/DMX-2.0/AlsaSeqLib.cs @@ -12,6 +12,10 @@ namespace DMX2 //static int inport; //static int outport; + static System.Threading.Thread eventthread=null; + static MidiPort systemPort=null; + + static internal Dictionary openports = new Dictionary(); public class Client { @@ -61,11 +65,12 @@ namespace DMX2 } } - public static int ClientId { + /*public static int ClientId { get { return clientId; } - } + }*/ + public class Port { int portId; @@ -115,31 +120,20 @@ namespace DMX2 } } - public static void Init () + public static void Init (string appname) { if (seq_handle != null) return; - seq_handle = new SeqHandleWrapper (); + seq_handle = new SeqHandleWrapper (appname); clientId = Invoke.snd_seq_client_id (seq_handle.Handle); - } - 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 - ); - } + System.Threading.ThreadStart ts = new System.Threading.ThreadStart (EventLoop); + eventthread = new System.Threading.Thread (ts); - public static void DeletePort(int port){ - Invoke.snd_seq_delete_simple_port (seq_handle.Handle, - port); + systemPort = new MidiPort ("system"); + systemPort.ConnectTo (SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE); } public static void Close () @@ -150,7 +144,34 @@ namespace DMX2 seq_handle = null; } - public static bool GetEvent (out snd_seq_event_t ev) + public static void EventLoop(){ + snd_seq_event_t ev = new snd_seq_event_t ();; + while (seq_handle != null) { + while (seq_handle != null && Invoke.snd_seq_event_input_pending (seq_handle.Handle, 1) > 0) { + IntPtr evPtr; + // Recup du pointeur vers l'ev + Invoke.snd_seq_event_input (seq_handle.Handle, out evPtr); + // Copie de la zone mémoire dans une structure managee + ev = (snd_seq_event_t)Marshal.PtrToStructure (evPtr, typeof(snd_seq_event_t)); + // liberation du pointeur + Invoke.snd_seq_free_event (evPtr); + + if (ev.dest.port == systemPort.portid) { + if (ev.type == AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_PORT_START) { + + } + } else { + // queue + if (openports.ContainsKey (ev.dest.port)) { + openports [ev.dest.port].eventqueue.Enqueue (ev); + } + } + } + System.Threading.Thread.Sleep (1); + } + } + + /*static bool GetEvent (out snd_seq_event_t ev) { if (seq_handle == null) throw new InvalidOperationException (); @@ -173,32 +194,11 @@ namespace DMX2 return true; - } + }*/ static PointerWrapper evOutPtr = new PointerWrapper (32); - public static void SendEvent (snd_seq_event_t ev) - { - if (seq_handle == null) - throw new InvalidOperationException (); - ev.queue = SND_SEQ_QUEUE_DIRECT; - ev.source.client = (byte)clientId; - //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); - } - - public static void SendEventToSubscribers (snd_seq_event_t ev) - { - if (seq_handle == null) - throw new InvalidOperationException (); - ev.dest.client = SND_SEQ_ADDRESS_SUBSCRIBERS; - ev.dest.port = SND_SEQ_ADDRESS_UNKNOWN; - SendEvent (ev); - } - - public static IEnumerable EnumClients () + static IEnumerable EnumClients () { if (seq_handle == null) throw new InvalidOperationException (); @@ -210,7 +210,7 @@ namespace DMX2 } } - public static Client GetClientByID (int client) + static Client GetClientByID (int client) { if (seq_handle == null) throw new InvalidOperationException (); @@ -222,7 +222,7 @@ namespace DMX2 } } - public static Port GetPortByIDs (int client, int port) + static Port GetPortByIDs (int client, int port) { if (seq_handle == null) throw new InvalidOperationException (); @@ -234,107 +234,6 @@ namespace DMX2 } } - public static bool Connect (int localport, Port port) - { - if (seq_handle == null) - throw new InvalidOperationException (); - bool isInput = (port.Caps & SND_SEQ_PORT_CAP_WRITE) == SND_SEQ_PORT_CAP_WRITE; - bool isOutput = (port.Caps & SND_SEQ_PORT_CAP_READ) == SND_SEQ_PORT_CAP_READ; - - if (isInput) - if (!ConnectTo (localport,port.ClientId, port.PortId)) - return false; - - if (isOutput) - if (!ConnectFrom (localport,port.ClientId, port.PortId)) - return false; - - return true; - } - - 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, localoutport, client, port) == 0; - } - - 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, localinport, client, port) == 0; - } - - 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)localport; - - snd_seq_addr_t addr; - using (PointerWrapper subqueryInfo = new PointerWrapper(GetQuerySubscribeInfoSize())) - using (PointerWrapper localAddr =new PointerWrapper(local.SndSeqAddrToPtr())) { - Invoke.snd_seq_query_subscribe_set_root (subqueryInfo.Pointer, localAddr.Pointer); - Invoke.snd_seq_query_subscribe_set_type (subqueryInfo.Pointer, SND_SEQ_QUERY_SUBS_WRITE); - - for (Invoke.snd_seq_query_subscribe_set_index(subqueryInfo.Pointer,0); - Invoke.snd_seq_query_port_subscribers (seq_handle.Handle,subqueryInfo.Pointer)>=0; - Invoke.snd_seq_query_subscribe_set_index(subqueryInfo.Pointer, - Invoke.snd_seq_query_subscribe_get_index(subqueryInfo.Pointer) +1) - ) { - - //root = Invoke.snd_seq_query_subscribe_get_root(subqueryInfo.Pointer).PtrToSndSeqAddr(); - addr = Invoke.snd_seq_query_subscribe_get_addr (subqueryInfo.Pointer).PtrToSndSeqAddr (); - - if (addr.client != client || addr.port != port) - continue; - - Invoke.snd_seq_disconnect_from (seq_handle.Handle, localport, client, port); - - - } - - Invoke.snd_seq_query_subscribe_set_type (subqueryInfo.Pointer, SND_SEQ_QUERY_SUBS_READ); - - for (Invoke.snd_seq_query_subscribe_set_index(subqueryInfo.Pointer,0); - Invoke.snd_seq_query_port_subscribers (seq_handle.Handle,subqueryInfo.Pointer)>=0; - Invoke.snd_seq_query_subscribe_set_index(subqueryInfo.Pointer, - Invoke.snd_seq_query_subscribe_get_index(subqueryInfo.Pointer) +1) - ) { - - //root = Invoke.snd_seq_query_subscribe_get_root(subqueryInfo.Pointer).PtrToSndSeqAddr(); - addr = Invoke.snd_seq_query_subscribe_get_addr (subqueryInfo.Pointer).PtrToSndSeqAddr (); - - if (addr.client != client || addr.port != port) - continue; - - Invoke.snd_seq_disconnect_to (seq_handle.Handle, localport, client, port); - } - } - - } - - - /* - public static void GetConnections() - { - using(PointerWrapper subscribeInfo = new PointerWrapper(GetQuerySubscribeInfoSize())){ - int index=0; - Invoke.snd_seq_query_subscribe_set_client (subscribeInfo.Pointer,clientId); - Invoke.snd_seq_query_subscribe_set_port (subscribeInfo.Pointer,inport); - Invoke.snd_seq_query_subscribe_set_index(subscribeInfo.Pointer,index++); - Invoke.snd_seq_query_subscribe_set_type(subscribeInfo.Pointer,SND_SEQ_QUERY_SUBS_WRITE); - - while (Invoke.snd_seq_query_port_subscribers(seq_handle.Handle,subscribeInfo.Pointer) ==0){ - - //Console.WriteLine("Remote => {0}:{1}",rclient,rport); - Invoke.snd_seq_query_subscribe_set_index(subscribeInfo.Pointer,index++); - } - } - }*/ } } diff --git a/DMX-2.0/DMX-2.0.csproj b/DMX-2.0/DMX-2.0.csproj index 82cd163..6578677 100644 --- a/DMX-2.0/DMX-2.0.csproj +++ b/DMX-2.0/DMX-2.0.csproj @@ -148,6 +148,7 @@ + diff --git a/DMX-2.0/GestionMidiUI.cs b/DMX-2.0/GestionMidiUI.cs index 80afa71..45c6736 100644 --- a/DMX-2.0/GestionMidiUI.cs +++ b/DMX-2.0/GestionMidiUI.cs @@ -16,7 +16,7 @@ namespace DMX2 this.Build (); lsDetect = new Gtk.ListStore (typeof(string)); - lsKnown = new Gtk.ListStore (typeof(MidiEventProvider.MidiDevice)); + lsKnown = new Gtk.ListStore (typeof(MidiEventProvider.MidiControler)); var nameCol = new Gtk.TreeViewColumn (); @@ -81,7 +81,7 @@ namespace DMX2 void RenderMidiDev (Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel tree_model, Gtk.TreeIter iter) { - MidiEventProvider.MidiDevice dev = tree_model.GetValue (iter, 0) as MidiEventProvider.MidiDevice; + MidiEventProvider.MidiControler dev = tree_model.GetValue (iter, 0) as MidiEventProvider.MidiControler; (cell as Gtk.CellRendererText).Text = dev.ConnectedPorts.Count>0 ?string.Format("{0} ({1} connectés)",dev.Name,dev.ConnectedPorts.Count) :string.Format("{0} (Déconnecté)",dev.Name); @@ -124,7 +124,7 @@ namespace DMX2 chkFB.Sensitive = btnDesactiv.Sensitive = (listKnown.Selection.CountSelectedRows() >0); TreeIter iter; if(!listKnown.Selection.GetSelected(out iter)) return; - MidiEventProvider.MidiDevice dev = lsKnown.GetValue(iter,0) as MidiEventProvider.MidiDevice ; + MidiEventProvider.MidiControler dev = lsKnown.GetValue(iter,0) as MidiEventProvider.MidiControler ; chkFB.Active = dev.HasFeedback; } @@ -144,7 +144,7 @@ namespace DMX2 { TreeIter iter; if(!listKnown.Selection.GetSelected(out iter)) return; - MidiEventProvider.MidiDevice dev = lsKnown.GetValue(iter,0) as MidiEventProvider.MidiDevice ; + MidiEventProvider.MidiControler dev = lsKnown.GetValue(iter,0) as MidiEventProvider.MidiControler ; Conduite.Courante.Midi.DisconnectDevice(dev); FillLsDetect () ; FillLsKnown(); @@ -156,7 +156,7 @@ namespace DMX2 { TreeIter iter; if(!listKnown.Selection.GetSelected(out iter)) return; - MidiEventProvider.MidiDevice dev = lsKnown.GetValue(iter,0) as MidiEventProvider.MidiDevice ; + MidiEventProvider.MidiControler dev = lsKnown.GetValue(iter,0) as MidiEventProvider.MidiControler ; dev.HasFeedback = chkFB.Active; Conduite.Courante.Midi.RefreshFeedback(dev.Name); diff --git a/DMX-2.0/Main.cs b/DMX-2.0/Main.cs index 2d74489..6a82a77 100644 --- a/DMX-2.0/Main.cs +++ b/DMX-2.0/Main.cs @@ -60,7 +60,7 @@ namespace DMX2 if (oscEn) osc = new OSCServer (); - AlsaSeqLib.Init (); + AlsaSeqLib.Init ("Loupiottes"); // Initialisation GTK# Application.Init (); diff --git a/DMX-2.0/MidiEventProvider.cs b/DMX-2.0/MidiEventProvider.cs index b7947f6..ba0ee8e 100644 --- a/DMX-2.0/MidiEventProvider.cs +++ b/DMX-2.0/MidiEventProvider.cs @@ -33,7 +33,7 @@ namespace DMX2 /// /// Liste des peripheriques connus (presents ou non) /// - readonly Dictionary knowndevices = new Dictionary (); + readonly Dictionary knowndevices = new Dictionary (); /// /// Liste des ports connectés avec feedback @@ -60,7 +60,7 @@ namespace DMX2 uint pageUpCC = 127; uint pageDownCC = 126; - int eventmidiport; + AlsaSeqLib.MidiPort midiport; public uint CurrentPage { get { @@ -133,7 +133,7 @@ namespace DMX2 public void ConnectDevice (string name) { - knowndevices.Add (name, new MidiDevice (name)); + knowndevices.Add (name, new MidiControler (name)); AutoConnect (); } @@ -150,7 +150,7 @@ namespace DMX2 } } - public void DisconnectDevice (MidiEventProvider.MidiDevice dev) + public void DisconnectDevice (MidiEventProvider.MidiControler dev) { if (!knowndevices.ContainsKey (dev.Name)) return; @@ -168,7 +168,7 @@ namespace DMX2 return knowndevices.ContainsKey (name); } - public IEnumerable KnownDevices { + public IEnumerable KnownDevices { get { return knowndevices.Values; } @@ -177,20 +177,18 @@ namespace DMX2 public MidiEventProvider (EventManager manager) { #if DEBUG - MidiDevice dev = new MidiDevice("VMPK Input:VMPK Input"); + MidiControler dev = new MidiControler("VMPK Input:VMPK Input"); dev.HasFeedback = true; knowndevices.Add(dev.Name,dev); - dev = new MidiDevice("VMPK Output:VMPK Output"); + dev = new MidiControler("VMPK Output:VMPK Output"); dev.HasFeedback = true; knowndevices.Add(dev.Name,dev); #endif manager.RegisterProvider (this); //AlsaSeqLib.Init (); - eventmidiport = AlsaSeqLib.CreatePort ("event_prov_in_out"); + midiport = new AlsaSeqLib.MidiPort("event_prov_in_out"); - AlsaSeqLib.ConnectFrom (eventmidiport,AlsaSeqLib.SND_SEQ_CLIENT_SYSTEM, AlsaSeqLib.SND_SEQ_PORT_SYSTEM_ANNOUNCE); - AutoConnect (); } @@ -275,8 +273,7 @@ namespace DMX2 public void SendEvent (AlsaSeqLib.snd_seq_event_t ev) { - ev.source.port =(byte) eventmidiport; - AlsaSeqLib.SendEventToSubscribers (ev); + midiport.SendEvent (ev); } public void Refresh () @@ -378,7 +375,7 @@ namespace DMX2 uint evpage; // Tant qu'il y des evenements midi en attente - while (AlsaSeqLib.GetEvent(out evS)) { + while (midiport.GetEvent(out evS)) { Console.WriteLine(string.Format ("event {0}", evS.type) ); string id = null; int value = 0; @@ -444,12 +441,7 @@ namespace DMX2 case AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_PGMCHANGE: CurrentPage = (uint)evS.data_ev_ctrl.value; continue; - case AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_PORT_START: - PortDetected ( - AlsaSeqLib.GetClientByID (evS.data_addr.client), - AlsaSeqLib.GetPortByIDs (evS.data_addr.client, evS.data_addr.port) - ); - continue; + /*case AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_CLOCK: case AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_SENSING: @@ -600,7 +592,8 @@ namespace DMX2 return; disposed = true; //AlsaSeqLib.Close(); - AlsaSeqLib.DeletePort(eventmidiport); + midiport.Close(); + } #endregion @@ -615,7 +608,7 @@ namespace DMX2 el.SetAttribute ("max14b", max14bValue.ToString ()); System.Xml.XmlElement xmlEl; - foreach (MidiDevice dev in knowndevices.Values) { + foreach (MidiControler dev in knowndevices.Values) { el.AppendChild (xmlEl = parent.OwnerDocument.CreateElement ("MidiDev")); xmlEl.SetAttribute ("name", dev.Name); xmlEl.SetAttribute ("feedback", dev.HasFeedback.ToString ()); @@ -642,7 +635,7 @@ namespace DMX2 System.Xml.XmlElement xdev = xd as System.Xml.XmlElement; string name = xdev.GetAttribute ("name"); if (!knowndevices.ContainsKey (name)) - knowndevices.Add (name, new MidiDevice (name)); + knowndevices.Add (name, new MidiControler (name)); knowndevices [name].HasFeedback = bool.Parse (xdev.TryGetAttribute ("feedback", "false")); } unpaginatedchannels.Clear (); @@ -813,7 +806,7 @@ namespace DMX2 #endregion } - public class MidiDevice + public class MidiControler { string name; @@ -827,7 +820,7 @@ namespace DMX2 get{ return connected;} } - public MidiDevice (string _name) + public MidiControler (string _name) { name = _name; } diff --git a/DMX-2.0/SequenceurMidi.cs b/DMX-2.0/SequenceurMidi.cs index 39f6578..a5c2e2a 100644 --- a/DMX-2.0/SequenceurMidi.cs +++ b/DMX-2.0/SequenceurMidi.cs @@ -104,7 +104,8 @@ namespace DMX2 bool paused=false; - int midiport=-1; + + AlsaSeqLib.MidiPort midiport; static int portnum=0; List mididests = new List(); @@ -148,7 +149,7 @@ namespace DMX2 } ); string portname = string.Format ("midi_seq_{0}", portnum++); - midiport = AlsaSeqLib.CreatePort (portname); + midiport = new AlsaSeqLib.MidiPort (portname); } bool disposed=false; @@ -161,7 +162,7 @@ namespace DMX2 if (disposed) return; disposed = true; - AlsaSeqLib.DeletePort (midiport); + midiport.Close (); } public int IndexLigneEnCours @@ -173,7 +174,7 @@ namespace DMX2 } public void Connect (AlsaSeqLib.Port port){ - AlsaSeqLib.ConnectTo (midiport, port.ClientId, port.PortId); + midiport.ConnectTo (port); } public int IndexLigneaSuivre @@ -334,8 +335,7 @@ namespace DMX2 ev.data_ev_ctrl.channel = (byte)midiCh; ev.data_ev_ctrl.param = uint.Parse (match.Groups [4].Value); ev.data_ev_ctrl.value = int.Parse (match.Groups [5].Value); - ev.source.port = (byte)midiport; - AlsaSeqLib.SendEventToSubscribers (ev); + midiport.SendEvent (ev); } if (match.Groups [7].Success) { @@ -343,8 +343,7 @@ namespace DMX2 ev.type = AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_PGMCHANGE; ev.data_ev_ctrl.channel = (byte)midiCh; ev.data_ev_ctrl.value = int.Parse (match.Groups [7].Value); - ev.source.port = (byte)midiport; - AlsaSeqLib.SendEventToSubscribers (ev); + midiport.SendEvent (ev); } if (match.Groups [9].Success) { @@ -365,8 +364,7 @@ namespace DMX2 else ev.data_ev_note.off_velocity = 0; } - ev.source.port = (byte)midiport; - AlsaSeqLib.SendEventToSubscribers (ev); + midiport.SendEvent (ev); } } }