Preparation : ajout de la possibilite de plusieurs ports seq.
Adaptation du MidiEventProvider
This commit is contained in:
parent
33414c463f
commit
9607f81f36
4 changed files with 48 additions and 29 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 ();
|
||||
|
||||
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 ();
|
||||
}
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue