Compare commits
11
Commits
8d1790d164
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a47da65f3d | ||
|
|
6c3396ab4d | ||
|
|
3dcc81cc43 | ||
|
|
459f8ea7f5 | ||
|
|
b1d09c6abd | ||
|
|
ef388d82f4 | ||
|
|
4c8740774d | ||
|
|
d906222a39 | ||
|
|
2d88d17b22 | ||
|
|
526294ddeb | ||
|
|
8f483640cd |
No files matched your search
@@ -29,25 +29,27 @@ The interface is in German. This section names the controls as they appear on sc
|
||||
|
||||
1. **Import**: one page for both ways of adding music. Every result, added or failed, is listed under "Importiert" as soon as there is one, with a link to the library.
|
||||
- **Vom Computer**: drop MP3 or WAV files on the page or click **Dateien auswählen...**; several files at once are fine. The app copies each file into the music folder, reads title and artist from the file tags and measures the duration. A file that fails is reported and the others still get imported.
|
||||
- **Online**: choose Openverse, the Internet Archive or, while laut.fm is switched on, laut.fm in the list next to the search box. Search the catalog, preview a result and import it with **In Bibliothek importieren** or a double-click. Select several results with Ctrl or Shift to import them in one go; they are downloaded one after the other. The app downloads the file and stores its license and attribution with the song. Results that are already in the library or have no duration cannot be imported; the tooltip of the disabled button says why.
|
||||
- **Online**: one search runs on Openverse and the Internet Archive at the same time; each source's results appear as soon as it answers, and the **Quelle** column shows where a result comes from. If one source fails, the others' results stay and a warning names the problem. Untick licenses in the **Lizenzen** dropdown next to the search box to leave them out of the results (Openverse filters on its server, the Internet Archive after the search, so it may return fewer results). Search the catalog, preview a result and import it with **In Bibliothek importieren** or a double-click. Select several results with Ctrl or Shift to import them in one go; they are downloaded one after the other. The app downloads the file and stores its license and attribution with the song. Results that are already in the library or have no duration cannot be imported; the tooltip of the disabled button says why.
|
||||
2. **Bibliothek**: lists and searches all songs. Edit title, artist, license and attribution, or delete a song.
|
||||
3. **Sendeplan** (the start page):
|
||||
1. Choose the start (one of the next 12 full hours) and the number of hours (1 to 24), then click **Plan erstellen**.
|
||||
1. Choose the start and the number of hours (1 to 24), then click **Plan erstellen**.
|
||||
- **Unbegrenzt** plans without an end: the timeline shows the next 5 hours, and while the broadcast runs one more hour is added whenever less than 5 hours are left.
|
||||
- **Jetzt starten** ignores the start time, plans from this moment and goes on air at once. Music leads up to the first news at the next :00 or :30; the chosen hours count from there.
|
||||
- The start field defaults to **Jetzt**. It also lists the next twelve full hours, and you can type your own time such as `14:30`. A typed time that has already passed today means tomorrow. A **Jetzt** plan begins with music up to the first news at the next :00 or :30; the chosen hours count from there.
|
||||
- **Jetzt starten** starts the plan you created. A **Jetzt** plan moves to the moment you press it, so nothing is skipped while you looked it over. It stays disabled until a plan exists. While laut.fm is switched on the button reads **Live starten** and also starts the live stream; if laut.fm cannot be reached, the music still plays and a warning says why. While on air the button turns red and reads **Sendung beenden**, which stops playback and the live stream together.
|
||||
2. The timeline shows every item with start time, type (song, news, ad, moderator), title and duration.
|
||||
3. **Start** puts the plan on air on the real clock. Before the planned start the now-playing card shows when the broadcast begins; if the plan has already begun, playback joins at the next item. The same button then reads **Stopp** and ends it. The now-playing card shows the current item, its progress and the volume.
|
||||
4. **Edit the timeline**: select an upcoming row and use the buttons above the list to move it up or down, edit it, or remove it (trash icon). News, ad and moderator items have no title until you give them one; news and moderator items can also change their length. A double-click opens the editor too. Every item after a change follows on without a gap. The item on air can be edited too, but not moved or removed; **Jetzt beenden** in the now-playing card ends it at once and starts the next item.
|
||||
3. The now-playing card shows the current item and its progress. Before the planned start it shows when the broadcast begins; if the plan has already begun, playback joins at the next item.
|
||||
4. **Edit the timeline**: select an upcoming row and use the buttons above the list to move it up or down, edit it, or remove it (trash icon), or drag it to a new place with the mouse: a label with type and title follows the cursor, a line shows where it lands, and the row fades in at its new place. The grip on the left of a row shows it can be dragged. **Hinzufügen** inserts a song (the one chosen under **Songwunsch**), news, an ad or moderator talk as the item after next: two places after the item on air, or at position 3 of the list when nothing is on air; for everything but songs you set title and length first. News, ad and moderator items have no title until you give them one; news and moderator items can also change their length. A double-click opens the editor too. Every item after a change follows on without a gap. The item on air can be edited too, but not moved or removed; **Aktuelles Element stoppen** in the now-playing card ends it at once: its length becomes the time from its start until now, and the next item starts.
|
||||
5. **Speaking reminder**: 30 seconds before a news or moderator item goes on air, a dialog in the middle of the screen reminds you on any page and stays until you click **OK**.
|
||||
6. **Microphone**: **Mikro ein** in the now-playing card puts the default microphone on air, also over running music; the button turns red and reads **Mikro aus**. It works with or without a broadcast and stays on while you visit other pages.
|
||||
7. **Mix levels**, below the now-playing row: **Musik für andere** and **Ich für andere** set how loud the music and the microphone are for the listeners, **Musik für mich** how loud the music is on your own device. **Sendung 1:1 hören** lets you hear exactly what the listeners hear. The slider next to the loudspeaker stays the overall music volume.
|
||||
7. **Mix levels**, below the now-playing row: under **Was die Hörer hören**, **Musik** and **Mikrofon** set how loud the music and the microphone are for the listeners. Under **Was du hörst**, **Musik** sets how loud the music is on your own device; you never hear your own microphone there, because the delay is distracting. **Genau wie die Hörer** lets you hear exactly what the listeners hear, microphone included.
|
||||
8. **Songwunsch**: choose a song, select an upcoming row in the timeline and click **Auswahl ersetzen**. This also works while the broadcast is running.
|
||||
9. **Live** (only while laut.fm is switched on): sends everything on air, songs and microphone, live to your laut.fm station. It does not depend on the plan; the button turns red and reads **Live beenden**. See [laut.fm](#lautfm).
|
||||
|
||||
4. **Einstellungen** (bottom left): switch the speaking alert on or off for news and for moderator talk, set how many seconds before the start it appears and whether it plays a bing sound. Choose the playback device for the broadcast (for the listeners) and, if you have a second one such as headphones, the device for yourself. Set the minutes per hour for news, moderator talk and ads (defaults 10, 10 and 20); together they can take at most 60 minutes. **Zurücksetzen** puts the default values into the form, **Speichern** stores them in `settings.json` next to the database. Alerts change at once; minutes per hour apply to the next schedule. The **laut.fm** switch turns on live streaming and the station's library; its fields are described under [laut.fm](#lautfm).
|
||||
4. **Einstellungen** (bottom left): choose the language, **Deutsch** (default) or **English**; after **Speichern** the whole interface switches at once, without a restart. Switch the speaking alert on or off for news and for moderator talk, set how many seconds before the start it appears and whether it plays a bing sound. Choose the playback device for the broadcast (for the listeners) and, if you have a second one such as headphones, the device for yourself. Set the minutes per hour for news, moderator talk and ads (defaults 10, 10 and 20); together they can take at most 60 minutes. **Zurücksetzen** puts the default values into the form, **Speichern** stores them in `settings.json` next to the database. Alerts change at once; minutes per hour apply to the next schedule. The **laut.fm** switch turns on live streaming; its fields are described under [laut.fm](#lautfm).
|
||||
|
||||
News, ads and moderator talk are placeholders: the app shows them in the timeline and keeps silent for their duration, so the speaker can talk live.
|
||||
|
||||
Errors, such as invalid input or a failed save, search or import, open a popup with the message. Hints and warnings stay in the bar at the top of the page.
|
||||
|
||||
## How the schedule is built
|
||||
|
||||
`ScheduleGenerator` plans in half-hour slots:
|
||||
@@ -78,7 +80,7 @@ Main services:
|
||||
|
||||
- `SongRepository`: CRUD for songs in SQLite through Entity Framework Core, without SQL in the code
|
||||
- `SongImportService`: copies an uploaded file into the music folder, reads its tags with TagLibSharp and its duration with NAudio
|
||||
- `IMusicProvider`: an online catalog that can be searched. `OpenverseProvider` uses the anonymous Openverse API and `InternetArchiveProvider` the Internet Archive search, limited to Creative Commons licensed MP3 files. `LautFmProvider` searches the library of the user's laut.fm station.
|
||||
- `IMusicProvider`: an online catalog that can be searched. `OpenverseProvider` uses the anonymous Openverse API and `InternetArchiveProvider` the Internet Archive search, limited to Creative Commons licensed MP3 files.
|
||||
- `TrackDownloader`: downloads a search result into the music folder, the same way for every provider
|
||||
- `ProgramMixer`: mixes songs and the microphone twice in one pass, once for the listeners and once for the person at the desk, each with its own levels
|
||||
- `ProgramOutput`: the station's audio channel. It plays the broadcast mix on one device and, if a second device is chosen, the monitor mix on that one
|
||||
@@ -86,9 +88,10 @@ Main services:
|
||||
- `Microphone`: captures the default recording device and puts it on the `ProgramOutput`
|
||||
- `ScheduleGenerator`: builds the plan and handles song requests
|
||||
- `PlaybackEngine`: runs the plan item by item on a background thread and plays songs through `MusicPlayer`
|
||||
- `Loc`: the interface texts in German (`Strings.resx`, default) and English (`Strings.en.resx`) in `Services/Localization`. XAML uses `{l:Tr Key}`, which binds to `Loc` and follows a language switch; code uses `Loc.T` and `Loc.F` and refreshes its texts on `Loc.Changed`
|
||||
- `IcecastStream`: logs in at an Icecast server as a live source, encodes a copy of the broadcast mix to MP3 with Windows Media Foundation and sends it. `LiveController` starts and stops it and sets the stream title for each item through `StreamTitles`
|
||||
|
||||
Tests are in `tests/Radiosender.Tests` (xUnit). They cover the repository, import, Openverse parsing, the generator rules, the playback engine, the schedule controller and laut.fm (settings, Icecast login, ad trigger, track parsing).
|
||||
Tests are in `tests/Radiosender.Tests` (xUnit). They cover the repository, import, Openverse parsing, the generator rules, the playback engine, the schedule controller, laut.fm (settings, Icecast login, ad trigger) and the translations (same keys in both languages, every key used in code exists).
|
||||
|
||||
## Adding a music provider
|
||||
|
||||
@@ -97,9 +100,8 @@ Online sources sit behind `IMusicProvider`, so a new one needs no change to the
|
||||
1. Write a class that implements `IMusicProvider`: a `Name` for the interface and `SearchAsync`, which returns `MusicTrack` items (title, creator, https link to the audio file, license, attribution, duration).
|
||||
2. Give every track an `Id` that no other provider uses, for example prefixed with the provider name. Openverse ids are stored as they come.
|
||||
3. Register the class in `App.BuildServices` with `services.AddSingleton<IMusicProvider, YourProvider>()`.
|
||||
4. A provider that depends on a setting can return `false` from `IsAvailable`; the import page then leaves it out.
|
||||
|
||||
With one provider the import tab carries its name. With several, the tab is called "Online" and a list next to the search box chooses the provider.
|
||||
The import page searches all registered providers at the same time and shows each one's results as they arrive.
|
||||
|
||||
## Openverse attribution
|
||||
|
||||
@@ -129,29 +131,25 @@ For each downloaded track the app stores the license (for example `CC BY 4.0`) a
|
||||
|
||||
## laut.fm
|
||||
|
||||
With laut.fm switched on in the settings, the app streams live to a [laut.fm](https://laut.fm) station and offers the station's music on the Import page.
|
||||
With laut.fm switched on in the settings, the app streams live to a [laut.fm](https://laut.fm) station.
|
||||
|
||||
1. In Radioadmin, open **Live senden** and copy server, port, mountpoint, user and password into the laut.fm card on the Settings page. Save.
|
||||
2. For the library, enter the station id and the Radioadmin token. The token is the value of `laut.fm.api.token` in the browser's local storage after logging in to Radioadmin (developer tools).
|
||||
3. On the Sendeplan page, **Live** connects to laut.fm and sends the broadcast mix as MP3 at 128 kbit/s. laut.fm then plays the live stream instead of the station's regular program.
|
||||
2. On the Sendeplan page, **Live starten** connects to laut.fm and sends the broadcast mix as MP3 at 128 kbit/s. laut.fm then plays the live stream instead of the station's regular program.
|
||||
|
||||
The app connects as an Icecast source (`PUT` to the mountpoint with the user and password). Each item that starts sets the stream title: `Artist - Title` for songs and the item title otherwise. Ad items send `START_AD_BREAK`, which laut.fm needs to start its ad break; the app sends it at most once every 15 minutes, as laut.fm requires.
|
||||
|
||||
Password and token are stored in `settings.json` encrypted with Windows DPAPI for the current Windows user. Another user or computer cannot read them and has to enter them again.
|
||||
The password is stored in `settings.json` encrypted with Windows DPAPI for the current Windows user. Another user or computer cannot read it and has to enter it again.
|
||||
|
||||
Risks:
|
||||
|
||||
- The library uses the API behind Radioadmin (`search.api.radioadmin.laut.fm`). laut.fm does not publish it for other programs, so it can change or stop working without notice, and the token expires when Radioadmin logs out.
|
||||
- The import downloads the prelisten link that Radioadmin uses. Whether that is the full track or a shorter preview has not been checked against a real station.
|
||||
- laut.fm licenses the station's music for broadcasting on laut.fm. Imported laut.fm tracks are marked with that license and must not be played anywhere else.
|
||||
- Nothing here has been tested against a real laut.fm account. The tests run against a local fake server. If laut.fm expects a different format or login method, the settings show the error but do not adapt.
|
||||
- Nothing here has been tested against a real laut.fm account. The tests run against a local fake server. If laut.fm expects a different format or login method, the Sendeplan page shows the error but does not adapt.
|
||||
- The source connection and the title updates use plain HTTP, like every Icecast source client, so the live password crosses the network unencrypted.
|
||||
- The MP3 encoder comes with Windows. Windows "N" editions lack it until the Media Feature Pack is installed; **Live** then reports the missing encoder.
|
||||
- The MP3 encoder comes with Windows. Windows "N" editions lack it until the Media Feature Pack is installed; going live then reports the missing encoder.
|
||||
- laut.fm wants the ad trigger at least once every half hour. With 0 ad minutes per hour the plan has no ad items and the app never sends it.
|
||||
|
||||
## Known limitations
|
||||
|
||||
- **Waiting for the start**: a plan made with **Plan erstellen** starts at a full hour, so after **Start** the app stays silent until then. **Jetzt starten** avoids the wait.
|
||||
- **Waiting for the start**: a plan with a later start time stays silent after **Jetzt starten** until that time. Pick **Jetzt** to avoid the wait. News times in a **Jetzt** plan shift by however long you wait before starting it.
|
||||
- **Unlimited plans** keep every played item in the timeline, so the list grows by about 20 rows per hour.
|
||||
- **Manual edits** shift every later item, so after moving, removing or resizing an item the news can leave :00 and :30 and the plan can end earlier or later.
|
||||
- **Late items**: if a song plays longer than its stored duration, the following items start late by the same amount. Nothing is cut to catch up; the delay only disappears when a later item ends early.
|
||||
|
||||
@@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Radiosender.Controllers;
|
||||
using Radiosender.Services.Audio;
|
||||
using Radiosender.Services.Library;
|
||||
using Radiosender.Services.Localization;
|
||||
using Radiosender.Services.Providers;
|
||||
using Radiosender.Services.Scheduling;
|
||||
using Radiosender.Services.Settings;
|
||||
@@ -67,8 +68,8 @@ public partial class App : Application
|
||||
{
|
||||
base.OnStartup(e);
|
||||
_services = BuildServices();
|
||||
// Eager: applies settings to generator and audio output before first plan.
|
||||
_services.GetRequiredService<SettingsStore>();
|
||||
// Eager: applies settings to generator and audio output before first plan, language before first window.
|
||||
Loc.SetLanguage(_services.GetRequiredService<SettingsStore>().Current.Language);
|
||||
Wpf.Ui.Appearance.ApplicationThemeManager.ApplySystemTheme();
|
||||
_services.GetRequiredService<MainWindow>().Show();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Net.Http;
|
||||
using NAudio.Wave;
|
||||
using Radiosender.Services.Audio;
|
||||
using Radiosender.Services.Localization;
|
||||
using Radiosender.Services.Settings;
|
||||
using Radiosender.Services.Streaming;
|
||||
|
||||
@@ -43,7 +44,7 @@ public class LiveController
|
||||
return;
|
||||
var settings = _settings.Current;
|
||||
if (!settings.LautFmEnabled)
|
||||
throw new LiveStreamException("laut.fm ist in den Einstellungen ausgeschaltet.");
|
||||
throw new LiveStreamException(Loc.T("Live_Disabled"));
|
||||
var target = IcecastTarget.From(settings);
|
||||
var feed = _output.OpenLiveFeed();
|
||||
IcecastStream stream;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Radiosender.Models;
|
||||
using Radiosender.Services.Audio;
|
||||
using Radiosender.Services.Library;
|
||||
using Radiosender.Services.Localization;
|
||||
using Radiosender.Services.Scheduling;
|
||||
|
||||
namespace Radiosender.Controllers;
|
||||
@@ -18,6 +19,7 @@ public class ScheduleController
|
||||
private readonly Func<DateTime> _now;
|
||||
// Plan edits (UI thread) vs. hourly extension (engine thread).
|
||||
private readonly Lock _planLock = new();
|
||||
private bool _fromNow; // plan starts at its creation moment, not at a set time
|
||||
private DateTime _itemStartedAt;
|
||||
|
||||
public ScheduleController(SongRepository songs, ScheduleGenerator generator, PlaybackEngine engine, Func<DateTime> now)
|
||||
@@ -32,7 +34,7 @@ public class ScheduleController
|
||||
ExtendIfUnlimited();
|
||||
ItemStarted?.Invoke(this, e.Index);
|
||||
};
|
||||
_engine.ItemFailed += (_, e) => ItemFailed?.Invoke(this, $"\"{e.Item.Title}\" übersprungen: {e.Error.Message}");
|
||||
_engine.ItemFailed += (_, e) => ItemFailed?.Invoke(this, Loc.F("Schedule_ItemFailedText", e.Item.Title, e.Error.Message));
|
||||
_engine.Finished += (_, _) => Finished?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
@@ -54,12 +56,6 @@ public class ScheduleController
|
||||
? TimeSpan.FromTicks(Math.Clamp((_now() - _itemStartedAt).Ticks, 0, item.Duration.Ticks))
|
||||
: TimeSpan.Zero;
|
||||
|
||||
public float Volume
|
||||
{
|
||||
get => MusicPlayer.Instance.Volume;
|
||||
set => MusicPlayer.Instance.Volume = value;
|
||||
}
|
||||
|
||||
// hours null = unlimited; start null = next full hour.
|
||||
/// <exception cref="ScheduleException">Library cannot fill the plan.</exception>
|
||||
public IReadOnlyList<ScheduleItem> CreatePlan(int? hours, DateTime? start = null)
|
||||
@@ -79,17 +75,11 @@ public class ScheduleController
|
||||
{
|
||||
Plan = plan;
|
||||
IsUnlimited = hours is null;
|
||||
_fromNow = from <= now;
|
||||
}
|
||||
return plan;
|
||||
}
|
||||
|
||||
/// <exception cref="ScheduleException">Library cannot fill the plan.</exception>
|
||||
public void StartNow(int? hours)
|
||||
{
|
||||
CreatePlan(hours, _now());
|
||||
_engine.Start(Plan);
|
||||
}
|
||||
|
||||
// Engine thread. shortcut: played items stay in Plan (~20/h), trim if broadcasts run for weeks.
|
||||
private void ExtendIfUnlimited()
|
||||
{
|
||||
@@ -112,20 +102,32 @@ public class ScheduleController
|
||||
}
|
||||
catch (ScheduleException ex)
|
||||
{
|
||||
ItemFailed?.Invoke(this, $"Der Plan konnte nicht verlängert werden: {ex.Message}");
|
||||
ItemFailed?.Invoke(this, Loc.F("Schedule_ExtendFailed", ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime? WaitingUntil => CurrentItem is null ? _engine.WaitingUntil : null;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
lock (_planLock)
|
||||
{
|
||||
if (Plan.Count == 0)
|
||||
throw new InvalidOperationException("Zuerst einen Plan erstellen.");
|
||||
if (Plan[^1].Start <= _now())
|
||||
throw new InvalidOperationException("Dieser Plan ist bereits vorbei. Einen neuen erstellen.");
|
||||
throw new InvalidOperationException(Loc.T("Schedule_CreateFirst"));
|
||||
var now = _now();
|
||||
// "Jetzt" plan, first start: shift to now, else the engine skips what began while the user waited.
|
||||
// shortcut: news drift by that wait; regenerate if users wait minutes between create and start.
|
||||
if (_fromNow && Plan[0].Start < now)
|
||||
{
|
||||
var offset = new DateTime(now.Ticks - now.Ticks % TimeSpan.TicksPerSecond, now.Kind) - Plan[0].Start;
|
||||
Plan = [.. Plan.Select(item => item with { Start = item.Start + offset })];
|
||||
}
|
||||
_fromNow = false;
|
||||
if (Plan[^1].Start <= now)
|
||||
throw new InvalidOperationException(Loc.T("Schedule_PlanOver"));
|
||||
_engine.Start(Plan);
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop() => _engine.Stop();
|
||||
|
||||
@@ -159,7 +161,7 @@ public class ScheduleController
|
||||
{
|
||||
var target = index + offset;
|
||||
if (target < 0 || target >= Plan.Count)
|
||||
throw new ScheduleException("Das Element ist bereits am Rand des Plans.");
|
||||
throw new ScheduleException(Loc.T("Schedule_AtEdge"));
|
||||
return Change(Math.Min(index, target), change: items =>
|
||||
{
|
||||
var item = items[index];
|
||||
@@ -168,6 +170,23 @@ public class ScheduleController
|
||||
});
|
||||
}
|
||||
|
||||
// index == Plan.Count appends. Song: songId required, its length is used.
|
||||
/// <exception cref="ScheduleException">No plan, position on air or over, song missing, or length not positive.</exception>
|
||||
public IReadOnlyList<ScheduleItem> Insert(int index, ScheduleItemKind kind, string title, TimeSpan duration, long? songId = null)
|
||||
{
|
||||
Song? song = null;
|
||||
if (kind == ScheduleItemKind.Song)
|
||||
{
|
||||
song = (songId is { } id ? _songs.GetById(id) : null) ?? throw new ScheduleException(Loc.T("Schedule_SongGone"));
|
||||
title = string.IsNullOrWhiteSpace(song.Artist) ? song.Title : $"{song.Artist} - {song.Title}";
|
||||
duration = song.Duration;
|
||||
}
|
||||
if (duration <= TimeSpan.Zero)
|
||||
throw new ScheduleException(Loc.T("Schedule_LengthPositive"));
|
||||
var item = new ScheduleItem(kind, title.Trim(), default, duration, song);
|
||||
return Change(index, change: items => items.Insert(index, item), appendAllowed: true);
|
||||
}
|
||||
|
||||
/// <exception cref="ScheduleException">Item on air or over.</exception>
|
||||
public IReadOnlyList<ScheduleItem> Remove(int index) => Change(index, change: items => items.RemoveAt(index));
|
||||
|
||||
@@ -176,7 +195,7 @@ public class ScheduleController
|
||||
{
|
||||
var index = CurrentIndex;
|
||||
if (CurrentItem is null)
|
||||
throw new ScheduleException("Es ist nichts auf Sendung.");
|
||||
throw new ScheduleException(Loc.T("Schedule_NothingOnAirError"));
|
||||
var now = _now();
|
||||
// Whole seconds: next start not in the future.
|
||||
var end = new DateTime(now.Ticks - now.Ticks % TimeSpan.TicksPerSecond, now.Kind);
|
||||
@@ -192,29 +211,29 @@ public class ScheduleController
|
||||
{
|
||||
var item = items[index];
|
||||
if (item.Kind == ScheduleItemKind.Song)
|
||||
throw new ScheduleException("Songs werden in der Bibliothek bearbeitet.");
|
||||
throw new ScheduleException(Loc.T("Schedule_SongsEditInLibrary"));
|
||||
if (duration != item.Duration && item.Kind == ScheduleItemKind.Ad)
|
||||
throw new ScheduleException("Nur Nachrichten und Moderation können ihre Länge ändern.");
|
||||
throw new ScheduleException(Loc.T("Schedule_OnlyNewsModeratorLength"));
|
||||
if (duration <= TimeSpan.Zero)
|
||||
throw new ScheduleException("Die Länge muss größer als null sein.");
|
||||
throw new ScheduleException(Loc.T("Schedule_LengthPositive"));
|
||||
items[index] = item with { Title = title.Trim(), Duration = duration };
|
||||
});
|
||||
|
||||
// Ripple re-time from firstChanged; news may leave :00/:30 (intended).
|
||||
private IReadOnlyList<ScheduleItem> Change(int firstChanged, Action<List<ScheduleItem>> change, bool currentAllowed = false)
|
||||
private IReadOnlyList<ScheduleItem> Change(int firstChanged, Action<List<ScheduleItem>> change, bool currentAllowed = false, bool appendAllowed = false)
|
||||
{
|
||||
lock (_planLock)
|
||||
{
|
||||
if (firstChanged < 0 || firstChanged >= Plan.Count)
|
||||
throw new ScheduleException("Ein Element im Plan auswählen.");
|
||||
if (Plan.Count == 0)
|
||||
throw new ScheduleException(Loc.T("Schedule_CreateFirst"));
|
||||
if (firstChanged < 0 || firstChanged > Plan.Count || (firstChanged == Plan.Count && !appendAllowed))
|
||||
throw new ScheduleException(Loc.T("Schedule_SelectItem"));
|
||||
var onAir = IsPlaying && firstChanged == CurrentIndex;
|
||||
if (IsPlaying && (firstChanged < CurrentIndex || (onAir && !currentAllowed)))
|
||||
throw new ScheduleException(onAir
|
||||
? "Dieses Element ist auf Sendung. Es kann bearbeitet oder beendet, aber nicht verschoben oder entfernt werden."
|
||||
: "Dieses Element ist bereits vorbei. Ein späteres wählen.");
|
||||
throw new ScheduleException(Loc.T(onAir ? "Schedule_OnAirLocked" : "Schedule_ItemOver"));
|
||||
|
||||
List<ScheduleItem> items = [.. Plan];
|
||||
var start = items[firstChanged].Start;
|
||||
var start = firstChanged < items.Count ? items[firstChanged].Start : items[^1].End;
|
||||
change(items);
|
||||
for (var i = firstChanged; i < items.Count; i++)
|
||||
{
|
||||
@@ -223,7 +242,7 @@ public class ScheduleController
|
||||
}
|
||||
|
||||
if (IsPlaying && !(onAir ? _engine.ReplaceCurrent(items, firstChanged) : _engine.ReplaceUpcoming(items, firstChanged)))
|
||||
throw new ScheduleException("Die Sendung ist inzwischen weitergelaufen. Erneut versuchen.");
|
||||
throw new ScheduleException(Loc.T("Schedule_RunMovedOn"));
|
||||
Plan = items;
|
||||
return items;
|
||||
}
|
||||
@@ -238,16 +257,16 @@ public class ScheduleController
|
||||
lock (_planLock)
|
||||
{
|
||||
if (Plan.Count == 0)
|
||||
throw new ScheduleException("Zuerst einen Plan erstellen.");
|
||||
throw new ScheduleException(Loc.T("Schedule_CreateFirst"));
|
||||
if (index < 0 || index >= Plan.Count)
|
||||
throw new ScheduleException("Ein Element im Plan auswählen.");
|
||||
throw new ScheduleException(Loc.T("Schedule_SelectItem"));
|
||||
if (IsPlaying && index <= CurrentIndex)
|
||||
throw new ScheduleException("Dieses Element ist bereits auf Sendung oder vorbei. Ein späteres wählen.");
|
||||
var song = _songs.GetById(songId) ?? throw new ScheduleException("Der Song ist nicht mehr in der Bibliothek.");
|
||||
throw new ScheduleException(Loc.T("Schedule_SwapOnAirOrOver"));
|
||||
var song = _songs.GetById(songId) ?? throw new ScheduleException(Loc.T("Schedule_SongGone"));
|
||||
|
||||
var plan = _generator.Replace(Plan, index, song, _songs.GetAll());
|
||||
if (IsPlaying && !_engine.ReplaceUpcoming(plan, index))
|
||||
throw new ScheduleException("Dieses Element ist inzwischen auf Sendung gegangen. Ein späteres wählen.");
|
||||
throw new ScheduleException(Loc.T("Schedule_SwapWentOnAir"));
|
||||
Plan = plan;
|
||||
return plan;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
using Radiosender.Services.Localization;
|
||||
|
||||
namespace Radiosender.Models;
|
||||
|
||||
public record ScheduleItem(ScheduleItemKind Kind, string Title, DateTime Start, TimeSpan Duration, Song? Song = null)
|
||||
{
|
||||
public DateTime End => Start + Duration;
|
||||
|
||||
public string KindName => Kind switch
|
||||
{
|
||||
ScheduleItemKind.News => "Nachrichten",
|
||||
ScheduleItemKind.Ad => "Werbung",
|
||||
ScheduleItemKind.Moderator => "Moderation",
|
||||
_ => "Song",
|
||||
};
|
||||
public string KindName => Loc.T($"Kind_{Kind}");
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using NAudio.Wave;
|
||||
using Radiosender.Services.Localization;
|
||||
|
||||
namespace Radiosender.Services.Audio;
|
||||
|
||||
@@ -21,7 +22,7 @@ public sealed class Microphone(ProgramOutput output) : IDisposable
|
||||
if (_capture is not null)
|
||||
return;
|
||||
if (WaveIn.DeviceCount == 0)
|
||||
throw new InvalidOperationException("Es wurde kein Mikrofon gefunden.");
|
||||
throw new InvalidOperationException(Loc.T("Audio_NoMicrophone"));
|
||||
|
||||
var capture = new WaveIn { WaveFormat = new WaveFormat(44100, 16, 1), BufferMilliseconds = 30 };
|
||||
// Short dropping buffer: speech must not drift further behind.
|
||||
@@ -35,7 +36,7 @@ public sealed class Microphone(ProgramOutput output) : IDisposable
|
||||
catch (Exception e) when (e is NAudio.MmException or NotSupportedException)
|
||||
{
|
||||
capture.Dispose();
|
||||
throw new InvalidOperationException($"Das Mikrofon konnte nicht eingeschaltet werden: {e.Message}", e);
|
||||
throw new InvalidOperationException(Loc.F("Audio_MicrophoneFailed", e.Message), e);
|
||||
}
|
||||
_capture = capture;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.IO;
|
||||
using NAudio.Wave;
|
||||
using Radiosender.Services.Localization;
|
||||
|
||||
namespace Radiosender.Services.Audio;
|
||||
|
||||
@@ -12,7 +13,6 @@ public sealed class MusicPlayer : IAudioPlayer
|
||||
private readonly Lock _lock = new();
|
||||
private AudioFileReader? _reader;
|
||||
private ISampleProvider? _input;
|
||||
private float _volume = 1f;
|
||||
|
||||
private MusicPlayer()
|
||||
{
|
||||
@@ -36,21 +36,6 @@ public sealed class MusicPlayer : IAudioPlayer
|
||||
get { lock (_lock) return _reader?.TotalTime ?? TimeSpan.Zero; }
|
||||
}
|
||||
|
||||
public float Volume
|
||||
{
|
||||
get { lock (_lock) return _volume; }
|
||||
set
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(value, 0f);
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThan(value, 1f);
|
||||
lock (_lock)
|
||||
{
|
||||
_volume = value;
|
||||
_reader?.Volume = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(string filePath)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(filePath);
|
||||
@@ -60,17 +45,17 @@ public sealed class MusicPlayer : IAudioPlayer
|
||||
Release();
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
throw new FileNotFoundException($"Audiodatei nicht gefunden: {filePath}", filePath);
|
||||
throw new FileNotFoundException(Loc.F("Audio_FileNotFound", filePath), filePath);
|
||||
|
||||
try
|
||||
{
|
||||
_reader = new AudioFileReader(filePath) { Volume = _volume };
|
||||
_reader = new AudioFileReader(filePath);
|
||||
_input = _output.Add(_reader, AudioSource.Music);
|
||||
}
|
||||
catch (Exception ex) when (ex is not (OutOfMemoryException or NAudio.MmException))
|
||||
{
|
||||
Release();
|
||||
throw new InvalidDataException($"Audiodatei kann nicht gelesen werden: {filePath}", ex);
|
||||
throw new InvalidDataException(Loc.F("Audio_FileUnreadable", filePath), ex);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<data name="Audio_FileUnreadable" xml:space="preserve"><value>Audio file cannot be read: {0}</value></data>
|
||||
<data name="Audio_MicrophoneFailed" xml:space="preserve"><value>The microphone could not be turned on: {0}</value></data>
|
||||
<data name="Audio_NoMicrophone" xml:space="preserve"><value>No microphone was found.</value></data>
|
||||
<data name="Error_InvalidInput" xml:space="preserve"><value>Invalid input</value></data>
|
||||
<data name="Import_AllLicenses" xml:space="preserve"><value>All licenses</value></data>
|
||||
<data name="Import_ChooseFiles" xml:space="preserve"><value>Choose files...</value></data>
|
||||
<data name="Import_ColCreator" xml:space="preserve"><value>Creator</value></data>
|
||||
@@ -120,7 +121,7 @@
|
||||
<data name="Schedule_EndBroadcast" xml:space="preserve"><value>End broadcast</value></data>
|
||||
<data name="Schedule_EndBroadcastFailed" xml:space="preserve"><value>The broadcast could not be ended</value></data>
|
||||
<data name="Schedule_EndItemFailed" xml:space="preserve"><value>The item could not be ended</value></data>
|
||||
<data name="Schedule_EndNow" xml:space="preserve"><value>End now</value></data>
|
||||
<data name="Schedule_EndNow" xml:space="preserve"><value>Stop current item</value></data>
|
||||
<data name="Schedule_EndNowTip" xml:space="preserve"><value>Ends the current item right away; the next one starts.</value></data>
|
||||
<data name="Schedule_ExtendFailed" xml:space="preserve"><value>The schedule could not be extended: {0}</value></data>
|
||||
<data name="Schedule_Finished" xml:space="preserve"><value>Broadcast ended</value></data>
|
||||
@@ -185,7 +186,6 @@
|
||||
<data name="Schedule_StartTimeTip" xml:space="preserve"><value>“Now”, a full hour, or your own time like 14:30</value></data>
|
||||
<data name="Schedule_StartUnclear" xml:space="preserve"><value>Choose “Now” or a time, or type one, for example 14:30.</value></data>
|
||||
<data name="Schedule_StartUnclearTitle" xml:space="preserve"><value>Start time unclear</value></data>
|
||||
<data name="Schedule_Stop" xml:space="preserve"><value>Stop</value></data>
|
||||
<data name="Schedule_StopLiveTip" xml:space="preserve"><value>Stops playback and the live stream to laut.fm.</value></data>
|
||||
<data name="Schedule_StopTip" xml:space="preserve"><value>Stops playback.</value></data>
|
||||
<data name="Schedule_Swap" xml:space="preserve"><value>Replace selection</value></data>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<data name="Audio_FileUnreadable" xml:space="preserve"><value>Audiodatei kann nicht gelesen werden: {0}</value></data>
|
||||
<data name="Audio_MicrophoneFailed" xml:space="preserve"><value>Das Mikrofon konnte nicht eingeschaltet werden: {0}</value></data>
|
||||
<data name="Audio_NoMicrophone" xml:space="preserve"><value>Es wurde kein Mikrofon gefunden.</value></data>
|
||||
<data name="Error_InvalidInput" xml:space="preserve"><value>Ungültige Eingabe</value></data>
|
||||
<data name="Import_AllLicenses" xml:space="preserve"><value>Alle Lizenzen</value></data>
|
||||
<data name="Import_ChooseFiles" xml:space="preserve"><value>Dateien auswählen...</value></data>
|
||||
<data name="Import_ColCreator" xml:space="preserve"><value>Urheber</value></data>
|
||||
@@ -120,7 +121,7 @@
|
||||
<data name="Schedule_EndBroadcast" xml:space="preserve"><value>Sendung beenden</value></data>
|
||||
<data name="Schedule_EndBroadcastFailed" xml:space="preserve"><value>Die Sendung konnte nicht beendet werden</value></data>
|
||||
<data name="Schedule_EndItemFailed" xml:space="preserve"><value>Das Element konnte nicht beendet werden</value></data>
|
||||
<data name="Schedule_EndNow" xml:space="preserve"><value>Jetzt beenden</value></data>
|
||||
<data name="Schedule_EndNow" xml:space="preserve"><value>Aktuelles Element stoppen</value></data>
|
||||
<data name="Schedule_EndNowTip" xml:space="preserve"><value>Beendet das laufende Element sofort; das nächste startet.</value></data>
|
||||
<data name="Schedule_ExtendFailed" xml:space="preserve"><value>Der Plan konnte nicht verlängert werden: {0}</value></data>
|
||||
<data name="Schedule_Finished" xml:space="preserve"><value>Sendung beendet</value></data>
|
||||
@@ -185,7 +186,6 @@
|
||||
<data name="Schedule_StartTimeTip" xml:space="preserve"><value>„Jetzt“, eine volle Stunde oder eine eigene Uhrzeit wie 14:30</value></data>
|
||||
<data name="Schedule_StartUnclear" xml:space="preserve"><value>Wähle „Jetzt“ oder eine Uhrzeit, oder tippe eine ein, zum Beispiel 14:30.</value></data>
|
||||
<data name="Schedule_StartUnclearTitle" xml:space="preserve"><value>Startzeit unklar</value></data>
|
||||
<data name="Schedule_Stop" xml:space="preserve"><value>Stopp</value></data>
|
||||
<data name="Schedule_StopLiveTip" xml:space="preserve"><value>Stoppt die Wiedergabe und den Livestream zu laut.fm.</value></data>
|
||||
<data name="Schedule_StopTip" xml:space="preserve"><value>Stoppt die Wiedergabe.</value></data>
|
||||
<data name="Schedule_Swap" xml:space="preserve"><value>Auswahl ersetzen</value></data>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Radiosender.Models;
|
||||
using Radiosender.Services.Audio;
|
||||
using Radiosender.Services.Localization;
|
||||
|
||||
namespace Radiosender.Services.Scheduling;
|
||||
|
||||
@@ -203,7 +204,7 @@ public sealed class PlaybackEngine(IAudioPlayer player, Func<TimeSpan, Cancellat
|
||||
await timeout.CancelAsync();
|
||||
token.ThrowIfCancellationRequested();
|
||||
if (done == stuck)
|
||||
ItemFailed?.Invoke(this, (item, new TimeoutException($"Der Song wurde nicht rechtzeitig fertig: {item.Title}")));
|
||||
ItemFailed?.Invoke(this, (item, new TimeoutException(Loc.F("Scheduling_SongTimeout", item.Title))));
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Radiosender.Models;
|
||||
using Radiosender.Services.Localization;
|
||||
|
||||
namespace Radiosender.Services.Scheduling;
|
||||
|
||||
@@ -25,7 +26,7 @@ public class ScheduleGenerator(ScheduleOptions options, Random random)
|
||||
|
||||
List<Song> playable = [.. songs.Where(s => s.Duration > TimeSpan.Zero)];
|
||||
if (playable.Count == 0)
|
||||
throw new ScheduleException("Die Bibliothek enthält keine Songs zum Planen.");
|
||||
throw new ScheduleException(Loc.T("Scheduling_NoSongs"));
|
||||
|
||||
List<ScheduleItem> items = [];
|
||||
var firstNews = new DateTime((start.Ticks + HalfHour.Ticks - 1) / HalfHour.Ticks * HalfHour.Ticks, start.Kind);
|
||||
@@ -78,7 +79,7 @@ public class ScheduleGenerator(ScheduleOptions options, Random random)
|
||||
var (picked, gap) = PickBest(options, length, target, songs);
|
||||
if (picked.Count == 0 && target < length)
|
||||
throw new ScheduleException(
|
||||
$"Keine Song-Kombination füllt den Abschnitt ab {slotStart:HH:mm} so, dass der letzte Song pünktlich endet. Mehr Songs hinzufügen, vor allem kürzere.");
|
||||
Loc.F("Scheduling_NoCombination", slotStart));
|
||||
|
||||
var (ads, moderator) = Split(options, gap, adTarget, moderatorTarget);
|
||||
return Arrange(options, slotStart, picked, ads, moderator, keepFirstSongFirst: false);
|
||||
@@ -91,9 +92,9 @@ public class ScheduleGenerator(ScheduleOptions options, Random random)
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(index);
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, plan.Count);
|
||||
if (plan[index].Kind == ScheduleItemKind.News)
|
||||
throw new ScheduleException("Nachrichten können nicht ersetzt werden.");
|
||||
throw new ScheduleException(Loc.T("Schedule_NewsNoReplace"));
|
||||
if (requested.Duration <= TimeSpan.Zero)
|
||||
throw new ScheduleException("Der gewünschte Song hat keine Dauer.");
|
||||
throw new ScheduleException(Loc.T("Scheduling_NoDuration"));
|
||||
|
||||
var slotStartIndex = LastIndexOf(plan, index, ScheduleItemKind.News); // -1 if the plan does not start with news
|
||||
var nextNewsIndex = IndexOf(plan, index, ScheduleItemKind.News);
|
||||
@@ -103,7 +104,7 @@ public class ScheduleGenerator(ScheduleOptions options, Random random)
|
||||
|
||||
if (requested.Duration > length)
|
||||
throw new ScheduleException(
|
||||
$"\"{requested.Title}\" ({requested.Duration:m\\:ss}) passt nicht vor die Nachrichten um {slotEnd:HH:mm}; es sind nur noch {length:m\\:ss} übrig. Ein früheres Element wählen.");
|
||||
Loc.F("Scheduling_DoesNotFit", requested.Title, requested.Duration, slotEnd, length));
|
||||
|
||||
// Ads/talk already in this slot count against its targets.
|
||||
var options = Options;
|
||||
@@ -193,7 +194,7 @@ public class ScheduleGenerator(ScheduleOptions options, Random random)
|
||||
var pairs = Math.Max(adPieces.Count, moderatorPieces.Count);
|
||||
|
||||
// Hot swap: requested song stays first, breaks start after it.
|
||||
var firstBreakSong = keepFirstSongFirst && songs.Count > 1 ? 1 : 0;
|
||||
var firstBreakSong = keepFirstSongFirst ? 1 : 0; // also when it is the only song: breaks then follow it
|
||||
var breakSlots = Math.Max(songs.Count - firstBreakSong, 1);
|
||||
var breaks = Math.Min(pairs, breakSlots);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Radiosender.Services.Localization;
|
||||
using Radiosender.Services.Scheduling;
|
||||
|
||||
namespace Radiosender.Services.Settings;
|
||||
@@ -14,6 +15,8 @@ public record AppSettings
|
||||
|
||||
private static readonly JsonSerializerOptions WriteOptions = new() { WriteIndented = true };
|
||||
|
||||
public string Language { get; init; } = Loc.German;
|
||||
|
||||
public bool NewsAlert { get; init; } = true;
|
||||
|
||||
public int NewsAlertSeconds { get; init; } = 30;
|
||||
@@ -37,8 +40,6 @@ public record AppSettings
|
||||
|
||||
public bool LautFmEnabled { get; init; }
|
||||
|
||||
public string LautFmStationId { get; init; } = "";
|
||||
|
||||
public string LautFmHost { get; init; } = "";
|
||||
|
||||
public int LautFmPort { get; init; } = 8080;
|
||||
@@ -47,20 +48,14 @@ public record AppSettings
|
||||
|
||||
public string LautFmUser { get; init; } = "source";
|
||||
|
||||
// Secrets: plain in memory, DPAPI-encrypted in the file via the Protected* properties.
|
||||
// Secret: plain in memory, DPAPI-encrypted in the file via ProtectedLautFmPassword.
|
||||
[JsonIgnore]
|
||||
public string LautFmPassword { get; init; } = "";
|
||||
|
||||
[JsonIgnore]
|
||||
public string LautFmToken { get; init; } = "";
|
||||
|
||||
[JsonInclude, JsonPropertyName("LautFmPassword")]
|
||||
private string? ProtectedLautFmPassword { get => Protect(LautFmPassword); init => LautFmPassword = Unprotect(value); }
|
||||
|
||||
[JsonInclude, JsonPropertyName("LautFmToken")]
|
||||
private string? ProtectedLautFmToken { get => Protect(LautFmToken); init => LautFmToken = Unprotect(value); }
|
||||
|
||||
// Record ToString would leak secrets into logs/debugger.
|
||||
// Record ToString would leak the password into logs/debugger.
|
||||
public override string ToString() => nameof(AppSettings);
|
||||
|
||||
public static string DefaultPath { get; } = Path.Combine(
|
||||
@@ -68,24 +63,24 @@ public record AppSettings
|
||||
|
||||
public string? Validate()
|
||||
{
|
||||
if (!Loc.IsSupported(Language))
|
||||
return Loc.T("Settings_LanguageUnsupported");
|
||||
if (NewsAlertSeconds is < MinAlertSeconds or > MaxAlertSeconds || ModeratorAlertSeconds is < MinAlertSeconds or > MaxAlertSeconds)
|
||||
return $"Die Hinweiszeit muss zwischen {MinAlertSeconds} und {MaxAlertSeconds} Sekunden liegen.";
|
||||
return Loc.F("Settings_AlertSecondsRange", MinAlertSeconds, MaxAlertSeconds);
|
||||
if (NewsMinutesPerHour < 2)
|
||||
return "Nachrichten brauchen mindestens 2 Minuten pro Stunde.";
|
||||
return Loc.T("Settings_NewsMinMinutes");
|
||||
if (ModeratorMinutesPerHour < 0 || AdMinutesPerHour < 0)
|
||||
return "Minuten pro Stunde dürfen nicht negativ sein.";
|
||||
return Loc.T("Settings_MinutesNegative");
|
||||
if (NewsMinutesPerHour + ModeratorMinutesPerHour + AdMinutesPerHour > 60)
|
||||
return "Nachrichten, Moderation und Werbung dürfen zusammen höchstens 60 Minuten pro Stunde dauern.";
|
||||
return Loc.T("Settings_MinutesTotal");
|
||||
if (LautFmEnabled)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(LautFmHost) || Uri.CheckHostName(LautFmHost.Trim()) == UriHostNameType.Unknown)
|
||||
return "Für laut.fm fehlt ein gültiger Server.";
|
||||
return Loc.T("Settings_LautFmHostMissing");
|
||||
if (LautFmPort is < 1 or > 65535)
|
||||
return "Der laut.fm-Port muss zwischen 1 und 65535 liegen.";
|
||||
return Loc.T("Settings_LautFmPortRange");
|
||||
if (string.IsNullOrWhiteSpace(LautFmMount))
|
||||
return "Für laut.fm fehlt der Mountpoint.";
|
||||
if (LautFmToken.Length > 0 && string.IsNullOrWhiteSpace(LautFmStationId))
|
||||
return "Für die laut.fm-Bibliothek fehlt die Stations-ID.";
|
||||
return Loc.T("Settings_LautFmMountMissing");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using NAudio.MediaFoundation;
|
||||
using NAudio.Wave;
|
||||
using Radiosender.Services.Localization;
|
||||
|
||||
namespace Radiosender.Services.Streaming;
|
||||
|
||||
@@ -33,7 +34,7 @@ public sealed class IcecastStream : IDisposable
|
||||
// Security: values go into request line/headers; a line break would inject headers.
|
||||
if (new[] { target.Host, target.Path, target.User }.Any(value => value.Any(c => char.IsWhiteSpace(c) || char.IsControl(c)))
|
||||
|| target.User.Contains(':'))
|
||||
throw new LiveStreamException("Server, Mountpoint oder Benutzer enthalten ungültige Zeichen.");
|
||||
throw new LiveStreamException(Loc.T("Stream_InvalidChars"));
|
||||
|
||||
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
|
||||
timeout.CancelAfter(ConnectTimeout);
|
||||
@@ -58,10 +59,10 @@ public sealed class IcecastStream : IDisposable
|
||||
{
|
||||
throw new LiveStreamException(status switch
|
||||
{
|
||||
401 => "laut.fm hat die Anmeldung abgelehnt: Benutzer oder Passwort stimmen nicht.",
|
||||
403 => "laut.fm nimmt gerade keinen Livestream an: Der Mountpoint ist belegt oder nicht freigeschaltet.",
|
||||
404 => "Diesen Mountpoint gibt es auf dem Server nicht.",
|
||||
_ => $"Der Server hat den Livestream abgelehnt (HTTP {status}).",
|
||||
401 => Loc.T("Stream_LoginRefused"),
|
||||
403 => Loc.T("Stream_MountBusy"),
|
||||
404 => Loc.T("Stream_MountMissing"),
|
||||
_ => Loc.F("Stream_Rejected", status),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -76,8 +77,8 @@ public sealed class IcecastStream : IDisposable
|
||||
throw;
|
||||
throw ex switch
|
||||
{
|
||||
OperationCanceledException => new LiveStreamException("Der laut.fm-Server antwortet nicht.", ex),
|
||||
SocketException or IOException => new LiveStreamException($"Keine Verbindung zum laut.fm-Server: {ex.Message}", ex),
|
||||
OperationCanceledException => new LiveStreamException(Loc.T("Stream_NoResponse"), ex),
|
||||
SocketException or IOException => new LiveStreamException(Loc.F("Stream_NoConnection", ex.Message), ex),
|
||||
_ => ex,
|
||||
};
|
||||
}
|
||||
@@ -97,11 +98,11 @@ public sealed class IcecastStream : IDisposable
|
||||
{
|
||||
using var response = await http.SendAsync(request, cancellationToken);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
throw new LiveStreamException($"laut.fm hat den Titel nicht angenommen (HTTP {(int)response.StatusCode}).");
|
||||
throw new LiveStreamException(Loc.F("Stream_TitleRejected", (int)response.StatusCode));
|
||||
}
|
||||
catch (Exception ex) when (ex is HttpRequestException or TaskCanceledException && !cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
throw new LiveStreamException($"Der Titel konnte nicht an laut.fm gesendet werden: {ex.Message}", ex);
|
||||
throw new LiveStreamException(Loc.F("Stream_TitleFailed", ex.Message), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,17 +123,17 @@ public sealed class IcecastStream : IDisposable
|
||||
MediaFoundationApi.Startup();
|
||||
var pcm = _reader.ToSampleProvider().ToWaveProvider16();
|
||||
var mediaType = MediaFoundationEncoder.SelectMediaType(AudioSubtypes.MFAudioFormat_MP3, pcm.WaveFormat, Bitrate)
|
||||
?? throw new LiveStreamException("Windows hat keinen MP3-Encoder.");
|
||||
?? throw new LiveStreamException(Loc.T("Stream_NoEncoder"));
|
||||
using var encoder = new MediaFoundationEncoder(mediaType);
|
||||
encoder.Encode(_client.GetStream(), pcm, TranscodeContainerTypes.MFTranscodeContainerType_MP3);
|
||||
if (!_stopping)
|
||||
Failed?.Invoke(this, "Der Livestream wurde unerwartet beendet.");
|
||||
Failed?.Invoke(this, Loc.T("Stream_EndedUnexpectedly"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Stopping: socket closed under the encoder is expected.
|
||||
if (!_stopping)
|
||||
Failed?.Invoke(this, ex is LiveStreamException ? ex.Message : $"Verbindung zu laut.fm verloren: {ex.Message}");
|
||||
Failed?.Invoke(this, ex is LiveStreamException ? ex.Message : Loc.F("Stream_ConnectionLost", ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,13 +145,13 @@ public sealed class IcecastStream : IDisposable
|
||||
{
|
||||
var read = await network.ReadAsync(buffer, cancellationToken);
|
||||
if (read == 0 || header.Length > 8192)
|
||||
throw new LiveStreamException("Der Server hat die Verbindung ohne gültige Antwort beendet.");
|
||||
throw new LiveStreamException(Loc.T("Stream_NoValidReply"));
|
||||
header.Append(Encoding.ASCII.GetString(buffer, 0, read));
|
||||
}
|
||||
var parts = header.ToString().Split(' ', 3);
|
||||
return parts.Length >= 2 && int.TryParse(parts[1], out var status)
|
||||
? status
|
||||
: throw new LiveStreamException("Der Server hat ungültig geantwortet.");
|
||||
: throw new LiveStreamException(Loc.T("Stream_InvalidReply"));
|
||||
}
|
||||
|
||||
// Empty feed: wait instead of ending, so the encoder runs in real time.
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Windows;
|
||||
using Radiosender.Services.Localization;
|
||||
using MessageBox = Wpf.Ui.Controls.MessageBox;
|
||||
|
||||
namespace Radiosender.Views;
|
||||
|
||||
// Errors as a modal popup, so they cannot be missed like an InfoBar at the top of a long page.
|
||||
public static class ErrorPopup
|
||||
{
|
||||
public static void Show(DependencyObject source, string title, string message) =>
|
||||
_ = new MessageBox
|
||||
{
|
||||
Title = title,
|
||||
Content = message,
|
||||
CloseButtonText = Loc.T("Main_Ok"),
|
||||
Owner = Window.GetWindow(source) is { IsLoaded: true } owner ? owner : null,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen,
|
||||
}.ShowDialogAsync();
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
xmlns:pages="clr-namespace:Radiosender.Views.Pages"
|
||||
xmlns:l="clr-namespace:Radiosender.Views"
|
||||
Title="Radiosender"
|
||||
Width="1100" Height="700"
|
||||
MinWidth="800" MinHeight="500"
|
||||
@@ -22,18 +23,18 @@
|
||||
ScrollViewer.CanContentScroll="False" and let their lists scroll themselves. -->
|
||||
<ui:NavigationView x:Name="RootNavigation" Grid.Row="1" IsBackButtonVisible="Collapsed">
|
||||
<ui:NavigationView.MenuItems>
|
||||
<ui:NavigationViewItem Content="Sendeplan"
|
||||
<ui:NavigationViewItem Content="{l:Tr Main_NavSchedule}"
|
||||
Icon="{ui:SymbolIcon CalendarLtr24}"
|
||||
TargetPageType="{x:Type pages:SchedulePage}" />
|
||||
<ui:NavigationViewItem Content="Bibliothek"
|
||||
<ui:NavigationViewItem Content="{l:Tr Main_NavLibrary}"
|
||||
Icon="{ui:SymbolIcon MusicNote224}"
|
||||
TargetPageType="{x:Type pages:LibraryPage}" />
|
||||
<ui:NavigationViewItem Content="Import"
|
||||
<ui:NavigationViewItem Content="{l:Tr Main_NavImport}"
|
||||
Icon="{ui:SymbolIcon ArrowDownload24}"
|
||||
TargetPageType="{x:Type pages:ImportPage}" />
|
||||
</ui:NavigationView.MenuItems>
|
||||
<ui:NavigationView.FooterMenuItems>
|
||||
<ui:NavigationViewItem Content="Einstellungen"
|
||||
<ui:NavigationViewItem Content="{l:Tr Main_NavSettings}"
|
||||
Icon="{ui:SymbolIcon Settings24}"
|
||||
TargetPageType="{x:Type pages:SettingsPage}" />
|
||||
</ui:NavigationView.FooterMenuItems>
|
||||
|
||||
@@ -3,6 +3,7 @@ using NAudio.Wave;
|
||||
using NAudio.Wave.SampleProviders;
|
||||
using Radiosender.Controllers;
|
||||
using Radiosender.Models;
|
||||
using Radiosender.Services.Localization;
|
||||
using Radiosender.Services.Settings;
|
||||
using Radiosender.Views.Pages;
|
||||
using Wpf.Ui.Controls;
|
||||
@@ -42,9 +43,9 @@ public partial class MainWindow : FluentWindow
|
||||
PlayBing();
|
||||
_ = new Wpf.Ui.Controls.MessageBox
|
||||
{
|
||||
Title = "Gleich bist du dran.",
|
||||
Content = item.Title.Length > 0 ? $"{what} um {item.Start:HH:mm:ss}: {item.Title}" : $"{what} um {item.Start:HH:mm:ss}",
|
||||
CloseButtonText = "OK",
|
||||
Title = Loc.T("Main_ReminderTitle"),
|
||||
Content = item.Title.Length > 0 ? Loc.F("Main_ReminderTextTitled", what, item.Start, item.Title) : Loc.F("Main_ReminderText", what, item.Start),
|
||||
CloseButtonText = Loc.T("Main_Ok"),
|
||||
WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen,
|
||||
Topmost = true,
|
||||
}.ShowDialogAsync();
|
||||
|
||||
@@ -322,6 +322,12 @@ public partial class ImportPage : Page
|
||||
|
||||
private void Show(InfoBarSeverity severity, string title, string message)
|
||||
{
|
||||
if (severity == InfoBarSeverity.Error)
|
||||
{
|
||||
Message.IsOpen = false;
|
||||
ErrorPopup.Show(this, title, message);
|
||||
return;
|
||||
}
|
||||
Message.Severity = severity;
|
||||
Message.Title = title;
|
||||
Message.Message = message;
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
Title="Bibliothek"
|
||||
xmlns:l="clr-namespace:Radiosender.Views"
|
||||
Title="{l:Tr Library_Title}"
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
ScrollViewer.CanContentScroll="False"
|
||||
Loaded="OnLoaded">
|
||||
Loaded="OnLoaded"
|
||||
Unloaded="OnUnloaded">
|
||||
<Grid Margin="24">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
@@ -17,20 +19,20 @@
|
||||
<ui:Button x:Name="DeleteButton"
|
||||
DockPanel.Dock="Right"
|
||||
Margin="8,0,0,0"
|
||||
Content="Löschen"
|
||||
Content="{l:Tr Library_Delete}"
|
||||
Icon="{ui:SymbolIcon Delete24}"
|
||||
IsEnabled="False"
|
||||
Click="OnDelete" />
|
||||
<ui:Button x:Name="EditButton"
|
||||
DockPanel.Dock="Right"
|
||||
Margin="8,0,0,0"
|
||||
Content="Bearbeiten"
|
||||
Content="{l:Tr Library_Edit}"
|
||||
Icon="{ui:SymbolIcon Edit24}"
|
||||
IsEnabled="False"
|
||||
Click="OnEdit" />
|
||||
<ui:TextBox x:Name="SearchBox"
|
||||
AutomationProperties.Name="Songs suchen"
|
||||
PlaceholderText="Titel oder Interpret suchen"
|
||||
AutomationProperties.Name="{l:Tr Library_SearchName}"
|
||||
PlaceholderText="{l:Tr Library_SearchPlaceholder}"
|
||||
Icon="{ui:SymbolIcon Search24}"
|
||||
TextChanged="OnSearchChanged" />
|
||||
</DockPanel>
|
||||
@@ -38,15 +40,15 @@
|
||||
<ui:ListView x:Name="SongList"
|
||||
Grid.Row="2"
|
||||
SelectionMode="Single"
|
||||
AutomationProperties.Name="Songs"
|
||||
AutomationProperties.Name="{l:Tr Library_ListName}"
|
||||
SelectionChanged="OnSelectionChanged"
|
||||
MouseDoubleClick="OnEdit"
|
||||
KeyDown="OnListKeyDown">
|
||||
<ui:ListView.View>
|
||||
<ui:GridView>
|
||||
<ui:GridViewColumn Width="220" Header="Titel" DisplayMemberBinding="{Binding Title}" />
|
||||
<ui:GridViewColumn Width="160" Header="Interpret" DisplayMemberBinding="{Binding Artist}" />
|
||||
<ui:GridViewColumn Width="80" Header="Dauer">
|
||||
<ui:GridViewColumn Width="220" Header="{l:Tr Song_Title}" DisplayMemberBinding="{Binding Title}" />
|
||||
<ui:GridViewColumn Width="160" Header="{l:Tr Song_Artist}" DisplayMemberBinding="{Binding Artist}" />
|
||||
<ui:GridViewColumn Width="80" Header="{l:Tr Song_Duration}">
|
||||
<ui:GridViewColumn.DisplayMemberBinding>
|
||||
<Binding Path="Duration" StringFormat="m\:ss" />
|
||||
</ui:GridViewColumn.DisplayMemberBinding>
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Radiosender.Controllers;
|
||||
using Radiosender.Models;
|
||||
using Radiosender.Services.Localization;
|
||||
using Wpf.Ui.Controls;
|
||||
using MessageBox = Wpf.Ui.Controls.MessageBox;
|
||||
|
||||
@@ -19,7 +20,15 @@ public partial class LibraryPage : Page
|
||||
|
||||
private Song? Selected => SongList.SelectedItem as Song;
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs e) => Refresh();
|
||||
private void OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Loc.Changed += OnLanguageChanged;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void OnUnloaded(object sender, RoutedEventArgs e) => Loc.Changed -= OnLanguageChanged;
|
||||
|
||||
private void OnLanguageChanged(object? sender, EventArgs e) => ShowEmptyText();
|
||||
|
||||
private void OnSearchChanged(object sender, TextChangedEventArgs e) => Refresh();
|
||||
|
||||
@@ -31,12 +40,13 @@ public partial class LibraryPage : Page
|
||||
var songs = _controller.Search(SearchBox.Text);
|
||||
SongList.ItemsSource = songs;
|
||||
GridColumns.Fit(SongList);
|
||||
EmptyText.Text = string.IsNullOrWhiteSpace(SearchBox.Text)
|
||||
? "Noch keine Songs. Musik auf der Seite Import hinzufügen."
|
||||
: "Kein Song passt zur Suche.";
|
||||
EmptyText.Visibility = songs.Count == 0 ? Visibility.Visible : Visibility.Collapsed;
|
||||
ShowEmptyText();
|
||||
}
|
||||
|
||||
private void ShowEmptyText() =>
|
||||
EmptyText.Text = Loc.T(string.IsNullOrWhiteSpace(SearchBox.Text) ? "Library_Empty" : "Library_NoMatch");
|
||||
|
||||
private void OnListKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == System.Windows.Input.Key.Enter) OnEdit(sender, e);
|
||||
@@ -61,10 +71,10 @@ public partial class LibraryPage : Page
|
||||
|
||||
var result = await new MessageBox
|
||||
{
|
||||
Title = "Song löschen",
|
||||
Content = $"\"{song.Title}\" von {song.Artist} aus der Bibliothek löschen?",
|
||||
PrimaryButtonText = "Löschen",
|
||||
CloseButtonText = "Abbrechen",
|
||||
Title = Loc.T("Library_DeleteTitle"),
|
||||
Content = Loc.F("Library_DeleteConfirm", song.Title, song.Artist),
|
||||
PrimaryButtonText = Loc.T("Library_Delete"),
|
||||
CloseButtonText = Loc.T("Library_Cancel"),
|
||||
}.ShowDialogAsync();
|
||||
|
||||
if (result != Wpf.Ui.Controls.MessageBoxResult.Primary)
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
Title="Sendeplan"
|
||||
xmlns:models="clr-namespace:Radiosender.Models"
|
||||
xmlns:l="clr-namespace:Radiosender.Views"
|
||||
Title="{l:Tr Schedule_Title}"
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
ScrollViewer.CanContentScroll="False"
|
||||
Loaded="OnLoaded"
|
||||
@@ -45,20 +47,23 @@
|
||||
|
||||
<!-- Wraps on narrow windows instead of cutting off the buttons. -->
|
||||
<WrapPanel Grid.Row="1" Margin="0,-8,0,0">
|
||||
<ui:TextBlock Margin="0,8,8,0" VerticalAlignment="Center" Text="Start" />
|
||||
<ui:TextBlock Margin="0,8,8,0" VerticalAlignment="Center" Text="{l:Tr Schedule_Start}" />
|
||||
<!-- Editable: pick "Jetzt" or a full hour, or type a time like 14:30 -->
|
||||
<ComboBox x:Name="StartBox"
|
||||
Width="112"
|
||||
IsEditable="True"
|
||||
ToolTip="{l:Tr Schedule_StartTimeTip}"
|
||||
Margin="0,8,12,0"
|
||||
VerticalAlignment="Center"
|
||||
AutomationProperties.Name="Startzeit"
|
||||
AutomationProperties.Name="{l:Tr Schedule_StartTimeName}"
|
||||
DisplayMemberPath="Label"
|
||||
DropDownOpened="OnStartDropDownOpened" />
|
||||
<ui:TextBlock Margin="0,8,8,0" VerticalAlignment="Center" Text="Stunden" />
|
||||
<ui:TextBlock Margin="0,8,8,0" VerticalAlignment="Center" Text="{l:Tr Schedule_Hours}" />
|
||||
<ui:NumberBox x:Name="HoursBox"
|
||||
Width="112"
|
||||
Margin="0,8,12,0"
|
||||
VerticalAlignment="Center"
|
||||
AutomationProperties.Name="Zu planende Stunden"
|
||||
AutomationProperties.Name="{l:Tr Schedule_HoursName}"
|
||||
Minimum="1"
|
||||
Maximum="24"
|
||||
Value="1"
|
||||
@@ -69,33 +74,22 @@
|
||||
MinWidth="0"
|
||||
Margin="0,8,0,0"
|
||||
VerticalAlignment="Center"
|
||||
Content="Unbegrenzt"
|
||||
ToolTip="Ohne Ende: Die nächsten 5 Stunden sind geplant, jede Stunde kommt eine weitere dazu."
|
||||
Content="{l:Tr Schedule_Unlimited}"
|
||||
ToolTip="{l:Tr Schedule_UnlimitedTip}"
|
||||
Checked="OnUnlimitedChanged"
|
||||
Unchecked="OnUnlimitedChanged" />
|
||||
<ui:Button x:Name="CreateButton"
|
||||
Margin="0,8,8,0"
|
||||
VerticalAlignment="Center"
|
||||
Appearance="Primary"
|
||||
Content="Plan erstellen"
|
||||
Content="{l:Tr Schedule_Create}"
|
||||
Click="OnCreate" />
|
||||
<!-- Start: plan from now, play, and go live when laut.fm is on. Stop: ends both. Text set in code. -->
|
||||
<ui:Button x:Name="StartNowButton"
|
||||
MinWidth="150"
|
||||
Margin="0,8,0,0"
|
||||
VerticalAlignment="Center"
|
||||
Content="Jetzt starten"
|
||||
Icon="{ui:SymbolIcon Play24}"
|
||||
ToolTip="Plant ab diesem Moment und geht sofort auf Sendung. Die Startzeit wird ignoriert."
|
||||
Click="OnStartNow" />
|
||||
<!-- Only while laut.fm is on: sends the program live to the station, independent of the plan. -->
|
||||
<ui:Button x:Name="LiveButton"
|
||||
MinWidth="100"
|
||||
Margin="8,8,0,0"
|
||||
VerticalAlignment="Center"
|
||||
Content="Live"
|
||||
Icon="{ui:SymbolIcon Live24}"
|
||||
ToolTip="Sendet alles, was auf Sendung ist, live auf deine laut.fm-Station."
|
||||
Visibility="Collapsed"
|
||||
Click="OnLiveToggle" />
|
||||
Click="OnStartNowToggle" />
|
||||
</WrapPanel>
|
||||
|
||||
<ui:InfoBar x:Name="Message"
|
||||
@@ -122,7 +116,7 @@
|
||||
<StackPanel VerticalAlignment="Center">
|
||||
<ui:TextBlock FontTypography="Caption"
|
||||
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
|
||||
Text="Läuft gerade" />
|
||||
Text="{l:Tr Schedule_NowPlaying}" />
|
||||
<DockPanel Margin="0,4,0,0">
|
||||
<ContentPresenter x:Name="NowKind"
|
||||
Margin="0,0,8,0"
|
||||
@@ -132,7 +126,7 @@
|
||||
<ui:TextBlock x:Name="NowTitle"
|
||||
FontTypography="Subtitle"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
Text="Nichts auf Sendung" />
|
||||
Text="{l:Tr Schedule_NothingOnAir}" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
|
||||
@@ -141,30 +135,22 @@
|
||||
<ui:Button x:Name="MicButton"
|
||||
MinWidth="120"
|
||||
Margin="0,0,20,0"
|
||||
Content="Mikro ein"
|
||||
Content="{l:Tr Schedule_MicOn}"
|
||||
Icon="{ui:SymbolIcon Mic24}"
|
||||
ToolTip="Schaltet das Mikrofon auf Sendung, auch über laufende Musik."
|
||||
ToolTip="{l:Tr Schedule_MicTip}"
|
||||
Click="OnMicToggle" />
|
||||
<ui:Button x:Name="EndNowButton"
|
||||
Content="Jetzt beenden"
|
||||
Icon="{ui:SymbolIcon Next24}"
|
||||
ToolTip="Beendet das laufende Element sofort; das nächste startet."
|
||||
Content="{l:Tr Schedule_EndNow}"
|
||||
Icon="{ui:SymbolIcon Stop24}"
|
||||
ToolTip="{l:Tr Schedule_EndNowTip}"
|
||||
IsEnabled="False"
|
||||
Click="OnEndNow" />
|
||||
<!-- One button: Start while idle, Stop while on air. -->
|
||||
<ui:Button x:Name="PlayButton"
|
||||
MinWidth="110"
|
||||
Margin="8,0,0,0"
|
||||
Content="Start"
|
||||
Icon="{ui:SymbolIcon Play24}"
|
||||
IsEnabled="False"
|
||||
Click="OnPlayToggle" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<ProgressBar x:Name="NowProgress"
|
||||
Margin="0,14,0,0"
|
||||
AutomationProperties.Name="Fortschritt des aktuellen Elements"
|
||||
AutomationProperties.Name="{l:Tr Schedule_ProgressName}"
|
||||
Maximum="1" />
|
||||
<ui:TextBlock x:Name="NowTime"
|
||||
Margin="0,6,0,0"
|
||||
@@ -197,7 +183,7 @@
|
||||
</WrapPanel.Resources>
|
||||
|
||||
<StackPanel Style="{StaticResource Group}">
|
||||
<ui:TextBlock Style="{StaticResource Heading}" Text="Sendung (für andere)" />
|
||||
<ui:TextBlock Style="{StaticResource Heading}" Text="{l:Tr Schedule_MixListeners}" />
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="MixLabel" />
|
||||
@@ -207,17 +193,17 @@
|
||||
<RowDefinition Height="32" />
|
||||
<RowDefinition Height="32" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:TextBlock VerticalAlignment="Center" Text="Musik" />
|
||||
<ui:TextBlock VerticalAlignment="Center" Text="{l:Tr Schedule_Music}" />
|
||||
<Slider x:Name="MusicForOthersSlider" Grid.Column="1"
|
||||
AutomationProperties.Name="Musik für andere" ValueChanged="OnMixChanged" />
|
||||
<ui:TextBlock Grid.Row="1" VerticalAlignment="Center" Text="Mikrofon" />
|
||||
AutomationProperties.Name="{l:Tr Schedule_MusicForListenersName}" ValueChanged="OnMixChanged" />
|
||||
<ui:TextBlock Grid.Row="1" VerticalAlignment="Center" Text="{l:Tr Schedule_Microphone}" />
|
||||
<Slider x:Name="MicrophoneForOthersSlider" Grid.Row="1" Grid.Column="1"
|
||||
AutomationProperties.Name="Mikrofon für andere" ValueChanged="OnMixChanged" />
|
||||
AutomationProperties.Name="{l:Tr Schedule_MicForListenersName}" ValueChanged="OnMixChanged" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Style="{StaticResource Group}">
|
||||
<ui:TextBlock Style="{StaticResource Heading}" Text="Für mich" />
|
||||
<StackPanel Style="{StaticResource Group}" Margin="0,0,0,8">
|
||||
<ui:TextBlock Style="{StaticResource Heading}" Text="{l:Tr Schedule_MixYou}" />
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="MixLabel" />
|
||||
@@ -227,36 +213,22 @@
|
||||
<RowDefinition Height="32" />
|
||||
<RowDefinition Height="32" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:TextBlock VerticalAlignment="Center" Text="Musik" />
|
||||
<ui:TextBlock VerticalAlignment="Center" Text="{l:Tr Schedule_Music}" />
|
||||
<Slider x:Name="MusicForMeSlider" Grid.Column="1"
|
||||
AutomationProperties.Name="Musik für mich" ValueChanged="OnMixChanged" />
|
||||
AutomationProperties.Name="{l:Tr Schedule_MusicForMeName}"
|
||||
ToolTip="{l:Tr Schedule_MusicForMeTip}"
|
||||
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."
|
||||
Content="{l:Tr Schedule_SameAsListeners}"
|
||||
ToolTip="{l:Tr Schedule_SameAsListenersTip}"
|
||||
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>
|
||||
@@ -271,11 +243,11 @@
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Column="0" VerticalAlignment="Center" Text="Songwunsch" />
|
||||
<ui:TextBlock Grid.Column="0" VerticalAlignment="Center" Text="{l:Tr Schedule_RequestLabel}" />
|
||||
<ComboBox x:Name="RequestSong"
|
||||
Grid.Column="1"
|
||||
Margin="12,0,0,0"
|
||||
AutomationProperties.Name="Gewünschter Song"
|
||||
AutomationProperties.Name="{l:Tr Schedule_RequestName}"
|
||||
DisplayMemberPath="Label"
|
||||
IsEditable="True"
|
||||
IsTextSearchEnabled="True"
|
||||
@@ -284,36 +256,52 @@
|
||||
<ui:Button x:Name="SwapButton"
|
||||
Grid.Column="2"
|
||||
Margin="12,0,0,0"
|
||||
Content="Auswahl ersetzen"
|
||||
Content="{l:Tr Schedule_Swap}"
|
||||
Icon="{ui:SymbolIcon ArrowSwap24}"
|
||||
IsEnabled="False"
|
||||
Click="OnSwap" />
|
||||
<StackPanel Grid.Column="4" Margin="12,0,0,0" Orientation="Horizontal">
|
||||
<!-- Inserts as the one after next -->
|
||||
<ui:DropDownButton x:Name="AddButton"
|
||||
Margin="0,0,8,0"
|
||||
Content="{l:Tr Schedule_Add}"
|
||||
Icon="{ui:SymbolIcon Add24}"
|
||||
ToolTip="{l:Tr Schedule_AddTip}"
|
||||
IsEnabled="False">
|
||||
<ui:DropDownButton.Flyout>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="{l:Tr Schedule_AddSong}" Tag="{x:Static models:ScheduleItemKind.Song}" Click="OnAddItem" />
|
||||
<MenuItem Header="{l:Tr Kind_News}" Tag="{x:Static models:ScheduleItemKind.News}" Click="OnAddItem" />
|
||||
<MenuItem Header="{l:Tr Kind_Ad}" Tag="{x:Static models:ScheduleItemKind.Ad}" Click="OnAddItem" />
|
||||
<MenuItem Header="{l:Tr Kind_Moderator}" Tag="{x:Static models:ScheduleItemKind.Moderator}" Click="OnAddItem" />
|
||||
</ContextMenu>
|
||||
</ui:DropDownButton.Flyout>
|
||||
</ui:DropDownButton>
|
||||
<ui:Button x:Name="MoveUpButton"
|
||||
Icon="{ui:SymbolIcon ArrowUp24}"
|
||||
ToolTip="Nach oben"
|
||||
AutomationProperties.Name="Ausgewähltes Element nach oben verschieben"
|
||||
ToolTip="{l:Tr Schedule_MoveUp}"
|
||||
AutomationProperties.Name="{l:Tr Schedule_MoveUpName}"
|
||||
IsEnabled="False"
|
||||
Click="OnMoveUp" />
|
||||
<ui:Button x:Name="MoveDownButton"
|
||||
Margin="4,0,0,0"
|
||||
Icon="{ui:SymbolIcon ArrowDown24}"
|
||||
ToolTip="Nach unten"
|
||||
AutomationProperties.Name="Ausgewähltes Element nach unten verschieben"
|
||||
ToolTip="{l:Tr Schedule_MoveDown}"
|
||||
AutomationProperties.Name="{l:Tr Schedule_MoveDownName}"
|
||||
IsEnabled="False"
|
||||
Click="OnMoveDown" />
|
||||
<ui:Button x:Name="EditItemButton"
|
||||
Margin="4,0,0,0"
|
||||
Icon="{ui:SymbolIcon Edit24}"
|
||||
ToolTip="Titel und Länge bearbeiten"
|
||||
AutomationProperties.Name="Ausgewähltes Element bearbeiten"
|
||||
ToolTip="{l:Tr Schedule_EditTip}"
|
||||
AutomationProperties.Name="{l:Tr Schedule_EditName}"
|
||||
IsEnabled="False"
|
||||
Click="OnEditItem" />
|
||||
<ui:Button x:Name="RemoveButton"
|
||||
Margin="4,0,0,0"
|
||||
Icon="{ui:SymbolIcon Delete24}"
|
||||
ToolTip="Aus dem Plan entfernen"
|
||||
AutomationProperties.Name="Ausgewähltes Element entfernen"
|
||||
ToolTip="{l:Tr Schedule_RemoveTip}"
|
||||
AutomationProperties.Name="{l:Tr Schedule_RemoveName}"
|
||||
IsEnabled="False"
|
||||
Click="OnRemove" />
|
||||
</StackPanel>
|
||||
@@ -329,42 +317,71 @@
|
||||
Grid.Row="5"
|
||||
SelectionMode="Single"
|
||||
IsHitTestVisible="True"
|
||||
AutomationProperties.Name="Sendeplan"
|
||||
AutomationProperties.Name="{l:Tr Schedule_Title}"
|
||||
AllowDrop="True"
|
||||
SelectionChanged="OnTimelineSelectionChanged"
|
||||
MouseDoubleClick="OnEditItem">
|
||||
MouseDoubleClick="OnEditItem"
|
||||
PreviewMouseLeftButtonDown="OnTimelineMouseDown"
|
||||
PreviewMouseMove="OnTimelineMouseMove"
|
||||
DragOver="OnTimelineDragOver"
|
||||
DragLeave="OnTimelineDragLeave"
|
||||
Drop="OnTimelineDrop">
|
||||
<ui:ListView.View>
|
||||
<ui:GridView>
|
||||
<ui:GridViewColumn Width="36">
|
||||
<ui:GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<ui:SymbolIcon x:Name="OnAir"
|
||||
Symbol="Play24"
|
||||
Filled="True"
|
||||
Foreground="{DynamicResource AccentTextFillColorPrimaryBrush}"
|
||||
AutomationProperties.Name="Auf Sendung"
|
||||
AutomationProperties.Name="{l:Tr Schedule_OnAirName}"
|
||||
Visibility="Collapsed" />
|
||||
<!-- Grip on hover or selection: the row can be dragged -->
|
||||
<ui:SymbolIcon x:Name="Grip"
|
||||
Symbol="ReOrderDotsVertical24"
|
||||
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
|
||||
Cursor="SizeAll"
|
||||
ToolTip="{l:Tr Schedule_DragTip}"
|
||||
Visibility="Hidden" />
|
||||
</Grid>
|
||||
<DataTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding IsCurrent}" Value="True">
|
||||
<Setter TargetName="OnAir" Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding CanMove}" Value="True" />
|
||||
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType=ListViewItem}}" Value="True" />
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter TargetName="Grip" Property="Visibility" Value="Visible" />
|
||||
</MultiDataTrigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding CanMove}" Value="True" />
|
||||
<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListViewItem}}" Value="True" />
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter TargetName="Grip" Property="Visibility" Value="Visible" />
|
||||
</MultiDataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
</ui:GridViewColumn.CellTemplate>
|
||||
</ui:GridViewColumn>
|
||||
<ui:GridViewColumn Width="90" Header="Start">
|
||||
<ui:GridViewColumn Width="90" Header="{l:Tr Schedule_Start}">
|
||||
<ui:GridViewColumn.DisplayMemberBinding>
|
||||
<Binding Path="Item.Start" StringFormat="HH:mm:ss" />
|
||||
</ui:GridViewColumn.DisplayMemberBinding>
|
||||
</ui:GridViewColumn>
|
||||
<ui:GridViewColumn Width="120" Header="Typ">
|
||||
<ui:GridViewColumn Width="120" Header="{l:Tr Schedule_ColType}">
|
||||
<ui:GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ContentPresenter Content="{Binding Item}" ContentTemplate="{StaticResource KindChip}" />
|
||||
</DataTemplate>
|
||||
</ui:GridViewColumn.CellTemplate>
|
||||
</ui:GridViewColumn>
|
||||
<ui:GridViewColumn Width="360" Header="Titel" DisplayMemberBinding="{Binding Item.Title}" />
|
||||
<ui:GridViewColumn Width="90" Header="Dauer">
|
||||
<ui:GridViewColumn Width="360" Header="{l:Tr Schedule_ColTitle}" DisplayMemberBinding="{Binding Item.Title}" />
|
||||
<ui:GridViewColumn Width="90" Header="{l:Tr Schedule_ColDuration}">
|
||||
<ui:GridViewColumn.DisplayMemberBinding>
|
||||
<Binding Path="Item.Duration" StringFormat="m\:ss" />
|
||||
</ui:GridViewColumn.DisplayMemberBinding>
|
||||
@@ -379,7 +396,7 @@
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top"
|
||||
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
|
||||
Text="Noch kein Plan. Stunden wählen und Plan erstellen."
|
||||
Text="{l:Tr Schedule_Empty}"
|
||||
Visibility="Visible" />
|
||||
</Grid>
|
||||
</Page>
|
||||
@@ -1,13 +1,19 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Threading;
|
||||
using Radiosender.Controllers;
|
||||
using Radiosender.Models;
|
||||
using Radiosender.Services.Audio;
|
||||
using Radiosender.Services.Localization;
|
||||
using Radiosender.Services.Scheduling;
|
||||
using Radiosender.Services.Streaming;
|
||||
using Wpf.Ui.Controls;
|
||||
using MenuItem = System.Windows.Controls.MenuItem;
|
||||
|
||||
namespace Radiosender.Views.Pages;
|
||||
|
||||
@@ -17,10 +23,7 @@ public partial class SchedulePage : Page
|
||||
private readonly DispatcherTimer _progressTimer = new() { Interval = TimeSpan.FromMilliseconds(250) };
|
||||
private bool _loading;
|
||||
private int _scrolledTo = -1;
|
||||
private bool _shownPlaying;
|
||||
|
||||
// UI language, not Windows culture.
|
||||
private static readonly System.Globalization.CultureInfo German = new("de-DE");
|
||||
private (bool OnAir, bool Live, bool Enabled)? _shownStart;
|
||||
|
||||
private readonly ObservableCollection<TimelineRow> _rows = [];
|
||||
|
||||
@@ -55,9 +58,9 @@ public partial class SchedulePage : Page
|
||||
_controller.ItemFailed += OnItemFailed;
|
||||
_controller.Finished += OnFinished;
|
||||
_live.Problem += OnLiveProblem;
|
||||
Loc.Changed += OnLanguageChanged;
|
||||
|
||||
_loading = true;
|
||||
VolumeSlider.Value = _controller.Volume;
|
||||
MusicForMeSlider.Value = _mixer.MusicForMe;
|
||||
MusicForOthersSlider.Value = _mixer.MusicForOthers;
|
||||
MicrophoneForOthersSlider.Value = _mixer.MicrophoneForOthers;
|
||||
@@ -65,7 +68,6 @@ public partial class SchedulePage : Page
|
||||
MusicForMeSlider.IsEnabled = !_mixer.ListenToBroadcast;
|
||||
_loading = false;
|
||||
ShowMicrophone();
|
||||
ShowLive();
|
||||
FillStartTimes();
|
||||
if (_controller.Plan.Count > 0)
|
||||
UnlimitedBox.IsChecked = _controller.IsUnlimited;
|
||||
@@ -85,19 +87,37 @@ public partial class SchedulePage : Page
|
||||
_controller.ItemFailed -= OnItemFailed;
|
||||
_controller.Finished -= OnFinished;
|
||||
_live.Problem -= OnLiveProblem;
|
||||
Loc.Changed -= OnLanguageChanged;
|
||||
_progressTimer.Stop();
|
||||
}
|
||||
|
||||
// Rewrite every text set in code; the open InfoBar keeps its language.
|
||||
private void OnLanguageChanged(object? sender, EventArgs e) => Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
_shownStart = null;
|
||||
var selected = Timeline.SelectedIndex;
|
||||
_rows.Clear();
|
||||
NowKind.Content = null; // same item again would not refresh the chip
|
||||
ShowMicrophone();
|
||||
FillStartTimes();
|
||||
ShowCurrent();
|
||||
if (selected < _rows.Count)
|
||||
Timeline.SelectedIndex = selected;
|
||||
});
|
||||
|
||||
// Rebuilt on dropdown open: never offers a past hour.
|
||||
private void FillStartTimes()
|
||||
{
|
||||
var selected = (StartBox.SelectedItem as StartOption)?.Time;
|
||||
var now = DateTime.Now;
|
||||
var next = now.Date.AddHours(now.Hour + 1);
|
||||
var options = Enumerable.Range(0, 12)
|
||||
List<StartOption> options =
|
||||
[
|
||||
new(null, Loc.T("Schedule_Now")),
|
||||
.. Enumerable.Range(0, 12)
|
||||
.Select(i => next.AddHours(i))
|
||||
.Select(t => new StartOption(t, t.Date == now.Date ? $"{t:HH:mm}" : t.ToString("ddd HH:mm", German)))
|
||||
.ToList();
|
||||
.Select(t => new StartOption(t, t.Date == now.Date ? $"{t:HH:mm}" : t.ToString("ddd HH:mm", Loc.Culture))),
|
||||
];
|
||||
StartBox.ItemsSource = options;
|
||||
StartBox.SelectedItem = options.FirstOrDefault(o => o.Time == selected) ?? options[0];
|
||||
}
|
||||
@@ -107,22 +127,77 @@ public partial class SchedulePage : Page
|
||||
private void OnUnlimitedChanged(object sender, RoutedEventArgs e) =>
|
||||
HoursBox.IsEnabled = UnlimitedBox.IsChecked != true;
|
||||
|
||||
private void OnCreate(object sender, RoutedEventArgs e) => CreatePlan(startNow: false);
|
||||
private static readonly string[] TimeFormats = ["H:mm", "HH:mm", "H.mm", "HH.mm", "H"];
|
||||
|
||||
private void OnStartNow(object sender, RoutedEventArgs e) => CreatePlan(startNow: true);
|
||||
|
||||
private async void CreatePlan(bool startNow)
|
||||
private async void OnCreate(object sender, RoutedEventArgs e)
|
||||
{
|
||||
int? hours = UnlimitedBox.IsChecked == true ? null : (int)(HoursBox.Value ?? 1);
|
||||
var start = (StartBox.SelectedItem as StartOption)?.Time;
|
||||
if (startNow)
|
||||
_expectPlaying = true;
|
||||
await RunAsync("Der Plan konnte nicht erstellt werden", () =>
|
||||
if (ChosenStart() is not { } start)
|
||||
{
|
||||
if (startNow)
|
||||
_controller.StartNow(hours);
|
||||
ShowMessage(InfoBarSeverity.Warning, Loc.T("Schedule_StartUnclearTitle"), Loc.T("Schedule_StartUnclear"));
|
||||
return;
|
||||
}
|
||||
await RunAsync(Loc.T("Schedule_CreateFailed"),() => _controller.CreatePlan(hours, start));
|
||||
}
|
||||
|
||||
// Typed time already passed today: tomorrow.
|
||||
private DateTime? ChosenStart()
|
||||
{
|
||||
if (StartBox.SelectedItem is StartOption option)
|
||||
return option.Time ?? DateTime.Now;
|
||||
if (!TimeOnly.TryParseExact(StartBox.Text.Trim(), TimeFormats, Loc.Culture, System.Globalization.DateTimeStyles.None, out var time))
|
||||
return null;
|
||||
var start = DateTime.Today.Add(time.ToTimeSpan());
|
||||
return start <= DateTime.Now ? start.AddDays(1) : start;
|
||||
}
|
||||
|
||||
private void OnStartNowToggle(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (OnAir)
|
||||
EndBroadcast();
|
||||
else
|
||||
_controller.CreatePlan(hours, start);
|
||||
StartBroadcast();
|
||||
}
|
||||
|
||||
private bool OnAir => (_expectPlaying ?? _controller.IsPlaying) || _live.IsLive;
|
||||
|
||||
private async void StartBroadcast()
|
||||
{
|
||||
_expectPlaying = true;
|
||||
if (await RunAsync(Loc.T("Schedule_StartFailed"), _controller.Start) && _live.IsEnabled)
|
||||
await GoLiveAsync();
|
||||
}
|
||||
|
||||
// Music keeps playing when laut.fm fails: a broken stream must not silence the program.
|
||||
private async Task GoLiveAsync()
|
||||
{
|
||||
_working = true;
|
||||
UpdateButtons();
|
||||
try
|
||||
{
|
||||
await Task.Run(() => _live.StartAsync());
|
||||
}
|
||||
catch (Exception ex) when (ex is LiveStreamException or NAudio.MmException)
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Warning, Loc.T("Schedule_NoLautFm"), ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_working = false;
|
||||
UpdateButtons();
|
||||
}
|
||||
}
|
||||
|
||||
private async void EndBroadcast()
|
||||
{
|
||||
NowKind.Visibility = Visibility.Collapsed;
|
||||
_expectPlaying = false;
|
||||
UpdateProgress();
|
||||
await RunAsync(Loc.T("Schedule_EndBroadcastFailed"), () =>
|
||||
{
|
||||
_live.Stop();
|
||||
if (_controller.IsPlaying)
|
||||
_controller.Stop();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -154,9 +229,9 @@ public partial class SchedulePage : Page
|
||||
if (Timeline.SelectedItem is not TimelineRow row || RequestSong.SelectedItem is not SongOption song)
|
||||
return;
|
||||
ScheduleItem? placed = null;
|
||||
if (await RunAsync("Der Songwunsch konnte nicht eingeplant werden", () => placed = _controller.Swap(row.Index, song.Id)[row.Index]))
|
||||
ShowMessage(InfoBarSeverity.Success, "Songwunsch eingeplant",
|
||||
$"\"{placed!.Title}\" läuft um {placed.Start:HH:mm:ss}.");
|
||||
if (await RunAsync(Loc.T("Schedule_SwapFailed"), () => placed = _controller.Swap(row.Index, song.Id)[row.Index]))
|
||||
ShowMessage(InfoBarSeverity.Success, Loc.T("Schedule_SwapDone"),
|
||||
Loc.F("Schedule_SwapDoneText", placed!.Title, placed.Start));
|
||||
}
|
||||
|
||||
private void OnRequestChanged(object sender, SelectionChangedEventArgs e) => UpdateButtons();
|
||||
@@ -165,11 +240,11 @@ public partial class SchedulePage : Page
|
||||
|
||||
private void OnMoveDown(object sender, RoutedEventArgs e) => MoveSelected(1);
|
||||
|
||||
private void MoveSelected(int offset) => ChangeSelected(row =>
|
||||
private void MoveSelected(int offset)
|
||||
{
|
||||
_controller.Move(row.Index, offset);
|
||||
Timeline.SelectedIndex = row.Index + offset;
|
||||
});
|
||||
if (Timeline.SelectedItem is TimelineRow row)
|
||||
MoveRow(row.Index, row.Index + offset);
|
||||
}
|
||||
|
||||
private void OnMixChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
@@ -196,7 +271,7 @@ public partial class SchedulePage : Page
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Error, "Mikrofon nicht verfügbar", ex.Message);
|
||||
ShowMessage(InfoBarSeverity.Error, Loc.T("Schedule_MicUnavailable"), ex.Message);
|
||||
}
|
||||
MicButton.IsEnabled = true;
|
||||
ShowMicrophone();
|
||||
@@ -205,50 +280,35 @@ public partial class SchedulePage : Page
|
||||
private void ShowMicrophone()
|
||||
{
|
||||
var on = _microphone.IsOn;
|
||||
MicButton.Content = on ? "Mikro aus" : "Mikro ein";
|
||||
MicButton.Content = Loc.T(on ? "Schedule_MicOff" : "Schedule_MicOn");
|
||||
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 async void OnLiveToggle(object sender, RoutedEventArgs e)
|
||||
{
|
||||
LiveButton.IsEnabled = false;
|
||||
try
|
||||
{
|
||||
if (_live.IsLive)
|
||||
{
|
||||
await Task.Run(_live.Stop);
|
||||
}
|
||||
else
|
||||
{
|
||||
await Task.Run(() => _live.StartAsync());
|
||||
Message.IsOpen = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is LiveStreamException or NAudio.MmException)
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Error, "Live nicht möglich", ex.Message);
|
||||
}
|
||||
LiveButton.IsEnabled = true;
|
||||
ShowLive();
|
||||
System.Windows.Automation.AutomationProperties.SetName(MicButton, Loc.T(on ? "Schedule_MicOffName" : "Schedule_MicOnName"));
|
||||
}
|
||||
|
||||
// Background thread.
|
||||
private void OnLiveProblem(object? sender, string message) => Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Warning, "laut.fm", message);
|
||||
ShowLive();
|
||||
UpdateButtons();
|
||||
});
|
||||
|
||||
private void ShowLive()
|
||||
private void ShowStartButton()
|
||||
{
|
||||
var onAir = OnAir;
|
||||
var live = _live.IsLive;
|
||||
// Visible while live: stoppable after laut.fm was switched off.
|
||||
LiveButton.Visibility = _live.IsEnabled || live ? Visibility.Visible : Visibility.Collapsed;
|
||||
LiveButton.Content = live ? "Live beenden" : "Live";
|
||||
LiveButton.Appearance = live ? ControlAppearance.Danger : ControlAppearance.Secondary;
|
||||
System.Windows.Automation.AutomationProperties.SetName(LiveButton, live ? "Livestream zu laut.fm beenden, er läuft" : "Livestream zu laut.fm starten");
|
||||
if (_shownStart == (onAir, live, _live.IsEnabled))
|
||||
return;
|
||||
_shownStart = (onAir, live, _live.IsEnabled);
|
||||
StartNowButton.Content = Loc.T(onAir ? "Schedule_EndBroadcast" : _live.IsEnabled ? "Schedule_GoLive" : "Schedule_StartNow");
|
||||
StartNowButton.Icon = new SymbolIcon(onAir ? SymbolRegular.Stop24 : _live.IsEnabled ? SymbolRegular.Live24 : SymbolRegular.Play24);
|
||||
StartNowButton.Appearance = onAir ? ControlAppearance.Danger : ControlAppearance.Secondary;
|
||||
StartNowButton.ToolTip = Loc.T(onAir
|
||||
? live ? "Schedule_StopLiveTip" : "Schedule_StopTip"
|
||||
: _live.IsEnabled
|
||||
? "Schedule_StartLiveTip"
|
||||
: "Schedule_StartPlanTip");
|
||||
System.Windows.Automation.AutomationProperties.SetName(StartNowButton, (string)StartNowButton.Content);
|
||||
}
|
||||
|
||||
private void OnEndNow(object sender, RoutedEventArgs e)
|
||||
@@ -260,13 +320,197 @@ public partial class SchedulePage : Page
|
||||
}
|
||||
catch (ScheduleException ex)
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Error, "Das Element konnte nicht beendet werden", ex.Message);
|
||||
ShowMessage(InfoBarSeverity.Error, Loc.T("Schedule_EndItemFailed"), ex.Message);
|
||||
}
|
||||
ShowCurrent();
|
||||
}
|
||||
|
||||
private void OnRemove(object sender, RoutedEventArgs e) => ChangeSelected(row => _controller.Remove(row.Index));
|
||||
|
||||
private void OnAddItem(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not MenuItem { Tag: ScheduleItemKind kind })
|
||||
return;
|
||||
var index = InsertPosition();
|
||||
if (kind == ScheduleItemKind.Song)
|
||||
{
|
||||
if (RequestSong.SelectedItem is not SongOption song)
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Warning, Loc.T("Schedule_NoSong"), Loc.T("Schedule_NoSongText"));
|
||||
return;
|
||||
}
|
||||
if (ChangePlan(() => _controller.Insert(index, kind, "", TimeSpan.Zero, song.Id), select: index))
|
||||
FadeIn(index);
|
||||
return;
|
||||
}
|
||||
var length = kind switch
|
||||
{
|
||||
ScheduleItemKind.News => TimeSpan.FromMinutes(5),
|
||||
ScheduleItemKind.Ad => TimeSpan.FromSeconds(30),
|
||||
_ => TimeSpan.FromMinutes(1),
|
||||
};
|
||||
var dialog = new ScheduleItemEditWindow(new ScheduleItem(kind, "", default, length), adding: true) { Owner = Window.GetWindow(this) };
|
||||
if (dialog.ShowDialog() == true && ChangePlan(() => _controller.Insert(index, kind, dialog.ItemTitle, dialog.Duration), select: index))
|
||||
FadeIn(index);
|
||||
}
|
||||
|
||||
// Always the one after next: two after the item on air, else position 2.
|
||||
private int InsertPosition() => Math.Min((_controller.IsPlaying ? _controller.CurrentIndex : 0) + 2, _rows.Count);
|
||||
|
||||
private Point _dragStart;
|
||||
private TimelineRow? _dragRow;
|
||||
private TimelineDragAdorner? _drag;
|
||||
private ScrollViewer? _timelineScroll;
|
||||
private long _lastScroll;
|
||||
|
||||
private void OnTimelineMouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
_dragStart = e.GetPosition(Timeline);
|
||||
_dragRow = RowAt(e.OriginalSource) is { CanMove: true } row ? row : null;
|
||||
}
|
||||
|
||||
private void OnTimelineMouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton != MouseButtonState.Pressed || _dragRow is not { } row)
|
||||
return;
|
||||
var moved = e.GetPosition(Timeline) - _dragStart;
|
||||
if (Math.Abs(moved.X) < SystemParameters.MinimumHorizontalDragDistance && Math.Abs(moved.Y) < SystemParameters.MinimumVerticalDragDistance)
|
||||
return;
|
||||
_dragRow = null;
|
||||
if (Container(row.Index) is not { } item || AdornerLayer.GetAdornerLayer(Timeline) is not { } layer)
|
||||
return;
|
||||
var label = row.Item.Title.Length > 0 ? $"{row.Item.KindName} · {row.Item.Title}" : row.Item.KindName;
|
||||
_drag = new TimelineDragAdorner(Timeline, label, e.GetPosition(Timeline),
|
||||
ThemeBrush("AccentFillColorDefaultBrush", SystemColors.HighlightBrush),
|
||||
ThemeBrush("SolidBackgroundFillColorTertiaryBrush", SystemColors.WindowBrush),
|
||||
ThemeBrush("TextFillColorPrimaryBrush", SystemColors.WindowTextBrush),
|
||||
ThemeBrush("CardStrokeColorDefaultBrush", SystemColors.ActiveBorderBrush));
|
||||
layer.Add(_drag);
|
||||
item.Opacity = 0.35;
|
||||
try
|
||||
{
|
||||
DragDrop.DoDragDrop(Timeline, row, DragDropEffects.Move);
|
||||
}
|
||||
finally
|
||||
{
|
||||
item.Opacity = 1;
|
||||
layer.Remove(_drag);
|
||||
_drag = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTimelineDragOver(object sender, DragEventArgs e)
|
||||
{
|
||||
e.Handled = true;
|
||||
if (e.Data.GetData(typeof(TimelineRow)) is not TimelineRow row)
|
||||
{
|
||||
e.Effects = DragDropEffects.None;
|
||||
return;
|
||||
}
|
||||
var cursor = e.GetPosition(Timeline);
|
||||
var y = cursor.Y;
|
||||
var gap = DropGap(y, out var lineY);
|
||||
e.Effects = gap >= 0 ? DragDropEffects.Move : DragDropEffects.None;
|
||||
// No line where the row would stay put.
|
||||
_drag?.Update(cursor, gap >= 0 && gap != row.Index && gap != row.Index + 1 ? lineY : null);
|
||||
AutoScroll(y);
|
||||
}
|
||||
|
||||
// Also raised when the cursor crosses child elements: hide the line only when really outside.
|
||||
private void OnTimelineDragLeave(object sender, DragEventArgs e)
|
||||
{
|
||||
var at = e.GetPosition(Timeline);
|
||||
if (at.X < 0 || at.Y < 0 || at.X >= Timeline.ActualWidth || at.Y >= Timeline.ActualHeight)
|
||||
_drag?.Update(at, null);
|
||||
}
|
||||
|
||||
private void OnTimelineDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetData(typeof(TimelineRow)) is not TimelineRow row)
|
||||
return;
|
||||
var gap = DropGap(e.GetPosition(Timeline).Y, out _);
|
||||
var target = gap > row.Index ? gap - 1 : gap;
|
||||
if (gap >= 0 && target != row.Index)
|
||||
MoveRow(row.Index, target);
|
||||
}
|
||||
|
||||
// Gap under the cursor, 0..Count: before the first row whose middle is below. -1: before the item on air.
|
||||
private int DropGap(double y, out double lineY)
|
||||
{
|
||||
lineY = 0;
|
||||
var gap = -1;
|
||||
for (var i = 0; i < _rows.Count; i++)
|
||||
{
|
||||
if (Container(i) is not { } item)
|
||||
continue;
|
||||
var top = TopOf(item);
|
||||
if (y < top + item.ActualHeight / 2)
|
||||
{
|
||||
(gap, lineY) = (i, top);
|
||||
break;
|
||||
}
|
||||
(gap, lineY) = (i + 1, top + item.ActualHeight);
|
||||
}
|
||||
return _controller.IsPlaying && gap <= _controller.CurrentIndex ? -1 : gap;
|
||||
}
|
||||
|
||||
// Edges of the rows area, not of the list: the column header sits on top.
|
||||
private void AutoScroll(double y)
|
||||
{
|
||||
const double Edge = 24;
|
||||
if (Environment.TickCount64 - _lastScroll < 120)
|
||||
return;
|
||||
_timelineScroll ??= Descendant<ScrollViewer>(Timeline);
|
||||
var header = Descendant<System.Windows.Controls.GridViewHeaderRowPresenter>(Timeline);
|
||||
var top = header is null ? 0 : header.TranslatePoint(new Point(0, header.ActualHeight), Timeline).Y;
|
||||
if (y >= top && y < top + Edge)
|
||||
_timelineScroll?.LineUp();
|
||||
else if (y > Timeline.ActualHeight - Edge)
|
||||
_timelineScroll?.LineDown();
|
||||
else
|
||||
return;
|
||||
_lastScroll = Environment.TickCount64;
|
||||
}
|
||||
|
||||
private void MoveRow(int from, int to)
|
||||
{
|
||||
if (ChangePlan(() => _controller.Move(from, to - from), select: to))
|
||||
FadeIn(to);
|
||||
}
|
||||
|
||||
// Fade only, no sliding: rows are rebuilt after a change, so old positions are not reliable.
|
||||
private void FadeIn(int index)
|
||||
{
|
||||
if (!SystemParameters.ClientAreaAnimation)
|
||||
return;
|
||||
Timeline.UpdateLayout();
|
||||
Container(index)?.BeginAnimation(OpacityProperty,
|
||||
new DoubleAnimation(0.2, 1, TimeSpan.FromMilliseconds(300)) { EasingFunction = new QuadraticEase { EasingMode = EasingMode.EaseOut } });
|
||||
}
|
||||
|
||||
private FrameworkElement? Container(int index) =>
|
||||
Timeline.ItemContainerGenerator.ContainerFromIndex(index) is FrameworkElement { IsVisible: true } item ? item : null;
|
||||
|
||||
private double TopOf(UIElement item) => item.TranslatePoint(default, Timeline).Y;
|
||||
|
||||
private Brush ThemeBrush(string key, Brush fallback) => TryFindResource(key) as Brush ?? fallback;
|
||||
|
||||
private static T? Descendant<T>(DependencyObject parent) where T : DependencyObject
|
||||
{
|
||||
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
|
||||
{
|
||||
var child = VisualTreeHelper.GetChild(parent, i);
|
||||
if ((child as T ?? Descendant<T>(child)) is { } found)
|
||||
return found;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private TimelineRow? RowAt(object source) =>
|
||||
source is DependencyObject element && ItemsControl.ContainerFromElement(Timeline, element) is System.Windows.Controls.ListViewItem item
|
||||
? item.DataContext as TimelineRow
|
||||
: null;
|
||||
|
||||
private void OnEditItem(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!EditItemButton.IsEnabled || Timeline.SelectedItem is not TimelineRow row)
|
||||
@@ -278,46 +522,40 @@ public partial class SchedulePage : Page
|
||||
|
||||
private void ChangeSelected(Action<TimelineRow> change)
|
||||
{
|
||||
if (Timeline.SelectedItem is not TimelineRow row)
|
||||
return;
|
||||
if (Timeline.SelectedItem is TimelineRow row)
|
||||
ChangePlan(() => change(row));
|
||||
}
|
||||
|
||||
private bool ChangePlan(Action change, int? select = null)
|
||||
{
|
||||
var changed = true;
|
||||
try
|
||||
{
|
||||
change(row);
|
||||
change();
|
||||
Message.IsOpen = false;
|
||||
}
|
||||
catch (ScheduleException ex)
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Error, "Der Plan konnte nicht geändert werden", ex.Message);
|
||||
ShowMessage(InfoBarSeverity.Error, Loc.T("Schedule_ChangeFailed"), ex.Message);
|
||||
changed = false;
|
||||
}
|
||||
ShowCurrent();
|
||||
if (changed && select is { } index)
|
||||
Timeline.SelectedIndex = index;
|
||||
return changed;
|
||||
}
|
||||
|
||||
private void OnTimelineSelectionChanged(object sender, SelectionChangedEventArgs e) => UpdateButtons();
|
||||
|
||||
private async void OnPlayToggle(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var stop = _controller.IsPlaying;
|
||||
_expectPlaying = !stop;
|
||||
if (stop)
|
||||
NowKind.Visibility = Visibility.Collapsed;
|
||||
UpdateProgress();
|
||||
await RunAsync("Start nicht möglich", stop ? _controller.Stop : _controller.Start);
|
||||
}
|
||||
|
||||
private void OnVolumeChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
|
||||
{
|
||||
if (!_loading) _controller.Volume = (float)e.NewValue;
|
||||
}
|
||||
|
||||
// BeginInvoke, not Invoke: engine Stop waits for this pool thread -> deadlock.
|
||||
private void OnItemStarted(object? sender, int index) => Dispatcher.BeginInvoke(ShowCurrent);
|
||||
|
||||
private void OnItemFailed(object? sender, string message) =>
|
||||
Dispatcher.BeginInvoke(() => ShowMessage(InfoBarSeverity.Warning, "Element übersprungen", message));
|
||||
Dispatcher.BeginInvoke(() => ShowMessage(InfoBarSeverity.Warning, Loc.T("Schedule_ItemSkipped"), message));
|
||||
|
||||
private void OnFinished(object? sender, EventArgs e) => Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Informational, "Sendung beendet", "Der ganze Plan wurde gespielt.");
|
||||
ShowMessage(InfoBarSeverity.Informational, Loc.T("Schedule_Finished"), Loc.T("Schedule_FinishedText"));
|
||||
ShowCurrent();
|
||||
});
|
||||
|
||||
@@ -331,7 +569,7 @@ public partial class SchedulePage : Page
|
||||
// Replace changed rows only: keeps selection (swap target).
|
||||
for (var i = 0; i < plan.Count; i++)
|
||||
{
|
||||
var updated = new TimelineRow(i, plan[i], i == current);
|
||||
var updated = new TimelineRow(i, plan[i], i == current, !_controller.IsPlaying || i > current);
|
||||
if (i == _rows.Count)
|
||||
_rows.Add(updated);
|
||||
else if (_rows[i] != updated)
|
||||
@@ -359,14 +597,10 @@ public partial class SchedulePage : Page
|
||||
private void UpdateButtons()
|
||||
{
|
||||
var playing = _expectPlaying ?? _controller.IsPlaying;
|
||||
PlayButton.IsEnabled = !_working && (playing || _controller.Plan.Count > 0);
|
||||
CreateButton.IsEnabled = StartNowButton.IsEnabled = !_working;
|
||||
if (playing != _shownPlaying)
|
||||
{
|
||||
_shownPlaying = playing;
|
||||
PlayButton.Content = playing ? "Stopp" : "Start";
|
||||
PlayButton.Icon = new SymbolIcon(playing ? SymbolRegular.Stop24 : SymbolRegular.Play24);
|
||||
}
|
||||
CreateButton.IsEnabled = !_working;
|
||||
// Without a plan only stopping makes sense.
|
||||
StartNowButton.IsEnabled = !_working && (OnAir || _controller.Plan.Count > 0);
|
||||
ShowStartButton();
|
||||
|
||||
var row = Timeline.SelectedItem as TimelineRow;
|
||||
|
||||
@@ -374,6 +608,7 @@ public partial class SchedulePage : Page
|
||||
var current = _controller.CurrentIndex;
|
||||
bool Editable(int i) => !_working && i >= 0 && i < count && (!playing || i > current);
|
||||
var index = row?.Index ?? -1;
|
||||
AddButton.IsEnabled = !_working && count > 0 && (!playing || index >= current || index < 0);
|
||||
MoveUpButton.IsEnabled = Editable(index) && Editable(index - 1);
|
||||
MoveDownButton.IsEnabled = Editable(index) && Editable(index + 1);
|
||||
RemoveButton.IsEnabled = Editable(index);
|
||||
@@ -383,12 +618,12 @@ public partial class SchedulePage : Page
|
||||
|
||||
var blocker = row switch
|
||||
{
|
||||
null => "Ein kommendes Element im Plan auswählen.",
|
||||
{ Item.Kind: ScheduleItemKind.News } => "Nachrichten können nicht ersetzt werden.",
|
||||
_ when playing && row.Index <= _controller.CurrentIndex => "Dieses Element ist bereits auf Sendung oder vorbei.",
|
||||
null => Loc.T("Schedule_HintSelect"),
|
||||
{ Item.Kind: ScheduleItemKind.News } => Loc.T("Schedule_NewsNoReplace"),
|
||||
_ when playing && row.Index <= _controller.CurrentIndex => Loc.T("Schedule_HintOnAirOrOver"),
|
||||
_ => null,
|
||||
};
|
||||
SwapHint.Text = blocker ?? $"Ersetzt das Element um {row!.Item.Start:HH:mm:ss}.";
|
||||
SwapHint.Text = blocker ?? Loc.F("Schedule_HintReplaces", row!.Item.Start);
|
||||
var requested = RequestSong.SelectedItem is not null;
|
||||
SwapHint.Visibility = requested ? Visibility.Visible : Visibility.Collapsed;
|
||||
SwapButton.IsEnabled = !_working && requested && blocker is null;
|
||||
@@ -401,7 +636,7 @@ public partial class SchedulePage : Page
|
||||
NowProgress.Value = 0;
|
||||
// Here, not in ShowCurrent: engine starts waiting shortly after Start.
|
||||
var waiting = _expectPlaying == false ? null : _controller.WaitingUntil;
|
||||
NowTitle.Text = waiting is { } at ? $"Auf Sendung um {at:HH:mm:ss}" : "Nichts auf Sendung";
|
||||
NowTitle.Text = waiting is { } at ? Loc.F("Schedule_WaitingUntil", at) : Loc.T("Schedule_NothingOnAir");
|
||||
NowTime.Text = " ";
|
||||
return;
|
||||
}
|
||||
@@ -413,15 +648,21 @@ public partial class SchedulePage : Page
|
||||
|
||||
private void ShowMessage(InfoBarSeverity severity, string title, string text)
|
||||
{
|
||||
if (severity == InfoBarSeverity.Error)
|
||||
{
|
||||
Message.IsOpen = false;
|
||||
ErrorPopup.Show(this, title, text);
|
||||
return;
|
||||
}
|
||||
Message.Severity = severity;
|
||||
Message.Title = title;
|
||||
Message.Message = text;
|
||||
Message.IsOpen = true;
|
||||
}
|
||||
|
||||
private sealed record TimelineRow(int Index, ScheduleItem Item, bool IsCurrent);
|
||||
private sealed record TimelineRow(int Index, ScheduleItem Item, bool IsCurrent, bool CanMove);
|
||||
|
||||
private sealed record SongOption(long Id, string Label);
|
||||
|
||||
private sealed record StartOption(DateTime Time, string Label);
|
||||
private sealed record StartOption(DateTime? Time, string Label); // Time null: now
|
||||
}
|
||||
@@ -2,9 +2,11 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
Title="Einstellungen"
|
||||
xmlns:l="clr-namespace:Radiosender.Views"
|
||||
Title="{l:Tr Settings_Title}"
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
Loaded="OnLoaded">
|
||||
Loaded="OnLoaded"
|
||||
Unloaded="OnUnloaded">
|
||||
<Page.Resources>
|
||||
<Style x:Key="Card" TargetType="Border">
|
||||
<Setter Property="Margin" Value="0,0,0,12" />
|
||||
@@ -37,6 +39,22 @@
|
||||
<StackPanel MaxWidth="640" Margin="24" HorizontalAlignment="Left">
|
||||
<ui:InfoBar x:Name="Message" Margin="0,0,0,12" IsClosable="True" IsOpen="False" />
|
||||
|
||||
<!-- Language: names stay in their own language so everyone finds theirs -->
|
||||
<Border Style="{StaticResource Card}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="220" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label VerticalAlignment="Center" Content="{l:Tr Settings_Language}" Target="{Binding ElementName=LanguageBox}" />
|
||||
<ComboBox x:Name="LanguageBox" Grid.Column="1" Width="200" HorizontalAlignment="Left"
|
||||
AutomationProperties.Name="{l:Tr Settings_Language}">
|
||||
<ComboBoxItem Content="Deutsch" Tag="de" />
|
||||
<ComboBoxItem Content="English" Tag="en" />
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- Speaking alerts: one block per kind -->
|
||||
<Border Style="{StaticResource Card}">
|
||||
<Grid>
|
||||
@@ -49,17 +67,17 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:ToggleSwitch x:Name="NewsAlertSwitch" Grid.ColumnSpan="2" Content="Hinweis vor Nachrichten" />
|
||||
<ui:ToggleSwitch x:Name="NewsAlertSwitch" Grid.ColumnSpan="2" Content="{l:Tr Settings_NewsAlert}" />
|
||||
<Label Grid.Row="1" Margin="0,12,0,0" VerticalAlignment="Center"
|
||||
Content="Sekunden vor dem Start"
|
||||
Content="{l:Tr Settings_SecondsBefore}"
|
||||
Target="{Binding ElementName=NewsSecondsBox}"
|
||||
IsEnabled="{Binding IsChecked, ElementName=NewsAlertSwitch}" />
|
||||
<ui:NumberBox x:Name="NewsSecondsBox" Grid.Row="1" Grid.Column="1" Margin="0,12,0,0"
|
||||
Style="{StaticResource Seconds}"
|
||||
AutomationProperties.Name="Sekunden vor Nachrichten"
|
||||
AutomationProperties.Name="{l:Tr Settings_NewsSecondsName}"
|
||||
IsEnabled="{Binding IsChecked, ElementName=NewsAlertSwitch}" />
|
||||
<CheckBox x:Name="NewsSoundBox" Grid.Row="2" Grid.ColumnSpan="2" Margin="0,8,0,0"
|
||||
Content="Bing-Ton abspielen"
|
||||
Content="{l:Tr Settings_PlayChime}"
|
||||
IsEnabled="{Binding IsChecked, ElementName=NewsAlertSwitch}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
@@ -75,17 +93,17 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:ToggleSwitch x:Name="ModeratorAlertSwitch" Grid.ColumnSpan="2" Content="Hinweis vor Moderation" />
|
||||
<ui:ToggleSwitch x:Name="ModeratorAlertSwitch" Grid.ColumnSpan="2" Content="{l:Tr Settings_ModeratorAlert}" />
|
||||
<Label Grid.Row="1" Margin="0,12,0,0" VerticalAlignment="Center"
|
||||
Content="Sekunden vor dem Start"
|
||||
Content="{l:Tr Settings_SecondsBefore}"
|
||||
Target="{Binding ElementName=ModeratorSecondsBox}"
|
||||
IsEnabled="{Binding IsChecked, ElementName=ModeratorAlertSwitch}" />
|
||||
<ui:NumberBox x:Name="ModeratorSecondsBox" Grid.Row="1" Grid.Column="1" Margin="0,12,0,0"
|
||||
Style="{StaticResource Seconds}"
|
||||
AutomationProperties.Name="Sekunden vor Moderation"
|
||||
AutomationProperties.Name="{l:Tr Settings_ModeratorSecondsName}"
|
||||
IsEnabled="{Binding IsChecked, ElementName=ModeratorAlertSwitch}" />
|
||||
<CheckBox x:Name="ModeratorSoundBox" Grid.Row="2" Grid.ColumnSpan="2" Margin="0,8,0,0"
|
||||
Content="Bing-Ton abspielen"
|
||||
Content="{l:Tr Settings_PlayChime}"
|
||||
IsEnabled="{Binding IsChecked, ElementName=ModeratorAlertSwitch}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
@@ -103,18 +121,18 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:TextBlock Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="Audio-Ausgabe" />
|
||||
<ui:TextBlock Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="{l:Tr Settings_AudioOutput}" />
|
||||
<Label Grid.Row="1" Margin="0,12,0,0" VerticalAlignment="Center"
|
||||
Content="Sendung (für andere)" Target="{Binding ElementName=BroadcastDeviceBox}" />
|
||||
Content="{l:Tr Settings_ForListeners}" 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" />
|
||||
AutomationProperties.Name="{l:Tr Settings_BroadcastDeviceName}" />
|
||||
<Label Grid.Row="2" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Für mich (Kopfhörer)" Target="{Binding ElementName=MonitorDeviceBox}" />
|
||||
Content="{l:Tr Settings_ForYou}" 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" />
|
||||
AutomationProperties.Name="{l:Tr Settings_MonitorDeviceName}" />
|
||||
<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." />
|
||||
Text="{l:Tr Settings_DevicesHint}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
@@ -132,36 +150,36 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:TextBlock Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="Minuten pro Stunde" />
|
||||
<ui:TextBlock Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="{l:Tr Settings_MinutesPerHour}" />
|
||||
<Label Grid.Row="1" Margin="0,12,0,0" VerticalAlignment="Center"
|
||||
Content="Nachrichten" Target="{Binding ElementName=NewsMinutesBox}" />
|
||||
Content="{l:Tr Settings_News}" Target="{Binding ElementName=NewsMinutesBox}" />
|
||||
<ui:NumberBox x:Name="NewsMinutesBox" Grid.Row="1" Grid.Column="1" Margin="0,12,0,0"
|
||||
Style="{StaticResource Minutes}" Minimum="2"
|
||||
AutomationProperties.Name="Nachrichten-Minuten pro Stunde" />
|
||||
AutomationProperties.Name="{l:Tr Settings_NewsMinutesName}" />
|
||||
<Label Grid.Row="2" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Moderation" Target="{Binding ElementName=ModeratorMinutesBox}" />
|
||||
Content="{l:Tr Settings_Moderation}" Target="{Binding ElementName=ModeratorMinutesBox}" />
|
||||
<ui:NumberBox x:Name="ModeratorMinutesBox" Grid.Row="2" Grid.Column="1" Margin="0,8,0,0"
|
||||
Style="{StaticResource Minutes}"
|
||||
AutomationProperties.Name="Moderations-Minuten pro Stunde" />
|
||||
AutomationProperties.Name="{l:Tr Settings_ModeratorMinutesName}" />
|
||||
<Label Grid.Row="3" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Werbung" Target="{Binding ElementName=AdMinutesBox}" />
|
||||
Content="{l:Tr Settings_Ads}" Target="{Binding ElementName=AdMinutesBox}" />
|
||||
<ui:NumberBox x:Name="AdMinutesBox" Grid.Row="3" Grid.Column="1" Margin="0,8,0,0"
|
||||
Style="{StaticResource Minutes}"
|
||||
AutomationProperties.Name="Werbe-Minuten pro Stunde" />
|
||||
AutomationProperties.Name="{l:Tr Settings_AdMinutesName}" />
|
||||
<ui:TextBlock Grid.Row="4" Grid.ColumnSpan="2" Margin="0,12,0,0" TextWrapping="Wrap"
|
||||
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
|
||||
Text="Sollwerte, zusammen höchstens 60 Minuten. Gilt für den nächsten Plan." />
|
||||
Text="{l:Tr Settings_MinutesHint}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- laut.fm: live streaming and the station's library -->
|
||||
<!-- laut.fm: live streaming -->
|
||||
<Border Style="{StaticResource Card}">
|
||||
<StackPanel>
|
||||
<ui:ToggleSwitch x:Name="LautFmSwitch" Content="laut.fm"
|
||||
Checked="OnLautFmChanged" Unchecked="OnLautFmChanged" />
|
||||
<ui:TextBlock Margin="0,8,0,0" TextWrapping="Wrap"
|
||||
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
|
||||
Text="Sendet live auf deine laut.fm-Station und bietet ihre Musik beim Import an. Im Plan erscheint dann der Button „Live“." />
|
||||
Text="{l:Tr Settings_LautFmInfo}" />
|
||||
<Grid x:Name="LautFmFields" Margin="0,4,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="220" />
|
||||
@@ -175,57 +193,44 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:TextBlock Margin="0,12,0,0" Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="Live senden" />
|
||||
<ui:TextBlock Margin="0,12,0,0" Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="{l:Tr Settings_LiveHeader}" />
|
||||
<Label Grid.Row="1" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Server" Target="{Binding ElementName=LautFmHostBox}" />
|
||||
<ui:TextBox x:Name="LautFmHostBox" Grid.Row="1" Grid.Column="1" Margin="0,8,0,0"
|
||||
AutomationProperties.Name="laut.fm-Server" />
|
||||
AutomationProperties.Name="{l:Tr Settings_LautFmHostName}" />
|
||||
<Label Grid.Row="2" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Port" Target="{Binding ElementName=LautFmPortBox}" />
|
||||
<ui:NumberBox x:Name="LautFmPortBox" Grid.Row="2" Grid.Column="1" Margin="0,8,0,0"
|
||||
Width="130" HorizontalAlignment="Left" Minimum="1" Maximum="65535"
|
||||
MaxDecimalPlaces="0" SmallChange="1" ClearButtonEnabled="False"
|
||||
AutomationProperties.Name="laut.fm-Port" />
|
||||
AutomationProperties.Name="{l:Tr Settings_LautFmPortName}" />
|
||||
<Label Grid.Row="3" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Mountpoint" Target="{Binding ElementName=LautFmMountBox}" />
|
||||
<ui:TextBox x:Name="LautFmMountBox" Grid.Row="3" Grid.Column="1" Margin="0,8,0,0"
|
||||
AutomationProperties.Name="laut.fm-Mountpoint" />
|
||||
AutomationProperties.Name="{l:Tr Settings_LautFmMountName}" />
|
||||
<Label Grid.Row="4" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Benutzer" Target="{Binding ElementName=LautFmUserBox}" />
|
||||
Content="{l:Tr Settings_User}" Target="{Binding ElementName=LautFmUserBox}" />
|
||||
<ui:TextBox x:Name="LautFmUserBox" Grid.Row="4" Grid.Column="1" Margin="0,8,0,0"
|
||||
AutomationProperties.Name="laut.fm-Benutzer" />
|
||||
AutomationProperties.Name="{l:Tr Settings_LautFmUserName}" />
|
||||
<Label Grid.Row="5" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Passwort" Target="{Binding ElementName=LautFmPasswordBox}" />
|
||||
Content="{l:Tr Settings_Password}" Target="{Binding ElementName=LautFmPasswordBox}" />
|
||||
<ui:PasswordBox x:Name="LautFmPasswordBox" Grid.Row="5" Grid.Column="1" Margin="0,8,0,0"
|
||||
AutomationProperties.Name="laut.fm-Passwort" />
|
||||
AutomationProperties.Name="{l:Tr Settings_LautFmPasswordName}" />
|
||||
<ui:TextBlock Grid.Row="6" Grid.ColumnSpan="2" Margin="0,8,0,0" TextWrapping="Wrap"
|
||||
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
|
||||
Text="Diese Werte stehen in Radioadmin unter „Live senden“." />
|
||||
<ui:TextBlock Grid.Row="7" Margin="0,16,0,0" Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="Bibliothek" />
|
||||
<Label Grid.Row="8" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Stations-ID" Target="{Binding ElementName=LautFmStationBox}" />
|
||||
<ui:TextBox x:Name="LautFmStationBox" Grid.Row="8" Grid.Column="1" Margin="0,8,0,0"
|
||||
AutomationProperties.Name="laut.fm-Stations-ID" />
|
||||
<Label Grid.Row="9" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Radioadmin-Token" Target="{Binding ElementName=LautFmTokenBox}" />
|
||||
<ui:PasswordBox x:Name="LautFmTokenBox" Grid.Row="9" Grid.Column="1" Margin="0,8,0,0"
|
||||
AutomationProperties.Name="Radioadmin-Token"
|
||||
ToolTip="Nach dem Login in Radioadmin in den Entwicklertools des Browsers: Lokaler Speicher, Schlüssel laut.fm.api.token." />
|
||||
Text="{l:Tr Settings_LautFmValuesHint}" />
|
||||
</Grid>
|
||||
<ui:TextBlock x:Name="LautFmHint" Margin="0,12,0,0" TextWrapping="Wrap"
|
||||
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
|
||||
Text="Passwort und Token werden verschlüsselt für deinen Windows-Benutzer gespeichert. Die Bibliothek nutzt eine nicht offizielle laut.fm-Schnittstelle und kann ohne Vorwarnung ausfallen." />
|
||||
Text="{l:Tr Settings_LautFmPasswordHint}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<StackPanel Margin="0,4,0,0" Orientation="Horizontal">
|
||||
<ui:Button Appearance="Primary" MinWidth="110" Content="Speichern" Icon="{ui:SymbolIcon Save24}" Click="OnSave" />
|
||||
<ui:Button Margin="8,0,0,0" MinWidth="110" Content="Zurücksetzen" Icon="{ui:SymbolIcon ArrowReset24}"
|
||||
ToolTip="Setzt die Standardwerte ins Formular. Mit Speichern übernehmen."
|
||||
<ui:Button Appearance="Primary" MinWidth="110" Content="{l:Tr Settings_Save}" Icon="{ui:SymbolIcon Save24}" Click="OnSave" />
|
||||
<ui:Button Margin="8,0,0,0" MinWidth="110" Content="{l:Tr Settings_Reset}" Icon="{ui:SymbolIcon ArrowReset24}"
|
||||
ToolTip="{l:Tr Settings_ResetTooltip}"
|
||||
Click="OnReset" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Radiosender.Services.Audio;
|
||||
using Radiosender.Services.Localization;
|
||||
using Radiosender.Services.Settings;
|
||||
using Wpf.Ui.Controls;
|
||||
|
||||
@@ -17,19 +18,41 @@ public partial class SettingsPage : Page
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs e) => Show(_store.Current);
|
||||
private void OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Loc.Changed -= OnLanguageChanged;
|
||||
Loc.Changed += OnLanguageChanged;
|
||||
Show(_store.Current);
|
||||
}
|
||||
|
||||
private void OnUnloaded(object sender, RoutedEventArgs e) => Loc.Changed -= OnLanguageChanged;
|
||||
|
||||
// Re-fill the code-set first entries, keep the selection.
|
||||
private void OnLanguageChanged(object? sender, EventArgs e)
|
||||
{
|
||||
var (broadcast, monitor) = (BroadcastDeviceBox.SelectedIndex, MonitorDeviceBox.SelectedIndex);
|
||||
FillDevices();
|
||||
BroadcastDeviceBox.SelectedIndex = broadcast;
|
||||
MonitorDeviceBox.SelectedIndex = monitor;
|
||||
}
|
||||
|
||||
private List<string> _devices = [];
|
||||
|
||||
// Index 0 of each list = no device name (null).
|
||||
private const string DefaultDevice = "Windows-Standardgerät";
|
||||
private const string NoDevice = "Kein eigenes Gerät";
|
||||
private void FillDevices()
|
||||
{
|
||||
BroadcastDeviceBox.ItemsSource = _devices.Prepend(Loc.T("Settings_DefaultDevice")).ToList();
|
||||
MonitorDeviceBox.ItemsSource = _devices.Prepend(Loc.T("Settings_NoDevice")).ToList();
|
||||
}
|
||||
|
||||
private void Show(AppSettings settings)
|
||||
{
|
||||
var devices = ProgramOutput.DeviceNames().ToList();
|
||||
BroadcastDeviceBox.ItemsSource = devices.Prepend(DefaultDevice).ToList();
|
||||
MonitorDeviceBox.ItemsSource = devices.Prepend(NoDevice).ToList();
|
||||
_devices = ProgramOutput.DeviceNames().ToList();
|
||||
var devices = _devices;
|
||||
FillDevices();
|
||||
BroadcastDeviceBox.SelectedIndex = devices.IndexOf(settings.BroadcastDevice ?? "") + 1;
|
||||
MonitorDeviceBox.SelectedIndex = devices.IndexOf(settings.MonitorDevice ?? "") + 1;
|
||||
LanguageBox.SelectedIndex = settings.Language == Loc.English ? 1 : 0;
|
||||
NewsAlertSwitch.IsChecked = settings.NewsAlert;
|
||||
NewsSecondsBox.Value = settings.NewsAlertSeconds;
|
||||
NewsSoundBox.IsChecked = settings.NewsAlertSound;
|
||||
@@ -45,8 +68,6 @@ public partial class SettingsPage : Page
|
||||
LautFmMountBox.Text = settings.LautFmMount;
|
||||
LautFmUserBox.Text = settings.LautFmUser;
|
||||
LautFmPasswordBox.Password = settings.LautFmPassword;
|
||||
LautFmStationBox.Text = settings.LautFmStationId;
|
||||
LautFmTokenBox.Password = settings.LautFmToken;
|
||||
OnLautFmChanged(this, new RoutedEventArgs());
|
||||
}
|
||||
|
||||
@@ -58,6 +79,7 @@ public partial class SettingsPage : Page
|
||||
|
||||
private AppSettings Read() => new()
|
||||
{
|
||||
Language = (LanguageBox.SelectedItem as ComboBoxItem)?.Tag as string ?? Loc.German,
|
||||
NewsAlert = NewsAlertSwitch.IsChecked == true,
|
||||
NewsAlertSeconds = (int)(NewsSecondsBox.Value ?? Defaults.NewsAlertSeconds),
|
||||
NewsAlertSound = NewsSoundBox.IsChecked == true,
|
||||
@@ -75,8 +97,6 @@ public partial class SettingsPage : Page
|
||||
LautFmMount = LautFmMountBox.Text.Trim(),
|
||||
LautFmUser = LautFmUserBox.Text.Trim(),
|
||||
LautFmPassword = LautFmPasswordBox.Password,
|
||||
LautFmStationId = LautFmStationBox.Text.Trim(),
|
||||
LautFmToken = LautFmTokenBox.Password.Trim(),
|
||||
};
|
||||
|
||||
private void OnSave(object sender, RoutedEventArgs e)
|
||||
@@ -84,33 +104,40 @@ public partial class SettingsPage : Page
|
||||
var settings = Read();
|
||||
if (settings.Validate() is { } problem)
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Error, "Nicht gespeichert", problem);
|
||||
ShowMessage(InfoBarSeverity.Error, Loc.T("Settings_NotSaved"), problem);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_store.Save(settings);
|
||||
ShowMessage(InfoBarSeverity.Success, "Gespeichert", "Minuten pro Stunde gelten für den nächsten Plan.");
|
||||
Loc.SetLanguage(settings.Language);
|
||||
ShowMessage(InfoBarSeverity.Success, Loc.T("Settings_Saved"), Loc.T("Settings_SavedDetail"));
|
||||
}
|
||||
catch (NAudio.MmException)
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Error, "Nicht gespeichert", "Ein gewähltes Audiogerät konnte nicht geöffnet werden. Die bisherigen Geräte bleiben aktiv.");
|
||||
ShowMessage(InfoBarSeverity.Error, Loc.T("Settings_NotSaved"), Loc.T("Settings_AudioDeviceFailed"));
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Error, "Nicht gespeichert", ex.Message);
|
||||
ShowMessage(InfoBarSeverity.Error, Loc.T("Settings_NotSaved"), ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnReset(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Show(Defaults);
|
||||
ShowMessage(InfoBarSeverity.Informational, "Standardwerte eingesetzt", "Mit Speichern übernehmen.");
|
||||
ShowMessage(InfoBarSeverity.Informational, Loc.T("Settings_DefaultsApplied"), Loc.T("Settings_DefaultsApplyHint"));
|
||||
}
|
||||
|
||||
private void ShowMessage(InfoBarSeverity severity, string title, string text)
|
||||
{
|
||||
if (severity == InfoBarSeverity.Error)
|
||||
{
|
||||
Message.IsOpen = false;
|
||||
ErrorPopup.Show(this, title, text);
|
||||
return;
|
||||
}
|
||||
Message.Severity = severity;
|
||||
Message.Title = title;
|
||||
Message.Message = text;
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
Title="Element bearbeiten"
|
||||
xmlns:l="clr-namespace:Radiosender.Views"
|
||||
Title="{l:Tr ItemEdit_Window}"
|
||||
Width="400" SizeToContent="Height"
|
||||
ResizeMode="NoResize"
|
||||
ShowInTaskbar="False"
|
||||
@@ -11,25 +12,19 @@
|
||||
WindowStartupLocation="CenterOwner"
|
||||
FocusManager.FocusedElement="{Binding ElementName=TitleBox}">
|
||||
<StackPanel>
|
||||
<ui:TitleBar x:Name="Bar" Title="Element bearbeiten" ShowMinimize="False" ShowMaximize="False" />
|
||||
<ui:TitleBar x:Name="Bar" Title="{l:Tr ItemEdit_Window}" ShowMinimize="False" ShowMaximize="False" />
|
||||
|
||||
<StackPanel Margin="24,8,24,24">
|
||||
<Label Content="_Titel" Target="{Binding ElementName=TitleBox}" />
|
||||
<ui:TextBox x:Name="TitleBox" Margin="0,0,0,12" PlaceholderText="Optional" />
|
||||
<Label Content="{l:Tr ItemEdit_TitleLabel}" Target="{Binding ElementName=TitleBox}" />
|
||||
<ui:TextBox x:Name="TitleBox" Margin="0,0,0,12" PlaceholderText="{l:Tr ItemEdit_Optional}" />
|
||||
|
||||
<Label x:Name="DurationLabel" Content="_Länge (m:ss)" Target="{Binding ElementName=DurationBox}" />
|
||||
<Label x:Name="DurationLabel" Content="{l:Tr ItemEdit_Length}" Target="{Binding ElementName=DurationBox}" />
|
||||
<ui:TextBox x:Name="DurationBox" />
|
||||
|
||||
<TextBlock x:Name="ErrorText"
|
||||
Margin="0,12,0,0"
|
||||
Foreground="{DynamicResource SystemFillColorCriticalBrush}"
|
||||
Text="Länge als Minuten und Sekunden eingeben, zum Beispiel 5:00."
|
||||
TextWrapping="Wrap"
|
||||
Visibility="Collapsed" />
|
||||
|
||||
<StackPanel Margin="0,24,0,0" HorizontalAlignment="Right" Orientation="Horizontal">
|
||||
<ui:Button Content="Speichern" Appearance="Primary" IsDefault="True" MinWidth="90" Click="OnSave" />
|
||||
<ui:Button Margin="8,0,0,0" Content="Abbrechen" IsCancel="True" MinWidth="90" />
|
||||
<ui:Button x:Name="SaveButton" Content="{l:Tr ItemEdit_Save}" Appearance="Primary" IsDefault="True" MinWidth="90" Click="OnSave" />
|
||||
<ui:Button Margin="8,0,0,0" Content="{l:Tr ItemEdit_Cancel}" IsCancel="True" MinWidth="90" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using Radiosender.Models;
|
||||
using Radiosender.Services.Localization;
|
||||
using Wpf.Ui.Controls;
|
||||
|
||||
namespace Radiosender.Views;
|
||||
@@ -9,14 +10,16 @@ public partial class ScheduleItemEditWindow : FluentWindow
|
||||
{
|
||||
private static readonly string[] DurationFormats = [@"m\:ss", @"mm\:ss"];
|
||||
|
||||
public ScheduleItemEditWindow(ScheduleItem item)
|
||||
// adding: new item, so every kind may set its length.
|
||||
public ScheduleItemEditWindow(ScheduleItem item, bool adding = false)
|
||||
{
|
||||
InitializeComponent();
|
||||
Title = Bar.Title = $"{item.KindName} bearbeiten";
|
||||
Title = Bar.Title = Loc.F(adding ? "ItemEdit_AddTitle" : "ItemEdit_EditTitle", item.KindName);
|
||||
SaveButton.Content = Loc.T(adding ? "Schedule_Add" : "ItemEdit_Save");
|
||||
TitleBox.Text = item.Title;
|
||||
DurationBox.Text = item.Duration.ToString(@"m\:ss");
|
||||
Duration = item.Duration;
|
||||
DurationLabel.IsEnabled = DurationBox.IsEnabled = item.Kind is ScheduleItemKind.News or ScheduleItemKind.Moderator;
|
||||
DurationLabel.IsEnabled = DurationBox.IsEnabled = adding || item.Kind is ScheduleItemKind.News or ScheduleItemKind.Moderator;
|
||||
}
|
||||
|
||||
public string ItemTitle => TitleBox.Text;
|
||||
@@ -30,7 +33,7 @@ public partial class ScheduleItemEditWindow : FluentWindow
|
||||
if (!TimeSpan.TryParseExact(DurationBox.Text.Trim(), DurationFormats, CultureInfo.InvariantCulture, out var duration)
|
||||
|| duration <= TimeSpan.Zero)
|
||||
{
|
||||
ErrorText.Visibility = Visibility.Visible;
|
||||
ErrorPopup.Show(this, Loc.T("Error_InvalidInput"), Loc.T("ItemEdit_LengthError"));
|
||||
return;
|
||||
}
|
||||
Duration = duration;
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
Title="Song bearbeiten"
|
||||
xmlns:l="clr-namespace:Radiosender.Views"
|
||||
Title="{l:Tr SongEdit_Title}"
|
||||
Width="460" SizeToContent="Height"
|
||||
ResizeMode="NoResize"
|
||||
ShowInTaskbar="False"
|
||||
@@ -11,30 +12,25 @@
|
||||
WindowStartupLocation="CenterOwner"
|
||||
FocusManager.FocusedElement="{Binding ElementName=TitleBox}">
|
||||
<StackPanel>
|
||||
<ui:TitleBar Title="Song bearbeiten" ShowMinimize="False" ShowMaximize="False" />
|
||||
<ui:TitleBar Title="{l:Tr SongEdit_Title}" ShowMinimize="False" ShowMaximize="False" />
|
||||
|
||||
<StackPanel Margin="24,8,24,24">
|
||||
<Label Content="_Titel" Target="{Binding ElementName=TitleBox}" />
|
||||
<Label Content="{l:Tr SongEdit_LabelTitle}" Target="{Binding ElementName=TitleBox}" />
|
||||
<ui:TextBox x:Name="TitleBox" Margin="0,0,0,12" />
|
||||
|
||||
<Label Content="_Interpret" Target="{Binding ElementName=ArtistBox}" />
|
||||
<Label Content="{l:Tr SongEdit_LabelArtist}" Target="{Binding ElementName=ArtistBox}" />
|
||||
<ui:TextBox x:Name="ArtistBox" Margin="0,0,0,12" />
|
||||
|
||||
<Label Content="_Lizenz" Target="{Binding ElementName=LicenseBox}" />
|
||||
<ui:TextBox x:Name="LicenseBox" Margin="0,0,0,12" PlaceholderText="Optional, z. B. CC BY 4.0" />
|
||||
<Label Content="{l:Tr SongEdit_LabelLicense}" Target="{Binding ElementName=LicenseBox}" />
|
||||
<ui:TextBox x:Name="LicenseBox" Margin="0,0,0,12" PlaceholderText="{l:Tr SongEdit_LicensePlaceholder}" />
|
||||
|
||||
<Label Content="_Namensnennung" Target="{Binding ElementName=AttributionBox}" />
|
||||
<ui:TextBox x:Name="AttributionBox" PlaceholderText="Optional" />
|
||||
<Label Content="{l:Tr SongEdit_LabelAttribution}" Target="{Binding ElementName=AttributionBox}" />
|
||||
<ui:TextBox x:Name="AttributionBox" PlaceholderText="{l:Tr SongEdit_Optional}" />
|
||||
|
||||
<TextBlock x:Name="ErrorText"
|
||||
Margin="0,12,0,0"
|
||||
Foreground="{DynamicResource SystemFillColorCriticalBrush}"
|
||||
Text="Titel und Interpret sind erforderlich."
|
||||
Visibility="Collapsed" />
|
||||
|
||||
<StackPanel Margin="0,24,0,0" HorizontalAlignment="Right" Orientation="Horizontal">
|
||||
<ui:Button Content="Speichern" Appearance="Primary" IsDefault="True" MinWidth="90" Click="OnSave" />
|
||||
<ui:Button Margin="8,0,0,0" Content="Abbrechen" IsCancel="True" MinWidth="90" />
|
||||
<ui:Button Content="{l:Tr SongEdit_Save}" Appearance="Primary" IsDefault="True" MinWidth="90" Click="OnSave" />
|
||||
<ui:Button Margin="8,0,0,0" Content="{l:Tr Library_Cancel}" IsCancel="True" MinWidth="90" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Windows;
|
||||
using Radiosender.Services.Localization;
|
||||
using Radiosender.Models;
|
||||
using Wpf.Ui.Controls;
|
||||
|
||||
@@ -24,7 +25,7 @@ public partial class SongEditWindow : FluentWindow
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(SongTitle) || string.IsNullOrWhiteSpace(Artist))
|
||||
{
|
||||
ErrorText.Visibility = Visibility.Visible;
|
||||
ErrorPopup.Show(this, Loc.T("Error_InvalidInput"), Loc.T("SongEdit_Required"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -102,13 +102,6 @@ public sealed class MusicPlayerTests : IDisposable
|
||||
Assert.False(MusicPlayer.Instance.IsPlaying);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Volume_OutOfRange_Throws()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => MusicPlayer.Instance.Volume = 1.5f);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => MusicPlayer.Instance.Volume = -0.1f);
|
||||
}
|
||||
|
||||
[AudioDeviceFact]
|
||||
public void Stop_DoesNotRaiseTrackFinished()
|
||||
{
|
||||
|
||||
@@ -100,18 +100,23 @@ public sealed class ScheduleControllerTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StartNow_PlansFromThisMomentAndGoesOnAir()
|
||||
public void PlanFromNow_ShiftsToTheMomentOfTheFirstStart()
|
||||
{
|
||||
AddSongs();
|
||||
var hold = new TaskCompletionSource();
|
||||
var controller = Create((_, token) => hold.Task.WaitAsync(token));
|
||||
var created = controller.CreatePlan(1, _now);
|
||||
Assert.Equal(_now, created[0].Start);
|
||||
Assert.NotEqual(ScheduleItemKind.News, created[0].Kind);
|
||||
Assert.Equal(new DateTime(2026, 11, 23, 16, 0, 0), created[^1].End);
|
||||
|
||||
controller.StartNow(1);
|
||||
_now = _now.AddSeconds(40); // the user waited before pressing Start
|
||||
controller.Start();
|
||||
|
||||
Assert.True(controller.IsPlaying);
|
||||
Assert.Equal(_now, controller.Plan[0].Start);
|
||||
Assert.NotEqual(ScheduleItemKind.News, controller.Plan[0].Kind);
|
||||
Assert.Equal(new DateTime(2026, 11, 23, 16, 0, 0), controller.Plan[^1].End);
|
||||
Assert.Equal(created[^1].End.AddSeconds(40), controller.Plan[^1].End);
|
||||
Assert.Equal(created.Select(i => i.Duration), controller.Plan.Select(i => i.Duration));
|
||||
controller.Stop();
|
||||
}
|
||||
|
||||
@@ -150,6 +155,39 @@ public sealed class ScheduleControllerTests : IDisposable
|
||||
Assert.Throws<ScheduleException>(() => controller.Move(0, -1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Insert_AddsAnyKindAndShiftsTheLaterItems()
|
||||
{
|
||||
AddSongs();
|
||||
var controller = Create();
|
||||
var plan = controller.CreatePlan(1);
|
||||
var song = _songs.GetAll()[0];
|
||||
|
||||
var withAd = controller.Insert(1, ScheduleItemKind.Ad, " Spot ", TimeSpan.FromSeconds(30));
|
||||
var withSong = controller.Insert(withAd.Count, ScheduleItemKind.Song, "", TimeSpan.Zero, song.Id);
|
||||
|
||||
Assert.Equal(plan.Count + 2, withSong.Count);
|
||||
Assert.Equal(new ScheduleItem(ScheduleItemKind.Ad, "Spot", plan[0].End, TimeSpan.FromSeconds(30)), withSong[1]);
|
||||
Assert.Equal(plan[1].Start + TimeSpan.FromSeconds(30), withSong[2].Start);
|
||||
Assert.Equal(ScheduleItemKind.Song, withSong[^1].Kind);
|
||||
Assert.Equal("Artist - Song 0", withSong[^1].Title);
|
||||
Assert.Equal(song.Duration, withSong[^1].Duration);
|
||||
Assert.Equal(withSong[^2].End, withSong[^1].Start);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Insert_RejectsMissingPlanSongAndLength()
|
||||
{
|
||||
AddSongs();
|
||||
var controller = Create();
|
||||
|
||||
Assert.Throws<ScheduleException>(() => controller.Insert(0, ScheduleItemKind.News, "", TimeSpan.FromMinutes(5)));
|
||||
controller.CreatePlan(1);
|
||||
Assert.Throws<ScheduleException>(() => controller.Insert(0, ScheduleItemKind.Moderator, "", TimeSpan.Zero));
|
||||
Assert.Throws<ScheduleException>(() => controller.Insert(0, ScheduleItemKind.Song, "", TimeSpan.Zero, songId: 999));
|
||||
Assert.Throws<ScheduleException>(() => controller.Insert(controller.Plan.Count + 1, ScheduleItemKind.Ad, "", TimeSpan.FromSeconds(30)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Remove_ClosesTheGap()
|
||||
{
|
||||
|
||||
@@ -265,6 +265,8 @@ public class ScheduleGeneratorTests
|
||||
try { swapped = Generator(seed).Replace(plan, index, Request, Library); }
|
||||
catch (ScheduleException) { continue; } // too little time left before the news
|
||||
|
||||
// Also when only the requested song fits: breaks go after it, not before.
|
||||
Assert.Equal(Request, swapped[index].Song);
|
||||
Assert.Equal(plan[^1].End, swapped[^1].End);
|
||||
for (var i = 1; i < swapped.Count; i++)
|
||||
Assert.False(swapped[i - 1].Kind == ScheduleItemKind.Ad && swapped[i].Kind == ScheduleItemKind.Ad,
|
||||
|
||||
Reference in new issue
Block a user