Separation du MidiEventProvider d'une nouvelle lib AlsaSeq réutilisable

This commit is contained in:
tzim 2014-05-16 10:23:52 +00:00
parent 1381590f28
commit 98b112a1d3
8 changed files with 729 additions and 488 deletions

View file

@ -0,0 +1,275 @@
using System;
using System.Runtime.InteropServices;
namespace DMX2
{
public static partial class AlsaSeqLib
{
public const int SND_SEQ_NONBLOCK = 1;
public const int SND_SEQ_OPEN_INPUT = 1;
public const int SND_SEQ_OPEN_OUTPUT = 2;
public const int SND_SEQ_OPEN_DUPLEX = 3;
public const int SND_SEQ_PORT_CAP_NO_EXPORT = (1 << 7);
public const int SND_SEQ_PORT_CAP_READ = (1 << 0);
public const int SND_SEQ_PORT_CAP_WRITE = (1 << 1);
public const int SND_SEQ_PORT_CAP_DUPLEX = (1 << 4);
public const int SND_SEQ_PORT_CAP_SUBS_READ = (1 << 5);
public const int SND_SEQ_PORT_CAP_SUBS_WRITE = (1 << 6);
public const int SND_SEQ_USER_CLIENT = 1;
public const int SND_SEQ_PORT_SYSTEM_TIMER = 0;
public const int SND_SEQ_PORT_SYSTEM_ANNOUNCE = 1;
public const int SND_SEQ_QUERY_SUBS_READ = 0;
public const int SND_SEQ_PORT_TYPE_APPLICATION = (1 << 20);
public const byte SND_SEQ_CLIENT_SYSTEM = 0;
public const byte SND_SEQ_ADDRESS_UNKNOWN = 253;
public const byte SND_SEQ_ADDRESS_SUBSCRIBERS = 254;
public const byte SND_SEQ_ADDRESS_BROADCAST = 255;
public const byte SND_SEQ_QUEUE_DIRECT = 253;
public enum snd_seq_client_type_t : int {
SND_SEQ_USER_CLIENT = 1,
SND_SEQ_KERNEL_CLIENT = 2
}
public enum snd_seq_event_type_t : byte
{
SND_SEQ_EVENT_SYSTEM = 0,
/** returned result status; event data type = #snd_seq_result_t */
SND_SEQ_EVENT_RESULT,
/** note on and off with duration; event data type = #snd_seq_ev_note_t */
SND_SEQ_EVENT_NOTE = 5,
/** note on; event data type = #snd_seq_ev_note_t */
SND_SEQ_EVENT_NOTEON,
/** note off; event data type = #snd_seq_ev_note_t */
SND_SEQ_EVENT_NOTEOFF,
/** key pressure change (aftertouch); event data type = #snd_seq_ev_note_t */
SND_SEQ_EVENT_KEYPRESS,
/** controller; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_CONTROLLER = 10,
/** program change; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_PGMCHANGE,
/** channel pressure; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_CHANPRESS,
/** pitchwheel; event data type = #snd_seq_ev_ctrl_t; data is from -8192 to 8191) */
SND_SEQ_EVENT_PITCHBEND,
/** 14 bit controller value; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_CONTROL14,
/** 14 bit NRPN; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_NONREGPARAM,
/** 14 bit RPN; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_REGPARAM,
/** SPP with LSB and MSB values; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_SONGPOS = 20,
/** Song Select with song ID number; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_SONGSEL,
/** midi time code quarter frame; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_QFRAME,
/** SMF Time Signature event; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_TIMESIGN,
/** SMF Key Signature event; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_KEYSIGN,
/** MIDI Real Time Start message; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_START = 30,
/** MIDI Real Time Continue message; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_CONTINUE,
/** MIDI Real Time Stop message; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_STOP,
/** Set tick queue position; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_SETPOS_TICK,
/** Set real-time queue position; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_SETPOS_TIME,
/** (SMF) Tempo event; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_TEMPO,
/** MIDI Real Time Clock message; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_CLOCK,
/** MIDI Real Time Tick message; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_TICK,
/** Queue timer skew; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_QUEUE_SKEW,
/** Sync position changed; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_SYNC_POS,
/** Tune request; event data type = none */
SND_SEQ_EVENT_TUNE_REQUEST = 40,
/** Reset to power-on state; event data type = none */
SND_SEQ_EVENT_RESET,
/** Active sensing event; event data type = none */
SND_SEQ_EVENT_SENSING,
/** Echo-back event; event data type = any type */
SND_SEQ_EVENT_ECHO = 50,
/** OSS emulation raw event; event data type = any type */
SND_SEQ_EVENT_OSS,
/** New client has connected; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_CLIENT_START = 60,
/** Client has left the system; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_CLIENT_EXIT,
/** Client status/info has changed; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_CLIENT_CHANGE,
/** New port was created; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_PORT_START,
/** Port was deleted from system; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_PORT_EXIT,
/** Port status/info has changed; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_PORT_CHANGE,
/** Ports connected; event data type = #snd_seq_connect_t */
SND_SEQ_EVENT_PORT_SUBSCRIBED,
/** Ports disconnected; event data type = #snd_seq_connect_t */
SND_SEQ_EVENT_PORT_UNSUBSCRIBED,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR0 = 90,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR1,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR2,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR3,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR4,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR5,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR6,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR7,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR8,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR9,
/** system exclusive data (variable length); event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_SYSEX = 130,
/** error event; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_BOUNCE,
/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_USR_VAR0 = 135,
/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_USR_VAR1,
/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_USR_VAR2,
/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_USR_VAR3,
/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_USR_VAR4,
/** NOP; ignored in any case */
SND_SEQ_EVENT_NONE = 255
}
[StructLayout(LayoutKind.Sequential)]
public struct snd_seq_addr_t
{
public byte client;
public byte port;
}
[StructLayout(LayoutKind.Sequential)]
public struct snd_seq_ev_ctrl_t
{
public byte channel;
public byte unused1;
public byte unused2;
public byte unused3;
public uint param;
public int value;
}
[StructLayout(LayoutKind.Sequential)]
public struct snd_seq_ev_note_t
{
public byte channel;
public byte note;
public byte velocity;
public byte off_velocity;
public uint duration;
}
[StructLayout(LayoutKind.Sequential)]
public struct snd_seq_connect_t
{
public snd_seq_addr_t sender;
public snd_seq_addr_t dest;
}
[StructLayout(LayoutKind.Sequential)]
public struct snd_seq_result_t
{
public int eventt;
public int result;
}
public const int sizeof_snd_seq_event_t = 24;
[StructLayout(LayoutKind.Explicit)]
public struct snd_seq_event_t
{
[FieldOffset(0)]
public snd_seq_event_type_t
type;
[FieldOffset(1)]
public byte
flags;
[FieldOffset(2)]
public byte
tag;
[FieldOffset(3)]
public byte
queue;
[FieldOffset(4)]
public uint
time;
[FieldOffset(12)]
public snd_seq_addr_t
source;
[FieldOffset(14)]
public snd_seq_addr_t
dest;
[FieldOffset(16)]
public snd_seq_ev_ctrl_t
data_ev_ctrl;
[FieldOffset(16)]
public snd_seq_ev_note_t
data_ev_note;
[FieldOffset(16)]
public snd_seq_connect_t
data_connect;
[FieldOffset(16)]
public snd_seq_result_t
data_result;
}
static int _clientInfoSize;
static int _portInfoSize;
static int _subscriberInfoSize;
static int GetClientInfoSize ()
{
if (_clientInfoSize == 0) {
_clientInfoSize = Invoke.snd_seq_client_info_sizeof ();
}
return _clientInfoSize;
}
static int GetPortInfoSize ()
{
if (_portInfoSize == 0) {
_portInfoSize = Invoke.snd_seq_port_info_sizeof ();
}
return _portInfoSize;
}
static int GetSubscriberInfoSize ()
{
if (_subscriberInfoSize == 0) {
_subscriberInfoSize = Invoke.snd_seq_port_subscribe_sizeof ();
}
return _subscriberInfoSize;
}
}
}

