Feedback Midi fonctionnel
This commit is contained in:
parent
21023ce2fa
commit
86bb4c46a0
4 changed files with 101 additions and 5 deletions
|
|
@ -20,6 +20,7 @@
|
|||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<Commandlineparameters>aguibtn</Commandlineparameters>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<DebugType>none</DebugType>
|
||||
|
|
|
|||
|
|
@ -209,6 +209,8 @@ namespace DMX2
|
|||
public int result;
|
||||
}
|
||||
|
||||
const int sizeof_snd_seq_event_t = 24;
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
struct snd_seq_event_t {
|
||||
[FieldOffset(0)]
|
||||
|
|
@ -255,6 +257,12 @@ namespace DMX2
|
|||
|
||||
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
|
||||
static extern int snd_seq_free_event(IntPtr ev);
|
||||
|
||||
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
|
||||
static extern int snd_seq_event_output (IntPtr seq, IntPtr ev);
|
||||
|
||||
[DllImport(ASOUND_LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
|
||||
static extern int snd_seq_drain_output (IntPtr seq);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,12 +40,28 @@ namespace DMX2
|
|||
}
|
||||
}
|
||||
|
||||
int inport;
|
||||
int outport;
|
||||
|
||||
public static int InPort {
|
||||
get {
|
||||
return singleton.inport;
|
||||
}
|
||||
}
|
||||
public static int OutPort {
|
||||
get {
|
||||
return singleton.outport;
|
||||
}
|
||||
}
|
||||
MidiSeqHandle(){
|
||||
snd_seq_open(out midi_seq_handle, "default",SND_SEQ_OPEN_DUPLEX,0);
|
||||
snd_seq_set_client_name(midi_seq_handle,"DMX2");
|
||||
snd_seq_create_simple_port(midi_seq_handle,"dmx_ctrl",
|
||||
inport= snd_seq_create_simple_port(midi_seq_handle,"dmx_ctrl_in",
|
||||
SND_SEQ_PORT_CAP_WRITE + SND_SEQ_PORT_CAP_SUBS_WRITE,
|
||||
SND_SEQ_PORT_TYPE_APPLICATION);
|
||||
outport= snd_seq_create_simple_port(midi_seq_handle,"dmx_ctrl_out",
|
||||
SND_SEQ_PORT_CAP_READ + SND_SEQ_PORT_CAP_SUBS_READ,
|
||||
SND_SEQ_PORT_TYPE_APPLICATION);
|
||||
}
|
||||
|
||||
#region IDisposable implementation
|
||||
|
|
@ -72,17 +88,76 @@ namespace DMX2
|
|||
}
|
||||
}
|
||||
|
||||
class midiFeedbackInfo : IFeedbackInfo {
|
||||
|
||||
class feedbackinfo : IFeedbackInfo {
|
||||
|
||||
MidiEventProvider prov;
|
||||
snd_seq_event_t ev;
|
||||
|
||||
public feedbackinfo(MidiEventProvider _prov, byte channel,uint param){
|
||||
ev = new snd_seq_event_t(); prov=_prov;
|
||||
ev.data_ev_ctrl.channel = channel;
|
||||
ev.data_ev_ctrl.param= param;
|
||||
ev.type = snd_seq_event_type_t.SND_SEQ_EVENT_CONTROLLER;
|
||||
}
|
||||
|
||||
#region IFeedbackInfo implementation
|
||||
bool IFeedbackInfo.FeedBack (byte data)
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
ev.data_ev_ctrl.value = (byte)((int)data * 127 / 255) ;
|
||||
prov.SendEvent(ev);
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Dictionary<string,internalEvent> eventlist = new Dictionary<string, internalEvent>();
|
||||
public 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PointerWrapper evPtr = new PointerWrapper(32);
|
||||
|
||||
void SendEvent (snd_seq_event_t ev)
|
||||
{
|
||||
ev.queue = 253;
|
||||
ev.source.port = (byte) MidiSeqHandle.OutPort;
|
||||
ev.dest.client=254;
|
||||
ev.dest.port= 0;
|
||||
Marshal.StructureToPtr(ev,evPtr.Pointer,false);
|
||||
snd_seq_event_output(MidiSeqHandle.Handle,evPtr.Pointer);
|
||||
snd_seq_drain_output(MidiSeqHandle.Handle);
|
||||
}
|
||||
|
||||
Dictionary<string,internalEvent> eventlist = new Dictionary<string, internalEvent>();
|
||||
EventData last;
|
||||
internalEvent levent=null;
|
||||
bool connected=false;
|
||||
|
|
@ -212,9 +287,21 @@ namespace DMX2
|
|||
}
|
||||
}
|
||||
|
||||
static System.Text.RegularExpressions.Regex regexCtrlEventID = new System.Text.RegularExpressions.Regex(
|
||||
@"MIDI-CTRL-C(?<chan>\d+)P(?<param>\d+)",
|
||||
System.Text.RegularExpressions.RegexOptions.Compiled);
|
||||
|
||||
IFeedbackInfo IEventProvider.GetFeedbackInfo (string eventId)
|
||||
{
|
||||
var res = regexCtrlEventID.Match (eventId);
|
||||
if (res.Success) {
|
||||
Console.WriteLine("Succes");
|
||||
byte chan = byte.Parse (res.Groups ["chan"].Value);
|
||||
uint param = uint.Parse (res.Groups ["param"].Value);
|
||||
return new feedbackinfo (this, chan, param);
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ namespace DMX2
|
|||
|
||||
List<IFeedbackInfo> feedbacks = new List<IFeedbackInfo>();
|
||||
|
||||
bool IEventTarget.CanFeedback { get { return false; } }
|
||||
bool IEventTarget.CanFeedback { get { return true; } }
|
||||
|
||||
void IEventTarget.AddFeedback (IFeedbackInfo info)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue