Ajout MidiPort

This commit is contained in:
Tzim 2017-07-05 17:02:31 +02:00
parent 910a3af980
commit 404f968587
8 changed files with 208 additions and 188 deletions

View file

@ -0,0 +1,129 @@
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Concurrent;
namespace DMX2
{
public static partial class AlsaSeqLib
{ public class MidiPort : IDisposable
{
internal ConcurrentQueue<snd_seq_event_t> eventqueue = new ConcurrentQueue<snd_seq_event_t> ();
internal int portid;
public MidiPort(string portname){
portid=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
);
openports[portid]=this;
}
bool closed = false;
public void Close()
{
if (closed)
return;
closed = true;
Invoke.snd_seq_delete_simple_port (seq_handle.Handle,
portid);
if(openports.ContainsKey(portid))
if (openports [portid] == this)
openports.Remove (portid);
}
void IDisposable.Dispose(){
Close ();
}
public void SendEvent(snd_seq_event_t ev){
if (seq_handle == null)
throw new InvalidOperationException ();
ev.source.client = (byte)clientId;
ev.source.port = (byte)portid;
ev.dest.client = SND_SEQ_ADDRESS_SUBSCRIBERS;
ev.dest.port = SND_SEQ_ADDRESS_UNKNOWN;
ev.queue = SND_SEQ_QUEUE_DIRECT;
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 bool GetEvent(out snd_seq_event_t ev){
return eventqueue.TryDequeue (out ev);
}
public bool ConnectTo(Port p){
if (seq_handle == null)
throw new InvalidOperationException ();
return Invoke.snd_seq_connect_to (seq_handle.Handle, portid, p.ClientId, p.PortId) == 0;
}
internal bool ConnectTo(int client, int port){
if (seq_handle == null)
throw new InvalidOperationException ();
return Invoke.snd_seq_connect_to (seq_handle.Handle, portid, client, port) == 0;
}
public bool ConnectFrom(Port p){
if (seq_handle == null)
throw new InvalidOperationException ();
return Invoke.snd_seq_connect_from (seq_handle.Handle, portid, p.ClientId, p.PortId) == 0;
}
public void Deconnecte(Port p){
if (seq_handle == null)
throw new InvalidOperationException ();
snd_seq_addr_t local = new snd_seq_addr_t ();
local.client = (byte)clientId;
local.port = (byte)portid;
snd_seq_addr_t addr;
using (PointerWrapper subqueryInfo = new PointerWrapper(GetQuerySubscribeInfoSize()))
using (PointerWrapper localAddr =new PointerWrapper(local.SndSeqAddrToPtr())) {
Invoke.snd_seq_query_subscribe_set_root (subqueryInfo.Pointer, localAddr.Pointer);
Invoke.snd_seq_query_subscribe_set_type (subqueryInfo.Pointer, SND_SEQ_QUERY_SUBS_WRITE);
for (Invoke.snd_seq_query_subscribe_set_index(subqueryInfo.Pointer,0);
Invoke.snd_seq_query_port_subscribers (seq_handle.Handle,subqueryInfo.Pointer)>=0;
Invoke.snd_seq_query_subscribe_set_index(subqueryInfo.Pointer,
Invoke.snd_seq_query_subscribe_get_index(subqueryInfo.Pointer) +1)
) {
addr = Invoke.snd_seq_query_subscribe_get_addr (subqueryInfo.Pointer).PtrToSndSeqAddr ();
if (addr.client != p.ClientId || addr.port != p.PortId)
continue;
Invoke.snd_seq_disconnect_from (seq_handle.Handle, portid, p.ClientId, p.PortId);
}
Invoke.snd_seq_query_subscribe_set_type (subqueryInfo.Pointer, SND_SEQ_QUERY_SUBS_READ);
for (Invoke.snd_seq_query_subscribe_set_index(subqueryInfo.Pointer,0);
Invoke.snd_seq_query_port_subscribers (seq_handle.Handle,subqueryInfo.Pointer)>=0;
Invoke.snd_seq_query_subscribe_set_index(subqueryInfo.Pointer,
Invoke.snd_seq_query_subscribe_get_index(subqueryInfo.Pointer) +1)
) {
addr = Invoke.snd_seq_query_subscribe_get_addr (subqueryInfo.Pointer).PtrToSndSeqAddr ();
if (addr.client != p.ClientId || addr.port != p.PortId)
continue;
Invoke.snd_seq_disconnect_to (seq_handle.Handle, portid, p.ClientId, p.PortId);
}
}
}
}
}
}

