Skip to content

Commit

Permalink
feat: switches from old IHasDspPresets to IDspPresets
Browse files Browse the repository at this point in the history
  • Loading branch information
ndorin committed May 21, 2024
1 parent e9abff2 commit f5763c6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Tesira-DSP-EPI.4Series.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PepperDashEssentials" Version="2.0.0-beta-2468" />
<PackageReference Include="PepperDashEssentials" Version="2.0.0-alpha-2502" />
</ItemGroup>
</Project>
34 changes: 17 additions & 17 deletions src/TesiraDsp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace Tesira_DSP_EPI
{
public class TesiraDsp : EssentialsBridgeableDevice, IHasDspPresets, ICommunicationMonitor
public class TesiraDsp : EssentialsBridgeableDevice, IDspPresets, ICommunicationMonitor
{
/// <summary>
/// Collection of all Device Feedbacks
Expand Down Expand Up @@ -95,7 +95,7 @@ public bool IsSubscribed {
private Dictionary<string, TesiraDspMeter> Meters { get; set; }
private Dictionary<string, TesiraDspCrosspointState> CrosspointStates { get; set; }
private Dictionary<string, TesiraDspRoomCombiner> RoomCombiners { get; set; }
public List<IDspPreset> Presets { get; private set; }
public Dictionary<string, IKeyName> Presets { get; private set; }
public List<TesiraPreset> TesiraPresets { get; private set; }
private List<ISubscribedComponent> ControlPointList { get; set; }

Expand Down Expand Up @@ -166,7 +166,7 @@ public TesiraDsp(string key, string name, IBasicCommunication comm, DeviceConfig
//Initialize Dictionaries
Feedbacks = new FeedbackCollection<Feedback>();
Faders = new Dictionary<string, TesiraDspFaderControl>();
Presets = new List<IDspPreset>();
Presets = new Dictionary<string, IKeyName>();
TesiraPresets = new List<TesiraPreset>();
Dialers = new Dictionary<string, TesiraDspDialer>();
Switchers = new Dictionary<string, TesiraDspSwitcher>();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -803,7 +803,7 @@ public void RunPresetNumber(ushort n)
foreach (var preset in Presets.OfType<TesiraPreset>().Where(preset => preset.Index == n))
{
Debug.Console(2, this, "Found a matching Preset - {0}", preset.PresetData.PresetId);
RecallPreset(preset);
RecallPreset(preset.Key);
}

}
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions src/TesiraDspPreset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Tesira_DSP_EPI
{
public class TesiraDspPresetDevice : TesiraDspControlPoint, IHasDspPresets
public class TesiraDspPresetDevice : TesiraDspControlPoint, IDspPresets
{
private const string KeyFormatter = "{0}--{1}";

Expand All @@ -24,7 +24,7 @@ public TesiraDspPresetDevice(TesiraDsp parent)

#region IHasDspPresets Members

public List<IDspPreset> Presets { get; private set; }
public Dictionary<string, IKeyName> Presets { get; private set; }


#endregion
Expand Down Expand Up @@ -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));
}


Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f5763c6

Please sign in to comment.