fin de modifs objet d'AlsaSeqLib
This commit is contained in:
parent
c02a312764
commit
e91e43b76c
2 changed files with 85 additions and 41 deletions
|
|
@ -17,6 +17,12 @@ namespace DMX2
|
||||||
|
|
||||||
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
|
public class Client
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
|
|
@ -59,7 +65,7 @@ namespace DMX2
|
||||||
Invoke.snd_seq_port_info_set_client (portInfo.Pointer, id);
|
Invoke.snd_seq_port_info_set_client (portInfo.Pointer, id);
|
||||||
Invoke.snd_seq_port_info_set_port (portInfo.Pointer, -1);
|
Invoke.snd_seq_port_info_set_port (portInfo.Pointer, -1);
|
||||||
while (Invoke.snd_seq_query_next_port(seq_handle.Handle, portInfo.Pointer) >= 0) {
|
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;
|
string name;
|
||||||
uint caps;
|
uint caps;
|
||||||
uint type;
|
uint type;
|
||||||
|
int srcid;
|
||||||
|
|
||||||
public int ClientId {
|
public int ClientId {
|
||||||
get {
|
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);
|
IntPtr namePtr = Invoke.snd_seq_port_info_get_name (portInfo.Pointer);
|
||||||
caps = Invoke.snd_seq_port_info_get_capability (portInfo.Pointer);
|
caps = Invoke.snd_seq_port_info_get_capability (portInfo.Pointer);
|
||||||
type = Invoke.snd_seq_port_info_get_type (portInfo.Pointer);
|
type = Invoke.snd_seq_port_info_get_type (portInfo.Pointer);
|
||||||
name = namePtr.PtrToString ();
|
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)
|
public static void Init (string appname)
|
||||||
|
|
@ -131,7 +176,7 @@ namespace DMX2
|
||||||
|
|
||||||
System.Threading.ThreadStart ts = new System.Threading.ThreadStart (EventLoop);
|
System.Threading.ThreadStart ts = new System.Threading.ThreadStart (EventLoop);
|
||||||
eventthread = new System.Threading.Thread (ts);
|
eventthread = new System.Threading.Thread (ts);
|
||||||
|
eventthread.Start();
|
||||||
systemPort = new MidiPort ("system");
|
systemPort = new MidiPort ("system");
|
||||||
systemPort.ConnectTo (SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE);
|
systemPort.ConnectTo (SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE);
|
||||||
}
|
}
|
||||||
|
|
@ -198,7 +243,7 @@ namespace DMX2
|
||||||
|
|
||||||
static PointerWrapper evOutPtr = new PointerWrapper (32);
|
static PointerWrapper evOutPtr = new PointerWrapper (32);
|
||||||
|
|
||||||
static IEnumerable<Client> EnumClients ()
|
public static IEnumerable<Client> EnumClients ()
|
||||||
{
|
{
|
||||||
if (seq_handle == null)
|
if (seq_handle == null)
|
||||||
throw new InvalidOperationException ();
|
throw new InvalidOperationException ();
|
||||||
|
|
@ -210,7 +255,7 @@ namespace DMX2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Client GetClientByID (int client)
|
public static Client GetClientByID (int client)
|
||||||
{
|
{
|
||||||
if (seq_handle == null)
|
if (seq_handle == null)
|
||||||
throw new InvalidOperationException ();
|
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)
|
if (seq_handle == null)
|
||||||
throw new InvalidOperationException ();
|
throw new InvalidOperationException ();
|
||||||
using (PointerWrapper portInfo = new PointerWrapper(GetPortInfoSize ())) {
|
using (PointerWrapper portInfo = new PointerWrapper(GetPortInfoSize ())) {
|
||||||
if (Invoke.snd_seq_get_any_port_info (seq_handle.Handle, client, port, portInfo.Pointer) >= 0) {
|
if (Invoke.snd_seq_get_any_port_info (seq_handle.Handle, clientid, portid, portInfo.Pointer) >= 0) {
|
||||||
return new Port (portInfo);
|
return Port.GetPort (portInfo);
|
||||||
} else
|
} else
|
||||||
return null;
|
return Port.GetPort (clientid,portid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ namespace DMX2
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Liste des ports connectés avec feedback
|
/// Liste des ports connectés avec feedback
|
||||||
/// </summary>
|
/// </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>();
|
//static readonly Dictionary<int,MidiDev> srcidToDev = new Dictionary<int, MidiDev>();
|
||||||
readonly List<byte> unpaginatedchannels = new List<byte> ();
|
readonly List<byte> unpaginatedchannels = new List<byte> ();
|
||||||
|
|
@ -139,7 +139,7 @@ namespace DMX2
|
||||||
|
|
||||||
public void RefreshFeedback (string name)
|
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 (knowndevices [name].HasFeedback) {
|
||||||
if (!feedbacksources.Contains (port))
|
if (!feedbacksources.Contains (port))
|
||||||
feedbacksources.Add (port);
|
feedbacksources.Add (port);
|
||||||
|
|
@ -156,10 +156,8 @@ namespace DMX2
|
||||||
return;
|
return;
|
||||||
knowndevices.Remove (dev.Name);
|
knowndevices.Remove (dev.Name);
|
||||||
|
|
||||||
foreach (int connectedport in dev.ConnectedPorts) {
|
foreach (AlsaSeqLib.Port connectedport in dev.ConnectedPorts) {
|
||||||
int client = connectedport >> 8;
|
midiport.Deconnecte ( connectedport);
|
||||||
int port = connectedport & 0xFF;
|
|
||||||
AlsaSeqLib.Deconnecte (eventmidiport, client, port);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -212,10 +210,11 @@ namespace DMX2
|
||||||
string fullportname = cli.Name + ':' + p.Name;
|
string fullportname = cli.Name + ':' + p.Name;
|
||||||
if (knowndevices.ContainsKey (fullportname)) {
|
if (knowndevices.ContainsKey (fullportname)) {
|
||||||
int srcid = p.ClientId << 8 + p.PortId;
|
int srcid = p.ClientId << 8 + p.PortId;
|
||||||
if (knowndevices [fullportname].ConnectedPorts.Contains (srcid))
|
if (knowndevices [fullportname].ConnectedPorts.Contains (p))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AlsaSeqLib.Connect (eventmidiport,p);
|
midiport.ConnectFrom(p);
|
||||||
|
midiport.ConnectTo(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -230,16 +229,18 @@ namespace DMX2
|
||||||
portId = cn.dest.port;
|
portId = cn.dest.port;
|
||||||
}
|
}
|
||||||
|
|
||||||
int srcid = clientId << 8 + portId;
|
AlsaSeqLib.Port p = AlsaSeqLib.GetPortByIDs(clientId, portId);
|
||||||
|
|
||||||
if (connect) {
|
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))
|
if (!knowndevices.ContainsKey (fpname))
|
||||||
return;
|
return;
|
||||||
if (knowndevices [fpname].ConnectedPorts.Contains (srcid))
|
if (knowndevices [fpname].ConnectedPorts.Contains (p))
|
||||||
return;
|
return;
|
||||||
knowndevices [fpname].ConnectedPorts.Add (srcid);
|
knowndevices [fpname].ConnectedPorts.Add (p);
|
||||||
if (knowndevices [fpname].HasFeedback)
|
if (knowndevices [fpname].HasFeedback)
|
||||||
feedbacksources.Add (srcid);
|
feedbacksources.Add (p);
|
||||||
guirefreshflag = true;
|
guirefreshflag = true;
|
||||||
|
|
||||||
//srcidToDev[srcid] = knowndevices [fpname];
|
//srcidToDev[srcid] = knowndevices [fpname];
|
||||||
|
|
@ -248,10 +249,8 @@ namespace DMX2
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var dev in knowndevices.Values) {
|
foreach (var dev in knowndevices.Values) {
|
||||||
if (dev.ConnectedPorts.Contains (srcid)) {
|
if (dev.ConnectedPorts.Contains (p)) {
|
||||||
/*if(srcidToDev.ContainsKey(srcid))
|
dev.ConnectedPorts.Remove (p);
|
||||||
srcidToDev.Remove(srcid);*/
|
|
||||||
dev.ConnectedPorts.Remove (srcid);
|
|
||||||
guirefreshflag = true;
|
guirefreshflag = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -266,7 +265,7 @@ namespace DMX2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected bool HasFeedback (int source)
|
protected bool HasFeedback (AlsaSeqLib.Port source)
|
||||||
{
|
{
|
||||||
return feedbacksources.Contains (source);
|
return feedbacksources.Contains (source);
|
||||||
}
|
}
|
||||||
|
|
@ -281,8 +280,8 @@ namespace DMX2
|
||||||
foreach (var ievent in eventlist.Values) {
|
foreach (var ievent in eventlist.Values) {
|
||||||
if (ievent.Page == page) {
|
if (ievent.Page == page) {
|
||||||
ievent.SendFeedback();
|
ievent.SendFeedback();
|
||||||
foreach (int src in feedbacksources) {
|
foreach (AlsaSeqLib.Port src in feedbacksources) {
|
||||||
int lnvk = CombineHash (src, ievent.MidiEvCode);
|
int lnvk = CombineHash (src.SrcId, ievent.MidiEvCode);
|
||||||
if (ievent.LastKnownValue != -1)
|
if (ievent.LastKnownValue != -1)
|
||||||
lastValueOfSrc [lnvk] = (byte)ievent.LastKnownValue;
|
lastValueOfSrc [lnvk] = (byte)ievent.LastKnownValue;
|
||||||
}
|
}
|
||||||
|
|
@ -794,8 +793,8 @@ namespace DMX2
|
||||||
|
|
||||||
if (prov.CurrentPage == iev.Page || iev.Page == 0) {
|
if (prov.CurrentPage == iev.Page || iev.Page == 0) {
|
||||||
iev.SendFeedback();
|
iev.SendFeedback();
|
||||||
foreach (int src in prov.feedbacksources) {
|
foreach (AlsaSeqLib.Port src in prov.feedbacksources) {
|
||||||
int lnvk = CombineHash (src, iev.MidiEvCode);
|
int lnvk = CombineHash (src.SrcId, iev.MidiEvCode);
|
||||||
if (iev.LastKnownValue != -1)
|
if (iev.LastKnownValue != -1)
|
||||||
prov.lastValueOfSrc [lnvk] = (byte)iev.LastKnownValue;
|
prov.lastValueOfSrc [lnvk] = (byte)iev.LastKnownValue;
|
||||||
}
|
}
|
||||||
|
|
@ -814,9 +813,9 @@ namespace DMX2
|
||||||
|
|
||||||
public bool HasFeedback { get; set; }
|
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;}
|
get{ return connected;}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue