- initialize faders with initial volumes

master
Simon G 5 years ago
parent 8f69b3a062
commit a3a3619cbb
  1. 20
      Lib.Audio/Channel.cs
  2. 2
      Lib.Audio/Controllable.cs
  3. 6
      Lib.Audio/Controls/Fader.cs
  4. 2
      Lib.Audio/Controls/Interfaces/IFader.cs
  5. 2
      Lib.Audio/Device.cs
  6. 4
      Lib.Audio/Interfaces/IChannel.cs
  7. 1
      Lib.Audio/Interfaces/IControllable.cs
  8. 5
      Lib.Audio/MasterControllable.cs

@ -58,9 +58,10 @@ namespace Lib.Audio
{ {
Controllable = controllable; Controllable = controllable;
ToggleSelectButtonLed(); ToggleSelectButtonLed();
InitializeFader(controllable);
} }
public void UnMapControllable() private void UnMapControllable()
{ {
if (Controllable == null) if (Controllable == null)
return; return;
@ -109,6 +110,17 @@ namespace Lib.Audio
_acknowledgeMessage = null; _acknowledgeMessage = null;
} }
private void InitializeFader(IControllable controllable)
{
if (Fader == null)
return;
float volume = controllable.GetVolume();
Fader.RelativePosition = volume;
_midiCommunication.Send(new PitchWheelChangeMessage(0, _channelNumber, Fader.Position));
}
private void ToggleSelectButtonLed() private void ToggleSelectButtonLed()
{ {
ISelectButton? selectButton = Buttons?.OfType<ISelectButton>().FirstOrDefault(); ISelectButton? selectButton = Buttons?.OfType<ISelectButton>().FirstOrDefault();
@ -127,5 +139,11 @@ namespace Lib.Audio
} }
public override string ToString() => $"Channel {_channelNumber}"; public override string ToString() => $"Channel {_channelNumber}";
public void Dispose()
{
UnMapControllable();
_midiCommunication.Send(new PitchWheelChangeMessage(0, _channelNumber, 0));
}
} }
} }

@ -23,6 +23,8 @@ namespace Lib.Audio
public string? IconPath => _audioSessionControls.FirstOrDefault(c => !string.IsNullOrEmpty(c.IconPath))?.IconPath; public string? IconPath => _audioSessionControls.FirstOrDefault(c => !string.IsNullOrEmpty(c.IconPath))?.IconPath;
public void SetVolume(float volume) => _audioSessionControls.ForEach(c => c.SimpleAudioVolume.Volume = volume); public void SetVolume(float volume) => _audioSessionControls.ForEach(c => c.SimpleAudioVolume.Volume = volume);
public float GetVolume() => _audioSessionControls[0].SimpleAudioVolume.Volume; //TODO: Can we always take 0?
public void Mute() => _audioSessionControls.ForEach(c => c.SimpleAudioVolume.Mute = true); public void Mute() => _audioSessionControls.ForEach(c => c.SimpleAudioVolume.Mute = true);
public void UnMute() => _audioSessionControls.ForEach(c => c.SimpleAudioVolume.Mute = false); public void UnMute() => _audioSessionControls.ForEach(c => c.SimpleAudioVolume.Mute = false);

@ -29,7 +29,11 @@ namespace Lib.Audio.Controls
} }
public bool IsTouched { get; set; } public bool IsTouched { get; set; }
public float RelativePosition => Position / (MAX_POSITION - MIN_POSITION); public float RelativePosition
{
get => Position / (MAX_POSITION - MIN_POSITION);
set => _position = (int) (value * (MAX_POSITION - MIN_POSITION));
}
public event EventHandler<int>? PositionChanged; public event EventHandler<int>? PositionChanged;
} }

@ -13,7 +13,7 @@ namespace Lib.Audio.Controls.Interfaces
bool IsTouched { get; set; } bool IsTouched { get; set; }
float RelativePosition { get; } float RelativePosition { get; set; }
event EventHandler<int>? PositionChanged; event EventHandler<int>? PositionChanged;
} }

@ -50,7 +50,7 @@ namespace Lib.Audio
public void Dispose() public void Dispose()
{ {
Channels.ForEach(c => c.UnMapControllable()); Channels.ForEach(c => c.Dispose());
_midiCommunication.Close(); _midiCommunication.Close();
} }
} }

@ -2,6 +2,7 @@
// Created: 2021-04-07 // Created: 2021-04-07
// Copyright(c) 2021 SimonG. All Rights Reserved. // Copyright(c) 2021 SimonG. All Rights Reserved.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Lib.Audio.Controls.Buttons.Interfaces; using Lib.Audio.Controls.Buttons.Interfaces;
using Lib.Audio.Controls.Interfaces; using Lib.Audio.Controls.Interfaces;
@ -9,7 +10,7 @@ using Lib.Midi.Messages.Interfaces;
namespace Lib.Audio.Interfaces namespace Lib.Audio.Interfaces
{ {
public interface IChannel public interface IChannel : IDisposable
{ {
IFader? Fader { get; } IFader? Fader { get; }
IKnob? Knob { get; } IKnob? Knob { get; }
@ -18,7 +19,6 @@ namespace Lib.Audio.Interfaces
IControllable? Controllable { get; } IControllable? Controllable { get; }
void MapControllable(IControllable controllable); void MapControllable(IControllable controllable);
void UnMapControllable();
void HandleMessage(IMidiMessage message); void HandleMessage(IMidiMessage message);
void SendAcknowledge(); void SendAcknowledge();
} }

@ -10,6 +10,7 @@ namespace Lib.Audio.Interfaces
string? IconPath { get; } string? IconPath { get; }
void SetVolume(float volume); void SetVolume(float volume);
float GetVolume();
void Mute(); void Mute();
void UnMute(); void UnMute();
} }

@ -43,6 +43,11 @@ namespace Lib.Audio
// } // }
} }
public float GetVolume()
{
throw new System.NotImplementedException();
}
public void Mute() => _audioEndpointVolume.Mute = true; public void Mute() => _audioEndpointVolume.Mute = true;
public void UnMute() => _audioEndpointVolume.Mute = false; public void UnMute() => _audioEndpointVolume.Mute = false;

Loading…
Cancel
Save