diff --git a/Lib.Audio/Channel.cs b/Lib.Audio/Channel.cs index c938ec5..d7312d1 100644 --- a/Lib.Audio/Channel.cs +++ b/Lib.Audio/Channel.cs @@ -19,14 +19,17 @@ namespace Lib.Audio { public class Channel : IChannel { + private readonly IMidiCommunication _midiCommunication; private readonly int _channelNumber; private IMidiMessage? _acknowledgeMessage; public Channel(XmlChannel xmlChannel, + IMidiCommunication midiCommunication, IFaderFactory faderFactory, IKnobFactory knobFactory, IButtonFactory buttonFactory) { + _midiCommunication = midiCommunication; _channelNumber = xmlChannel.ChannelNumber; if (xmlChannel.Fader != null) @@ -51,7 +54,19 @@ namespace Lib.Audio public List? Buttons { get; } public IControllable? Controllable { get; private set; } - public void MapControllable(IControllable controllable) => Controllable = controllable; + public void MapControllable(IControllable controllable) + { + Controllable = controllable; + + ISelectButton? selectButton = Buttons?.OfType().FirstOrDefault(); + IMidiMessage? selectMessage = selectButton?.Select(); + + if (selectMessage != null) + _midiCommunication.Send(selectMessage); + + + } + public void HandleMessage(IMidiMessage message) { if (message is NoteOnMessage noteOnMessage) @@ -84,12 +99,12 @@ namespace Lib.Audio } } - public void SendAcknowledge(IMidiCommunication midiCommunication) + public void SendAcknowledge() { if (_acknowledgeMessage == null) return; - midiCommunication.Send(_acknowledgeMessage); + _midiCommunication.Send(_acknowledgeMessage); _acknowledgeMessage = null; } diff --git a/Lib.Audio/Controls/Buttons/Interfaces/ISelectButton.cs b/Lib.Audio/Controls/Buttons/Interfaces/ISelectButton.cs index cbe04c4..f61b339 100644 --- a/Lib.Audio/Controls/Buttons/Interfaces/ISelectButton.cs +++ b/Lib.Audio/Controls/Buttons/Interfaces/ISelectButton.cs @@ -2,10 +2,12 @@ // Created: 2021-04-17 // Copyright(c) 2021 SimonG. All Rights Reserved. +using Lib.Midi.Messages.Interfaces; + namespace Lib.Audio.Controls.Buttons.Interfaces { public interface ISelectButton : IButton { - + IMidiMessage? Select(); } } \ No newline at end of file diff --git a/Lib.Audio/Controls/Buttons/SelectButton.cs b/Lib.Audio/Controls/Buttons/SelectButton.cs index b1abf5e..7420d2f 100644 --- a/Lib.Audio/Controls/Buttons/SelectButton.cs +++ b/Lib.Audio/Controls/Buttons/SelectButton.cs @@ -3,6 +3,8 @@ // Copyright(c) 2021 SimonG. All Rights Reserved. using Lib.Audio.Controls.Buttons.Interfaces; +using Lib.Audio.Interfaces; +using Lib.Midi.Messages.Interfaces; namespace Lib.Audio.Controls.Buttons { @@ -13,5 +15,8 @@ namespace Lib.Audio.Controls.Buttons { } + + public override IMidiMessage? Handle(IControllable? controllable, Velocity velocity) => null; //for now don't do anything when pressed + public IMidiMessage? Select() => base.Handle(null, Velocity.On); } } \ No newline at end of file diff --git a/Lib.Audio/Device.cs b/Lib.Audio/Device.cs index f168e53..b039134 100644 --- a/Lib.Audio/Device.cs +++ b/Lib.Audio/Device.cs @@ -37,12 +37,12 @@ namespace Lib.Audio public void StartCommunication(bool useMidiView) => _midiCommunication.Open(useMidiView); private List InitializeChannels() => _driver.Channels == null ? new List() - : _driver.Channels.Select(c => _channelFactory.Create(c)).ToList(); + : _driver.Channels.Select(c => _channelFactory.Create(c, _midiCommunication)).ToList(); private void OnMidiCommunicationMessageReceived(object? sender, IMidiMessage message) { Channels[message.ChannelNumber - 1].HandleMessage(message); - Channels[message.ChannelNumber - 1].SendAcknowledge(_midiCommunication); + Channels[message.ChannelNumber - 1].SendAcknowledge(); } private void OnMidiCommunicationErrorReceived(object? sender, IMidiMessage message) => diff --git a/Lib.Audio/Factories/IChannelFactory.cs b/Lib.Audio/Factories/IChannelFactory.cs index 817f3a3..bd5c7f1 100644 --- a/Lib.Audio/Factories/IChannelFactory.cs +++ b/Lib.Audio/Factories/IChannelFactory.cs @@ -4,11 +4,12 @@ using Lib.Audio.Interfaces; using Lib.Driver.Xml; +using Lib.Midi.Interfaces; namespace Lib.Audio.Factories { public interface IChannelFactory { - IChannel Create(XmlChannel xmlChannel); + IChannel Create(XmlChannel xmlChannel, IMidiCommunication midiCommunication); } } \ No newline at end of file diff --git a/Lib.Audio/Interfaces/IChannel.cs b/Lib.Audio/Interfaces/IChannel.cs index 8a0aa0f..631c428 100644 --- a/Lib.Audio/Interfaces/IChannel.cs +++ b/Lib.Audio/Interfaces/IChannel.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using Lib.Audio.Controls.Buttons.Interfaces; using Lib.Audio.Controls.Interfaces; -using Lib.Midi.Interfaces; using Lib.Midi.Messages.Interfaces; namespace Lib.Audio.Interfaces @@ -20,6 +19,6 @@ namespace Lib.Audio.Interfaces void MapControllable(IControllable controllable); void HandleMessage(IMidiMessage message); - void SendAcknowledge(IMidiCommunication midiCommunication); + void SendAcknowledge(); } } \ No newline at end of file