View file

@ -15,10 +15,10 @@ namespace DMX2
} }
} }
public SeqHandleWrapper () public SeqHandleWrapper (string appname)
{ {
Invoke.snd_seq_open (out _seq, "default", SND_SEQ_OPEN_DUPLEX, 0); Invoke.snd_seq_open (out _seq, "default", SND_SEQ_OPEN_DUPLEX, 0);
Invoke.snd_seq_set_client_name (_seq, "Loupiottes"); Invoke.snd_seq_set_client_name (_seq, appname);
} }
~SeqHandleWrapper () ~SeqHandleWrapper ()

View file

@ -12,6 +12,10 @@ namespace DMX2
//static int inport; //static int inport;
//static int outport; //static int outport;
static System.Threading.Thread eventthread=null;
static MidiPort systemPort=null;
static internal Dictionary<int,MidiPort> openports = new Dictionary<int, MidiPort>();
public class Client public class Client
{ {
@ -61,11 +65,12 @@ namespace DMX2
} }
} }
public static int ClientId { /*public static int ClientId {
get { get {
return clientId; return clientId;
} }
} }*/
public class Port public class Port
{ {
int portId; int portId;
@ -115,31 +120,20 @@ namespace DMX2
} }
} }
public static void Init () public static void Init (string appname)
{ {
if (seq_handle != null) if (seq_handle != null)
return; return;
seq_handle = new SeqHandleWrapper (); seq_handle = new SeqHandleWrapper (appname);
clientId = Invoke.snd_seq_client_id (seq_handle.Handle); clientId = Invoke.snd_seq_client_id (seq_handle.Handle);
}
public static int CreatePort(string portname){ System.Threading.ThreadStart ts = new System.Threading.ThreadStart (EventLoop);
return Invoke.snd_seq_create_simple_port (seq_handle.Handle, eventthread = new System.Threading.Thread (ts);
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){ systemPort = new MidiPort ("system");
Invoke.snd_seq_delete_simple_port (seq_handle.Handle, systemPort.ConnectTo (SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE);
port);
} }
public static void Close () public static void Close ()
@ -150,7 +144,34 @@ namespace DMX2
seq_handle = null; seq_handle = null;
} }
public static bool GetEvent (out snd_seq_event_t ev) public static void EventLoop(){
snd_seq_event_t ev = new snd_seq_event_t ();;
while (seq_handle != null) {
while (seq_handle != null && Invoke.snd_seq_event_input_pending (seq_handle.Handle, 1) > 0) {
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);
if (ev.dest.port == systemPort.portid) {
if (ev.type == AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_PORT_START) {
}
} else {
// queue
if (openports.ContainsKey (ev.dest.port)) {
openports [ev.dest.port].eventqueue.Enqueue (ev);
}
}
}
System.Threading.Thread.Sleep (1);
}
}
/*static bool GetEvent (out snd_seq_event_t ev)
{ {
if (seq_handle == null) if (seq_handle == null)
throw new InvalidOperationException (); throw new InvalidOperationException ();
@ -173,32 +194,11 @@ namespace DMX2
return true; return true;
} }*/
static PointerWrapper evOutPtr = new PointerWrapper (32); static PointerWrapper evOutPtr = new PointerWrapper (32);
public static void SendEvent (snd_seq_event_t ev) static IEnumerable<Client> EnumClients ()
{
if (seq_handle == null)
throw new InvalidOperationException ();
ev.queue = SND_SEQ_QUEUE_DIRECT;
ev.source.client = (byte)clientId;
//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);
}
public static void SendEventToSubscribers (snd_seq_event_t ev)
{
if (seq_handle == null)
throw new InvalidOperationException ();
ev.dest.client = SND_SEQ_ADDRESS_SUBSCRIBERS;
ev.dest.port = SND_SEQ_ADDRESS_UNKNOWN;
SendEvent (ev);
}
public static IEnumerable<Client> EnumClients ()
{ {
if (seq_handle == null) if (seq_handle == null)
throw new InvalidOperationException (); throw new InvalidOperationException ();
@ -210,7 +210,7 @@ namespace DMX2
} }
} }
public static Client GetClientByID (int client) static Client GetClientByID (int client)
{ {
if (seq_handle == null) if (seq_handle == null)
throw new InvalidOperationException (); throw new InvalidOperationException ();
@ -222,7 +222,7 @@ namespace DMX2
} }
} }
public static Port GetPortByIDs (int client, int port) static Port GetPortByIDs (int client, int port)
{ {
if (seq_handle == null) if (seq_handle == null)
throw new InvalidOperationException (); throw new InvalidOperationException ();
@ -234,107 +234,6 @@ namespace DMX2
} }
} }
public static bool Connect (int localport, Port port)
{
if (seq_handle == null)
throw new InvalidOperationException ();
bool isInput = (port.Caps & SND_SEQ_PORT_CAP_WRITE) == SND_SEQ_PORT_CAP_WRITE;
bool isOutput = (port.Caps & SND_SEQ_PORT_CAP_READ) == SND_SEQ_PORT_CAP_READ;
if (isInput)
if (!ConnectTo (localport,port.ClientId, port.PortId))
return false;
if (isOutput)
if (!ConnectFrom (localport,port.ClientId, port.PortId))
return false;
return true;
}
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, localoutport, client, port) == 0;
}
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, localinport, client, port) == 0;
}
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)localport;
snd_seq_addr_t addr;
using (PointerWrapper subqueryInfo = new PointerWrapper(GetQuerySubscribeInfoSize()))
using (PointerWrapper localAddr =new PointerWrapper(local.SndSeqAddrToPtr())) {
Invoke.snd_seq_query_subscribe_set_root (subqueryInfo.Pointer, localAddr.Pointer);
Invoke.snd_seq_query_subscribe_set_type (subqueryInfo.Pointer, SND_SEQ_QUERY_SUBS_WRITE);
for (Invoke.snd_seq_query_subscribe_set_index(subqueryInfo.Pointer,0);
Invoke.snd_seq_query_port_subscribers (seq_handle.Handle,subqueryInfo.Pointer)>=0;
Invoke.snd_seq_query_subscribe_set_index(subqueryInfo.Pointer,
Invoke.snd_seq_query_subscribe_get_index(subqueryInfo.Pointer) +1)
) {
//root = Invoke.snd_seq_query_subscribe_get_root(subqueryInfo.Pointer).PtrToSndSeqAddr();
addr = Invoke.snd_seq_query_subscribe_get_addr (subqueryInfo.Pointer).PtrToSndSeqAddr ();
if (addr.client != client || addr.port != port)
continue;
Invoke.snd_seq_disconnect_from (seq_handle.Handle, localport, client, port);
}
Invoke.snd_seq_query_subscribe_set_type (subqueryInfo.Pointer, SND_SEQ_QUERY_SUBS_READ);
for (Invoke.snd_seq_query_subscribe_set_index(subqueryInfo.Pointer,0);
Invoke.snd_seq_query_port_subscribers (seq_handle.Handle,subqueryInfo.Pointer)>=0;
Invoke.snd_seq_query_subscribe_set_index(subqueryInfo.Pointer,
Invoke.snd_seq_query_subscribe_get_index(subqueryInfo.Pointer) +1)
) {
//root = Invoke.snd_seq_query_subscribe_get_root(subqueryInfo.Pointer).PtrToSndSeqAddr();
addr = Invoke.snd_seq_query_subscribe_get_addr (subqueryInfo.Pointer).PtrToSndSeqAddr ();
if (addr.client != client || addr.port != port)
continue;
Invoke.snd_seq_disconnect_to (seq_handle.Handle, localport, client, port);
}
}
}
/*
public static void GetConnections()
{
using(PointerWrapper subscribeInfo = new PointerWrapper(GetQuerySubscribeInfoSize())){
int index=0;
Invoke.snd_seq_query_subscribe_set_client (subscribeInfo.Pointer,clientId);
Invoke.snd_seq_query_subscribe_set_port (subscribeInfo.Pointer,inport);
Invoke.snd_seq_query_subscribe_set_index(subscribeInfo.Pointer,index++);
Invoke.snd_seq_query_subscribe_set_type(subscribeInfo.Pointer,SND_SEQ_QUERY_SUBS_WRITE);
while (Invoke.snd_seq_query_port_subscribers(seq_handle.Handle,subscribeInfo.Pointer) ==0){
//Console.WriteLine("Remote => {0}:{1}",rclient,rport);
Invoke.snd_seq_query_subscribe_set_index(subscribeInfo.Pointer,index++);
}
}
}*/
} }
} }

