Enregistrement des attaches evenements

This commit is contained in:
tzim 2013-11-15 10:00:52 +00:00
parent 19ab3ac359
commit a22447e2e7
9 changed files with 137 additions and 18 deletions

View file

@ -11,7 +11,9 @@ namespace DMX2
public class Conduite : IComparer<Circuit>, IDisposable public class Conduite : IComparer<Circuit>, IDisposable
{ {
public static Conduite Courante = null; static Conduite courante = null;
public static Conduite Courante { get { return courante; } }
Timer timer = null; Timer timer = null;
DateTime dernierTick; DateTime dernierTick;
@ -32,6 +34,11 @@ namespace DMX2
public Conduite() public Conduite()
{ {
if(courante!= null)
courante.Dispose();
courante = this;
timer = new Timer(new TimerCallback(TimerTick),this, 1000,10); timer = new Timer(new TimerCallback(TimerTick),this, 1000,10);
derniereMaj = dernierTick=DateTime.Now; derniereMaj = dernierTick=DateTime.Now;
@ -242,6 +249,8 @@ namespace DMX2
public void Dispose() public void Dispose()
{ {
if(courante==this)
courante = null;
disposed=true; disposed=true;
if(timer!=null) if(timer!=null)
timer.Dispose(); timer.Dispose();

View file

@ -106,7 +106,7 @@
<Compile Include="EventManager.cs" /> <Compile Include="EventManager.cs" />
<Compile Include="MidiEventProvider.cs" /> <Compile Include="MidiEventProvider.cs" />
<Compile Include="MidiEventProvider.PInvoke.cs" /> <Compile Include="MidiEventProvider.PInvoke.cs" />
<Compile Include="ContextMenuHelper.cs" /> <Compile Include="HelperFunctions.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions> <ProjectExtensions>

View file

@ -25,6 +25,9 @@ namespace DMX2
public interface IEventTarget public interface IEventTarget
{ {
bool FireEvent(EventData data); bool FireEvent(EventData data);
void Bind(string id);
void Unbind(string id);
IEnumerable<string> IDs { get; }
} }
public delegate void EventManagerCallback(EventData data); public delegate void EventManagerCallback(EventData data);
@ -33,6 +36,7 @@ namespace DMX2
public class actionEventTarget : IEventTarget { public class actionEventTarget : IEventTarget {
public delegate bool EventAction (EventData data); public delegate bool EventAction (EventData data);
EventAction action; EventAction action;
List<string> eventIds = new List<string>();
public actionEventTarget(EventAction _action) public actionEventTarget(EventAction _action)
{ {
action=_action; action=_action;
@ -42,6 +46,23 @@ namespace DMX2
{ {
return action(data); return action(data);
} }
void IEventTarget.Bind (string id)
{
if(!eventIds.Contains(id))
eventIds.Add(id);
}
void IEventTarget.Unbind (string id)
{
eventIds.Remove(id);
}
IEnumerable<string> IEventTarget.IDs {
get {
return eventIds;
}
}
#endregion #endregion
} }
@ -102,7 +123,7 @@ namespace DMX2
foreach (IEventProvider prov in providers) { foreach (IEventProvider prov in providers) {
Gtk.MenuItem provitem = new Gtk.MenuItem(prov.MenuName); Gtk.MenuItem provitem = new Gtk.MenuItem(prov.MenuName);
provitem.Submenu = prov.GetProviderSubMenu(evd, handler); provitem.Submenu = prov.GetProviderSubMenu(evd, handler);
menu.Add(provitem); if(provitem.Submenu!=null) menu.Add(provitem);
} }
Gtk.MenuItem itemNone = new Gtk.MenuItem("Aucun"); Gtk.MenuItem itemNone = new Gtk.MenuItem("Aucun");
@ -140,6 +161,7 @@ namespace DMX2
if(!bindings.ContainsKey(eventId)) if(!bindings.ContainsKey(eventId))
bindings.Add (eventId,new eventBinding()); bindings.Add (eventId,new eventBinding());
bindings[eventId].AddTarget(target); bindings[eventId].AddTarget(target);
target.Bind(eventId);
foreach (IEventProvider prov in providers) { foreach (IEventProvider prov in providers) {
if(prov.Bind(eventId)) return true; if(prov.Bind(eventId)) return true;
} }
@ -164,6 +186,8 @@ namespace DMX2
prov.Unbind(eventId); prov.Unbind(eventId);
} }
} }
target.Unbind(eventId);
} }
public void EventCallBack (EventData data) public void EventCallBack (EventData data)
@ -175,6 +199,29 @@ namespace DMX2
} }
} }
} }
public static bool SaveBindings (System.Xml.XmlElement xmlParent, IEventTarget target)
{
bool ret=false;
System.Xml.XmlElement xmlB;
foreach (string id in target.IDs) {
ret=true;
xmlParent.AppendChild(xmlB = xmlParent.OwnerDocument.CreateElement("EventBinding"));
xmlB.SetAttribute("id",id);
}
return ret;
}
public static string[] LoadBindings (System.Xml.XmlElement xmlParent)
{
var all=xmlParent.GetElementsByTagName("EventBinding");
string[] ret = new string[all.Count]; int index=0;
foreach (var xb in all) {
ret[index++] = (xb as System.Xml.XmlElement).GetAttribute("id");
}
return ret;
}
} }
} }

