correction du mode de pagination
This commit is contained in:
parent
df7e0f1d45
commit
4ca07bbef0
1 changed files with 79 additions and 47 deletions
|
|
@ -28,8 +28,10 @@ namespace DMX2
|
|||
|
||||
class internalEvent {
|
||||
|
||||
public string InternalName{ get; set; }
|
||||
readonly string internalName;
|
||||
bool bound=false;
|
||||
readonly int page;
|
||||
readonly int midiEvCode;
|
||||
|
||||
public bool Bound {
|
||||
get {
|
||||
|
|
@ -40,26 +42,40 @@ namespace DMX2
|
|||
}
|
||||
}
|
||||
|
||||
public internalEvent(string _id)
|
||||
{
|
||||
InternalName=_id;
|
||||
public string InternalName {
|
||||
get {
|
||||
return internalName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int[] sources=null;
|
||||
public IEnumerable<int> Sources {
|
||||
public int Page {
|
||||
get {
|
||||
if(sources == null || sources.Length!=lastknownvalues.Count) sources = lastknownvalues.Keys.ToArray();
|
||||
return sources;
|
||||
return page;
|
||||
}
|
||||
}
|
||||
|
||||
public int MidiEvCode {
|
||||
get {
|
||||
return midiEvCode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
readonly Dictionary<int,byte> lastknownvalues = new Dictionary<int, byte>();
|
||||
public internalEvent(string _id, int _page, int _evHCode)
|
||||
{
|
||||
internalName=_id;
|
||||
page=_page;
|
||||
midiEvCode = _evHCode;
|
||||
}
|
||||
|
||||
public Dictionary<int, byte> LastKnownValues {
|
||||
byte lastknownvalue;
|
||||
|
||||
public byte LastKnownValue {
|
||||
get {
|
||||
return lastknownvalues;
|
||||
return lastknownvalue;
|
||||
}
|
||||
set {
|
||||
lastknownvalue = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -75,17 +91,14 @@ namespace DMX2
|
|||
}
|
||||
|
||||
abstract class feedbackinfo : IFeedbackInfo {
|
||||
|
||||
MidiEventProvider prov;
|
||||
readonly internalEvent iev;
|
||||
protected AlsaSeqLib.snd_seq_event_t ev;
|
||||
string eventId;
|
||||
int page;
|
||||
|
||||
|
||||
public feedbackinfo(MidiEventProvider _prov, string _eventId, int _page){
|
||||
public feedbackinfo(MidiEventProvider _prov, internalEvent _iev){
|
||||
prov = _prov;
|
||||
eventId = _eventId;
|
||||
page = _page;
|
||||
iev=_iev;
|
||||
}
|
||||
|
||||
protected abstract bool UpdateEvent(byte data);
|
||||
|
|
@ -93,33 +106,29 @@ namespace DMX2
|
|||
#region IFeedbackInfo implementation
|
||||
bool IFeedbackInfo.FeedBack (byte data)
|
||||
{
|
||||
if (!prov.eventlist.ContainsKey (eventId))
|
||||
return false;
|
||||
|
||||
bool update = UpdateEvent (data);
|
||||
iev.StoredEvent = ev;
|
||||
if (!update) return true;
|
||||
|
||||
prov.eventlist[eventId].StoredEvent = ev;
|
||||
iev.LastKnownValue = data;
|
||||
|
||||
if(!update) return true;
|
||||
|
||||
foreach (var src in prov.eventlist[eventId].Sources) {
|
||||
if(prov.HasFeedback(src))
|
||||
{
|
||||
prov.eventlist[eventId].LastKnownValues[src]=data;
|
||||
if (prov.CurrentPage == iev.Page || iev.Page == 0) {
|
||||
prov.SendEvent (ev);
|
||||
foreach (int srcid in prov.feedbacksources) {
|
||||
int lnvk = srcid ^ iev.MidiEvCode;
|
||||
prov.lastKnownValues[lnvk] = data;
|
||||
}
|
||||
}
|
||||
|
||||
if(prov.CurrentPage == page || page == 0)
|
||||
prov.SendEvent (ev);
|
||||
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
class ctrlfeedbackinfo : feedbackinfo {
|
||||
public ctrlfeedbackinfo(MidiEventProvider _prov, string _eventId, int _page, byte channel,uint param)
|
||||
:base(_prov,_eventId,_page)
|
||||
public ctrlfeedbackinfo(MidiEventProvider _prov, internalEvent _iev, byte channel,uint param)
|
||||
:base(_prov,_iev)
|
||||
{
|
||||
ev = new AlsaSeqLib.snd_seq_event_t();
|
||||
ev.data_ev_ctrl.channel = channel;
|
||||
|
|
@ -137,8 +146,8 @@ namespace DMX2
|
|||
}
|
||||
|
||||
class pitchbendfeedbackinfo : feedbackinfo {
|
||||
public pitchbendfeedbackinfo(MidiEventProvider _prov, string _eventId,int _page, byte channel)
|
||||
:base(_prov,_eventId,_page)
|
||||
public pitchbendfeedbackinfo(MidiEventProvider _prov, internalEvent _iev, byte channel)
|
||||
:base(_prov,_iev)
|
||||
{
|
||||
ev = new AlsaSeqLib.snd_seq_event_t();
|
||||
ev.data_ev_ctrl.channel = channel;
|
||||
|
|
@ -175,6 +184,7 @@ namespace DMX2
|
|||
readonly Dictionary<string,MidiDev> knowndevices = new Dictionary<string,MidiDev>();
|
||||
readonly List<int> feedbacksources = new List<int>();
|
||||
readonly List<byte> unpaginatedchannels = new List<byte>();
|
||||
readonly Dictionary<int,byte> lastKnownValues = new Dictionary<int, byte>();
|
||||
|
||||
|
||||
EventData last;
|
||||
|
|
@ -265,21 +275,38 @@ namespace DMX2
|
|||
|
||||
public void Refresh ()
|
||||
{
|
||||
string pageStr = string.Format("PAGE{0}",page);
|
||||
foreach (var ievent in eventlist.Values) {
|
||||
if (ievent.InternalName.Contains(pageStr)){
|
||||
if (ievent.Page == page){
|
||||
SendEvent(ievent.StoredEvent);
|
||||
foreach(int src in feedbacksources){
|
||||
int lnvk = src ^ ievent.MidiEvCode;
|
||||
lastKnownValues[lnvk] = ievent.LastKnownValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region IEventProvider implementation
|
||||
|
||||
|
||||
static System.Text.RegularExpressions.Regex regexEventID = new System.Text.RegularExpressions.Regex(
|
||||
@"MIDI-PAGE(?<page>\d+)-(?<id>.+)",
|
||||
System.Text.RegularExpressions.RegexOptions.Compiled);
|
||||
|
||||
bool IEventProvider.Bind (string eventId)
|
||||
{
|
||||
// On indique a l'EventManager qu'on traite, si l'ID commence par 'MIDI-'
|
||||
if(! eventId.StartsWith("MIDI-")) return false;
|
||||
if(! eventlist.ContainsKey(eventId)) eventlist.Add(eventId, new internalEvent(eventId));
|
||||
if (! eventId.StartsWith ("MIDI-"))
|
||||
return false;
|
||||
|
||||
if (! eventlist.ContainsKey (eventId)) {
|
||||
var res = regexEventID.Match (eventId);
|
||||
if (!res.Success) return false;
|
||||
int _page = byte.Parse (res.Groups ["page"].Value);
|
||||
int _evHC = res.Groups["id"].Value.GetHashCode();
|
||||
eventlist.Add (eventId, new internalEvent (eventId,_page,_evHC ));
|
||||
}
|
||||
|
||||
eventlist[eventId].Bound = true;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -346,11 +373,11 @@ namespace DMX2
|
|||
connected = true;
|
||||
continue;
|
||||
case AlsaSeqLib.snd_seq_event_type_t.SND_SEQ_EVENT_CONTROLLER:
|
||||
if(evS.data_ev_ctrl.param==127 && value>0){
|
||||
if(evS.data_ev_ctrl.param==127 && evS.data_ev_ctrl.value >0){
|
||||
CurrentPage++; continue;
|
||||
}
|
||||
|
||||
if(evS.data_ev_ctrl.param==126 && value>0){
|
||||
if(evS.data_ev_ctrl.param==126 && evS.data_ev_ctrl.value>0){
|
||||
CurrentPage--; continue;
|
||||
}
|
||||
|
||||
|
|
@ -401,6 +428,8 @@ namespace DMX2
|
|||
if(id!=null)
|
||||
{
|
||||
|
||||
int evHC = id.GetHashCode();
|
||||
|
||||
if(channel == 255 || unpaginatedchannels.Contains(channel))
|
||||
evpage= 0;
|
||||
else
|
||||
|
|
@ -410,19 +439,20 @@ namespace DMX2
|
|||
|
||||
|
||||
if(!eventlist.ContainsKey(id))
|
||||
eventlist.Add(id,new internalEvent(id));
|
||||
eventlist.Add(id,new internalEvent(id,page,evHC));
|
||||
levent= eventlist[id]; //Dernier Evenement recu conserve pour menu
|
||||
|
||||
int srcid = evS.source.client <<8 + evS.source.port;
|
||||
if(!eventlist[id].LastKnownValues.ContainsKey(srcid))
|
||||
eventlist[id].LastKnownValues[srcid] = (byte)value;
|
||||
int lnvk = srcid ^ evHC;
|
||||
if(!lastKnownValues.ContainsKey(lnvk))
|
||||
lastKnownValues[lnvk]= (byte)value;
|
||||
|
||||
EventData evData = new EventData();
|
||||
evData.id = id;
|
||||
evData.value = (byte)value;
|
||||
evData.prev_value = eventlist[id].LastKnownValues[srcid];
|
||||
evData.prev_value = lastKnownValues[lnvk];
|
||||
|
||||
eventlist[id].LastKnownValues[srcid] = (byte)value;
|
||||
lastKnownValues[lnvk] = (byte)value;
|
||||
|
||||
if(evData.Equals(last)) continue;
|
||||
last = evData;
|
||||
|
|
@ -457,19 +487,21 @@ namespace DMX2
|
|||
|
||||
IFeedbackInfo IEventProvider.GetFeedbackInfo (string eventId)
|
||||
{
|
||||
if(!eventlist.ContainsKey(eventId)) return null;
|
||||
|
||||
var res = regexCtrlEventID.Match (eventId);
|
||||
if (res.Success) {
|
||||
Console.WriteLine("Succes");
|
||||
byte chan = byte.Parse (res.Groups ["chan"].Value);
|
||||
uint param = uint.Parse (res.Groups ["param"].Value);
|
||||
return new ctrlfeedbackinfo (this, eventId, page, chan, param);
|
||||
return new ctrlfeedbackinfo (this, eventlist[eventId],chan, param);
|
||||
}
|
||||
res = regexPbEventID.Match (eventId);
|
||||
if (res.Success) {
|
||||
Console.WriteLine("Succes");
|
||||
byte chan = byte.Parse (res.Groups ["chan"].Value);
|
||||
|
||||
return new pitchbendfeedbackinfo (this, eventId,page, chan);
|
||||
return new pitchbendfeedbackinfo (this, eventlist[eventId], chan);
|
||||
}
|
||||
return null;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue