Skip to content

Commit

Permalink
Merge branch 'feature/icons'
Browse files Browse the repository at this point in the history
  • Loading branch information
oddbear committed Feb 24, 2022
2 parents e927f7d + dadc6b1 commit c658da6
Show file tree
Hide file tree
Showing 62 changed files with 316 additions and 264 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,4 @@ FodyWeavers.xsd

#Raw image resources
*.afphoto
*.afdesign
7 changes: 1 addition & 6 deletions Revelator.io24.Api/Configuration/ServiceProviderExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,8 @@ public static void AddRevelatorAPI(this IServiceCollection serviceCollection)
serviceCollection.AddSingleton<Device>();
}

public static void UseRevelatorAPI(this IServiceProvider serviceProvider)
public static void StartRevelatorAPI(this IServiceProvider serviceProvider)
{
//TODO: These two might not be created before the syncronization event is set. In that case they will never get the event.
// This means that the RoutingTable should probarbly be rewriten (I don't think this will be a problem for the Device).
serviceProvider.GetService<RoutingTable>();
serviceProvider.GetService<Device>();

serviceProvider
.GetRequiredService<BroadcastService>()
.StartReceive();
Expand Down
75 changes: 41 additions & 34 deletions Revelator.io24.Api/RoutingTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ public class RoutingTable

public event EventHandler<(Input, Output)>? RouteUpdated;
public event EventHandler<(Input, Output)>? VolumeUpdated;
public event EventHandler<Headphones>? HeadphoneUpdated;

public RoutingTable(RawService rawService)
{
_rawService = rawService;
_rawService.Syncronized += Syncronized;
_rawService.ValueStateUpdated += ValueStateUpdated;
SetupRoutes();
}

private Dictionary<(Input input, Output output), (string route, string volume)> _routes = new();
Expand Down Expand Up @@ -105,16 +103,6 @@ private float GetOffState(string route)
? 1.0f
: 0.0f;

private void Register((Input input, Output output) key, string routeAssign, string routeVolume)
{
_routeToKey[routeAssign] = key;
_routeToKey[routeVolume] = key;
_routes[key] = (routeAssign, routeVolume);

RouteUpdated?.Invoke(this, key);
VolumeUpdated?.Invoke(this, key);
}

private void ValueStateUpdated(string route, float value)
{
if (!_routeToKey.TryGetValue(route, out var key))
Expand All @@ -138,75 +126,94 @@ private void ValueStateUpdated(string route, float value)

private void Syncronized()
{
Register((Input.Mic_L, Output.Main),
foreach (var key in _routes.Keys)
{
RouteUpdated?.Invoke(this, key);
VolumeUpdated?.Invoke(this, key);
}
}

private void SetupRoutes()
{
SetupRouting((Input.Mic_L, Output.Main),
"line/ch1/mute",
"line/ch1/volume");
Register((Input.Mic_L, Output.Mix_A),
SetupRouting((Input.Mic_L, Output.Mix_A),
"line/ch1/assign_aux1",
"line/ch1/aux1");
Register((Input.Mic_L, Output.Mix_B),
SetupRouting((Input.Mic_L, Output.Mix_B),
"line/ch1/assign_aux2",
"line/ch1/aux2");

Register((Input.Mic_R, Output.Main),
SetupRouting((Input.Mic_R, Output.Main),
"line/ch2/mute",
"line/ch2/volume");
Register((Input.Mic_R, Output.Mix_A),
SetupRouting((Input.Mic_R, Output.Mix_A),
"line/ch2/assign_aux1",
"line/ch2/aux1");
Register((Input.Mic_R, Output.Mix_B),
SetupRouting((Input.Mic_R, Output.Mix_B),
"line/ch2/assign_aux2",
"line/ch2/aux2");

Register((Input.Playback, Output.Main),
SetupRouting((Input.Playback, Output.Main),
"return/ch1/mute",
"return/ch1/volume");
Register((Input.Playback, Output.Mix_A),
SetupRouting((Input.Playback, Output.Mix_A),
"return/ch1/assign_aux1",
"return/ch1/aux1");
Register((Input.Playback, Output.Mix_B),
SetupRouting((Input.Playback, Output.Mix_B),
"return/ch1/assign_aux2",
"return/ch1/aux2");

Register((Input.Virtual_A, Output.Main),
SetupRouting((Input.Virtual_A, Output.Main),
"return/ch2/mute",
"return/ch2/volume");
Register((Input.Virtual_A, Output.Mix_A),
SetupRouting((Input.Virtual_A, Output.Mix_A),
"return/ch2/assign_aux1",
"return/ch2/aux1");
Register((Input.Virtual_A, Output.Mix_B),
SetupRouting((Input.Virtual_A, Output.Mix_B),
"return/ch2/assign_aux2",
"return/ch2/aux2");

Register((Input.Virtual_B, Output.Main),
SetupRouting((Input.Virtual_B, Output.Main),
"return/ch3/mute",
"return/ch3/volume");
Register((Input.Virtual_B, Output.Mix_A),
SetupRouting((Input.Virtual_B, Output.Mix_A),
"return/ch3/assign_aux1",
"return/ch3/aux1");
Register((Input.Virtual_B, Output.Mix_B),
SetupRouting((Input.Virtual_B, Output.Mix_B),
"return/ch3/assign_aux2",
"return/ch3/aux2");

Register((Input.Reverb, Output.Main),
SetupRouting((Input.Reverb, Output.Main),
"fxreturn/ch1/mute",
"fxreturn/ch1/volume");
Register((Input.Reverb, Output.Mix_A),
SetupRouting((Input.Reverb, Output.Mix_A),
"fxreturn/ch1/assign_aux1",
"fxreturn/ch1/aux1");
Register((Input.Reverb, Output.Mix_B),
SetupRouting((Input.Reverb, Output.Mix_B),
"fxreturn/ch1/assign_aux2",
"fxreturn/ch1/aux2");

Register((Input.Mix, Output.Main),
SetupRouting((Input.Mix, Output.Main),
"main/ch1/mute",
"main/ch1/volume");
Register((Input.Mix, Output.Mix_A),
SetupRouting((Input.Mix, Output.Mix_A),
"aux/ch1/mute",
"aux/ch1/volume");
Register((Input.Mix, Output.Mix_B),
SetupRouting((Input.Mix, Output.Mix_B),
"aux/ch2/mute",
"aux/ch2/volume");

_rawService.Syncronized += Syncronized;
_rawService.ValueStateUpdated += ValueStateUpdated;
}

private void SetupRouting((Input input, Output output) key, string routeAssign, string routeVolume)
{
_routeToKey[routeAssign] = key;
_routeToKey[routeVolume] = key;
_routes[key] = (routeAssign, routeVolume);
}
}
}
90 changes: 90 additions & 0 deletions Revelator.io24.StreamDeck/Actions/ActionBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using SharpDeck;
using SharpDeck.Enums;
using SharpDeck.Events.Received;

namespace Revelator.io24.StreamDeck.Actions
{
public abstract class ActionBase<TSettings> : StreamDeckAction
where TSettings : class, new()
{
//We need some how to know the settings when Events are received.
//In other situations, use GetSettings.
protected TSettings _settings { get; private set; } = new ();

protected async Task RefreshState()
{
var state = GetButtonState() ? 0 : 1;
await SetStateAsync(state);
}

protected override async Task OnDidReceiveSettings(ActionEventArgs<ActionPayload> args)
{
await base.OnDidReceiveSettings(args);

_settings = args.Payload
.GetSettings<TSettings>() ?? new ();

await SettingsChanged();

await RefreshState();
}

protected override async Task OnWillAppear(ActionEventArgs<AppearancePayload> args)
{
await base.OnWillAppear(args);

_settings = args.Payload
.GetSettings<TSettings>() ?? new();

RegisterCallbacks();

await SettingsChanged();

await RefreshState();
}

protected override async Task OnWillDisappear(ActionEventArgs<AppearancePayload> args)
{
await base.OnWillDisappear(args);

UnregisterCallbacks();
}

protected override async Task OnKeyUp(ActionEventArgs<KeyPayload> args)
{
await base.OnKeyUp(args);

_settings = args.Payload
.GetSettings<TSettings>() ?? new();

OnButtonPress();

var state = GetButtonState() ? 0 : 1;
await SetStateAsync(state);
}

protected abstract void RegisterCallbacks();
protected abstract void UnregisterCallbacks();
protected abstract void OnButtonPress();
protected abstract bool GetButtonState();
protected abstract Task SettingsChanged();

protected async Task SetImageStates(string on, string off)
{
try
{
var onImageBytes = File.ReadAllBytes($"./Images/Plugin/{on}.png");
var onBase64 = Convert.ToBase64String(onImageBytes);
await SetImageAsync("data:image/png;base64," + onBase64, TargetType.Both, 0);

var offImageBytes = File.ReadAllBytes($"./Images/Plugin/{off}.png");
var offBase64 = Convert.ToBase64String(offImageBytes);
await SetImageAsync("data:image/png;base64," + offBase64, TargetType.Both, 1);
}
catch
{
await SetImageAsync(null);
}
}
}
}
75 changes: 24 additions & 51 deletions Revelator.io24.StreamDeck/Actions/FatChannelToggleAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,107 +3,80 @@
using Revelator.io24.Api.Models.Inputs;
using Revelator.io24.StreamDeck.Settings;
using SharpDeck;
using SharpDeck.Events.Received;
using System.ComponentModel;
using System.Diagnostics;

namespace Revelator.io24.StreamDeck.Actions
{
[StreamDeckAction("com.oddbear.revelator.io24.fatchanneltoggle")]
public class FatChannelToggleAction : StreamDeckAction
public class FatChannelToggleAction : ActionBase<FatChannelToggleSettings>
{
private readonly Device _device;

//We need some how to know the route when Events are received.
//In other situations, use GetSettings.
private MicrophoneChannel? _channel;

public FatChannelToggleAction(
Device device)
{
_device = device;
}

protected override async Task OnDidReceiveSettings(ActionEventArgs<ActionPayload> args)
{
await base.OnDidReceiveSettings(args);

var settings = args.Payload
.GetSettings<FatChannelToggleSettings>();

_channel = settings.Channel;

await StateUpdated(settings.Channel);
}

protected override async Task OnWillAppear(ActionEventArgs<AppearancePayload> args)
protected override void RegisterCallbacks()
{
await base.OnWillAppear(args);
_device.MicrohoneLeft.PropertyChanged += PropertyChanged;
_device.MicrohoneRight.PropertyChanged += PropertyChanged;

var settings = args.Payload
.GetSettings<FatChannelToggleSettings>();

_channel = settings.Channel;

await StateUpdated(settings.Channel);
}

protected override async Task OnWillDisappear(ActionEventArgs<AppearancePayload> args)
protected override void UnregisterCallbacks()
{
await base.OnWillDisappear(args);
_device.MicrohoneLeft.PropertyChanged -= PropertyChanged;
_device.MicrohoneRight.PropertyChanged -= PropertyChanged;
}

protected override async Task OnKeyUp(ActionEventArgs<KeyPayload> args)
protected override void OnButtonPress()
{
await base.OnKeyUp(args);

var settings = args.Payload
.GetSettings<FatChannelToggleSettings>();

var c = GetMicrophoneChannel(settings.Channel);
switch (settings.Action)
var lineChannel = GetMicrophoneChannel(_settings.Channel);
switch (_settings.Action)
{
case Value.On:
c.BypassDSP = false;
lineChannel.BypassDSP = false;
break;
case Value.Off:
c.BypassDSP = true;
lineChannel.BypassDSP = true;
break;
case Value.Toggle:
default:
c.BypassDSP = !c.BypassDSP;
lineChannel.BypassDSP = !lineChannel.BypassDSP;
break;
}
}

protected override bool GetButtonState()
{
return GetMicrophoneChannel(_settings.Channel).BypassDSP == false;
}

protected override async Task SettingsChanged()
{
var title = _settings.Channel == MicrophoneChannel.Left
? "Fat L" : "Fat R";

await StateUpdated(settings.Channel);
await SetTitleAsync(title);
}

private async void PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
try
{
if (e.PropertyName != nameof(LineChannel.BypassDSP) || _channel is null)
if (e.PropertyName != nameof(LineChannel.BypassDSP))
return;

await StateUpdated(_channel.Value);
await RefreshState();
}
catch (Exception exception)
{
Trace.TraceError(exception.ToString());
}
}

private async Task StateUpdated(MicrophoneChannel channel)
{
var state = GetMicrophoneChannel(channel).BypassDSP ? 1 : 0;

await SetStateAsync(state);
}


private LineChannel GetMicrophoneChannel(MicrophoneChannel channel)
=> channel == MicrophoneChannel.Left
? _device.MicrohoneLeft
Expand Down
Loading

0 comments on commit c658da6

Please sign in to comment.