feat: mix music and microphone on one program output

Songs and the microphone now go through one audio channel,
ProgramOutput, instead of each opening its own device. ProgramMixer
builds two mixes in one pass: the broadcast for the listeners and a
monitor mix for the person at the desk. With two playback devices each
mix gets its own device; with one device the desk hears the monitor
mix.

The Schedule page gets a microphone button that works with or without
a running broadcast, and sliders for the music and microphone levels
on the broadcast, the music level on the monitor, and an option to
hear the broadcast exactly. The Settings page lets the user choose
the playback devices for the broadcast and for themselves.

MusicPlayer plays its tracks into the mixer; pause takes the track
out of the mix and resume puts it back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
fraujulianandClaude Opus 5.5 committed 2026-11-25 08:21:13 +01:00
1 parent 2380f233b5
commit 5d261717fe
14 files changed
+829 -89

No files matched your search

+130 -46
View File
@@ -94,47 +94,47 @@
IsClosable="True"
IsOpen="False" />
<!-- Now playing -->
<!-- Now playing: what is on air and its buttons on top, the mixing desk below -->
<Border Grid.Row="3"
Margin="0,16,0,16"
Padding="16"
Padding="20,16,20,12"
CornerRadius="8"
BorderThickness="1"
BorderBrush="{DynamicResource CardStrokeColorDefaultBrush}"
Background="{DynamicResource CardBackgroundFillColorDefaultBrush}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<ui:TextBlock FontTypography="Caption"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Text="Läuft gerade" />
<StackPanel Margin="0,4,0,0" Orientation="Horizontal">
<ContentPresenter x:Name="NowKind"
VerticalAlignment="Center"
ContentTemplate="{StaticResource KindChip}"
Visibility="Collapsed" />
<ui:TextBlock x:Name="NowTitle"
Margin="8,0,0,0"
FontTypography="Subtitle"
TextTrimming="CharacterEllipsis"
Text="Nichts auf Sendung" />
<StackPanel VerticalAlignment="Center">
<ui:TextBlock FontTypography="Caption"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Text="Läuft gerade" />
<DockPanel Margin="0,4,0,0">
<ContentPresenter x:Name="NowKind"
Margin="0,0,8,0"
VerticalAlignment="Center"
ContentTemplate="{StaticResource KindChip}"
Visibility="Collapsed" />
<ui:TextBlock x:Name="NowTitle"
FontTypography="Subtitle"
TextTrimming="CharacterEllipsis"
Text="Nichts auf Sendung" />
</DockPanel>
</StackPanel>
<ProgressBar x:Name="NowProgress"
Margin="0,12,0,0"
AutomationProperties.Name="Fortschritt des aktuellen Elements"
Maximum="1" />
<ui:TextBlock x:Name="NowTime"
Margin="0,6,0,0"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Text=" " />
</StackPanel>
<StackPanel Grid.Column="1" Margin="24,0,0,0" VerticalAlignment="Center">
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<StackPanel Grid.Column="1" Margin="24,0,0,0" VerticalAlignment="Center" Orientation="Horizontal">
<!-- Live microphone on the program channel; label and icon say whether it is on. -->
<ui:Button x:Name="MicButton"
MinWidth="120"
Margin="0,0,20,0"
Content="Mikro ein"
Icon="{ui:SymbolIcon Mic24}"
ToolTip="Schaltet das Mikrofon auf Sendung, auch ĂĽber laufende Musik."
Click="OnMicToggle" />
<ui:Button x:Name="EndNowButton"
Content="Jetzt beenden"
Icon="{ui:SymbolIcon Next24}"
@@ -150,21 +150,105 @@
IsEnabled="False"
Click="OnPlayToggle" />
</StackPanel>
<StackPanel Margin="0,12,0,0" Orientation="Horizontal">
<ui:SymbolIcon VerticalAlignment="Center" Symbol="Speaker224" />
<Slider x:Name="VolumeSlider"
Width="140"
Margin="8,0,0,0"
VerticalAlignment="Center"
AutomationProperties.Name="Lautstärke"
Minimum="0"
Maximum="1"
SmallChange="0.05"
LargeChange="0.1"
ValueChanged="OnVolumeChanged" />
</Grid>
<ProgressBar x:Name="NowProgress"
Margin="0,14,0,0"
AutomationProperties.Name="Fortschritt des aktuellen Elements"
Maximum="1" />
<ui:TextBlock x:Name="NowTime"
Margin="0,6,0,0"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Text=" " />
<Border Height="1" Margin="0,4,0,14" Background="{DynamicResource CardStrokeColorDefaultBrush}" />
<!-- Mixing desk: three groups of the same width, each a heading with its levels.
The groups wrap below each other on a narrow window. -->
<WrapPanel x:Name="MixPanel" Grid.IsSharedSizeScope="True">
<WrapPanel.Resources>
<Style TargetType="Slider" BasedOn="{StaticResource {x:Type Slider}}">
<Setter Property="Margin" Value="12,0,0,0" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Minimum" Value="0" />
<Setter Property="Maximum" Value="1" />
<Setter Property="SmallChange" Value="0.05" />
<Setter Property="LargeChange" Value="0.1" />
</Style>
<Style x:Key="Group" TargetType="StackPanel">
<Setter Property="Width" Value="208" />
<Setter Property="Margin" Value="0,0,28,8" />
</Style>
<Style x:Key="Heading" TargetType="ui:TextBlock">
<Setter Property="FontTypography" Value="Caption" />
<Setter Property="Foreground" Value="{DynamicResource TextFillColorSecondaryBrush}" />
<Setter Property="Margin" Value="0,0,0,4" />
</Style>
</WrapPanel.Resources>
<StackPanel Style="{StaticResource Group}">
<ui:TextBlock Style="{StaticResource Heading}" Text="Sendung (fĂĽr andere)" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="MixLabel" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="32" />
<RowDefinition Height="32" />
</Grid.RowDefinitions>
<ui:TextBlock VerticalAlignment="Center" Text="Musik" />
<Slider x:Name="MusicForOthersSlider" Grid.Column="1"
AutomationProperties.Name="Musik fĂĽr andere" ValueChanged="OnMixChanged" />
<ui:TextBlock Grid.Row="1" VerticalAlignment="Center" Text="Mikrofon" />
<Slider x:Name="MicrophoneForOthersSlider" Grid.Row="1" Grid.Column="1"
AutomationProperties.Name="Mikrofon fĂĽr andere" ValueChanged="OnMixChanged" />
</Grid>
</StackPanel>
</StackPanel>
</Grid>
<StackPanel Style="{StaticResource Group}">
<ui:TextBlock Style="{StaticResource Heading}" Text="FĂĽr mich" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="MixLabel" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="32" />
<RowDefinition Height="32" />
</Grid.RowDefinitions>
<ui:TextBlock VerticalAlignment="Center" Text="Musik" />
<Slider x:Name="MusicForMeSlider" Grid.Column="1"
AutomationProperties.Name="Musik fĂĽr mich" ValueChanged="OnMixChanged" />
<CheckBox x:Name="ListenToBroadcastBox"
Grid.Row="1" Grid.ColumnSpan="2"
MinWidth="0"
Padding="8,0,0,0"
VerticalAlignment="Center"
Content="Sendung 1:1 hören"
ToolTip="Du hörst genau das, was andere hören: gleiche Lautstärke von dir, Musik und allem anderen."
Checked="OnMixChanged"
Unchecked="OnMixChanged" />
</Grid>
</StackPanel>
<StackPanel Style="{StaticResource Group}" Margin="0,0,0,8">
<ui:TextBlock Style="{StaticResource Heading}" Text="Musik gesamt" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="MixLabel" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="32" />
</Grid.RowDefinitions>
<ui:TextBlock VerticalAlignment="Center" Text="Lautstärke" />
<Slider x:Name="VolumeSlider" Grid.Column="1"
AutomationProperties.Name="Lautstärke der Musik gesamt" ValueChanged="OnVolumeChanged" />
</Grid>
</StackPanel>
</WrapPanel>
</StackPanel>
</Border>
<!-- Song request (hot swap) on the left, actions for the selected timeline row on the right -->
@@ -29,9 +29,14 @@ public partial class SchedulePage : Page
// Optimistic state: what the user just asked for, shown before the engine has caught up.
private bool? _expectPlaying;
public SchedulePage(ScheduleController controller)
private readonly Microphone _microphone;
private readonly ProgramMixer _mixer;
public SchedulePage(ScheduleController controller, Microphone microphone, ProgramOutput output)
{
_controller = controller;
_microphone = microphone;
_mixer = output.Mixer;
InitializeComponent();
Timeline.ItemsSource = _rows;
// Also refreshes the buttons: Finished can arrive just before the engine reports it stopped.
@@ -51,7 +56,13 @@ public partial class SchedulePage : Page
_loading = true;
VolumeSlider.Value = _controller.Volume;
MusicForMeSlider.Value = _mixer.MusicForMe;
MusicForOthersSlider.Value = _mixer.MusicForOthers;
MicrophoneForOthersSlider.Value = _mixer.MicrophoneForOthers;
ListenToBroadcastBox.IsChecked = _mixer.ListenToBroadcast;
MusicForMeSlider.IsEnabled = !_mixer.ListenToBroadcast;
_loading = false;
ShowMicrophone(); // it stays on while the user visits other pages
FillStartTimes();
if (_controller.Plan.Count > 0)
UnlimitedBox.IsChecked = _controller.IsUnlimited;
@@ -162,6 +173,49 @@ public partial class SchedulePage : Page
Timeline.SelectedIndex = row.Index + offset;
});
private void OnMixChanged(object sender, RoutedEventArgs e)
{
if (_loading) return;
_mixer.MusicForMe = (float)MusicForMeSlider.Value;
_mixer.MusicForOthers = (float)MusicForOthersSlider.Value;
_mixer.MicrophoneForOthers = (float)MicrophoneForOthersSlider.Value;
_mixer.ListenToBroadcast = ListenToBroadcastBox.IsChecked == true;
// While the monitor copies the broadcast, its own music level has no effect.
MusicForMeSlider.IsEnabled = !_mixer.ListenToBroadcast;
}
private async void OnMicToggle(object sender, RoutedEventArgs e)
{
var turnOn = !_microphone.IsOn;
MicButton.IsEnabled = false;
try
{
// Opening the devices can take a moment, so it runs off the UI thread.
await Task.Run(() =>
{
if (turnOn) _microphone.TurnOn();
else _microphone.TurnOff();
});
Message.IsOpen = false;
}
catch (InvalidOperationException ex)
{
ShowMessage(InfoBarSeverity.Error, "Mikrofon nicht verfĂĽgbar", ex.Message);
}
MicButton.IsEnabled = true;
ShowMicrophone();
}
private void ShowMicrophone()
{
var on = _microphone.IsOn;
// The label names the action; the red button shows that the microphone is live.
MicButton.Content = on ? "Mikro aus" : "Mikro ein";
MicButton.Icon = new SymbolIcon(on ? SymbolRegular.MicOff24 : SymbolRegular.Mic24);
MicButton.Appearance = on ? ControlAppearance.Danger : ControlAppearance.Secondary;
System.Windows.Automation.AutomationProperties.SetName(MicButton, on ? "Mikrofon ausschalten, es ist auf Sendung" : "Mikrofon einschalten");
}
private void OnEndNow(object sender, RoutedEventArgs e)
{
try
@@ -90,6 +90,34 @@
</Grid>
</Border>
<!-- Audio devices -->
<Border Style="{StaticResource Card}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="220" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ui:TextBlock Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="Audio-Ausgabe" />
<Label Grid.Row="1" Margin="0,12,0,0" VerticalAlignment="Center"
Content="Sendung (fĂĽr andere)" Target="{Binding ElementName=BroadcastDeviceBox}" />
<ComboBox x:Name="BroadcastDeviceBox" Grid.Row="1" Grid.Column="1" Margin="0,12,0,0"
AutomationProperties.Name="Ausgabegerät für die Sendung" />
<Label Grid.Row="2" Margin="0,8,0,0" VerticalAlignment="Center"
Content="Für mich (Kopfhörer)" Target="{Binding ElementName=MonitorDeviceBox}" />
<ComboBox x:Name="MonitorDeviceBox" Grid.Row="2" Grid.Column="1" Margin="0,8,0,0"
AutomationProperties.Name="Ausgabegerät für mich" />
<ui:TextBlock Grid.Row="3" Grid.ColumnSpan="2" Margin="0,12,0,0" TextWrapping="Wrap"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Text="Getrennte Lautstärken für dich und für andere brauchen zwei verschiedene Geräte. Mit nur einem Gerät hörst du deinen eigenen Mix." />
</Grid>
</Border>
<!-- Minutes per hour -->
<Border Style="{StaticResource Card}">
<Grid>
@@ -20,8 +20,18 @@ public partial class SettingsPage : Page
// Loaded fires on every navigation to the page, so unsaved edits from an earlier visit are dropped.
private void OnLoaded(object sender, RoutedEventArgs e) => Show(_store.Current);
// First entry of each list: the choice that names no device.
private const string DefaultDevice = "Windows-Standardgerät";
private const string NoDevice = "Kein eigenes Gerät";
private void Show(AppSettings settings)
{
// Read again on every visit, so a headset plugged in meanwhile shows up.
var devices = ProgramOutput.DeviceNames().ToList();
BroadcastDeviceBox.ItemsSource = devices.Prepend(DefaultDevice).ToList();
MonitorDeviceBox.ItemsSource = devices.Prepend(NoDevice).ToList();
BroadcastDeviceBox.SelectedIndex = devices.IndexOf(settings.BroadcastDevice ?? "") + 1;
MonitorDeviceBox.SelectedIndex = devices.IndexOf(settings.MonitorDevice ?? "") + 1;
NewsAlertSwitch.IsChecked = settings.NewsAlert;
NewsSecondsBox.Value = settings.NewsAlertSeconds;
NewsSoundBox.IsChecked = settings.NewsAlertSound;
@@ -47,6 +57,8 @@ public partial class SettingsPage : Page
NewsMinutesPerHour = (int)(NewsMinutesBox.Value ?? Defaults.NewsMinutesPerHour),
ModeratorMinutesPerHour = (int)(ModeratorMinutesBox.Value ?? Defaults.ModeratorMinutesPerHour),
AdMinutesPerHour = (int)(AdMinutesBox.Value ?? Defaults.AdMinutesPerHour),
BroadcastDevice = BroadcastDeviceBox.SelectedIndex > 0 ? (string)BroadcastDeviceBox.SelectedItem : null,
MonitorDevice = MonitorDeviceBox.SelectedIndex > 0 ? (string)MonitorDeviceBox.SelectedItem : null,
};
private void OnSave(object sender, RoutedEventArgs e)
@@ -63,6 +75,10 @@ public partial class SettingsPage : Page
_store.Save(settings);
ShowMessage(InfoBarSeverity.Success, "Gespeichert", "Minuten pro Stunde gelten für den nächsten Plan.");
}
catch (NAudio.MmException)
{
ShowMessage(InfoBarSeverity.Error, "Nicht gespeichert", "Ein gewähltes Audiogerät konnte nicht geöffnet werden. Die bisherigen Geräte bleiben aktiv.");
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
ShowMessage(InfoBarSeverity.Error, "Nicht gespeichert", ex.Message);