Skip to content

Commit 924acbb

Browse files
committed
Finishing up testing, now with working profile / state indicators and setters.
1 parent c2f1489 commit 924acbb

File tree

14 files changed

+397
-223
lines changed

14 files changed

+397
-223
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
namespace Loupedeck.GoXLRPlugin.Commands
2+
{
3+
using System;
4+
using System.Drawing;
5+
using System.Linq;
6+
using System.Threading;
7+
8+
using GoXLR.Server.Models;
9+
10+
using Helpers;
11+
12+
class SetProfileCommand : PluginDynamicCommand
13+
{
14+
private GoXLRPlugin _plugin;
15+
16+
private Profile[] _profiles = Array.Empty<Profile>();
17+
private Profile _selected = Profile.Empty;
18+
19+
public SetProfileCommand() : base()
20+
{
21+
this.DisplayName = "Profile Set";
22+
this.GroupName = "";
23+
this.Description = "Select profile.";
24+
25+
this.MakeProfileAction("list;Profile:");
26+
}
27+
28+
protected override Boolean OnLoad()
29+
{
30+
this._plugin = (GoXLRPlugin)base.Plugin;
31+
return true;
32+
}
33+
34+
public void UpdateProfileList(Profile[] profiles) =>
35+
this._profiles = profiles;
36+
37+
public void UpdateSelectedProfile(Profile profile)
38+
{
39+
var prevProfile = this._selected;
40+
this._selected = profile;
41+
42+
if (this._selected != prevProfile)
43+
{
44+
var profileName = profile.Name;
45+
this.ActionImageChanged($"profile|{profileName}");
46+
}
47+
}
48+
49+
protected override void RunCommand(String actionParameter)
50+
{
51+
if (actionParameter.IndexOf('|') == -1)
52+
return;
53+
54+
var split = actionParameter.Split('|');
55+
var profileName = split[1];
56+
var profile = new Profile(profileName);
57+
58+
var server = this._plugin.Server;
59+
server.SetProfile(profile, CancellationToken.None)
60+
.GetAwaiter()
61+
.GetResult();
62+
}
63+
64+
protected override PluginActionParameter[] GetParameters() =>
65+
this._profiles
66+
.Select(profile => profile.Name)
67+
.Select(profileName => new PluginActionParameter($"profile|{profileName}", profileName, String.Empty))
68+
.ToArray();
69+
70+
protected override BitmapImage GetCommandImage(String actionParameter, PluginImageSize imageSize)
71+
{
72+
using (var bitmapBuilder = new BitmapBuilder(imageSize))
73+
{
74+
var background = ImageHelpers.GetImageBackground(imageSize, Color.Red);
75+
var bitmapImage = new BitmapImage(background);
76+
bitmapBuilder.SetBackgroundImage(bitmapImage);
77+
78+
var text = this.GetCommandDisplayName(actionParameter, imageSize);
79+
bitmapBuilder.DrawText(text);
80+
81+
return bitmapBuilder.ToImage();
82+
}
83+
}
84+
85+
protected override String GetCommandDisplayName(String actionParameter, PluginImageSize imageSize)
86+
{
87+
if (actionParameter is null)
88+
return String.Empty;
89+
90+
var text = actionParameter;
91+
if (actionParameter.IndexOf('|') != -1)
92+
{
93+
var split = actionParameter.Split('|');
94+
text = split[1];
95+
}
96+
97+
return text == this._selected.Name
98+
? $"[{text}]"
99+
: text;
100+
}
101+
}
102+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
namespace Loupedeck.GoXLRPlugin.Commands
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Threading;
8+
9+
using GoXLR.Server.Enums;
10+
using GoXLR.Server.Models;
11+
12+
using Helpers;
13+
14+
class SetRoutingCommand : PluginDynamicCommand
15+
{
16+
private readonly Dictionary<String, State> _states = new Dictionary<String, State>();
17+
18+
private GoXLRPlugin _plugin;
19+
20+
public SetRoutingCommand() : base()
21+
{
22+
this.DisplayName = "Routing Toggle";
23+
this.GroupName = "";
24+
this.Description = "Select input and output to toggle.";
25+
26+
this.MakeProfileAction("tree");
27+
}
28+
29+
protected override Boolean OnLoad()
30+
{
31+
this._plugin = (GoXLRPlugin)base.Plugin;
32+
return true;
33+
}
34+
35+
public void UpdateState(Routing routing, State state)
36+
{
37+
var actionParameter = $"{routing.Input}|{routing.Output}";
38+
if (this._states.TryGetValue(actionParameter, out var oldState) && oldState == state)
39+
return;
40+
41+
this._states[actionParameter] = state;
42+
43+
this.ActionImageChanged(actionParameter);
44+
}
45+
46+
protected override void RunCommand(String actionParameter)
47+
{
48+
if (!Routing.TryParseContext(actionParameter, out var routing))
49+
return;
50+
51+
var server = this._plugin.Server;
52+
server.SetRouting(RoutingAction.Toggle, routing, CancellationToken.None)
53+
.GetAwaiter()
54+
.GetResult();
55+
}
56+
57+
protected override PluginProfileActionData GetProfileActionData()
58+
{
59+
var tree = new PluginProfileActionTree("Routing Tree");
60+
61+
tree.AddLevel("Inputs");
62+
tree.AddLevel("Outputs");
63+
64+
var routingTable = Routing.GetRoutingTable();
65+
var inputs = routingTable
66+
.Select(routing => routing.Input)
67+
.Distinct();
68+
69+
foreach (var input in inputs)
70+
{
71+
var node = tree.Root.AddNode(input.ToString());
72+
73+
var outputs = routingTable
74+
.Where(routing => routing.Input == input)
75+
.Select(routing => routing.Output);
76+
77+
foreach (var output in outputs)
78+
{
79+
var description = GoXLR.Server.Extensions.EnumExtensions.GetEnumDescription(output);
80+
81+
node.AddItem($"{input}|{output}", output.ToString(), description);
82+
}
83+
}
84+
85+
return tree;
86+
}
87+
88+
protected override BitmapImage GetCommandImage(String actionParameter, PluginImageSize imageSize)
89+
{
90+
using (var bitmapBuilder = new BitmapBuilder(imageSize))
91+
{
92+
var background = ImageHelpers.GetImageBackground(imageSize, Color.Red);
93+
var bitmapImage = new BitmapImage(background);
94+
bitmapBuilder.SetBackgroundImage(bitmapImage);
95+
96+
//base: Routing Toggle
97+
//this: Input|Output\r\n- -> Input|Output\r\nOn
98+
var text = this.GetCommandDisplayName(actionParameter, imageSize);
99+
bitmapBuilder.DrawText(text);
100+
101+
return bitmapBuilder.ToImage();
102+
}
103+
}
104+
105+
protected override String GetCommandDisplayName(String actionParameter, PluginImageSize imageSize)
106+
{
107+
//Does not work...
108+
if (actionParameter is null)
109+
return string.Empty;
110+
111+
var text = actionParameter;
112+
if (actionParameter.IndexOf('|') != -1)
113+
{
114+
var split = actionParameter.Split('|');
115+
text = $"{split[0]}\r\n{split[1]}";
116+
}
117+
118+
return this._states.TryGetValue(actionParameter, out var state)
119+
? $"{text} \r\n {state}"
120+
: $"{text} \r\n -";
121+
}
122+
}
123+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace Loupedeck.GoXLRPlugin
2+
{
3+
using System.Linq;
4+
5+
public class DynamicActionProvider
6+
{
7+
private readonly GoXLRPlugin _plugin;
8+
9+
public DynamicActionProvider(GoXLRPlugin plugin)
10+
{
11+
_plugin = plugin;
12+
}
13+
14+
public TCommand Provide<TCommand>()
15+
where TCommand : PluginDynamicAction
16+
{
17+
return _plugin.DynamicCommands
18+
.OfType<TCommand>()
19+
.Single();
20+
}
21+
}
22+
}

GoXLR.Plugin/Enums/PluginState.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Loupedeck.GoXLRPlugin.Enums
2+
{
3+
public enum PluginState
4+
{
5+
AppNotConnected,
6+
PortInUse,
7+
AppConnected
8+
}
9+
}

GoXLR.Plugin/GoXLR.Plugin.csproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
</Reference>
4444
<Reference Include="System" />
4545
<Reference Include="System.Core" />
46+
<Reference Include="System.Drawing" />
4647
<Reference Include="System.Web" />
4748
<Reference Include="System.Xml.Linq" />
4849
<Reference Include="System.Data.DataSetExtensions" />
@@ -52,12 +53,15 @@
5253
<Reference Include="System.Xml" />
5354
</ItemGroup>
5455
<ItemGroup>
55-
<Compile Include="RoutingTreeCommand.cs" />
56+
<Compile Include="Commands\SetProfileCommand.cs" />
57+
<Compile Include="DynamicActionProvider.cs" />
58+
<Compile Include="Enums\PluginState.cs" />
59+
<Compile Include="Commands\SetRoutingCommand.cs" />
5660
<Compile Include="GoXLREventHandler.cs" />
61+
<Compile Include="Helpers\ImageHelpers.cs" />
5762
<Compile Include="Properties\AssemblyInfo.cs" />
5863
<Compile Include="GoXLRApplication.cs" />
5964
<Compile Include="GoXLRPlugin.cs" />
60-
<Compile Include="RoutingCommand.cs" />
6165
</ItemGroup>
6266
<ItemGroup>
6367
<EmbeddedResource Include="PluginConfiguration.json" />
@@ -78,5 +82,6 @@
7882
<EmbeddedResource Include="Resources\Icons\Icon-32.png" />
7983
<EmbeddedResource Include="Resources\Icons\Icon-48.png" />
8084
</ItemGroup>
85+
<ItemGroup />
8186
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8287
</Project>

GoXLR.Plugin/GoXLREventHandler.cs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
11
namespace Loupedeck.GoXLRPlugin
22
{
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
3+
using Commands;
84

5+
using Enums;
6+
7+
using GoXLR.Server.Enums;
98
using GoXLR.Server.Models;
109

1110
public class GoXLREventHandler : IGoXLREventHandler
1211
{
1312
private readonly GoXLRPlugin _plugin;
13+
private readonly DynamicActionProvider _actionProvider;
1414

15-
public GoXLREventHandler(GoXLRPlugin plugin)
15+
public GoXLREventHandler(GoXLRPlugin plugin, DynamicActionProvider actionProvider)
1616
{
1717
this._plugin = plugin;
18+
this._actionProvider = actionProvider;
1819
}
1920

20-
public void ConnectedClientChangedEvent(ConnectedClient client)
21+
public void ConnectedClientChangedEvent(in ConnectedClient client)
2122
{
22-
if (client == ConnectedClient.Empty)
23-
{
24-
_plugin.OnPluginStatusChanged(Loupedeck.PluginStatus.Error, "GoXLR App not connected.", "https://github.com/oddbear/Loupedeck.GoXLR.Plugin/");
25-
}
26-
else
27-
{
28-
_plugin.OnPluginStatusChanged(Loupedeck.PluginStatus.Normal, "GoXLR App not connected.", "https://github.com/oddbear/Loupedeck.GoXLR.Plugin/");
29-
}
23+
var pluginState = client == ConnectedClient.Empty
24+
? PluginState.AppNotConnected
25+
: PluginState.AppConnected;
26+
27+
this._plugin.SetPluginState(pluginState);
3028
}
3129

3230
public void ProfileListChangedEvent(Profile[] profiles)
3331
{
34-
//
32+
this._actionProvider.Provide<SetProfileCommand>()
33+
.UpdateProfileList(profiles);
3534
}
3635

37-
public void ProfileSelectedChangedEvent(Profile profile)
36+
public void ProfileSelectedChangedEvent(in Profile profile)
3837
{
39-
//
38+
this._actionProvider.Provide<SetProfileCommand>()
39+
.UpdateSelectedProfile(profile);
4040
}
4141

42-
public void RoutingStateChangedEvent(Routing routing, global::GoXLR.Server.Enums.State state)
42+
public void RoutingStateChangedEvent(in Routing routing, in State state)
4343
{
44-
//
44+
//How to pass this event?
45+
this._actionProvider.Provide<SetRoutingCommand>()
46+
.UpdateState(routing, state);
47+
4548
}
4649
}
4750
}

0 commit comments

Comments
 (0)