- 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.Factories;
using Lib.Audio.Controls.Interfaces; using Lib.Audio.Controls.Interfaces;
using Lib.Audio.Interfaces; using Lib.Audio.Interfaces;
using Lib.Driver.Xml;
namespace Lib.Audio namespace Lib.Audio
{ {
public class Channel : IChannel public class Channel : IChannel
{ {
private readonly uint _channelNumber; private readonly int _channelNumber;
public Channel(uint channelNumber, public Channel(int channelNumber,
IDeviceButtonConfiguration buttonConfiguration, XmlChannel xmlChannel,
IFaderFactory faderFactory, IFaderFactory faderFactory,
IKnobFactory knobFactory, IKnobFactory knobFactory,
IButtonFactory buttonFactory) IButtonFactory buttonFactory)
{ {
_channelNumber = channelNumber; _channelNumber = channelNumber;
Fader = faderFactory.Create();
Knob = knobFactory.Create();
Buttons = InitializeButtons(buttonConfiguration, buttonFactory);
if (xmlChannel.Fader != null)
{
Fader = faderFactory.Create();
Fader.PositionChanged += OnFaderPositionChanged; Fader.PositionChanged += OnFaderPositionChanged;
} }
public IFader Fader { get; } if (xmlChannel.Knob != null)
public IKnob Knob { get; } Knob = knobFactory.Create();
public List<IButton> Buttons { get; }
public IControllable? Controllable { get; private set; }
public void AllocateControllable(IControllable controllable) => Controllable = controllable;
//TODO: fix button handling if (xmlChannel.Buttons != null)
private List<IButton> InitializeButtons(IDeviceButtonConfiguration buttonConfiguration, IButtonFactory buttonFactory)
{ {
List<IButton> buttons = new(); Buttons = new List<IButton>();
for (int i = 0; i < buttonConfiguration.NumberOfButtons; i++) foreach (var button in xmlChannel.Buttons)
buttons.Add(buttonFactory.Create()); Buttons.Add(buttonFactory.Create(button));
}
return buttons;
} }
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); private void OnFaderPositionChanged(object? sender, float position) => Controllable?.SetVolume(position);
public override string ToString() => $"Channel {_channelNumber}"; 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. // Copyright(c) 2021 SimonG. All Rights Reserved.
using Lib.Audio.Controls.Buttons.Interfaces; using Lib.Audio.Controls.Buttons.Interfaces;
using Lib.Driver.Xml;
namespace Lib.Audio.Controls.Buttons.Factories namespace Lib.Audio.Controls.Buttons.Factories
{ {
public interface IButtonFactory public interface IButtonFactory
{ {
IButton Create(); IButton Create(XmlButton xmlButton);
// IMuteButton Create();
} }
} }

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

@ -3,11 +3,12 @@
// Copyright(c) 2021 SimonG. All Rights Reserved. // Copyright(c) 2021 SimonG. All Rights Reserved.
using Lib.Audio.Interfaces; using Lib.Audio.Interfaces;
using Lib.Driver.Xml;
namespace Lib.Audio.Factories namespace Lib.Audio.Factories
{ {
public interface IChannelFactory 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. // Copyright(c) 2021 SimonG. All Rights Reserved.
using Lib.Audio.Interfaces; using Lib.Audio.Interfaces;
using Lib.Driver.Interfaces;
namespace Lib.Audio.Factories namespace Lib.Audio.Factories
{ {
public interface IDeviceFactory public interface IDeviceFactory
{ {
IDevice Create(); IDevice Create(IDriver driver);
} }
} }

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

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

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