View file

@ -0,0 +1,157 @@
using System;
using System.Runtime.InteropServices;
namespace DMX2
{
public static partial class AlsaSeqLib
{
public static class Invoke
{
const string ASOUND_LIB_NAME = "libasound.so.2";
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_open (out IntPtr handle, string name, int streams, int mode);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_close (IntPtr seq);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_client_id (IntPtr seq);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_set_client_name (IntPtr seq, string name);
[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_event_input (IntPtr seq, out IntPtr ev);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_event_input_pending (IntPtr seq, int fetch_sequencer);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_free_event (IntPtr ev);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_event_output (IntPtr seq, IntPtr ev);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_drain_output (IntPtr seq);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_info_get_client (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_query_next_client (IntPtr seq, IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_client_info_get_client (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_client_info_set_client (IntPtr info, int client);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_port_info_set_client (IntPtr info, int client);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_port_info_set_port (IntPtr info, int val);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_query_next_port (IntPtr seq, IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr snd_seq_client_info_get_name (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_client_info_get_type (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr snd_seq_port_info_get_name (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr snd_seq_get_any_client_info (IntPtr seq, int client, IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr snd_seq_get_any_port_info (IntPtr seq, int client, int port, IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr snd_seq_port_info_get_addr (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_client_info_sizeof ();
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_port_info_sizeof ();
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_port_subscribe_sizeof ();
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern uint snd_seq_port_info_get_capability (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern uint snd_seq_port_info_get_type (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_port_info_get_port (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_port_info_get_client (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_query_subscribe_set_root (IntPtr info, IntPtr addr);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_query_subscribe_set_type (IntPtr info, int type);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_query_subscribe_set_index (IntPtr info, int index);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_query_subscribe_get_index (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_query_port_subscribers (IntPtr seq, IntPtr subs);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr snd_seq_query_subscribe_get_addr (IntPtr subs);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_port_subscribe_set_sender (IntPtr info, IntPtr addr);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_port_subscribe_set_dest (IntPtr info, IntPtr addr);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_port_subscribe_set_exclusive (IntPtr info, int val);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_port_subscribe_set_time_update (IntPtr info, int val);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_port_subscribe_set_time_real (IntPtr info, int val);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_subscribe_port (IntPtr handle, IntPtr sub);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_unsubscribe_port (IntPtr handle, IntPtr sub);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr snd_strerror (int errno);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_connect_from (IntPtr handle, int myport, int src_client, int src_port);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_connect_to (IntPtr handle, int myport, int dest_client, int dest_port);
}
}
}

View file

@ -0,0 +1,110 @@
using System;
using System.Runtime.InteropServices;
namespace DMX2
{
public static partial class AlsaSeqLib
{
class SeqHandleWrapper : IDisposable
{
IntPtr _seq = IntPtr.Zero;
public IntPtr Handle {
get {
return _seq;
}
}
public SeqHandleWrapper ()
{
Invoke.snd_seq_open (out _seq, "default", SND_SEQ_OPEN_DUPLEX, 0);
Invoke.snd_seq_set_client_name (_seq, "Loupiottes");
}
~SeqHandleWrapper ()
{
Dispose ();
}
#region IDisposable implementation
public void Dispose ()
{
if (_seq != IntPtr.Zero) {
Invoke.snd_seq_close (_seq);
}
_seq = IntPtr.Zero;
}
#endregion
}
internal class PointerWrapper : IDisposable
{
public IntPtr Pointer { get; private set; }
public PointerWrapper (int pointerSize)
{
Pointer = Marshal.AllocHGlobal (pointerSize);
}
public PointerWrapper (IntPtr ptr)
{
Pointer = ptr;
}
~PointerWrapper ()
{
Dispose (false);
}
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
protected virtual void Dispose (bool disposing)
{
if (Pointer != IntPtr.Zero) {
Marshal.FreeHGlobal (Pointer);
}
}
}
public static snd_seq_addr_t PtrToSndSeqAddr (this IntPtr ptr)
{
try {
return (snd_seq_addr_t)Marshal.PtrToStructure (
ptr,
typeof(snd_seq_addr_t)
);
} catch (Exception e) {
#if DEBUG
Console.WriteLine (e.Message);
#endif
return new snd_seq_addr_t ();
}
}
public static IntPtr SndSeqAddrToPtr (this snd_seq_addr_t addr)
{
IntPtr ptr = typeof(snd_seq_addr_t).Malloc ();
Marshal.StructureToPtr (addr, ptr, false);
return ptr;
}
static IntPtr Malloc (this Type type)
{
return Marshal.AllocHGlobal (Marshal.SizeOf (type));
}
public static string PtrToString (this IntPtr p)
{
if (p == IntPtr.Zero) {
return null;
}
return Marshal.PtrToStringAnsi (p);
}
}
}

View file

@ -1,412 +1,198 @@
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace DMX2
{
public static class AlsaSeqLib
public static partial class AlsaSeqLib
{
public const int SND_SEQ_NONBLOCK = 1;
public const int SND_SEQ_OPEN_INPUT = 1;
public const int SND_SEQ_OPEN_OUTPUT = 2;
public const int SND_SEQ_OPEN_DUPLEX = 3;
public const int SND_SEQ_PORT_CAP_NO_EXPORT = (1 << 7);
public const int SND_SEQ_PORT_CAP_READ = (1 << 0);
public const int SND_SEQ_PORT_CAP_WRITE = (1 << 1);
public const int SND_SEQ_PORT_CAP_DUPLEX = (1 << 4);
public const int SND_SEQ_PORT_CAP_SUBS_READ = (1 << 5);
public const int SND_SEQ_PORT_CAP_SUBS_WRITE = (1 << 6);
public const int SND_SEQ_USER_CLIENT = 1;
public const int SND_SEQ_PORT_SYSTEM_TIMER = 0;
public const int SND_SEQ_PORT_SYSTEM_ANNOUNCE = 1;
public const int SND_SEQ_QUERY_SUBS_READ = 0;
public const int SND_SEQ_PORT_TYPE_APPLICATION = (1 << 20);
public const byte SND_SEQ_CLIENT_SYSTEM = 0;
public const byte SND_SEQ_ADDRESS_UNKNOWN = 253;
public const byte SND_SEQ_ADDRESS_SUBSCRIBERS = 254;
public const byte SND_SEQ_ADDRESS_BROADCAST = 255;
public const byte SND_SEQ_QUEUE_DIRECT = 253;
static SeqHandleWrapper seq_handle=null;
public enum snd_seq_event_type_t : byte
{
SND_SEQ_EVENT_SYSTEM = 0,
/** returned result status; event data type = #snd_seq_result_t */
SND_SEQ_EVENT_RESULT,
static int clientId;
static int inport;
static int outport;
/** note on and off with duration; event data type = #snd_seq_ev_note_t */
SND_SEQ_EVENT_NOTE = 5,
/** note on; event data type = #snd_seq_ev_note_t */
SND_SEQ_EVENT_NOTEON,
/** note off; event data type = #snd_seq_ev_note_t */
SND_SEQ_EVENT_NOTEOFF,
/** key pressure change (aftertouch); event data type = #snd_seq_ev_note_t */
SND_SEQ_EVENT_KEYPRESS,
/** controller; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_CONTROLLER = 10,
/** program change; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_PGMCHANGE,
/** channel pressure; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_CHANPRESS,
/** pitchwheel; event data type = #snd_seq_ev_ctrl_t; data is from -8192 to 8191) */
SND_SEQ_EVENT_PITCHBEND,
/** 14 bit controller value; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_CONTROL14,
/** 14 bit NRPN; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_NONREGPARAM,
/** 14 bit RPN; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_REGPARAM,
/** SPP with LSB and MSB values; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_SONGPOS = 20,
/** Song Select with song ID number; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_SONGSEL,
/** midi time code quarter frame; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_QFRAME,
/** SMF Time Signature event; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_TIMESIGN,
/** SMF Key Signature event; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_KEYSIGN,
/** MIDI Real Time Start message; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_START = 30,
/** MIDI Real Time Continue message; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_CONTINUE,
/** MIDI Real Time Stop message; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_STOP,
/** Set tick queue position; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_SETPOS_TICK,
/** Set real-time queue position; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_SETPOS_TIME,
/** (SMF) Tempo event; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_TEMPO,
/** MIDI Real Time Clock message; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_CLOCK,
/** MIDI Real Time Tick message; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_TICK,
/** Queue timer skew; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_QUEUE_SKEW,
/** Sync position changed; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_SYNC_POS,
/** Tune request; event data type = none */
SND_SEQ_EVENT_TUNE_REQUEST = 40,
/** Reset to power-on state; event data type = none */
SND_SEQ_EVENT_RESET,
/** Active sensing event; event data type = none */
SND_SEQ_EVENT_SENSING,
/** Echo-back event; event data type = any type */
SND_SEQ_EVENT_ECHO = 50,
/** OSS emulation raw event; event data type = any type */
SND_SEQ_EVENT_OSS,
/** New client has connected; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_CLIENT_START = 60,
/** Client has left the system; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_CLIENT_EXIT,
/** Client status/info has changed; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_CLIENT_CHANGE,
/** New port was created; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_PORT_START,
/** Port was deleted from system; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_PORT_EXIT,
/** Port status/info has changed; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_PORT_CHANGE,
/** Ports connected; event data type = #snd_seq_connect_t */
SND_SEQ_EVENT_PORT_SUBSCRIBED,
/** Ports disconnected; event data type = #snd_seq_connect_t */
SND_SEQ_EVENT_PORT_UNSUBSCRIBED,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR0 = 90,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR1,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR2,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR3,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR4,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR5,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR6,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR7,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR8,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR9,
/** system exclusive data (variable length); event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_SYSEX = 130,
/** error event; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_BOUNCE,
/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_USR_VAR0 = 135,
/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_USR_VAR1,
/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_USR_VAR2,
/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_USR_VAR3,
/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_USR_VAR4,
/** NOP; ignored in any case */
SND_SEQ_EVENT_NONE = 255
}
[StructLayout(LayoutKind.Sequential)]
public struct snd_seq_addr_t
{
public byte client;
public byte port;
}
[StructLayout(LayoutKind.Sequential)]
public struct snd_seq_ev_ctrl_t
{
public byte channel;
public byte unused1;
public byte unused2;
public byte unused3;
public uint param;
public int value;
}
[StructLayout(LayoutKind.Sequential)]
public struct snd_seq_ev_note_t
{
public byte channel;
public byte note;
public byte velocity;
public byte off_velocity;
public uint duration;
}
[StructLayout(LayoutKind.Sequential)]
public struct snd_seq_connect_t
{
public snd_seq_addr_t sender;
public snd_seq_addr_t dest;
}
[StructLayout(LayoutKind.Sequential)]
public struct snd_seq_result_t
{
public int eventt;
public int result;
}
public const int sizeof_snd_seq_event_t = 24;
[StructLayout(LayoutKind.Explicit)]
public struct snd_seq_event_t
{
[FieldOffset(0)]
public snd_seq_event_type_t
type;
[FieldOffset(1)]
public byte
flags;
[FieldOffset(2)]
public byte
tag;
[FieldOffset(3)]
public byte
queue;
[FieldOffset(4)]
public uint
time;
[FieldOffset(12)]
public snd_seq_addr_t
source;
[FieldOffset(14)]
public snd_seq_addr_t
dest;
[FieldOffset(16)]
public snd_seq_ev_ctrl_t
data_ev_ctrl;
[FieldOffset(16)]
public snd_seq_ev_note_t
data_ev_note;
[FieldOffset(16)]
public snd_seq_connect_t
data_connect;
[FieldOffset(16)]
public snd_seq_result_t
data_result;
}
public static class Invoke
{
const string ASOUND_LIB_NAME = "libasound.so.2";
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_open (out IntPtr handle, string name, int streams, int mode);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_close (IntPtr seq);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_client_id (IntPtr seq);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_set_client_name (IntPtr seq, string name);
[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_event_input (IntPtr seq, out IntPtr ev);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_event_input_pending (IntPtr seq, int fetch_sequencer);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_free_event (IntPtr ev);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_event_output (IntPtr seq, IntPtr ev);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_drain_output (IntPtr seq);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_info_get_client (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_query_next_client (IntPtr seq, IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_client_info_get_client (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_client_info_set_client (IntPtr info, int client);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_port_info_set_client (IntPtr info, int client);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_port_info_set_port (IntPtr info, int val);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_query_next_port (IntPtr seq, IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr snd_seq_client_info_get_name (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_client_info_get_type (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr snd_seq_port_info_get_name (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr snd_seq_get_any_client_info (IntPtr seq, int client, IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr snd_seq_get_any_port_info (IntPtr seq, int client, int port, IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr snd_seq_port_info_get_addr (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_client_info_sizeof ();
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_port_info_sizeof ();
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_port_subscribe_sizeof ();
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_port_info_get_capability (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_port_info_get_type (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_query_subscribe_set_root (IntPtr info, IntPtr addr);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_query_subscribe_set_type (IntPtr info, int type);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_query_subscribe_set_index (IntPtr info, int index);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_query_subscribe_get_index (IntPtr info);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_query_port_subscribers (IntPtr seq, IntPtr subs);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr snd_seq_query_subscribe_get_addr (IntPtr subs);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_port_subscribe_set_sender (IntPtr info, IntPtr addr);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_port_subscribe_set_dest (IntPtr info, IntPtr addr);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_port_subscribe_set_exclusive (IntPtr info, int val);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_port_subscribe_set_time_update (IntPtr info, int val);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void snd_seq_port_subscribe_set_time_real (IntPtr info, int val);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_subscribe_port (IntPtr handle, IntPtr sub);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int snd_seq_unsubscribe_port (IntPtr handle, IntPtr sub);
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr snd_strerror (int errno);
}
public class Client
{
int id;
snd_seq_client_type_t type;
string name;
List<Port> ports = new List<Port>();
public int Id {
get {
return id;
}
}
public snd_seq_client_type_t Type {
get {
return type;
}
}
public string Name {
get {
return name;
}
}
public ReadOnlyCollection<Port> Ports {
get {
return ports.AsReadOnly();
}
}
internal Client(PointerWrapper clientInfo){
id = Invoke.snd_seq_client_info_get_client(clientInfo.Pointer);
IntPtr nameptr = Invoke.snd_seq_client_info_get_name(clientInfo.Pointer);
name = nameptr.PtrToString();
type = (snd_seq_client_type_t)Invoke.snd_seq_client_info_get_type(clientInfo.Pointer);
using (PointerWrapper portInfo = new PointerWrapper(GetPortInfoSize ())) {
Invoke.snd_seq_port_info_set_client (portInfo.Pointer, id);
Invoke.snd_seq_port_info_set_port (portInfo.Pointer, -1);
while(Invoke.snd_seq_query_next_port(seq_handle.Handle, portInfo.Pointer) >= 0) {
ports.Add(new Port(portInfo));
}
}
}
public override bool Equals (object obj)
{
return ((Client)obj).id == id;
}
}
public class Port
{
int portId;
int clientId;
string name;
uint caps;
uint type;
public int ClientId {
get {
return clientId;
}
}
public int PortId {
get {
return portId;
}
}
public string Name {
get {
return name;
}
}
public uint Caps {
get {
return caps;
}
}
public uint Type {
get {
return type;
}
}
internal Port(PointerWrapper portInfo){
clientId = Invoke.snd_seq_port_info_get_client(portInfo.Pointer);
portId = Invoke.snd_seq_port_info_get_port(portInfo.Pointer);
IntPtr namePtr = Invoke.snd_seq_port_info_get_name(portInfo.Pointer);
caps = Invoke.snd_seq_port_info_get_capability (portInfo.Pointer);
type = Invoke.snd_seq_port_info_get_type(portInfo.Pointer);
name = namePtr.PtrToString();
}
}
static int _clientInfoSize;
static int _portInfoSize;
static int _subscriberInfoSize;
static int GetClientInfoSize ()
public static void Init ()
{
if (_clientInfoSize == 0) {
_clientInfoSize = Invoke.snd_seq_client_info_sizeof ();
}
return _clientInfoSize;
if(seq_handle!=null) return;
seq_handle = new SeqHandleWrapper();
clientId = Invoke.snd_seq_client_id(seq_handle.Handle);
inport= Invoke.snd_seq_create_simple_port(seq_handle.Handle,"dmx_ctrl_in",
SND_SEQ_PORT_CAP_WRITE + SND_SEQ_PORT_CAP_SUBS_WRITE,
SND_SEQ_PORT_TYPE_APPLICATION);
outport= Invoke.snd_seq_create_simple_port(seq_handle.Handle,"dmx_ctrl_out",
SND_SEQ_PORT_CAP_READ + SND_SEQ_PORT_CAP_SUBS_READ,
SND_SEQ_PORT_TYPE_APPLICATION);
}
static int GetPortInfoSize ()
{
if (_portInfoSize == 0) {
_portInfoSize = Invoke.snd_seq_port_info_sizeof ();
}
return _portInfoSize;
public static bool GetEvent(out snd_seq_event_t ev){
if(seq_handle==null) throw new InvalidOperationException();
ev = new snd_seq_event_t();
if(Invoke.snd_seq_event_input_pending(seq_handle.Handle,1)<=0) return false;
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);
// TODO : Manage System Events here
return true;
}
static int GetSubscriberInfoSize ()
static PointerWrapper evOutPtr = new PointerWrapper(32);
public static void SendEventToSubscribers (snd_seq_event_t ev)
{
if (_subscriberInfoSize == 0) {
_subscriberInfoSize = Invoke.snd_seq_port_subscribe_sizeof ();
if(seq_handle==null) throw new InvalidOperationException();
ev.queue = SND_SEQ_QUEUE_DIRECT;
ev.source.port = (byte) outport;
ev.dest.client=SND_SEQ_ADDRESS_SUBSCRIBERS;
ev.dest.port= SND_SEQ_ADDRESS_UNKNOWN;
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 IEnumerable<Client> EnumClients ()
{
using (PointerWrapper clientInfo = new PointerWrapper(GetClientInfoSize())) {
Invoke.snd_seq_client_info_set_client(clientInfo.Pointer, -1);
while (Invoke.snd_seq_query_next_client(seq_handle.Handle,clientInfo.Pointer)>=0) {
yield return new Client(clientInfo);
}
}
return _subscriberInfoSize;
}
public static bool Connect(Port port)
{
// TODO : detecter le sens et se connecter au port.
return false;
}
public static bool ConnectTo(int client, int port){
return Invoke.snd_seq_connect_to(seq_handle.Handle,outport,client,port)==0;
}
public static bool ConnectFrom(int client, int port){
return Invoke.snd_seq_connect_from(seq_handle.Handle,inport,client,port)==0;
}
}
}

View file

@ -142,7 +142,6 @@
<Compile Include="Info.cs" />
<Compile Include="EventManager.cs" />
<Compile Include="MidiEventProvider.cs" />
<Compile Include="MidiEventProvider.PInvoke.cs" />
<Compile Include="HelperFunctions.cs" />
<Compile Include="GestionDriversUI.cs" />
<Compile Include="gtk-gui\DMX2.GestionDriversUI.cs" />
@ -159,6 +158,9 @@
<Compile Include="DriverBoitierV3UI.cs" />
<Compile Include="gtk-gui\DMX2.DriverBoitierV3UI.cs" />
<Compile Include="AlsaSeqLib.cs" />
<Compile Include="AlsaSeqLib.Invoke.cs" />
<Compile Include="AlsaSeqLib.AlsaTypes.cs" />
<Compile Include="AlsaSeqLib.Wrappers.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>

View file

@ -70,8 +70,9 @@ namespace DMX2
using (System.IO.TextReader reader = new System.IO.StreamReader(stream))
Gtk.Rc.ParseString (reader.ReadToEnd ());
// Force l'instanciation du handle midi.
//IntPtr ptr = MidiEventProvider.MidiSeqHandle.Handle;
AlsaSeqLib.Init();
// Creation de la fenetre principale
MainWindow win = new MainWindow ();

View file

@ -1,29 +0,0 @@
/*
Copyright (C) Arnaud Houdelette 2012-2014
Copyright (C) Emmanuel Langlois 2012-2014
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
namespace DMX2
{
public partial class MidiEventProvider
{
}
}

View file

@ -23,61 +23,9 @@ using System.Linq;
namespace DMX2
{
public partial class MidiEventProvider : IEventProvider
public class MidiEventProvider : IEventProvider
{
/// <summary>
/// Classe pour contenir et gérer un unique Handle d'acces au sequenceur midi Alsa.
/// </summary>
public class MidiSeqHandle : IDisposable
{
static MidiSeqHandle singleton = new MidiSeqHandle();
IntPtr midi_seq_handle = IntPtr.Zero;
public static IntPtr Handle {
get {
return singleton.midi_seq_handle;
}
}
int inport;
int outport;
public static int InPort {
get {
return singleton.inport;
}
}
public static int OutPort {
get {
return singleton.outport;
}
}
MidiSeqHandle(){
AlsaSeqLib.Invoke.snd_seq_open(out midi_seq_handle, "default",AlsaSeqLib.SND_SEQ_OPEN_DUPLEX,0);
AlsaSeqLib.Invoke.snd_seq_set_client_name(midi_seq_handle,"DMX2");
inport= AlsaSeqLib.Invoke.snd_seq_create_simple_port(midi_seq_handle,"dmx_ctrl_in",
AlsaSeqLib.SND_SEQ_PORT_CAP_WRITE + AlsaSeqLib.SND_SEQ_PORT_CAP_SUBS_WRITE,
AlsaSeqLib.SND_SEQ_PORT_TYPE_APPLICATION);
outport= AlsaSeqLib.Invoke.snd_seq_create_simple_port(midi_seq_handle,"dmx_ctrl_out",
AlsaSeqLib.SND_SEQ_PORT_CAP_READ + AlsaSeqLib.SND_SEQ_PORT_CAP_SUBS_READ,
AlsaSeqLib.SND_SEQ_PORT_TYPE_APPLICATION);
}
#region IDisposable implementation
void IDisposable.Dispose ()
{
if(midi_seq_handle != IntPtr.Zero)
AlsaSeqLib.Invoke.snd_seq_close(midi_seq_handle);
midi_seq_handle = IntPtr.Zero;
}
#endregion
~MidiSeqHandle(){
((IDisposable)this).Dispose ();
}
}
class internalEvent {
public string internalName;
public string description;
@ -144,18 +92,6 @@ namespace DMX2
}
}
PointerWrapper evPtr = new PointerWrapper(32);
void SendEvent (AlsaSeqLib.snd_seq_event_t ev)
{
ev.queue = AlsaSeqLib.SND_SEQ_QUEUE_DIRECT;
ev.source.port = (byte) MidiSeqHandle.OutPort;
ev.dest.client=AlsaSeqLib.SND_SEQ_ADDRESS_SUBSCRIBERS;
ev.dest.port= AlsaSeqLib.SND_SEQ_ADDRESS_UNKNOWN;
Marshal.StructureToPtr(ev,evPtr.Pointer,false);
AlsaSeqLib.Invoke.snd_seq_event_output(MidiSeqHandle.Handle,evPtr.Pointer);
AlsaSeqLib.Invoke.snd_seq_drain_output(MidiSeqHandle.Handle);
}
Dictionary<string,internalEvent> eventlist = new Dictionary<string, internalEvent>();
EventData last;
@ -165,8 +101,13 @@ namespace DMX2
public MidiEventProvider (EventManager manager)
{
manager.RegisterProvider(this);
AlsaSeqLib.Init();
}
public void SendEvent (AlsaSeqLib.snd_seq_event_t ev)
{
AlsaSeqLib.SendEventToSubscribers(ev);
}
#region IEventProvider implementation
bool IEventProvider.Bind (string eventId)
@ -220,13 +161,10 @@ namespace DMX2
void IEventProvider.ProcessEvents (EventManagerCallback callback)
{
IntPtr evPtr; // Pointeur vers la structure non managée alsa-seq
AlsaSeqLib.snd_seq_event_t evS;
// Tant qu'il y des evenements midi en attente
while ((AlsaSeqLib.Invoke.snd_seq_event_input_pending(MidiSeqHandle.Handle,1))>0) {
AlsaSeqLib.Invoke.snd_seq_event_input(MidiSeqHandle.Handle, out evPtr); // Recup du pointeur vers l'ev
AlsaSeqLib.snd_seq_event_t evS =(AlsaSeqLib.snd_seq_event_t) Marshal.PtrToStructure(evPtr,typeof(AlsaSeqLib.snd_seq_event_t)); // Copie de la zone mémoire dans une structure managee
AlsaSeqLib.Invoke.snd_seq_free_event(evPtr); // liberation du pointeur
// Tant qu'il y des evenements midi en attente
while (AlsaSeqLib.GetEvent(out evS)) {
string id=null, description=null; int value=0;
@ -258,6 +196,7 @@ namespace DMX2
id= null;
#if DEBUG
Info.Publish(string.Format ("event {0}", evS.type) ); // On affiche les evenements inconnus
Console.WriteLine(string.Format ("event {0}", evS.type) );
#endif
continue;
}