48 lines
2.0 KiB
C#
48 lines
2.0 KiB
C#
using RemSound.Core;
|
|||
|
|
|
||
|
|
namespace RemSound.App;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Plays a short cue whenever the user switches between tabs anywhere in RemSound - the main
|
||
|
|
/// window's tab strip and every tabbed dialog (Preferences, Recording settings, ...). Fired from
|
||
|
|
/// <see cref="QuietTabControl"/> on a selection change, gated on the tab control actually containing
|
||
|
|
/// focus, so a genuine user switch (arrow keys / Ctrl+Tab) clicks but the programmatic selection
|
||
|
|
/// done while building or restoring a window stays silent.
|
||
|
|
///
|
||
|
|
/// Machine-wide cue (<see cref="AppConfig.EnableTabSwitchCue"/>), shipped as numbered variants
|
||
|
|
/// ("tab switch 1.wav", ...) and configured in Preferences exactly like the other cues. Default on.
|
||
|
|
/// </summary>
|
||
|
|
internal static class TabSwitchSoundService
|
||
|
|
{
|
||
|
|
private static CuePlayer? switchSound;
|
||
|
|
|
||
|
|
/// <summary>When true, <see cref="Play"/> is a no-op. Reserved for bulk programmatic tab changes
|
||
|
|
/// the focus gate doesn't already cover; mirrors <see cref="CheckSoundService.Suppressed"/>.</summary>
|
||
|
|
public static bool Suppressed { get; set; }
|
||
|
|
|
||
|
|
/// <summary>(Re)load the cue from the current cue configuration. Call at startup and whenever cue
|
||
|
|
/// settings change, alongside <see cref="CheckSoundService.Reload"/>.</summary>
|
||
|
|
public static void Reload()
|
||
|
|
{
|
||
|
|
switchSound = LoadCue(MainForm.CueId.TabSwitch, "tab switch.wav", AppConfig.Load());
|
||
|
|
}
|
||
|
|
|
||
|
|
public static void Play()
|
||
|
|
{
|
||
|
|
if (Suppressed) return;
|
||
|
|
if (AppConfig.Load().EnableTabSwitchCue) switchSound?.Play();
|
||
|
|
}
|
||
|
|
|
||
|
|
private static CuePlayer? LoadCue(string cueId, string defaultFile, AppConfig cfg)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
string? path = cfg.MachineCueCustomPaths.TryGetValue(cueId, out var custom) && File.Exists(custom)
|
||
|
|
? custom
|
||
|
|
: CueSounds.ResolveDefaultPath(cueId, defaultFile, cfg);
|
||
|
|
return path is not null && File.Exists(path) ? new CuePlayer(path) : null;
|
||
|
|
}
|
||
|
|
catch { return null; }
|
||
|
|
}
|
||
|
|
}
|