From 0df7f0ecf2749095e441cf67172cdf444a69a2d8 Mon Sep 17 00:00:00 2001 From: Simon G Date: Sat, 10 Apr 2021 22:19:30 +0200 Subject: [PATCH] - correctly convert position to volume --- Lib.Audio/Channel.cs | 8 +++++++- Lib.Audio/Controls/Fader.cs | 7 +++++-- Lib.Audio/Controls/Interfaces/IFader.cs | 4 +++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Lib.Audio/Channel.cs b/Lib.Audio/Channel.cs index 325089c..0b62c24 100644 --- a/Lib.Audio/Channel.cs +++ b/Lib.Audio/Channel.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}"; } diff --git a/Lib.Audio/Controls/Fader.cs b/Lib.Audio/Controls/Fader.cs index 94f17a6..8560564 100644 --- a/Lib.Audio/Controls/Fader.cs +++ b/Lib.Audio/Controls/Fader.cs @@ -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? PositionChanged; + public event EventHandler? PositionChanged; } } \ No newline at end of file diff --git a/Lib.Audio/Controls/Interfaces/IFader.cs b/Lib.Audio/Controls/Interfaces/IFader.cs index 63301f7..9243443 100644 --- a/Lib.Audio/Controls/Interfaces/IFader.cs +++ b/Lib.Audio/Controls/Interfaces/IFader.cs @@ -12,7 +12,9 @@ namespace Lib.Audio.Controls.Interfaces int Position { get; set; } bool IsTouched { get; set; } + + float RelativePosition { get; } - event EventHandler? PositionChanged; + event EventHandler? PositionChanged; } } \ No newline at end of file