Mise au point de l'interrop avec la lib midi

This commit is contained in:
tzim 2013-11-13 11:15:34 +00:00
parent 767a47d33a
commit 55b06fe771
2 changed files with 49 additions and 25 deletions

View file

@ -5,7 +5,7 @@ namespace DMX2
{ {
public partial class MidiEventProvider public partial class MidiEventProvider
{ {
const string ASOUND_LIB_NAME = "libasound.so.2"; const string ASOUND_LIB_NAME = "libasound.so";
const int SND_SEQ_NONBLOCK = 1; const int SND_SEQ_NONBLOCK = 1;
const int SND_SEQ_OPEN_INPUT = 1; const int SND_SEQ_OPEN_INPUT = 1;
const int SND_SEQ_OPEN_OUTPUT = 2; const int SND_SEQ_OPEN_OUTPUT = 2;
@ -160,6 +160,37 @@ namespace DMX2
public byte port; public byte port;
} }
[StructLayout(LayoutKind.Sequential)]
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)]
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)]
struct snd_seq_connect_t {
public snd_seq_addr_t sender;
public snd_seq_addr_t dest;
}
[StructLayout(LayoutKind.Sequential)]
struct snd_seq_result_t {
public int eventt;
public int result;
}
[StructLayout(LayoutKind.Explicit)] [StructLayout(LayoutKind.Explicit)]
struct snd_seq_event_t { struct snd_seq_event_t {
[FieldOffset(0)] [FieldOffset(0)]
@ -172,18 +203,18 @@ namespace DMX2
public byte queue; public byte queue;
[FieldOffset(4)] [FieldOffset(4)]
public uint time; public uint time;
[FieldOffset(8)]
public snd_seq_addr_t source;
[FieldOffset(10)]
public snd_seq_addr_t dest;
[FieldOffset(12)] [FieldOffset(12)]
public byte data_control_channel; public snd_seq_addr_t source;
[FieldOffset(13)]
public byte data_control_unused;
[FieldOffset(14)] [FieldOffset(14)]
public uint data_control_param; public snd_seq_addr_t dest;
[FieldOffset(18)] [FieldOffset(16)]
public int data_control_value; 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;
} }
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)] [DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]

View file

@ -11,7 +11,7 @@ namespace DMX2
public MidiEventProvider () public MidiEventProvider ()
{ {
snd_seq_open(out midi_seq_handle, "default",SND_SEQ_OPEN_INPUT,0); snd_seq_open(out midi_seq_handle, "default",SND_SEQ_OPEN_DUPLEX,0);
snd_seq_set_client_name(midi_seq_handle,"DMX2"); snd_seq_set_client_name(midi_seq_handle,"DMX2");
midiport = snd_seq_create_simple_port(midi_seq_handle,"dmx_ctrl", midiport = snd_seq_create_simple_port(midi_seq_handle,"dmx_ctrl",
SND_SEQ_PORT_CAP_WRITE + SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_CAP_WRITE + SND_SEQ_PORT_CAP_SUBS_WRITE,
@ -22,21 +22,14 @@ namespace DMX2
public void Process () public void Process ()
{ {
int i= snd_seq_event_input_pending(midi_seq_handle,1); int i; IntPtr ev;
if( i!=0)Info.Publish(string.Format("i={0}",i)); while ((i = snd_seq_event_input_pending(midi_seq_handle,1))>0) {
IntPtr ev; //Console.WriteLine(i);
i=snd_seq_event_input(midi_seq_handle, out ev);
/*
while (snd_seq_event_input_pending(midi_seq_handle,1)>0) {
snd_seq_event_t evS =(snd_seq_event_t) Marshal.PtrToStructure(ev,typeof(snd_seq_event_t)); snd_seq_event_t evS =(snd_seq_event_t) Marshal.PtrToStructure(ev,typeof(snd_seq_event_t));
Info.Publish(string.Format ("event {0} {1}", evS.type, evS.data_ev_ctrl.value) );
Info.Publish(evS.data_control_value.ToString());
snd_seq_free_event(ev); snd_seq_free_event(ev);
}*/ }
} }
#region IDisposable implementation #region IDisposable implementation