|
|
|
|
@ -14,22 +14,31 @@ using Lib.Driver.Xml; |
|
|
|
|
using Lib.Midi.Interfaces; |
|
|
|
|
using Lib.Midi.Messages; |
|
|
|
|
using Lib.Midi.Messages.Interfaces; |
|
|
|
|
using Lib.ProcessManaging.Interfaces; |
|
|
|
|
|
|
|
|
|
namespace Lib.Audio |
|
|
|
|
{ |
|
|
|
|
public class Channel : IChannel |
|
|
|
|
{ |
|
|
|
|
private readonly IControllableCollector _controllableCollector; |
|
|
|
|
private readonly IMidiCommunication _midiCommunication; |
|
|
|
|
private readonly IProcessManager _processManager; |
|
|
|
|
|
|
|
|
|
private readonly int _channelNumber; |
|
|
|
|
|
|
|
|
|
private IMidiMessage? _acknowledgeMessage; |
|
|
|
|
|
|
|
|
|
public Channel(XmlChannel xmlChannel, |
|
|
|
|
IControllableCollector controllableCollector, |
|
|
|
|
IMidiCommunication midiCommunication, |
|
|
|
|
IProcessManager processManager, |
|
|
|
|
IFaderFactory faderFactory, |
|
|
|
|
IKnobFactory knobFactory, |
|
|
|
|
IButtonFactory buttonFactory) |
|
|
|
|
{ |
|
|
|
|
_controllableCollector = controllableCollector; |
|
|
|
|
_midiCommunication = midiCommunication; |
|
|
|
|
_processManager = processManager; |
|
|
|
|
_channelNumber = xmlChannel.ChannelNumber; |
|
|
|
|
|
|
|
|
|
if (xmlChannel.Fader != null) |
|
|
|
|
@ -47,6 +56,9 @@ namespace Lib.Audio |
|
|
|
|
foreach (var button in xmlChannel.Buttons) |
|
|
|
|
Buttons.Add(buttonFactory.Create(button, _channelNumber)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_processManager.ProcessStarted += OnProcessManagerProcessStarted; |
|
|
|
|
_processManager.ProcessExited += OnProcessManagerProcessExited; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public IFader? Fader { get; } |
|
|
|
|
@ -137,11 +149,36 @@ namespace Lib.Audio |
|
|
|
|
|
|
|
|
|
Controllable?.SetVolume(fader.RelativePosition); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void OnProcessManagerProcessStarted(object? sender, IObservedProcess process) |
|
|
|
|
{ |
|
|
|
|
if (Controllable?.Process == null) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (!Controllable.Process.IsSameExecutable(process)) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
Controllable = _controllableCollector.GetControllableForProcess(process); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void OnProcessManagerProcessExited(object? sender, IObservedProcess process) |
|
|
|
|
{ |
|
|
|
|
if (Controllable?.Process == null) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (!Controllable.Process.IsSameExecutable(process)) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
Controllable.IsValid = false; //TODO: Toggle Record button led |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override string ToString() => $"Channel {_channelNumber}"; |
|
|
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
|
{ |
|
|
|
|
_processManager.ProcessStarted -= OnProcessManagerProcessStarted; |
|
|
|
|
_processManager.ProcessExited -= OnProcessManagerProcessExited; |
|
|
|
|
|
|
|
|
|
UnMapControllable(); |
|
|
|
|
_midiCommunication.Send(new PitchWheelChangeMessage(0, _channelNumber, 0)); |
|
|
|
|
} |
|
|
|
|
|