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