Cross Platform Application to allow control with a MIDI controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.7 KiB

// Author: Gockner, Simon
// Created: 2021-04-07
// 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;
using Lib.Driver.Xml;
namespace Lib.Audio
{
public class Channel : IChannel
{
private readonly int _channelNumber;
public Channel(int channelNumber,
XmlChannel xmlChannel,
IFaderFactory faderFactory,
IKnobFactory knobFactory,
IButtonFactory buttonFactory)
{
_channelNumber = channelNumber;
if (xmlChannel.Fader != null)
{
Fader = faderFactory.Create();
Fader.PositionChanged += OnFaderPositionChanged;
}
if (xmlChannel.Knob != null)
Knob = knobFactory.Create();
if (xmlChannel.Buttons != null)
{
Buttons = new List<IButton>();
foreach (var button in xmlChannel.Buttons)
Buttons.Add(buttonFactory.Create(button));
}
}
public IFader? Fader { get; }
public IKnob? Knob { get; }
public List<IButton>? Buttons { get; }
public IControllable? Controllable { get; private set; }
public void AllocateControllable(IControllable controllable) => Controllable = controllable;
private void OnFaderPositionChanged(object? sender, float position) => Controllable?.SetVolume(position);
public override string ToString() => $"Channel {_channelNumber}";
}
}