Live mixer settings change works, but not instantly (playback buffer is filled in already).

This commit is contained in:
Alexander Shabarshov 2026-07-19 13:43:28 +01:00
parent 21e1f1e3f5
commit 5d3dceb89e
3 changed files with 41 additions and 3 deletions

View File

@ -1,4 +1,5 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Input; using System.Windows.Input;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;
@ -132,6 +133,41 @@ public sealed partial class PlaybackViewModel : ObservableObject
await _engine.PlayAsync(); await _engine.PlayAsync();
} }
partial void OnMixerChanged(MixerViewModel? oldValue, MixerViewModel newValue)
{
if (oldValue != null)
{
foreach (var stem in oldValue.Stems)
{
stem.PropertyChanged -= OnMixerSettingsChanged;
}
}
if (newValue != null)
{
foreach (var stem in newValue.Stems)
{
stem.PropertyChanged += OnMixerSettingsChanged;
}
}
}
private void OnMixerSettingsChanged(object? sender, PropertyChangedEventArgs e)
{
if (sender is not StemChannelViewModel stem)
return;
var mixerSettings = new MixerSettings
{
Stems = Mixer.Stems.Select(x => new StemMixSettings
{
GainDb = x.GainDb,
Enabled = x.Enabled,
Pan = x.Pan
}).ToList()
};
Task.Run(async () => await _engine.UpdateMixerAsync(mixerSettings));
}
partial void OnCurrentTimeChanged(TimeSpan value) partial void OnCurrentTimeChanged(TimeSpan value)
{ {
foreach (var band in Bands) foreach (var band in Bands)

View File

@ -5,8 +5,8 @@ public partial class StemChannelViewModel : ObservableObject
public StemType Type { get; } public StemType Type { get; }
[ObservableProperty] private bool _enabled = true; [ObservableProperty] private bool _enabled = true;
[ObservableProperty] private float _gainDb = 0f; [ObservableProperty] private float _gainDb;
[ObservableProperty] private float _pan = 0f; [ObservableProperty] private float _pan;
public StemChannelViewModel(StemType type) public StemChannelViewModel(StemType type)
{ {

View File

@ -5,6 +5,8 @@ public sealed class StemMixSettings
public bool Enabled { get; init; } = true; public bool Enabled { get; init; } = true;
public float GainDb { get; init; } = 0f; public float GainDb { get; init; } = 0f;
public float Pan { get; init; } = 0f; // -1..+1 public float Pan { get; init; } = 0f; // -1..+1
public override string ToString() => $"{(Enabled ? "[x]": "[ ]")} {GainDb:N2} {Pan:N2}";
} }
public sealed class MixerSettings public sealed class MixerSettings