diff --git a/src/Tesira-DSP-EPI.4Series.csproj b/src/Tesira-DSP-EPI.4Series.csproj index 43b42af..1bd3080 100644 --- a/src/Tesira-DSP-EPI.4Series.csproj +++ b/src/Tesira-DSP-EPI.4Series.csproj @@ -36,6 +36,6 @@ - + \ No newline at end of file diff --git a/src/TesiraDsp.cs b/src/TesiraDsp.cs index 10dd0ee..014d260 100644 --- a/src/TesiraDsp.cs +++ b/src/TesiraDsp.cs @@ -17,7 +17,7 @@ namespace Tesira_DSP_EPI { - public class TesiraDsp : EssentialsBridgeableDevice, IHasDspPresets, ICommunicationMonitor + public class TesiraDsp : EssentialsBridgeableDevice, IDspPresets, ICommunicationMonitor { /// /// Collection of all Device Feedbacks @@ -95,7 +95,7 @@ public bool IsSubscribed { private Dictionary Meters { get; set; } private Dictionary CrosspointStates { get; set; } private Dictionary RoomCombiners { get; set; } - public List Presets { get; private set; } + public Dictionary Presets { get; private set; } public List TesiraPresets { get; private set; } private List ControlPointList { get; set; } @@ -166,7 +166,7 @@ public TesiraDsp(string key, string name, IBasicCommunication comm, DeviceConfig //Initialize Dictionaries Feedbacks = new FeedbackCollection(); Faders = new Dictionary(); - Presets = new List(); + Presets = new Dictionary(); TesiraPresets = new List(); Dialers = new Dictionary(); Switchers = new Dictionary(); @@ -335,8 +335,8 @@ private void CreatePresets(TesiraDspPropertiesConfig props) foreach (var preset in props.Presets) { var value = preset.Value; - var tesiraPreset = new TesiraPreset(preset.Value); - Presets.Add(tesiraPreset); + var tesiraPreset = new TesiraPreset(preset.Key, preset.Value); + Presets.Add(preset.Key, tesiraPreset); TesiraPresets.Add(tesiraPreset); Debug.Console(2, this, "Added Preset {0} {1}", value.Label, value.PresetName); } @@ -803,7 +803,7 @@ public void RunPresetNumber(ushort n) foreach (var preset in Presets.OfType().Where(preset => preset.Index == n)) { Debug.Console(2, this, "Found a matching Preset - {0}", preset.PresetData.PresetId); - RecallPreset(preset); + RecallPreset(preset.Key); } } @@ -830,27 +830,27 @@ public void RunPreset(int id) //CommandQueue.EnqueueCommand(string.Format("DEVICE recallPreset {0}", id)); } - public void RecallPreset(IDspPreset preset) + public void RecallPreset(string key) { + var preset = Presets[key] as TesiraPreset; Debug.Console(2, this, "Running preset {0}", preset.Name); - var tesiraPreset = preset as TesiraPreset; - if (tesiraPreset == null) return; + if (preset == null) return; Debug.Console(2, this, "Checking Preset {0} | presetIndex {1} | presetId {2} | presetName {3}", - tesiraPreset.Name, tesiraPreset.PresetData.PresetIndex, tesiraPreset.PresetData.PresetId, tesiraPreset.PresetData.PresetName); + preset.Name, preset.PresetData.PresetIndex, preset.PresetData.PresetId, preset.PresetData.PresetName); // - changed string check reference from 'tesiraPreset.PresetName' to 'tesiraPreset.PreetData.PresetName' - if (!string.IsNullOrEmpty(tesiraPreset.PresetData.PresetName)) + if (!string.IsNullOrEmpty(preset.PresetData.PresetName)) { - RunPreset(tesiraPreset.PresetData.PresetName); + RunPreset(preset.PresetData.PresetName); } else { - if (tesiraPreset.PresetData.PresetId == 0) + if (preset.PresetData.PresetId == 0) { - Debug.Console(2, this, "Preset {0} has an invalid presetId {1}", tesiraPreset.Name, tesiraPreset.PresetData.PresetId); + Debug.Console(2, this, "Preset {0} has an invalid presetId {1}", preset.Name, preset.PresetData.PresetId); return; } - RunPreset(tesiraPreset.PresetData.PresetId); + RunPreset(preset.PresetData.PresetId); } } @@ -1308,13 +1308,13 @@ public override void LinkToApi(BasicTriList trilist, uint joinStart, string join // digital input executes preset reall using preset id (RunPresetNumber)) foreach (var preset in Presets) { - var p = preset as TesiraPreset; + var p = preset.Value as TesiraPreset; if (p == null) continue; var runPresetIndex = p.PresetData.PresetIndex; var presetIndex = runPresetIndex; trilist.StringInput[(uint)(presetJoinMap.PresetNameFeedback.JoinNumber + presetIndex)].StringValue = p.PresetData.Label; trilist.SetSigTrueAction((uint) (presetJoinMap.PresetSelection.JoinNumber + presetIndex), - () => RecallPreset(p)); + () => RecallPreset(p.Key)); } // VoIP Dialer diff --git a/src/TesiraDspPreset.cs b/src/TesiraDspPreset.cs index 30d79d9..74de7a2 100644 --- a/src/TesiraDspPreset.cs +++ b/src/TesiraDspPreset.cs @@ -9,7 +9,7 @@ namespace Tesira_DSP_EPI { - public class TesiraDspPresetDevice : TesiraDspControlPoint, IHasDspPresets + public class TesiraDspPresetDevice : TesiraDspControlPoint, IDspPresets { private const string KeyFormatter = "{0}--{1}"; @@ -24,7 +24,7 @@ public TesiraDspPresetDevice(TesiraDsp parent) #region IHasDspPresets Members - public List Presets { get; private set; } + public Dictionary Presets { get; private set; } #endregion @@ -62,13 +62,13 @@ public override void LinkToApi(BasicTriList trilist, uint joinStart, string join foreach (var preset in Presets) { - var p = preset as TesiraPreset; + var p = preset.Value as TesiraPreset; if (p == null) continue; var runPresetIndex = p.PresetData.PresetIndex; var presetIndex = runPresetIndex; trilist.StringInput[(uint)(presetJoinMap.PresetNameFeedback.JoinNumber + presetIndex - 1)].StringValue = p.PresetData.PresetName; trilist.SetSigTrueAction((uint)(presetJoinMap.PresetSelection.JoinNumber + presetIndex - 1), - () => RecallPreset(p)); + () => RecallPreset(p.Key)); } @@ -115,24 +115,26 @@ public void RunPreset(int id) //CommandQueue.EnqueueCommand(string.Format("DEVICE recallPreset {0}", id)); } - public void RecallPreset(IDspPreset preset) + public void RecallPreset(string key) { - Parent.RecallPreset(preset); + Parent.RecallPreset(key); } #endregion } - public class TesiraPreset : TesiraDspPresets, IDspPreset + public class TesiraPreset : TesiraDspPresets, IKeyName { + public string Key { get; private set; } public string Name { get; private set; } public int Index { get; private set; } public TesiraDspPresets PresetData { get; private set; } - public TesiraPreset(TesiraDspPresets data) + public TesiraPreset(string key, TesiraDspPresets data) { + Key = key; PresetData = data; Name = data.Label; Index = data.PresetIndex;