- correctly convert position to volume

master
Simon G 5 years ago
parent 06bc67be4a
commit 0df7f0ecf2
  1. 8
      Lib.Audio/Channel.cs
  2. 7
      Lib.Audio/Controls/Fader.cs
  3. 4
      Lib.Audio/Controls/Interfaces/IFader.cs

@ -82,7 +82,13 @@ namespace Lib.Audio
_acknowledgeMessage = null;
}
private void OnFaderPositionChanged(object? sender, float position) => Controllable?.SetVolume(position);
private void OnFaderPositionChanged(object? sender, int position)
{
if (sender is not IFader fader)
return;
Controllable?.SetVolume(fader.RelativePosition);
}
public override string ToString() => $"Channel {_channelNumber}";
}

@ -10,12 +10,14 @@ namespace Lib.Audio.Controls
{
public class Fader : IFader
{
private const float MIN_POSITION = 0; //TODO: calibrate? get from driver?
private const float MAX_POSITION = 16256; //TODO: calibrate? get from driver?
private int _position;
public Fader(XmlFader xmlFader) => NoteNumber = xmlFader.NoteNumber;
public int NoteNumber { get; }
public int Position
{
get => _position;
@ -27,7 +29,8 @@ namespace Lib.Audio.Controls
}
public bool IsTouched { get; set; }
public float RelativePosition => Position / (MAX_POSITION - MIN_POSITION);
public event EventHandler<float>? PositionChanged;
public event EventHandler<int>? PositionChanged;
}
}

@ -12,7 +12,9 @@ namespace Lib.Audio.Controls.Interfaces
int Position { get; set; }
bool IsTouched { get; set; }
float RelativePosition { get; }
event EventHandler<float>? PositionChanged;
event EventHandler<int>? PositionChanged;
}
}
Loading…
Cancel
Save