Enregistrement des attaches evenements
This commit is contained in:
parent
19ab3ac359
commit
a22447e2e7
9 changed files with 137 additions and 18 deletions
|
|
@ -11,7 +11,9 @@ namespace DMX2
|
|||
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;
|
||||
DateTime dernierTick;
|
||||
|
|
@ -32,6 +34,11 @@ namespace DMX2
|
|||
|
||||
public Conduite()
|
||||
{
|
||||
|
||||
if(courante!= null)
|
||||
courante.Dispose();
|
||||
courante = this;
|
||||
|
||||
timer = new Timer(new TimerCallback(TimerTick),this, 1000,10);
|
||||
derniereMaj = dernierTick=DateTime.Now;
|
||||
|
||||
|
|
@ -242,6 +249,8 @@ namespace DMX2
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
if(courante==this)
|
||||
courante = null;
|
||||
disposed=true;
|
||||
if(timer!=null)
|
||||
timer.Dispose();
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@
|
|||
<Compile Include="EventManager.cs" />
|
||||
<Compile Include="MidiEventProvider.cs" />
|
||||
<Compile Include="MidiEventProvider.PInvoke.cs" />
|
||||
<Compile Include="ContextMenuHelper.cs" />
|
||||
<Compile Include="HelperFunctions.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ namespace DMX2
|
|||
public interface IEventTarget
|
||||
{
|
||||
bool FireEvent(EventData data);
|
||||
void Bind(string id);
|
||||
void Unbind(string id);
|
||||
IEnumerable<string> IDs { get; }
|
||||
}
|
||||
|
||||
public delegate void EventManagerCallback(EventData data);
|
||||
|
|
@ -33,6 +36,7 @@ namespace DMX2
|
|||
public class actionEventTarget : IEventTarget {
|
||||
public delegate bool EventAction (EventData data);
|
||||
EventAction action;
|
||||
List<string> eventIds = new List<string>();
|
||||
public actionEventTarget(EventAction _action)
|
||||
{
|
||||
action=_action;
|
||||
|
|
@ -42,6 +46,23 @@ namespace DMX2
|
|||
{
|
||||
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
|
||||
}
|
||||
|
||||
|
|
@ -102,7 +123,7 @@ namespace DMX2
|
|||
foreach (IEventProvider prov in providers) {
|
||||
Gtk.MenuItem provitem = new Gtk.MenuItem(prov.MenuName);
|
||||
provitem.Submenu = prov.GetProviderSubMenu(evd, handler);
|
||||
menu.Add(provitem);
|
||||
if(provitem.Submenu!=null) menu.Add(provitem);
|
||||
}
|
||||
|
||||
Gtk.MenuItem itemNone = new Gtk.MenuItem("Aucun");
|
||||
|
|
@ -140,6 +161,7 @@ namespace DMX2
|
|||
if(!bindings.ContainsKey(eventId))
|
||||
bindings.Add (eventId,new eventBinding());
|
||||
bindings[eventId].AddTarget(target);
|
||||
target.Bind(eventId);
|
||||
foreach (IEventProvider prov in providers) {
|
||||
if(prov.Bind(eventId)) return true;
|
||||
}
|
||||
|
|
@ -164,6 +186,8 @@ namespace DMX2
|
|||
prov.Unbind(eventId);
|
||||
}
|
||||
}
|
||||
|
||||
target.Unbind(eventId);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,20 @@ using System;
|
|||
using Gdk;
|
||||
using GLib;
|
||||
using Gtk;
|
||||
using System.Xml;
|
||||
|
||||
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
|
||||
{
|
||||
private Widget widget;
|
||||
|
|
@ -282,7 +282,7 @@ namespace DMX2
|
|||
dlg.VBox.Add (new Label("Nom de la nouvelle Conduite :")); dlg.VBox.Add (entry); dlg.VBox.ShowAll ();
|
||||
entry.ActivatesDefault=true;
|
||||
if ((ResponseType)dlg.Run () == ResponseType.Ok) {
|
||||
Conduite.Courante = new Conduite ();
|
||||
new Conduite ();
|
||||
Conduite.Courante.Name = entry.Text;
|
||||
}
|
||||
MajWidgets();
|
||||
|
|
@ -293,7 +293,6 @@ namespace DMX2
|
|||
protected void OnCloseActionActivated (object sender, EventArgs e)
|
||||
{
|
||||
Conduite.Courante.Dispose();
|
||||
Conduite.Courante= null;
|
||||
MajWidgets();
|
||||
}
|
||||
|
||||
|
|
@ -399,8 +398,6 @@ namespace DMX2
|
|||
return;
|
||||
}
|
||||
|
||||
Conduite.Courante = cond;
|
||||
|
||||
conduiteFile = openFile;
|
||||
|
||||
} catch (IOException) {
|
||||
|
|
|
|||
|
|
@ -50,8 +50,7 @@ namespace DMX2
|
|||
|
||||
bool IEventProvider.Bind (string eventId)
|
||||
{
|
||||
// TODO : check if "MIDI ..."
|
||||
return true;
|
||||
return eventId.StartsWith("MIDI-");
|
||||
}
|
||||
|
||||
void IEventProvider.Unbind (string eventId)
|
||||
|
|
@ -62,6 +61,7 @@ namespace DMX2
|
|||
|
||||
Gtk.Menu IEventProvider.GetProviderSubMenu (EventManager.EventMenuData state, Gtk.ButtonPressEventHandler handler)
|
||||
{
|
||||
if(!connected) return null;
|
||||
Gtk.Menu retmenu = new Gtk.Menu ();
|
||||
if (levent != null) {
|
||||
Gtk.MenuItem lmenuitem = new Gtk.MenuItem ("Dernier");
|
||||
|
|
@ -96,6 +96,7 @@ namespace DMX2
|
|||
}
|
||||
|
||||
EventData last; internalEvent levent=null;
|
||||
bool connected=false;
|
||||
|
||||
void IEventProvider.ProcessEvents (EventManagerCallback callback)
|
||||
{
|
||||
|
|
@ -108,6 +109,9 @@ namespace DMX2
|
|||
string id=null, description=null; int value=0;
|
||||
|
||||
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:
|
||||
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);
|
||||
|
|
@ -133,7 +137,7 @@ namespace DMX2
|
|||
Info.Publish(string.Format ("event {0}", evS.type) );
|
||||
continue;
|
||||
}
|
||||
|
||||
connected=true;
|
||||
if(id!=null)
|
||||
{
|
||||
if(!eventlist.ContainsKey(id))
|
||||
|
|
|
|||
|
|
@ -141,6 +141,23 @@ namespace DMX2
|
|||
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
|
||||
|
|
@ -490,7 +507,6 @@ namespace DMX2
|
|||
return;
|
||||
}
|
||||
Conduite.Courante.EventManager.Bind(eventId,masterEventTarget);
|
||||
|
||||
}
|
||||
|
||||
public void BindEffetSuivantEvent (string eventId)
|
||||
|
|
@ -514,16 +530,30 @@ namespace DMX2
|
|||
public override void Save (System.Xml.XmlElement parent)
|
||||
{
|
||||
System.Xml.XmlElement el = parent.OwnerDocument.CreateElement ("SequenceurLineaire");
|
||||
System.Xml.XmlElement xmlC;
|
||||
System.Xml.XmlElement xmlEl;
|
||||
|
||||
parent.AppendChild (el);
|
||||
el.SetAttribute ("id", ID.ToString ());
|
||||
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) {
|
||||
el.AppendChild(xmlC = parent.OwnerDocument.CreateElement ("CircuitSeq"));
|
||||
xmlC.SetAttribute("id",c.ID.ToString());
|
||||
el.AppendChild(xmlEl = parent.OwnerDocument.CreateElement ("CircuitSeq"));
|
||||
xmlEl.SetAttribute("id",c.ID.ToString());
|
||||
|
||||
if(targets.ContainsKey(c))
|
||||
EventManager.SaveBindings(xmlEl,targets[c]);
|
||||
|
||||
}
|
||||
|
||||
foreach (Effet ef in effets) {
|
||||
|
|
@ -558,15 +588,34 @@ namespace DMX2
|
|||
|
||||
private void LoadSeq (Conduite conduite, System.Xml.XmlElement el)
|
||||
{
|
||||
System.Xml.XmlElement xmlE;
|
||||
|
||||
ID = int.Parse (el.GetAttribute ("id"));
|
||||
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")) {
|
||||
System.Xml.XmlElement xcir = xc as System.Xml.XmlElement;
|
||||
Circuit c = conduite.GetCircuitByID (int.Parse (xcir.GetAttribute ("id")));
|
||||
circuitsSeq.Add (c);
|
||||
AjouteCircuit (c);
|
||||
foreach(string id in EventManager.LoadBindings (xcir))
|
||||
BindCircuitEvent(c,id);
|
||||
}
|
||||
|
||||
foreach (var xe in el.GetElementsByTagName("Effet"))
|
||||
|
|
|
|||
|
|
@ -266,6 +266,7 @@ namespace DMX2
|
|||
this.moveDownAction.Activated += new global::System.EventHandler (this.OnMoveDownActionActivated);
|
||||
this.circuitsAction.Activated += new global::System.EventHandler (this.OnCircuitsActionActivated);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -817,6 +817,7 @@ au sequenceur</property>
|
|||
<property name="DrawValue">True</property>
|
||||
<property name="Digits">0</property>
|
||||
<property name="ValuePos">Right</property>
|
||||
<signal name="ValueChanged" handler="OnSeqMasterScaleValueChanged" />
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="Position">1</property>
|
||||
|
|
|
|||
Loading…
Reference in a new issue