From 05875b919c77d68fcd0db247e202bfd22273e4bf Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 5 Oct 2021 22:52:12 -0700 Subject: [PATCH] Separate out disc handling --- .../ViewModels/PlayerViewModel.cs | 8 ++ .../ViewModels/SettingsViewModel.cs | 18 ++- RedBookPlayer.GUI/Views/SettingsWindow.xaml | 5 + RedBookPlayer.Models/Enums.cs | 26 +++- RedBookPlayer.Models/Hardware/Player.cs | 131 ++++++++++-------- .../Hardware/PlayerOptions.cs | 5 + 6 files changed, 130 insertions(+), 63 deletions(-) diff --git a/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs b/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs index 4f7afd3..f8a7b31 100644 --- a/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs +++ b/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs @@ -656,6 +656,7 @@ namespace RedBookPlayer.GUI.ViewModels PlayerOptions playerOptions = new PlayerOptions { DataPlayback = App.Settings.DataPlayback, + DiscHandling = App.Settings.DiscHandling, LoadHiddenTracks = App.Settings.PlayHiddenTracks, RepeatMode = App.Settings.RepeatMode, SessionHandling = App.Settings.SessionHandling, @@ -684,6 +685,7 @@ namespace RedBookPlayer.GUI.ViewModels public void RefreshFromSettings() { SetDataPlayback(App.Settings.DataPlayback); + SetDiscHandling(App.Settings.DiscHandling); SetLoadHiddenTracks(App.Settings.PlayHiddenTracks); SetRepeatMode(App.Settings.RepeatMode); SetSessionHandling(App.Settings.SessionHandling); @@ -727,6 +729,12 @@ namespace RedBookPlayer.GUI.ViewModels /// New playback value public void SetDataPlayback(DataPlayback dataPlayback) => _player?.SetDataPlayback(dataPlayback); + /// + /// Set disc handling method + /// + /// New playback value + public void SetDiscHandling(DiscHandling discHandling) => _player?.SetDiscHandling(discHandling); + /// /// Set the value for loading hidden tracks [CompactDisc only] /// diff --git a/RedBookPlayer.GUI/ViewModels/SettingsViewModel.cs b/RedBookPlayer.GUI/ViewModels/SettingsViewModel.cs index 178273f..e51125d 100644 --- a/RedBookPlayer.GUI/ViewModels/SettingsViewModel.cs +++ b/RedBookPlayer.GUI/ViewModels/SettingsViewModel.cs @@ -21,6 +21,12 @@ namespace RedBookPlayer.GUI.ViewModels [JsonIgnore] public List DataPlaybackValues => GenerateDataPlaybackList(); + /// + /// List of all disc handling values + /// + [JsonIgnore] + public List DiscHandlingValues => GenerateDiscHandlingList(); + /// /// List of all repeat mode values /// @@ -49,6 +55,11 @@ namespace RedBookPlayer.GUI.ViewModels /// public int NumberOfDiscs { get; set; } = 1; + /// + /// Indicates how to deal with multiple discs + /// + public DiscHandling DiscHandling { get; set; } = DiscHandling.SingleDisc; + /// /// Indicates if an index change can trigger a track change /// @@ -77,7 +88,7 @@ namespace RedBookPlayer.GUI.ViewModels /// /// Indicates how to repeat tracks /// - public RepeatMode RepeatMode { get; set; } = RepeatMode.AllSingleDisc; + public RepeatMode RepeatMode { get; set; } = RepeatMode.All; /// /// Indicates how to handle tracks on different sessions @@ -290,6 +301,11 @@ namespace RedBookPlayer.GUI.ViewModels /// private List GenerateDataPlaybackList() => Enum.GetValues(typeof(DataPlayback)).Cast().ToList(); + /// + /// Generate the list of DiscHandling values + /// + private List GenerateDiscHandlingList() => Enum.GetValues(typeof(DiscHandling)).Cast().ToList(); + /// /// Generate the list of Key values /// diff --git a/RedBookPlayer.GUI/Views/SettingsWindow.xaml b/RedBookPlayer.GUI/Views/SettingsWindow.xaml index dad4f79..b348de8 100644 --- a/RedBookPlayer.GUI/Views/SettingsWindow.xaml +++ b/RedBookPlayer.GUI/Views/SettingsWindow.xaml @@ -45,6 +45,11 @@ + + Disc Handling + + Generate a TOC if the disc is missing one diff --git a/RedBookPlayer.Models/Enums.cs b/RedBookPlayer.Models/Enums.cs index a94aae9..5619e11 100644 --- a/RedBookPlayer.Models/Enums.cs +++ b/RedBookPlayer.Models/Enums.cs @@ -21,6 +21,23 @@ namespace RedBookPlayer.Models Play = 2, } + /// + /// Determine how to handle multiple discs + /// + /// Used with both repeat and shuffle + public enum DiscHandling + { + /// + /// Only deal with tracks on the current disc + /// + SingleDisc = 0, + + /// + /// Deal with tracks on all loaded discs + /// + MultiDisc = 1, + } + /// /// Current player state /// @@ -63,14 +80,9 @@ namespace RedBookPlayer.Models Single, /// - /// Repeat all tracks on a single disc + /// Repeat all tracks /// - AllSingleDisc, - - /// - /// Repeat all tracks on a multiple discs - /// - AllMultiDisc, + All, } /// diff --git a/RedBookPlayer.Models/Hardware/Player.cs b/RedBookPlayer.Models/Hardware/Player.cs index 4e26d8c..eed7163 100644 --- a/RedBookPlayer.Models/Hardware/Player.cs +++ b/RedBookPlayer.Models/Hardware/Player.cs @@ -22,6 +22,8 @@ namespace RedBookPlayer.Models.Hardware private set => this.RaiseAndSetIfChanged(ref _initialized, value); } + #region Playback Passthrough + /// /// Currently selected disc /// @@ -40,6 +42,60 @@ namespace RedBookPlayer.Models.Hardware } } + /// + /// Indicates how to deal with multiple discs + /// + public DiscHandling DiscHandling + { + get => _discHandling; + private set => this.RaiseAndSetIfChanged(ref _discHandling, value); + } + + /// + /// Indicates how to handle playback of data tracks + /// + public DataPlayback DataPlayback + { + get => _dataPlayback; + private set => this.RaiseAndSetIfChanged(ref _dataPlayback, value); + } + + /// + /// Indicate if hidden tracks should be loaded + /// + public bool LoadHiddenTracks + { + get => _loadHiddenTracks; + private set => this.RaiseAndSetIfChanged(ref _loadHiddenTracks, value); + } + + /// + /// Indicates the repeat mode + /// + public RepeatMode RepeatMode + { + get => _repeatMode; + private set => this.RaiseAndSetIfChanged(ref _repeatMode, value); + } + + /// + /// Indicates how tracks on different session should be handled + /// + public SessionHandling SessionHandling + { + get => _sessionHandling; + private set => this.RaiseAndSetIfChanged(ref _sessionHandling, value); + } + + /// + /// Indicates if de-emphasis should be applied + /// + public bool ApplyDeEmphasis + { + get => _applyDeEmphasis; + private set => this.RaiseAndSetIfChanged(ref _applyDeEmphasis, value); + } + /// /// Should invoke playback mode changes /// @@ -52,8 +108,16 @@ namespace RedBookPlayer.Models.Hardware private bool _initialized; private int _numberOfDiscs; private int _currentDisc; + private DiscHandling _discHandling; + private bool _loadHiddenTracks; + private DataPlayback _dataPlayback; + private RepeatMode _repeatMode; + private SessionHandling _sessionHandling; + private bool _applyDeEmphasis; private bool _shouldInvokePlaybackModes; + #endregion + #region OpticalDisc Passthrough /// @@ -206,51 +270,6 @@ namespace RedBookPlayer.Models.Hardware private set => this.RaiseAndSetIfChanged(ref _playerState, value); } - /// - /// Indicates how to handle playback of data tracks - /// - public DataPlayback DataPlayback - { - get => _dataPlayback; - private set => this.RaiseAndSetIfChanged(ref _dataPlayback, value); - } - - /// - /// Indicate if hidden tracks should be loaded - /// - public bool LoadHiddenTracks - { - get => _loadHiddenTracks; - private set => this.RaiseAndSetIfChanged(ref _loadHiddenTracks, value); - } - - /// - /// Indicates the repeat mode - /// - public RepeatMode RepeatMode - { - get => _repeatMode; - private set => this.RaiseAndSetIfChanged(ref _repeatMode, value); - } - - /// - /// Indicates how tracks on different session should be handled - /// - public SessionHandling SessionHandling - { - get => _sessionHandling; - private set => this.RaiseAndSetIfChanged(ref _sessionHandling, value); - } - - /// - /// Indicates if de-emphasis should be applied - /// - public bool ApplyDeEmphasis - { - get => _applyDeEmphasis; - private set => this.RaiseAndSetIfChanged(ref _applyDeEmphasis, value); - } - /// /// Current playback volume /// @@ -261,11 +280,6 @@ namespace RedBookPlayer.Models.Hardware } private PlayerState _playerState; - private DataPlayback _dataPlayback; - private bool _loadHiddenTracks; - private RepeatMode _repeatMode; - private SessionHandling _sessionHandling; - private bool _applyDeEmphasis; private int _volume; #endregion @@ -340,6 +354,7 @@ namespace RedBookPlayer.Models.Hardware // Set player options DataPlayback = playerOptions.DataPlayback; + DiscHandling = playerOptions.DiscHandling; LoadHiddenTracks = playerOptions.LoadHiddenTracks; RepeatMode = playerOptions.RepeatMode; SessionHandling = playerOptions.SessionHandling; @@ -710,7 +725,7 @@ namespace RedBookPlayer.Models.Hardware int cachedTrackNumber; // Take care of disc switching first - if(RepeatMode == RepeatMode.AllMultiDisc) + if(DiscHandling == DiscHandling.MultiDisc) { if(trackNumber > (int)compactDisc.Tracks.Max(t => t.TrackSequence)) { @@ -800,7 +815,7 @@ namespace RedBookPlayer.Models.Hardware { if(trackNumber >= _opticalDiscs[CurrentDisc].TotalTracks) { - if(RepeatMode == RepeatMode.AllMultiDisc) + if(DiscHandling == DiscHandling.MultiDisc) { do { @@ -813,7 +828,7 @@ namespace RedBookPlayer.Models.Hardware } else if(trackNumber < 1) { - if(RepeatMode == RepeatMode.AllMultiDisc) + if(DiscHandling == DiscHandling.MultiDisc) { do { @@ -1043,6 +1058,12 @@ namespace RedBookPlayer.Models.Hardware /// New playback value public void SetDataPlayback(DataPlayback dataPlayback) => DataPlayback = dataPlayback; + /// + /// Set disc handling method + /// + /// New playback value + public void SetDiscHandling(DiscHandling discHandling) => DiscHandling = discHandling; + /// /// Set the value for loading hidden tracks [CompactDisc only] /// @@ -1085,10 +1106,10 @@ namespace RedBookPlayer.Models.Hardware case RepeatMode.Single: _opticalDiscs[CurrentDisc].LoadTrack(CurrentTrackNumber); break; - case RepeatMode.AllSingleDisc: + case RepeatMode.All when DiscHandling == DiscHandling.SingleDisc: SelectTrack(1); break; - case RepeatMode.AllMultiDisc: + case RepeatMode.All when DiscHandling == DiscHandling.MultiDisc: do { NextDisc(); diff --git a/RedBookPlayer.Models/Hardware/PlayerOptions.cs b/RedBookPlayer.Models/Hardware/PlayerOptions.cs index 43a0cbd..d65170d 100644 --- a/RedBookPlayer.Models/Hardware/PlayerOptions.cs +++ b/RedBookPlayer.Models/Hardware/PlayerOptions.cs @@ -7,6 +7,11 @@ namespace RedBookPlayer.Models.Discs /// public DataPlayback DataPlayback { get; set; } = DataPlayback.Skip; + /// + /// Indicates how to deal with multiple discs + /// + public DiscHandling DiscHandling { get; set; } = DiscHandling.SingleDisc; + /// /// Indicate if hidden tracks should be loaded ///