View file

@ -148,6 +148,7 @@
<Compile Include="SeqOscUI.cs" /> <Compile Include="SeqOscUI.cs" />
<Compile Include="gtk-gui\DMX2.SeqOscUI.cs" /> <Compile Include="gtk-gui\DMX2.SeqOscUI.cs" />
<Compile Include="SequenceurOSC.cs" /> <Compile Include="SequenceurOSC.cs" />
<Compile Include="AlsaSeqLib.MidiPort.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions> <ProjectExtensions>

View file

@ -16,7 +16,7 @@ namespace DMX2
this.Build (); this.Build ();
lsDetect = new Gtk.ListStore (typeof(string)); lsDetect = new Gtk.ListStore (typeof(string));
lsKnown = new Gtk.ListStore (typeof(MidiEventProvider.MidiDevice)); lsKnown = new Gtk.ListStore (typeof(MidiEventProvider.MidiControler));
var nameCol = new Gtk.TreeViewColumn (); var nameCol = new Gtk.TreeViewColumn ();
@ -81,7 +81,7 @@ namespace DMX2
void RenderMidiDev (Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel tree_model, Gtk.TreeIter iter) void RenderMidiDev (Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel tree_model, Gtk.TreeIter iter)
{ {
MidiEventProvider.MidiDevice dev = tree_model.GetValue (iter, 0) as MidiEventProvider.MidiDevice; MidiEventProvider.MidiControler dev = tree_model.GetValue (iter, 0) as MidiEventProvider.MidiControler;
(cell as Gtk.CellRendererText).Text = dev.ConnectedPorts.Count>0 (cell as Gtk.CellRendererText).Text = dev.ConnectedPorts.Count>0
?string.Format("{0} ({1} connectés)",dev.Name,dev.ConnectedPorts.Count) ?string.Format("{0} ({1} connectés)",dev.Name,dev.ConnectedPorts.Count)
:string.Format("{0} (Déconnecté)",dev.Name); :string.Format("{0} (Déconnecté)",dev.Name);
@ -124,7 +124,7 @@ namespace DMX2
chkFB.Sensitive = btnDesactiv.Sensitive = (listKnown.Selection.CountSelectedRows() >0); chkFB.Sensitive = btnDesactiv.Sensitive = (listKnown.Selection.CountSelectedRows() >0);
TreeIter iter; TreeIter iter;
if(!listKnown.Selection.GetSelected(out iter)) return; if(!listKnown.Selection.GetSelected(out iter)) return;
MidiEventProvider.MidiDevice dev = lsKnown.GetValue(iter,0) as MidiEventProvider.MidiDevice ; MidiEventProvider.MidiControler dev = lsKnown.GetValue(iter,0) as MidiEventProvider.MidiControler ;
chkFB.Active = dev.HasFeedback; chkFB.Active = dev.HasFeedback;
} }
@ -144,7 +144,7 @@ namespace DMX2
{ {
TreeIter iter; TreeIter iter;
if(!listKnown.Selection.GetSelected(out iter)) return; if(!listKnown.Selection.GetSelected(out iter)) return;
MidiEventProvider.MidiDevice dev = lsKnown.GetValue(iter,0) as MidiEventProvider.MidiDevice ; MidiEventProvider.MidiControler dev = lsKnown.GetValue(iter,0) as MidiEventProvider.MidiControler ;
Conduite.Courante.Midi.DisconnectDevice(dev); Conduite.Courante.Midi.DisconnectDevice(dev);
FillLsDetect () ; FillLsDetect () ;
FillLsKnown(); FillLsKnown();
@ -156,7 +156,7 @@ namespace DMX2
{ {
TreeIter iter; TreeIter iter;
if(!listKnown.Selection.GetSelected(out iter)) return; if(!listKnown.Selection.GetSelected(out iter)) return;
MidiEventProvider.MidiDevice dev = lsKnown.GetValue(iter,0) as MidiEventProvider.MidiDevice ; MidiEventProvider.MidiControler dev = lsKnown.GetValue(iter,0) as MidiEventProvider.MidiControler ;
dev.HasFeedback = chkFB.Active; dev.HasFeedback = chkFB.Active;
Conduite.Courante.Midi.RefreshFeedback(dev.Name); Conduite.Courante.Midi.RefreshFeedback(dev.Name);

View file

@ -60,7 +60,7 @@ namespace DMX2
if (oscEn) if (oscEn)
osc = new OSCServer (); osc = new OSCServer ();
AlsaSeqLib.Init (); AlsaSeqLib.Init ("Loupiottes");
// Initialisation GTK# // Initialisation GTK#
Application.Init (); Application.Init ();

View file

@ -33,7 +33,7 @@ namespace DMX2
/// <summary> /// <summary>
/// Liste des peripheriques connus (presents ou non) /// Liste des peripheriques connus (presents ou non)
/// </summary> /// </summary>
readonly Dictionary<string,MidiDevice> knowndevices = new Dictionary<string,MidiDevice> (); readonly Dictionary<string,MidiControler> knowndevices = new Dictionary<string,MidiControler> ();
/// <summary> /// <summary>
/// Liste des ports connectés avec feedback /// Liste des ports connectés avec feedback
@ -60,7 +60,7 @@ namespace DMX2
uint pageUpCC = 127; uint pageUpCC = 127;
uint pageDownCC = 126; uint pageDownCC = 126;
int eventmidiport; AlsaSeqLib.MidiPort midiport;
public uint CurrentPage { public uint CurrentPage {
get { get {
@ -133,7 +133,7 @@ namespace DMX2
public void ConnectDevice (string name) public void ConnectDevice (string name)
{ {
knowndevices.Add (name, new MidiDevice (name)); knowndevices.Add (name, new MidiControler (name));
AutoConnect (); AutoConnect ();
} }
@ -150,7 +150,7 @@ namespace DMX2
} }
} }
public void DisconnectDevice (MidiEventProvider.MidiDevice dev) public void DisconnectDevice (MidiEventProvider.MidiControler dev)
{ {
if (!knowndevices.ContainsKey (dev.Name)) if (!knowndevices.ContainsKey (dev.Name))
return; return;
@ -168,7 +168,7 @@ namespace DMX2
return knowndevices.ContainsKey (name); return knowndevices.ContainsKey (name);
} }
public IEnumerable<MidiDevice> KnownDevices { public IEnumerable<MidiControler> KnownDevices {
get { get {
return knowndevices.Values; return knowndevices.Values;
} }
@ -177,19 +177,17 @@ namespace DMX2
public MidiEventProvider (EventManager manager) public MidiEventProvider (EventManager manager)
{ {
#if DEBUG #if DEBUG
MidiDevice dev = new MidiDevice("VMPK Input:VMPK Input"); MidiControler dev = new MidiControler("VMPK Input:VMPK Input");
dev.HasFeedback = true; dev.HasFeedback = true;
knowndevices.Add(dev.Name,dev); knowndevices.Add(dev.Name,dev);
dev = new MidiDevice("VMPK Output:VMPK Output"); dev = new MidiControler("VMPK Output:VMPK Output");
dev.HasFeedback = true; dev.HasFeedback = true;
knowndevices.Add(dev.Name,dev); knowndevices.Add(dev.Name,dev);
#endif #endif
manager.RegisterProvider (this); manager.RegisterProvider (this);
//AlsaSeqLib.Init (); //AlsaSeqLib.Init ();
eventmidiport = AlsaSeqLib.CreatePort ("event_prov_in_out"); midiport = new AlsaSeqLib.MidiPort("event_prov_in_out");
AlsaSeqLib.ConnectFrom (eventmidiport,AlsaSeqLib.SND_SEQ_CLIENT_SYSTEM, AlsaSeqLib.SND_SEQ_PORT_SYSTEM_ANNOUNCE);
AutoConnect (); AutoConnect ();
} }
@ -275,8 +273,7 @@ namespace DMX2
public void SendEvent (AlsaSeqLib.snd_seq_event_t ev) public void SendEvent (AlsaSeqLib.snd_seq_event_t ev)
{ {
ev.source.port =(byte) eventmidiport; midiport.SendEvent (ev);
AlsaSeqLib.SendEventToSubscribers (ev);
} }
public void Refresh () public void Refresh ()
@ -378,7 +375,7 @@ namespace DMX2
uint evpage; uint evpage;
// Tant qu'il y des evenements midi en attente // Tant qu'il y des evenements midi en attente
while (AlsaSeqLib.GetEvent(out evS)) { while (midiport.GetEvent(out evS)) {
Console.WriteLine(string.Format ("event {0}", evS.type) ); Console.WriteLine(string.Format ("event {0}", evS.type) );
string id = null; string id = null;
int value = 0; int value = 0;
@ -444,12 +441,7 @@ namespace DMX2
case AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_PGMCHANGE: case AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_PGMCHANGE:
CurrentPage = (uint)evS.data_ev_ctrl.value; CurrentPage = (uint)evS.data_ev_ctrl.value;
continue; continue;
case AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_PORT_START:
PortDetected (
AlsaSeqLib.GetClientByID (evS.data_addr.client),
AlsaSeqLib.GetPortByIDs (evS.data_addr.client, evS.data_addr.port)
);
continue;
/*case AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_CLOCK: /*case AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_CLOCK:
case AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_SENSING: case AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_SENSING:
@ -600,7 +592,8 @@ namespace DMX2
return; return;
disposed = true; disposed = true;
//AlsaSeqLib.Close(); //AlsaSeqLib.Close();
AlsaSeqLib.DeletePort(eventmidiport); midiport.Close();
} }
#endregion #endregion
@ -615,7 +608,7 @@ namespace DMX2
el.SetAttribute ("max14b", max14bValue.ToString ()); el.SetAttribute ("max14b", max14bValue.ToString ());
System.Xml.XmlElement xmlEl; System.Xml.XmlElement xmlEl;
foreach (MidiDevice dev in knowndevices.Values) { foreach (MidiControler dev in knowndevices.Values) {
el.AppendChild (xmlEl = parent.OwnerDocument.CreateElement ("MidiDev")); el.AppendChild (xmlEl = parent.OwnerDocument.CreateElement ("MidiDev"));
xmlEl.SetAttribute ("name", dev.Name); xmlEl.SetAttribute ("name", dev.Name);
xmlEl.SetAttribute ("feedback", dev.HasFeedback.ToString ()); xmlEl.SetAttribute ("feedback", dev.HasFeedback.ToString ());
@ -642,7 +635,7 @@ namespace DMX2
System.Xml.XmlElement xdev = xd as System.Xml.XmlElement; System.Xml.XmlElement xdev = xd as System.Xml.XmlElement;
string name = xdev.GetAttribute ("name"); string name = xdev.GetAttribute ("name");
if (!knowndevices.ContainsKey (name)) if (!knowndevices.ContainsKey (name))
knowndevices.Add (name, new MidiDevice (name)); knowndevices.Add (name, new MidiControler (name));
knowndevices [name].HasFeedback = bool.Parse (xdev.TryGetAttribute ("feedback", "false")); knowndevices [name].HasFeedback = bool.Parse (xdev.TryGetAttribute ("feedback", "false"));
} }
unpaginatedchannels.Clear (); unpaginatedchannels.Clear ();
@ -813,7 +806,7 @@ namespace DMX2
#endregion #endregion
} }
public class MidiDevice public class MidiControler
{ {
string name; string name;
@ -827,7 +820,7 @@ namespace DMX2
get{ return connected;} get{ return connected;}
} }
public MidiDevice (string _name) public MidiControler (string _name)
{ {
name = _name; name = _name;
} }

View file

@ -104,7 +104,8 @@ namespace DMX2
bool paused=false; bool paused=false;
int midiport=-1;
AlsaSeqLib.MidiPort midiport;
static int portnum=0; static int portnum=0;
List<AlsaSeqLib.Port> mididests = new List<AlsaSeqLib.Port>(); List<AlsaSeqLib.Port> mididests = new List<AlsaSeqLib.Port>();
@ -148,7 +149,7 @@ namespace DMX2
} }
); );
string portname = string.Format ("midi_seq_{0}", portnum++); string portname = string.Format ("midi_seq_{0}", portnum++);
midiport = AlsaSeqLib.CreatePort (portname); midiport = new AlsaSeqLib.MidiPort (portname);
} }
bool disposed=false; bool disposed=false;
@ -161,7 +162,7 @@ namespace DMX2
if (disposed) if (disposed)
return; return;
disposed = true; disposed = true;
AlsaSeqLib.DeletePort (midiport); midiport.Close ();
} }
public int IndexLigneEnCours public int IndexLigneEnCours
@ -173,7 +174,7 @@ namespace DMX2
} }
public void Connect (AlsaSeqLib.Port port){ public void Connect (AlsaSeqLib.Port port){
AlsaSeqLib.ConnectTo (midiport, port.ClientId, port.PortId); midiport.ConnectTo (port);
} }
public int IndexLigneaSuivre public int IndexLigneaSuivre
@ -334,8 +335,7 @@ namespace DMX2
ev.data_ev_ctrl.channel = (byte)midiCh; ev.data_ev_ctrl.channel = (byte)midiCh;
ev.data_ev_ctrl.param = uint.Parse (match.Groups [4].Value); ev.data_ev_ctrl.param = uint.Parse (match.Groups [4].Value);
ev.data_ev_ctrl.value = int.Parse (match.Groups [5].Value); ev.data_ev_ctrl.value = int.Parse (match.Groups [5].Value);
ev.source.port = (byte)midiport; midiport.SendEvent (ev);
AlsaSeqLib.SendEventToSubscribers (ev);
} }
if (match.Groups [7].Success) { if (match.Groups [7].Success) {
@ -343,8 +343,7 @@ namespace DMX2
ev.type = AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_PGMCHANGE; ev.type = AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_PGMCHANGE;
ev.data_ev_ctrl.channel = (byte)midiCh; ev.data_ev_ctrl.channel = (byte)midiCh;
ev.data_ev_ctrl.value = int.Parse (match.Groups [7].Value); ev.data_ev_ctrl.value = int.Parse (match.Groups [7].Value);
ev.source.port = (byte)midiport; midiport.SendEvent (ev);
AlsaSeqLib.SendEventToSubscribers (ev);
} }
if (match.Groups [9].Success) { if (match.Groups [9].Success) {
@ -365,8 +364,7 @@ namespace DMX2
else else
ev.data_ev_note.off_velocity = 0; ev.data_ev_note.off_velocity = 0;
} }
ev.source.port = (byte)midiport; midiport.SendEvent (ev);
AlsaSeqLib.SendEventToSubscribers (ev);
} }
} }
} }