debut Ajout midi
This commit is contained in:
parent
06bc112ad2
commit
767a47d33a
5 changed files with 434 additions and 3 deletions
|
|
@ -26,6 +26,7 @@ namespace DMX2
|
|||
|
||||
SequenceurMaitre seqmaitre = new SequenceurMaitre();
|
||||
|
||||
MidiEventProvider midip=null;
|
||||
|
||||
public Conduite()
|
||||
{
|
||||
|
|
@ -38,6 +39,20 @@ namespace DMX2
|
|||
u.Nom = "Univers par Défaut";
|
||||
|
||||
Pause = false;
|
||||
|
||||
|
||||
midip = new MidiEventProvider();
|
||||
}
|
||||
|
||||
EventManager eventManager = new EventManager();
|
||||
|
||||
public EventManager EventManager {
|
||||
get {
|
||||
return eventManager;
|
||||
}
|
||||
set {
|
||||
eventManager = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -160,10 +175,12 @@ namespace DMX2
|
|||
TimeSpan deltaT = tickTime - dernierTick;
|
||||
dernierTick = tickTime;
|
||||
|
||||
midip.Process();
|
||||
|
||||
if (!Pause) {
|
||||
|
||||
if (deltaT > TimeSpan.FromMilliseconds (15))
|
||||
Info.Publish(string.Format ("{0}", deltaT));
|
||||
/* if (deltaT > TimeSpan.FromMilliseconds (15))
|
||||
Info.Publish(string.Format ("{0}", deltaT));*/
|
||||
|
||||
lock (this) {
|
||||
|
||||
|
|
@ -210,6 +227,8 @@ namespace DMX2
|
|||
disposed=true;
|
||||
if(timer!=null)
|
||||
timer.Dispose();
|
||||
if(midip!=null)
|
||||
midip.Dispose();
|
||||
foreach(var driver in Drivers)
|
||||
driver.Dispose();
|
||||
timer=null;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
|
|
@ -103,6 +102,9 @@
|
|||
<Compile Include="SeqMacroUI.cs" />
|
||||
<Compile Include="gtk-gui\DMX2.SeqMacroUI.cs" />
|
||||
<Compile Include="Info.cs" />
|
||||
<Compile Include="EventManager.cs" />
|
||||
<Compile Include="MidiEventProvider.cs" />
|
||||
<Compile Include="MidiEventProvider.PInvoke.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
|
|
|
|||
117
DMX-2.0/EventManager.cs
Normal file
117
DMX-2.0/EventManager.cs
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DMX2
|
||||
{
|
||||
|
||||
public struct EventData
|
||||
{
|
||||
public string id;
|
||||
public byte value;
|
||||
}
|
||||
|
||||
public interface IEventProvider
|
||||
{
|
||||
string MenuName{ get; }
|
||||
string[] GetEventList();
|
||||
bool Bind (string eventId, IEventTarget target);
|
||||
void Unbind (string eventId, IEventTarget target);
|
||||
Gtk.Menu GetProviderSubMenu( Gtk.ButtonPressEventHandler handler );
|
||||
}
|
||||
|
||||
public interface IEventTarget
|
||||
{
|
||||
bool FireEvent(EventData data);
|
||||
}
|
||||
|
||||
public class EventManager
|
||||
{
|
||||
class eventBinding
|
||||
{
|
||||
private eventBinding(){}
|
||||
public eventBinding(string _id, IEventTarget _target, IEventProvider _provider){
|
||||
id=_id;
|
||||
target=_target;
|
||||
provider=_provider;
|
||||
}
|
||||
public string id;
|
||||
public IEventTarget target;
|
||||
public IEventProvider provider;
|
||||
}
|
||||
|
||||
List<eventBinding> bindings = new List<eventBinding>();
|
||||
List<IEventProvider> providers = new List<IEventProvider>();
|
||||
|
||||
public EventManager ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void RegisterProvider (IEventProvider prov)
|
||||
{
|
||||
providers.Add (prov);
|
||||
|
||||
List<string> evList = new List<string>(prov.GetEventList());
|
||||
|
||||
foreach (eventBinding b in bindings) {
|
||||
if(b.provider == null && evList.Contains(b.id))
|
||||
{
|
||||
prov.Bind(b.id,b.target);
|
||||
b.provider = prov;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Gtk.Menu GetMenu ( Gtk.ButtonPressEventHandler handler )
|
||||
{
|
||||
Gtk.Menu menu = new Gtk.Menu();
|
||||
|
||||
|
||||
return menu;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void UnregisterProvider (IEventProvider prov)
|
||||
{
|
||||
foreach (eventBinding b in bindings)
|
||||
if(b.provider == prov)
|
||||
b.provider = null;
|
||||
providers.Remove(prov);
|
||||
}
|
||||
|
||||
public bool Bind (string eventId, IEventTarget target)
|
||||
{
|
||||
|
||||
foreach (IEventProvider prov in providers) {
|
||||
if (prov.Bind (eventId, target)) {
|
||||
bindings.Add(new eventBinding(eventId,target,prov));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
bindings.Add(new eventBinding(eventId,target,null));
|
||||
return false;
|
||||
}
|
||||
|
||||
eventBinding findBinding (string eventId, IEventTarget target)
|
||||
{
|
||||
foreach (eventBinding b in bindings) {
|
||||
if (b.id == eventId && b.target == target) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Unbind (string eventId, IEventTarget target)
|
||||
{
|
||||
eventBinding b = findBinding(eventId,target);
|
||||
if(b==null)return;
|
||||
b.provider.Unbind(eventId,target);
|
||||
bindings.Remove (b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
211
DMX-2.0/MidiEventProvider.PInvoke.cs
Normal file
211
DMX-2.0/MidiEventProvider.PInvoke.cs
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DMX2
|
||||
{
|
||||
public partial class MidiEventProvider
|
||||
{
|
||||
const string ASOUND_LIB_NAME = "libasound.so.2";
|
||||
const int SND_SEQ_NONBLOCK = 1;
|
||||
const int SND_SEQ_OPEN_INPUT = 1;
|
||||
const int SND_SEQ_OPEN_OUTPUT = 2;
|
||||
const int SND_SEQ_OPEN_DUPLEX = 3;
|
||||
const int SND_SEQ_PORT_CAP_NO_EXPORT = (1 << 7);
|
||||
const int SND_SEQ_PORT_CAP_READ = (1 << 0);
|
||||
const int SND_SEQ_PORT_CAP_WRITE = (1 << 1);
|
||||
const int SND_SEQ_PORT_CAP_DUPLEX = (1 << 4);
|
||||
const int SND_SEQ_PORT_CAP_SUBS_READ=(1<<5);
|
||||
const int SND_SEQ_PORT_CAP_SUBS_WRITE = (1<<6);
|
||||
const int SND_SEQ_USER_CLIENT = 1;
|
||||
const int SND_SEQ_PORT_SYSTEM_TIMER = 0;
|
||||
const int SND_SEQ_PORT_SYSTEM_ANNOUNCE = 1;
|
||||
const int SND_SEQ_QUERY_SUBS_READ = 0;
|
||||
const int SND_SEQ_PORT_TYPE_APPLICATION = (1<<20);
|
||||
|
||||
|
||||
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)]
|
||||
struct snd_seq_addr_t {
|
||||
public byte client;
|
||||
public byte port;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
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(8)]
|
||||
public snd_seq_addr_t source;
|
||||
[FieldOffset(10)]
|
||||
public snd_seq_addr_t dest;
|
||||
[FieldOffset(12)]
|
||||
public byte data_control_channel;
|
||||
[FieldOffset(13)]
|
||||
public byte data_control_unused;
|
||||
[FieldOffset(14)]
|
||||
public uint data_control_param;
|
||||
[FieldOffset(18)]
|
||||
public int data_control_value;
|
||||
}
|
||||
|
||||
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
|
||||
static extern int snd_seq_open (out IntPtr handle, string name, int streams, int mode);
|
||||
|
||||
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
|
||||
static extern int snd_seq_close (IntPtr seq);
|
||||
|
||||
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
|
||||
static extern int snd_seq_set_client_name (IntPtr seq, string name);
|
||||
|
||||
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
|
||||
static extern int snd_seq_create_simple_port (IntPtr seq, string name, uint caps, uint type);
|
||||
|
||||
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
|
||||
static extern int snd_seq_event_input (IntPtr seq, out IntPtr ev);
|
||||
|
||||
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
|
||||
static extern int snd_seq_event_input_pending (IntPtr seq, int fetch_sequencer);
|
||||
|
||||
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
|
||||
static extern int snd_seq_free_event(IntPtr ev);
|
||||
}
|
||||
}
|
||||
|
||||
82
DMX-2.0/MidiEventProvider.cs
Normal file
82
DMX-2.0/MidiEventProvider.cs
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DMX2
|
||||
{
|
||||
public partial class MidiEventProvider : IEventProvider, IDisposable
|
||||
{
|
||||
|
||||
IntPtr midi_seq_handle = IntPtr.Zero;
|
||||
int midiport;
|
||||
|
||||
public MidiEventProvider ()
|
||||
{
|
||||
snd_seq_open(out midi_seq_handle, "default",SND_SEQ_OPEN_INPUT,0);
|
||||
snd_seq_set_client_name(midi_seq_handle,"DMX2");
|
||||
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_TYPE_APPLICATION);
|
||||
|
||||
Info.Publish(string.Format("Midi port {0}",midiport));
|
||||
}
|
||||
|
||||
public void Process ()
|
||||
{
|
||||
int i= snd_seq_event_input_pending(midi_seq_handle,1);
|
||||
if( i!=0)Info.Publish(string.Format("i={0}",i));
|
||||
IntPtr 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));
|
||||
|
||||
Info.Publish(evS.data_control_value.ToString());
|
||||
|
||||
snd_seq_free_event(ev);
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
#region IDisposable implementation
|
||||
public void Dispose ()
|
||||
{
|
||||
snd_seq_close(midi_seq_handle);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IEventProvider implementation
|
||||
string[] IEventProvider.GetEventList ()
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
}
|
||||
|
||||
bool IEventProvider.Bind (string eventId, IEventTarget target)
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
}
|
||||
|
||||
void IEventProvider.Unbind (string eventId, IEventTarget target)
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
}
|
||||
|
||||
Gtk.Menu IEventProvider.GetProviderSubMenu (Gtk.ButtonPressEventHandler handler)
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
}
|
||||
|
||||
string IEventProvider.MenuName {
|
||||
get {
|
||||
throw new System.NotImplementedException ();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in a new issue