diff --git a/Lib.Audio/Channel.cs b/Lib.Audio/Channel.cs index 11544f1..712a45a 100644 --- a/Lib.Audio/Channel.cs +++ b/Lib.Audio/Channel.cs @@ -3,6 +3,9 @@ // Copyright(c) 2021 SimonG. All Rights Reserved. using System.Collections.Generic; +using Lib.Audio.Controls.Buttons.Factories; +using Lib.Audio.Controls.Buttons.Interfaces; +using Lib.Audio.Controls.Factories; using Lib.Audio.Controls.Interfaces; using Lib.Audio.Interfaces; @@ -10,9 +13,35 @@ namespace Lib.Audio { public class Channel : IChannel { + public Channel(IDeviceButtonConfiguration buttonConfiguration, + IFaderFactory faderFactory, + IKnobFactory knobFactory, + IButtonFactory buttonFactory) + { + Fader = faderFactory.Create(); + Knob = knobFactory.Create(); + Buttons = InitializeButtons(buttonConfiguration, buttonFactory); + + Fader.PositionChanged += OnFaderPositionChanged; + } + public IFader Fader { get; } public IKnob Knob { get; } public List Buttons { get; } - public IControllable Controllable { get; } + public IControllable Controllable { get; private set; } + + public void AllocateControllable(IControllable controllable) => Controllable = controllable; + + //TODO: fix button handling + private List InitializeButtons(IDeviceButtonConfiguration buttonConfiguration, IButtonFactory buttonFactory) + { + List buttons = new(); + for (int i = 0; i < buttonConfiguration.NumberOfButtons; i++) + buttons.Add(buttonFactory.Create()); + + return buttons; + } + + private void OnFaderPositionChanged(object? sender, float position) => Controllable.SetVolume(position); } } \ No newline at end of file diff --git a/Lib.Audio/Factories/IChannelFactory.cs b/Lib.Audio/Factories/IChannelFactory.cs index c7f45ec..802f3c4 100644 --- a/Lib.Audio/Factories/IChannelFactory.cs +++ b/Lib.Audio/Factories/IChannelFactory.cs @@ -8,6 +8,6 @@ namespace Lib.Audio.Factories { public interface IChannelFactory { - IChannel Create(); + IChannel Create(IDeviceButtonConfiguration deviceButtonConfiguration); } } \ No newline at end of file diff --git a/Lib.Audio/Interfaces/IChannel.cs b/Lib.Audio/Interfaces/IChannel.cs index 1cba913..80b712a 100644 --- a/Lib.Audio/Interfaces/IChannel.cs +++ b/Lib.Audio/Interfaces/IChannel.cs @@ -3,6 +3,7 @@ // Copyright(c) 2021 SimonG. All Rights Reserved. using System.Collections.Generic; +using Lib.Audio.Controls.Buttons.Interfaces; using Lib.Audio.Controls.Interfaces; namespace Lib.Audio.Interfaces @@ -14,5 +15,7 @@ namespace Lib.Audio.Interfaces List Buttons { get; } IControllable Controllable { get; } + + void AllocateControllable(IControllable controllable); } } \ No newline at end of file