Preparation : ajout de la possibilite de plusieurs ports seq.

Adaptation du MidiEventProvider
This commit is contained in:
Tzim 2017-06-30 10:00:38 +02:00
parent 33414c463f
commit 9607f81f36
4 changed files with 48 additions and 29 deletions

View file

@ -26,6 +26,9 @@ namespace DMX2
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)] [DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_create_simple_port (IntPtr seq, string name, uint caps, uint type); 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)] [DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_event_input (IntPtr seq, out IntPtr ev); public static extern int snd_seq_event_input (IntPtr seq, out IntPtr ev);

View file

@ -9,8 +9,8 @@ namespace DMX2
{ {
static SeqHandleWrapper seq_handle = null; static SeqHandleWrapper seq_handle = null;
static int clientId; static int clientId;
static int inport; //static int inport;
static int outport; //static int outport;
public class Client public class Client
@ -123,17 +123,23 @@ namespace DMX2
seq_handle = new SeqHandleWrapper (); seq_handle = new SeqHandleWrapper ();
clientId = Invoke.snd_seq_client_id (seq_handle.Handle); clientId = Invoke.snd_seq_client_id (seq_handle.Handle);
}
outport = inport = Invoke.snd_seq_create_simple_port (seq_handle.Handle, public static int CreatePort(string portname){
"midi_in_out", return Invoke.snd_seq_create_simple_port (seq_handle.Handle,
SND_SEQ_PORT_CAP_WRITE portname,
//+ SND_SEQ_PORT_CAP_SUBS_WRITE SND_SEQ_PORT_CAP_WRITE
+ SND_SEQ_PORT_CAP_READ + SND_SEQ_PORT_CAP_SUBS_WRITE
+ SND_SEQ_PORT_CAP_SUBS_READ + SND_SEQ_PORT_CAP_READ
, + SND_SEQ_PORT_CAP_SUBS_READ
SND_SEQ_PORT_TYPE_APPLICATION ,
); 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 () public static void Close ()
@ -177,7 +183,7 @@ namespace DMX2
throw new InvalidOperationException (); throw new InvalidOperationException ();
ev.queue = SND_SEQ_QUEUE_DIRECT; ev.queue = SND_SEQ_QUEUE_DIRECT;
ev.source.client = (byte)clientId; ev.source.client = (byte)clientId;
ev.source.port = (byte)outport; //ev.source.port = (byte)outport;
Marshal.StructureToPtr (ev, evOutPtr.Pointer, false); Marshal.StructureToPtr (ev, evOutPtr.Pointer, false);
Invoke.snd_seq_event_output (seq_handle.Handle, evOutPtr.Pointer); Invoke.snd_seq_event_output (seq_handle.Handle, evOutPtr.Pointer);
Invoke.snd_seq_drain_output (seq_handle.Handle); 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) if (seq_handle == null)
throw new InvalidOperationException (); throw new InvalidOperationException ();
@ -236,37 +242,37 @@ namespace DMX2
bool isOutput = (port.Caps & SND_SEQ_PORT_CAP_READ) == SND_SEQ_PORT_CAP_READ; bool isOutput = (port.Caps & SND_SEQ_PORT_CAP_READ) == SND_SEQ_PORT_CAP_READ;
if (isInput) if (isInput)
if (!ConnectTo (port.ClientId, port.PortId)) if (!ConnectTo (localport,port.ClientId, port.PortId))
return false; return false;
if (isOutput) if (isOutput)
if (!ConnectFrom (port.ClientId, port.PortId)) if (!ConnectFrom (localport,port.ClientId, port.PortId))
return false; return false;
return true; return true;
} }
public static bool ConnectTo (int client, int port) public static bool ConnectTo (int localoutport, int client, int port)
{ {
if (seq_handle == null) if (seq_handle == null)
throw new InvalidOperationException (); 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) if (seq_handle == null)
throw new InvalidOperationException (); 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) if (seq_handle == null)
throw new InvalidOperationException (); throw new InvalidOperationException ();
snd_seq_addr_t local = new snd_seq_addr_t (); snd_seq_addr_t local = new snd_seq_addr_t ();
local.client = (byte)clientId; local.client = (byte)clientId;
local.port = (byte)inport; local.port = (byte)localport;
snd_seq_addr_t addr; snd_seq_addr_t addr;
using (PointerWrapper subqueryInfo = new PointerWrapper(GetQuerySubscribeInfoSize())) using (PointerWrapper subqueryInfo = new PointerWrapper(GetQuerySubscribeInfoSize()))
@ -286,7 +292,7 @@ namespace DMX2
if (addr.client != client || addr.port != port) if (addr.client != client || addr.port != port)
continue; 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) if (addr.client != client || addr.port != port)
continue; continue;
Invoke.snd_seq_disconnect_to (seq_handle.Handle, outport, client, port); Invoke.snd_seq_disconnect_to (seq_handle.Handle, localport, client, port);
} }
} }

