Unit 8. Re-houses the shipped TASK 22 offset in the dock:
- slider −200…+200 ms, snapping to 5 ms ticks (the existing property still clamps and persists)
- readable readout: "0 ms (aligned)" when right, signed otherwise ("+50 ms", "−120 ms")
- presets 0 / +50 / +100; 0 IS the detent — a button is easier to hit than a snap, and "the lip-sync
is right" deserves one click.
Guard: SyncBayTests pins the binding, the readout, the presets and the snapping, and that the
offset stays the persisted property (no second source of truth).
84 lines
3.0 KiB
C#
84 lines
3.0 KiB
C#
using System.Windows;
|
||
using System.Windows.Controls;
|
||
using ytLive.Models;
|
||
|
||
namespace ytLive.Controls;
|
||
|
||
/// <summary>The sound bars (creator ruling 2026-10-30). This unit owns the SHELL: the piece of the
|
||
/// window it occupies and the collapse behaviour. The bays and the master readouts fill in over
|
||
/// the following units, so nothing here pretends to be a working meter.
|
||
///
|
||
/// <para>Collapse is driven by the window height, not a user setting: at 1366×768 a full dock
|
||
/// squeezes the preview, and the creator should not have to manage that.</para></summary>
|
||
public partial class AudioDock : UserControl
|
||
{
|
||
private Window? _window;
|
||
|
||
public AudioDock()
|
||
{
|
||
InitializeComponent();
|
||
Loaded += OnLoaded;
|
||
Unloaded += OnUnloaded;
|
||
}
|
||
|
||
/// <summary>Is the dock showing only the telemetry strip?</summary>
|
||
internal bool IsCollapsed { get; private set; }
|
||
|
||
/// <summary>Test seam: the same code the window's SizeChanged runs, without a window.</summary>
|
||
internal void ApplyWindowHeight(double windowHeight)
|
||
{
|
||
var collapsed = AudioDockLayout.IsCollapsed(windowHeight);
|
||
IsCollapsed = collapsed;
|
||
Height = AudioDockLayout.HeightFor(windowHeight);
|
||
Bays.Visibility = collapsed ? Visibility.Collapsed : Visibility.Visible;
|
||
}
|
||
|
||
private void MicLabel_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||
{
|
||
if (DataContext is ViewModels.MainViewModel vm && vm.OpenMicPickerCommand.CanExecute(null))
|
||
vm.OpenMicPickerCommand.Execute(null);
|
||
}
|
||
|
||
private void SyncPreset_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
if (DataContext is not ViewModels.MainViewModel vm) return;
|
||
if (sender is Button { Tag: string tag } && int.TryParse(tag, out var ms))
|
||
vm.SetSyncOffset(ms);
|
||
}
|
||
|
||
private void TraxPlayPause_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
if (DataContext is ViewModels.MainViewModel vm) vm.TraxLeftClick();
|
||
}
|
||
|
||
private void TraxLabel_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||
{
|
||
if (DataContext is ViewModels.MainViewModel vm) vm.TraxLeftClick();
|
||
}
|
||
|
||
private void TraxLabel_MouseRightButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||
{
|
||
if (DataContext is ViewModels.MainViewModel vm) vm.ChooseTrack();
|
||
}
|
||
|
||
private void OnLoaded(object sender, RoutedEventArgs e)
|
||
{
|
||
_window = Window.GetWindow(this);
|
||
if (_window == null)
|
||
{
|
||
ApplyWindowHeight(AudioDockLayout.CollapseBelowHeight); // no host: show the dock
|
||
return;
|
||
}
|
||
_window.SizeChanged += OnWindowSizeChanged;
|
||
ApplyWindowHeight(_window.ActualHeight > 0 ? _window.ActualHeight : _window.Height);
|
||
}
|
||
|
||
private void OnUnloaded(object sender, RoutedEventArgs e)
|
||
{
|
||
if (_window != null) _window.SizeChanged -= OnWindowSizeChanged;
|
||
_window = null;
|
||
}
|
||
|
||
private void OnWindowSizeChanged(object sender, SizeChangedEventArgs e) => ApplyWindowHeight(e.NewSize.Height);
|
||
}
|