- use driver to initialize

master
Simon G 5 years ago
parent a1d2a71a74
commit 12b9bafa75
  1. 39
      Lib.Audio/Channel.cs
  2. 17
      Lib.Audio/Controls/Buttons/Factories/ButtonFactory.cs
  3. 4
      Lib.Audio/Controls/Buttons/Factories/IButtonFactory.cs
  4. 17
      Lib.Audio/Device.cs
  5. 3
      Lib.Audio/Factories/IChannelFactory.cs
  6. 3
      Lib.Audio/Factories/IDeviceFactory.cs
  7. 6
      Lib.Audio/Interfaces/IChannel.cs
  8. 1
      Lib.Audio/Lib.Audio.csproj
  9. 2
      Mystify/Installers/AudioInstaller.cs

@ -8,44 +8,45 @@ 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 uint _channelNumber;
private readonly int _channelNumber;
public Channel(uint channelNumber,
IDeviceButtonConfiguration buttonConfiguration,
public Channel(int channelNumber,
XmlChannel xmlChannel,
IFaderFactory faderFactory,
IKnobFactory knobFactory,
IButtonFactory buttonFactory)
{
_channelNumber = channelNumber;
Fader = faderFactory.Create();
Knob = knobFactory.Create();
Buttons = InitializeButtons(buttonConfiguration, buttonFactory);
if (xmlChannel.Fader != null)
{
Fader = faderFactory.Create();
Fader.PositionChanged += OnFaderPositionChanged;
}
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;
if (xmlChannel.Knob != null)
Knob = knobFactory.Create();
//TODO: fix button handling
private List<IButton> InitializeButtons(IDeviceButtonConfiguration buttonConfiguration, IButtonFactory buttonFactory)
if (xmlChannel.Buttons != null)
{
List<IButton> buttons = new();
for (int i = 0; i < buttonConfiguration.NumberOfButtons; i++)
buttons.Add(buttonFactory.Create());
return buttons;
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}";

@ -0,0 +1,17 @@
// Author: Simon Gockner
// Created: 2021-04-10
// Copyright(c) 2021 SimonG. All Rights Reserved.
using Lib.Audio.Controls.Buttons.Interfaces;
using Lib.Driver.Xml;
namespace Lib.Audio.Controls.Buttons.Factories
{
public class ButtonFactory : IButtonFactory
{
public IButton Create(XmlButton xmlButton)
{
return new Button();
}
}
}

@ -3,12 +3,12 @@
// Copyright(c) 2021 SimonG. All Rights Reserved.
using Lib.Audio.Controls.Buttons.Interfaces;
using Lib.Driver.Xml;
namespace Lib.Audio.Controls.Buttons.Factories
{
public interface IButtonFactory
{
IButton Create();
// IMuteButton Create();
IButton Create(XmlButton xmlButton);
}
}

@ -3,8 +3,10 @@
// Copyright(c) 2021 SimonG. All Rights Reserved.
using System.Collections.Generic;
using System.Linq;
using Lib.Audio.Factories;
using Lib.Audio.Interfaces;
using Lib.Driver.Interfaces;
using Lib.Midi.Factories;
using Lib.Midi.Interfaces;
using Lib.Midi.Messages;
@ -14,17 +16,17 @@ namespace Lib.Audio
{
public class Device : IDevice
{
private readonly IDriver _driver;
private readonly IMidiCommunication _midiCommunication;
private readonly IDeviceButtonConfiguration _buttonConfiguration;
private readonly IChannelFactory _channelFactory;
public Device(IMidiCommunicationFactory midiCommunicationFactory, IChannelFactory channelFactory)
public Device(IDriver driver, IMidiCommunicationFactory midiCommunicationFactory, IChannelFactory channelFactory)
{
_driver = driver;
_midiCommunication = midiCommunicationFactory.Create();
_buttonConfiguration = new DeviceButtonConfiguration {HasMuteButton = true, NumberOfButtons = 4}; //FixMe: remove hard coded config
_channelFactory = channelFactory;
Channels = new List<IChannel>();
for (uint i = 0; i < 8; i++) //FixMe: remove hard coded config
Channels.Add(channelFactory.Create(i, _buttonConfiguration));
Channels = InitializeChannels();
_midiCommunication.MessageReceived += OnMidiCommunicationMessageReceived;
_midiCommunication.ErrorReceived += OnMidiCommunicationErrorReceived;
@ -39,6 +41,9 @@ namespace Lib.Audio
_midiCommunication.Send(new ControlChangeMessage(0, 1, 127));
}
private List<IChannel> InitializeChannels() => _driver.Channels == null ? new List<IChannel>()
: _driver.Channels.Select(c => _channelFactory.Create(_driver.Channels.IndexOf(c), c)).ToList();
private void OnMidiCommunicationMessageReceived(object? sender, IMidiMessage message)
{
int i = 0;

@ -3,11 +3,12 @@
// Copyright(c) 2021 SimonG. All Rights Reserved.
using Lib.Audio.Interfaces;
using Lib.Driver.Xml;
namespace Lib.Audio.Factories
{
public interface IChannelFactory
{
IChannel Create(uint channelNumber, IDeviceButtonConfiguration deviceButtonConfiguration);
IChannel Create(int channelNumber, XmlChannel xmlChannel);
}
}

@ -3,11 +3,12 @@
// Copyright(c) 2021 SimonG. All Rights Reserved.
using Lib.Audio.Interfaces;
using Lib.Driver.Interfaces;
namespace Lib.Audio.Factories
{
public interface IDeviceFactory
{
IDevice Create();
IDevice Create(IDriver driver);
}
}

@ -10,9 +10,9 @@ namespace Lib.Audio.Interfaces
{
public interface IChannel
{
IFader Fader { get; }
IKnob Knob { get; }
List<IButton> Buttons { get; }
IFader? Fader { get; }
IKnob? Knob { get; }
List<IButton>? Buttons { get; }
IControllable? Controllable { get; }

@ -11,6 +11,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Lib.Driver\Lib.Driver.csproj" />
<ProjectReference Include="..\Lib.Midi\Lib.Midi.csproj" />
</ItemGroup>

@ -40,7 +40,7 @@ namespace Mystify.Installers
//control factories
container.RegisterFactory<IFaderFactory>();
container.RegisterFactory<IKnobFactory>();
container.RegisterFactory<IButtonFactory>();
container.Register<IButtonFactory, ButtonFactory>();
}
}
}
Loading…
Cancel
Save