- 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;
ToggleSelectButtonLed();
InitializeFader(controllable);
}
public void UnMapControllable()
private void UnMapControllable()
{
if (Controllable == null)
return;
@ -109,6 +110,17 @@ namespace Lib.Audio
_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()
{
ISelectButton? selectButton = Buttons?.OfType<ISelectButton>().FirstOrDefault();
@ -127,5 +139,11 @@ namespace Lib.Audio
}
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 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 UnMute() => _audioSessionControls.ForEach(c => c.SimpleAudioVolume.Mute = false);

@ -29,7 +29,11 @@ namespace Lib.Audio.Controls
}
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;
}

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

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

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

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

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

Loading…
Cancel
Save