fin de modifs objet d'AlsaSeqLib

This commit is contained in:
arnaud.houdelette 2018-10-04 10:31:48 +02:00
parent c02a312764
commit e91e43b76c
2 changed files with 85 additions and 41 deletions

View file

@ -12,10 +12,16 @@ namespace DMX2
//static int inport;
//static int outport;
static System.Threading.Thread eventthread=null;
static MidiPort systemPort=null;
static System.Threading.Thread eventthread = null;
static MidiPort systemPort = null;
static internal Dictionary<int,MidiPort> openports = new Dictionary<int, MidiPort>();
static internal Dictionary<int, MidiPort> openports = new Dictionary<int, MidiPort>();
public static int ClientId{
get {
return clientId;
}
}
public class Client
{
@ -59,7 +65,7 @@ namespace DMX2
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));
ports.Add (Port.GetPort(portInfo));
}
}
}
@ -78,6 +84,7 @@ namespace DMX2
string name;
uint caps;
uint type;
int srcid;
public int ClientId {
get {
@ -109,15 +116,53 @@ namespace DMX2
}
}
internal Port (PointerWrapper portInfo)
public int SrcId
{
get
{
return srcid;
}
}
private Port(int _clientId, int _portId)
{
clientId = _clientId;
portId = _portId;
srcid = clientId << 8 + portId;
}
private void Updateinfo (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 ();
}
internal static Port GetPort(PointerWrapper portInfo)
{
Port p;
int clientId = Invoke.snd_seq_port_info_get_client(portInfo.Pointer);
int portId = Invoke.snd_seq_port_info_get_port(portInfo.Pointer);
int srcid = clientId << 8 + portId;
if (ports.ContainsKey(srcid))
p = ports[srcid];
else
p = new Port(clientId, portId);
p.Updateinfo(portInfo);
return p;
}
internal static Port GetPort(int clientId, int portId)
{
int srcid = clientId << 8 + portId;
if (ports.ContainsKey(srcid))
return ports[srcid];
return null;
}
static Dictionary<int, Port> ports = new Dictionary<int, Port>();
}
public static void Init (string appname)
@ -131,7 +176,7 @@ namespace DMX2
System.Threading.ThreadStart ts = new System.Threading.ThreadStart (EventLoop);
eventthread = new System.Threading.Thread (ts);
eventthread.Start();
systemPort = new MidiPort ("system");
systemPort.ConnectTo (SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE);
}
@ -198,7 +243,7 @@ namespace DMX2
static PointerWrapper evOutPtr = new PointerWrapper (32);
static IEnumerable<Client> EnumClients ()
public static IEnumerable<Client> EnumClients ()
{
if (seq_handle == null)
throw new InvalidOperationException ();
@ -210,7 +255,7 @@ namespace DMX2
}
}
static Client GetClientByID (int client)
public static Client GetClientByID (int client)
{
if (seq_handle == null)
throw new InvalidOperationException ();
@ -222,15 +267,15 @@ namespace DMX2
}
}
static Port GetPortByIDs (int client, int port)
public static Port GetPortByIDs (int clientid, int portid)
{
if (seq_handle == null)
throw new InvalidOperationException ();
using (PointerWrapper portInfo = new PointerWrapper(GetPortInfoSize ())) {
if (Invoke.snd_seq_get_any_port_info (seq_handle.Handle, client, port, portInfo.Pointer) >= 0) {
return new Port (portInfo);
if (Invoke.snd_seq_get_any_port_info (seq_handle.Handle, clientid, portid, portInfo.Pointer) >= 0) {
return Port.GetPort (portInfo);
} else
return null;
return Port.GetPort (clientid,portid);
}
}

View file

@ -38,7 +38,7 @@ namespace DMX2
/// <summary>
/// Liste des ports connectés avec feedback
/// </summary>
readonly List<int> feedbacksources = new List<int> ();
readonly List<AlsaSeqLib.Port> feedbacksources = new List<AlsaSeqLib.Port> ();
//static readonly Dictionary<int,MidiDev> srcidToDev = new Dictionary<int, MidiDev>();
readonly List<byte> unpaginatedchannels = new List<byte> ();
@ -139,7 +139,7 @@ namespace DMX2
public void RefreshFeedback (string name)
{
foreach (int port in knowndevices[name].ConnectedPorts) {
foreach (AlsaSeqLib.Port port in knowndevices[name].ConnectedPorts) {
if (knowndevices [name].HasFeedback) {
if (!feedbacksources.Contains (port))
feedbacksources.Add (port);
@ -156,10 +156,8 @@ namespace DMX2
return;
knowndevices.Remove (dev.Name);
foreach (int connectedport in dev.ConnectedPorts) {
int client = connectedport >> 8;
int port = connectedport & 0xFF;
AlsaSeqLib.Deconnecte (eventmidiport, client, port);
foreach (AlsaSeqLib.Port connectedport in dev.ConnectedPorts) {
midiport.Deconnecte ( connectedport);
}
}
@ -212,10 +210,11 @@ namespace DMX2
string fullportname = cli.Name + ':' + p.Name;
if (knowndevices.ContainsKey (fullportname)) {
int srcid = p.ClientId << 8 + p.PortId;
if (knowndevices [fullportname].ConnectedPorts.Contains (srcid))
if (knowndevices [fullportname].ConnectedPorts.Contains (p))
return;
AlsaSeqLib.Connect (eventmidiport,p);
midiport.ConnectFrom(p);
midiport.ConnectTo(p);
}
}
@ -230,16 +229,18 @@ namespace DMX2
portId = cn.dest.port;
}
int srcid = clientId << 8 + portId;
AlsaSeqLib.Port p = AlsaSeqLib.GetPortByIDs(clientId, portId);
if (connect) {
string fpname = AlsaSeqLib.GetClientByID (clientId).Name + ":" + AlsaSeqLib.GetPortByIDs (clientId, portId).Name;
AlsaSeqLib.Client c = AlsaSeqLib.GetClientByID(clientId);
string fpname = c.Name + ":" + p.Name;
if (!knowndevices.ContainsKey (fpname))
return;
if (knowndevices [fpname].ConnectedPorts.Contains (srcid))
if (knowndevices [fpname].ConnectedPorts.Contains (p))
return;
knowndevices [fpname].ConnectedPorts.Add (srcid);
knowndevices [fpname].ConnectedPorts.Add (p);
if (knowndevices [fpname].HasFeedback)
feedbacksources.Add (srcid);
feedbacksources.Add (p);
guirefreshflag = true;
//srcidToDev[srcid] = knowndevices [fpname];
@ -248,10 +249,8 @@ namespace DMX2
}
foreach (var dev in knowndevices.Values) {
if (dev.ConnectedPorts.Contains (srcid)) {
/*if(srcidToDev.ContainsKey(srcid))
srcidToDev.Remove(srcid);*/
dev.ConnectedPorts.Remove (srcid);
if (dev.ConnectedPorts.Contains (p)) {
dev.ConnectedPorts.Remove (p);
guirefreshflag = true;
return;
}
@ -266,7 +265,7 @@ namespace DMX2
}
}
protected bool HasFeedback (int source)
protected bool HasFeedback (AlsaSeqLib.Port source)
{
return feedbacksources.Contains (source);
}
@ -281,8 +280,8 @@ namespace DMX2
foreach (var ievent in eventlist.Values) {
if (ievent.Page == page) {
ievent.SendFeedback();
foreach (int src in feedbacksources) {
int lnvk = CombineHash (src, ievent.MidiEvCode);
foreach (AlsaSeqLib.Port src in feedbacksources) {
int lnvk = CombineHash (src.SrcId, ievent.MidiEvCode);
if (ievent.LastKnownValue != -1)
lastValueOfSrc [lnvk] = (byte)ievent.LastKnownValue;
}
@ -794,8 +793,8 @@ namespace DMX2
if (prov.CurrentPage == iev.Page || iev.Page == 0) {
iev.SendFeedback();
foreach (int src in prov.feedbacksources) {
int lnvk = CombineHash (src, iev.MidiEvCode);
foreach (AlsaSeqLib.Port src in prov.feedbacksources) {
int lnvk = CombineHash (src.SrcId, iev.MidiEvCode);
if (iev.LastKnownValue != -1)
prov.lastValueOfSrc [lnvk] = (byte)iev.LastKnownValue;
}
@ -814,9 +813,9 @@ namespace DMX2
public bool HasFeedback { get; set; }
readonly List<int> connected = new List<int> ();
readonly List<AlsaSeqLib.Port> connected = new List<AlsaSeqLib.Port> ();
public List<int> ConnectedPorts {
public List<AlsaSeqLib.Port> ConnectedPorts {
get{ return connected;}
}