View file

@ -60,6 +60,8 @@ namespace DMX2
if (oscEn) if (oscEn)
osc = new OSCServer (); osc = new OSCServer ();
AlsaSeqLib.Init ();
// Initialisation GTK# // Initialisation GTK#
Application.Init (); Application.Init ();
@ -117,9 +119,11 @@ namespace DMX2
Conduite.Courante.Dispose (); Conduite.Courante.Dispose ();
} }
//if(ws!=null) ws.Dispose(); if(ws!=null) ws.Dispose();
if(osc!=null) osc.Dispose(); if(osc!=null) osc.Dispose();
AlsaSeqLib.Close ();
} }
static void HandleUnhandledException (GLib.UnhandledExceptionArgs args) static void HandleUnhandledException (GLib.UnhandledExceptionArgs args)

View file

@ -60,6 +60,8 @@ namespace DMX2
uint pageUpCC = 127; uint pageUpCC = 127;
uint pageDownCC = 126; uint pageDownCC = 126;
int eventmidiport;
public uint CurrentPage { public uint CurrentPage {
get { get {
return page; return page;
@ -157,7 +159,7 @@ namespace DMX2
foreach (int connectedport in dev.ConnectedPorts) { foreach (int connectedport in dev.ConnectedPorts) {
int client = connectedport >> 8; int client = connectedport >> 8;
int port = connectedport & 0xFF; int port = connectedport & 0xFF;
AlsaSeqLib.Deconnecte (client, port); AlsaSeqLib.Deconnecte (eventmidiport, client, port);
} }
} }
@ -183,9 +185,11 @@ namespace DMX2
knowndevices.Add(dev.Name,dev); knowndevices.Add(dev.Name,dev);
#endif #endif
manager.RegisterProvider (this); manager.RegisterProvider (this);
AlsaSeqLib.Init (); //AlsaSeqLib.Init ();
AlsaSeqLib.ConnectFrom (AlsaSeqLib.SND_SEQ_CLIENT_SYSTEM, AlsaSeqLib.SND_SEQ_PORT_SYSTEM_ANNOUNCE); eventmidiport = AlsaSeqLib.CreatePort ("event_prov_in_out");
AlsaSeqLib.ConnectFrom (eventmidiport,AlsaSeqLib.SND_SEQ_CLIENT_SYSTEM, AlsaSeqLib.SND_SEQ_PORT_SYSTEM_ANNOUNCE);
AutoConnect (); AutoConnect ();
} }
@ -213,7 +217,7 @@ namespace DMX2
if (knowndevices [fullportname].ConnectedPorts.Contains (srcid)) if (knowndevices [fullportname].ConnectedPorts.Contains (srcid))
return; return;
AlsaSeqLib.Connect (p); AlsaSeqLib.Connect (eventmidiport,p);
} }
} }
@ -271,6 +275,7 @@ namespace DMX2
public void SendEvent (AlsaSeqLib.snd_seq_event_t ev) public void SendEvent (AlsaSeqLib.snd_seq_event_t ev)
{ {
ev.source.port =(byte) eventmidiport;
AlsaSeqLib.SendEventToSubscribers (ev); AlsaSeqLib.SendEventToSubscribers (ev);
} }
@ -594,7 +599,8 @@ namespace DMX2
if (disposed) if (disposed)
return; return;
disposed = true; disposed = true;
AlsaSeqLib.Close(); //AlsaSeqLib.Close();
AlsaSeqLib.DeletePort(eventmidiport);
} }
#endregion #endregion