feat: add song requests with hot swap

A listener request can now replace any upcoming item in the schedule,
also while the broadcast is running. The user picks a song from the
library, selects a row in the timeline and clicks "Play instead of
selected".

ScheduleGenerator.Replace puts the song at that position and rebuilds
only the rest of its half hour. Filler goes before the songs, so the
last song still ends exactly when the next news starts. Items before
the swap and all later half hours stay as they were. The filler budget
counts the ads and talk already planned earlier in that half hour, and
an ad never follows another ad.

PlaybackEngine.ReplaceUpcoming switches the running engine to the new
plan. It refuses when the item has already started, and the engine
reads each next item under a lock, so a swap cannot hit an item that
is just going on air.

The timeline marks the item on air with a play icon instead of
selecting it, so the selection is free for the swap target. A hint
next to the button says why a row cannot be replaced (news, already
played, no song chosen).

Refs #11

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
fraujulianandClaude Opus 5.5 committed 2026-11-23 11:10:38 +01:00
1 parent ce0bc03ef7
commit 667501e805
8 files changed
+387 -30

No files matched your search

+24 -3
View File
@@ -61,6 +61,21 @@ public sealed class PlaybackEngine
}
}
/// <summary>
/// Hot swap: switches to <paramref name="items"/> while playing. Items before <paramref name="fromIndex"/>
/// must be unchanged. Returns <c>false</c> if the item at <paramref name="fromIndex"/> has already started.
/// </summary>
public bool ReplaceUpcoming(IReadOnlyList<ScheduleItem> items, int fromIndex)
{
lock (_lock)
{
if (IsRunning && CurrentIndex >= fromIndex)
return false;
Items = items;
return true;
}
}
/// <summary>Stops playback. Waits until the running schedule has ended.</summary>
public void Stop()
{
@@ -90,11 +105,17 @@ public sealed class PlaybackEngine
{
try
{
for (var i = 0; i < Items.Count; i++)
for (var i = 0; ; i++)
{
token.ThrowIfCancellationRequested();
var item = Items[i];
CurrentIndex = i;
ScheduleItem item;
// Under the lock so ReplaceUpcoming cannot swap the item that is about to start.
lock (_lock)
{
if (i >= Items.Count) break;
item = Items[i];
CurrentIndex = i;
}
ItemStarted?.Invoke(this, (i, item));
if (item.Kind == ScheduleItemKind.Song && item.Song is not null)