View file

@ -2,9 +2,20 @@ using System;
using Gdk; using Gdk;
using GLib; using GLib;
using Gtk; using Gtk;
using System.Xml;
namespace DMX2 namespace DMX2
{ {
public static class XmlHelpers {
public static string TryGetAttribute (this XmlElement element, string name, string defaultval)
{
if(!element.HasAttribute(name)) return defaultval;
return element.GetAttribute(name);
}
}
public class ContextMenuEventArgs : EventArgs public class ContextMenuEventArgs : EventArgs
{ {
private Widget widget; private Widget widget;

View file

@ -282,7 +282,7 @@ namespace DMX2
dlg.VBox.Add (new Label("Nom de la nouvelle Conduite :")); dlg.VBox.Add (entry); dlg.VBox.ShowAll (); dlg.VBox.Add (new Label("Nom de la nouvelle Conduite :")); dlg.VBox.Add (entry); dlg.VBox.ShowAll ();
entry.ActivatesDefault=true; entry.ActivatesDefault=true;
if ((ResponseType)dlg.Run () == ResponseType.Ok) { if ((ResponseType)dlg.Run () == ResponseType.Ok) {
Conduite.Courante = new Conduite (); new Conduite ();
Conduite.Courante.Name = entry.Text; Conduite.Courante.Name = entry.Text;
} }
MajWidgets(); MajWidgets();
@ -293,7 +293,6 @@ namespace DMX2
protected void OnCloseActionActivated (object sender, EventArgs e) protected void OnCloseActionActivated (object sender, EventArgs e)
{ {
Conduite.Courante.Dispose(); Conduite.Courante.Dispose();
Conduite.Courante= null;
MajWidgets(); MajWidgets();
} }
@ -399,8 +398,6 @@ namespace DMX2
return; return;
} }
Conduite.Courante = cond;
conduiteFile = openFile; conduiteFile = openFile;
} catch (IOException) { } catch (IOException) {

View file

@ -50,8 +50,7 @@ namespace DMX2
bool IEventProvider.Bind (string eventId) bool IEventProvider.Bind (string eventId)
{ {
// TODO : check if "MIDI ..." return eventId.StartsWith("MIDI-");
return true;
} }
void IEventProvider.Unbind (string eventId) void IEventProvider.Unbind (string eventId)
@ -62,6 +61,7 @@ namespace DMX2
Gtk.Menu IEventProvider.GetProviderSubMenu (EventManager.EventMenuData state, Gtk.ButtonPressEventHandler handler) Gtk.Menu IEventProvider.GetProviderSubMenu (EventManager.EventMenuData state, Gtk.ButtonPressEventHandler handler)
{ {
if(!connected) return null;
Gtk.Menu retmenu = new Gtk.Menu (); Gtk.Menu retmenu = new Gtk.Menu ();
if (levent != null) { if (levent != null) {
Gtk.MenuItem lmenuitem = new Gtk.MenuItem ("Dernier"); Gtk.MenuItem lmenuitem = new Gtk.MenuItem ("Dernier");
@ -96,6 +96,7 @@ namespace DMX2
} }
EventData last; internalEvent levent=null; EventData last; internalEvent levent=null;
bool connected=false;
void IEventProvider.ProcessEvents (EventManagerCallback callback) void IEventProvider.ProcessEvents (EventManagerCallback callback)
{ {
@ -108,6 +109,9 @@ namespace DMX2
string id=null, description=null; int value=0; string id=null, description=null; int value=0;
switch (evS.type) { switch (evS.type) {
case snd_seq_event_type_t.SND_SEQ_EVENT_PORT_SUBSCRIBED:
connected = true;
continue;
case snd_seq_event_type_t.SND_SEQ_EVENT_CONTROLLER: case snd_seq_event_type_t.SND_SEQ_EVENT_CONTROLLER:
id= string.Format("MIDI-CTRL-C{0}P{1}",evS.data_ev_ctrl.channel,evS.data_ev_ctrl.param); id= string.Format("MIDI-CTRL-C{0}P{1}",evS.data_ev_ctrl.channel,evS.data_ev_ctrl.param);
description = string.Format("Controller Ch {0} Param {1}",evS.data_ev_ctrl.channel,evS.data_ev_ctrl.param); description = string.Format("Controller Ch {0} Param {1}",evS.data_ev_ctrl.channel,evS.data_ev_ctrl.param);
@ -133,7 +137,7 @@ namespace DMX2
Info.Publish(string.Format ("event {0}", evS.type) ); Info.Publish(string.Format ("event {0}", evS.type) );
continue; continue;
} }
connected=true;
if(id!=null) if(id!=null)
{ {
if(!eventlist.ContainsKey(id)) if(!eventlist.ContainsKey(id))

View file

@ -103,7 +103,7 @@ namespace DMX2
} }
#region EventTargets #region EventTargets
class circuitEventTarget : IEventTarget { class circuitEventTarget : IEventTarget {
Circuit circuit; Circuit circuit;
Dictionary<string,int> valeursrecues= new Dictionary<string, int>(); Dictionary<string,int> valeursrecues= new Dictionary<string, int>();
SequenceurLineaire seq; SequenceurLineaire seq;
@ -141,6 +141,23 @@ namespace DMX2
return true; return true;
} }
void IEventTarget.Bind (string id)
{
valeursrecues[id] = 0;
}
void IEventTarget.Unbind (string id)
{
valeursrecues.Remove(id);
}
IEnumerable<string> IEventTarget.IDs {
get {
return valeursrecues.Keys;
}
}
} }
#endregion #endregion
@ -490,7 +507,6 @@ namespace DMX2
return; return;
} }
Conduite.Courante.EventManager.Bind(eventId,masterEventTarget); Conduite.Courante.EventManager.Bind(eventId,masterEventTarget);
} }
public void BindEffetSuivantEvent (string eventId) public void BindEffetSuivantEvent (string eventId)
@ -514,16 +530,30 @@ namespace DMX2
public override void Save (System.Xml.XmlElement parent) public override void Save (System.Xml.XmlElement parent)
{ {
System.Xml.XmlElement el = parent.OwnerDocument.CreateElement ("SequenceurLineaire"); System.Xml.XmlElement el = parent.OwnerDocument.CreateElement ("SequenceurLineaire");
System.Xml.XmlElement xmlC; System.Xml.XmlElement xmlEl;
parent.AppendChild (el); parent.AppendChild (el);
el.SetAttribute ("id", ID.ToString ()); el.SetAttribute ("id", ID.ToString ());
el.SetAttribute ("name", Name); el.SetAttribute ("name", Name);
el.SetAttribute ("master", master.ToString ()); //el.SetAttribute ("master", master.ToString ());
el.AppendChild(xmlEl = parent.OwnerDocument.CreateElement ("Master"));
xmlEl.SetAttribute("value",master.ToString());
EventManager.SaveBindings(xmlEl,masterEventTarget);
xmlEl = parent.OwnerDocument.CreateElement ("EffetSuivant");
if(EventManager.SaveBindings(xmlEl,goNextEventTarget )) el.AppendChild(xmlEl);
xmlEl = parent.OwnerDocument.CreateElement ("EffetPrecedent");
if(EventManager.SaveBindings(xmlEl,goBackEventTarget )) el.AppendChild(xmlEl);
foreach (Circuit c in circuitsSeq) { foreach (Circuit c in circuitsSeq) {
el.AppendChild(xmlC = parent.OwnerDocument.CreateElement ("CircuitSeq")); el.AppendChild(xmlEl = parent.OwnerDocument.CreateElement ("CircuitSeq"));
xmlC.SetAttribute("id",c.ID.ToString()); xmlEl.SetAttribute("id",c.ID.ToString());
if(targets.ContainsKey(c))
EventManager.SaveBindings(xmlEl,targets[c]);
} }
foreach (Effet ef in effets) { foreach (Effet ef in effets) {
@ -558,15 +588,34 @@ namespace DMX2
private void LoadSeq (Conduite conduite, System.Xml.XmlElement el) private void LoadSeq (Conduite conduite, System.Xml.XmlElement el)
{ {
System.Xml.XmlElement xmlE;
ID = int.Parse (el.GetAttribute ("id")); ID = int.Parse (el.GetAttribute ("id"));
Name = el.GetAttribute ("name"); Name = el.GetAttribute ("name");
master = int.Parse (el.GetAttribute ("master"));
if ((xmlE = el["Master"]) != null) {
master = int.Parse (xmlE.TryGetAttribute("value","100"));
foreach(string id in EventManager.LoadBindings(xmlE))
BindMasterEvent(id);
}
else master = int.Parse (el.TryGetAttribute("master","100"));
if ((xmlE = el["EffetSuivant"])!= null)
foreach(string id in EventManager.LoadBindings(xmlE))
BindEffetSuivantEvent(id);
if ((xmlE = el["EffetPrecedent"])!= null)
foreach(string id in EventManager.LoadBindings(xmlE))
BindEffetSuivantEvent(id);
foreach (var xc in el.GetElementsByTagName("CircuitSeq")) { foreach (var xc in el.GetElementsByTagName("CircuitSeq")) {
System.Xml.XmlElement xcir = xc as System.Xml.XmlElement; System.Xml.XmlElement xcir = xc as System.Xml.XmlElement;
Circuit c = conduite.GetCircuitByID (int.Parse (xcir.GetAttribute ("id"))); Circuit c = conduite.GetCircuitByID (int.Parse (xcir.GetAttribute ("id")));
circuitsSeq.Add (c); circuitsSeq.Add (c);
AjouteCircuit (c); AjouteCircuit (c);
foreach(string id in EventManager.LoadBindings (xcir))
BindCircuitEvent(c,id);
} }
foreach (var xe in el.GetElementsByTagName("Effet")) foreach (var xe in el.GetElementsByTagName("Effet"))

View file

@ -266,6 +266,7 @@ namespace DMX2
this.moveDownAction.Activated += new global::System.EventHandler (this.OnMoveDownActionActivated); this.moveDownAction.Activated += new global::System.EventHandler (this.OnMoveDownActionActivated);
this.circuitsAction.Activated += new global::System.EventHandler (this.OnCircuitsActionActivated); this.circuitsAction.Activated += new global::System.EventHandler (this.OnCircuitsActionActivated);
this.closeAction.Activated += new global::System.EventHandler (this.OnCloseActionActivated); this.closeAction.Activated += new global::System.EventHandler (this.OnCloseActionActivated);
this.seqMasterScale.ValueChanged += new global::System.EventHandler (this.OnSeqMasterScaleValueChanged);
this.zoneWid.SizeAllocated += new global::Gtk.SizeAllocatedHandler (this.OnZoneWidSizeAllocated); this.zoneWid.SizeAllocated += new global::Gtk.SizeAllocatedHandler (this.OnZoneWidSizeAllocated);
} }
} }

View file

@ -817,6 +817,7 @@ au sequenceur</property>
<property name="DrawValue">True</property> <property name="DrawValue">True</property>
<property name="Digits">0</property> <property name="Digits">0</property>
<property name="ValuePos">Right</property> <property name="ValuePos">Right</property>
<signal name="ValueChanged" handler="OnSeqMasterScaleValueChanged" />
</widget> </widget>
<packing> <packing>
<property name="Position">1</property> <property name="Position">1</property>