diff --git a/RedBookPlayer.Common/Discs/CompactDisc.cs b/RedBookPlayer.Common/Discs/CompactDisc.cs index 3338839..0fe5311 100644 --- a/RedBookPlayer.Common/Discs/CompactDisc.cs +++ b/RedBookPlayer.Common/Discs/CompactDisc.cs @@ -11,7 +11,7 @@ using static Aaru.Decoders.CD.FullTOC; namespace RedBookPlayer.Common.Discs { - public class CompactDisc : OpticalDisc, IReactiveObject + public class CompactDisc : OpticalDiscBase, IReactiveObject { #region Public Fields diff --git a/RedBookPlayer.Common/Discs/OpticalDisc.cs b/RedBookPlayer.Common/Discs/OpticalDiscBase.cs similarity index 98% rename from RedBookPlayer.Common/Discs/OpticalDisc.cs rename to RedBookPlayer.Common/Discs/OpticalDiscBase.cs index b522574..0a0ab60 100644 --- a/RedBookPlayer.Common/Discs/OpticalDisc.cs +++ b/RedBookPlayer.Common/Discs/OpticalDiscBase.cs @@ -4,7 +4,7 @@ using ReactiveUI; namespace RedBookPlayer.Common.Discs { - public abstract class OpticalDisc : ReactiveObject + public abstract class OpticalDiscBase : ReactiveObject { #region Public Fields diff --git a/RedBookPlayer.Common/Discs/OpticalDiscFactory.cs b/RedBookPlayer.Common/Factories/OpticalDiscFactory.cs similarity index 91% rename from RedBookPlayer.Common/Discs/OpticalDiscFactory.cs rename to RedBookPlayer.Common/Factories/OpticalDiscFactory.cs index 52ad9d8..b4f290c 100644 --- a/RedBookPlayer.Common/Discs/OpticalDiscFactory.cs +++ b/RedBookPlayer.Common/Factories/OpticalDiscFactory.cs @@ -3,8 +3,9 @@ using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Metadata; using Aaru.DiscImages; using Aaru.Filters; +using RedBookPlayer.Common.Discs; -namespace RedBookPlayer.Common.Discs +namespace RedBookPlayer.Common.Factories { public static class OpticalDiscFactory { @@ -17,7 +18,7 @@ namespace RedBookPlayer.Common.Discs /// Load data tracks for playback [CompactDisc only] /// True if the image should be playable immediately, false otherwise /// Instantiated OpticalDisc, if possible - public static OpticalDisc GenerateFromPath(string path, bool generateMissingToc, bool loadHiddenTracks, bool loadDataTracks, bool autoPlay) + public static OpticalDiscBase GenerateFromPath(string path, bool generateMissingToc, bool loadHiddenTracks, bool loadDataTracks, bool autoPlay) { try { @@ -51,14 +52,14 @@ namespace RedBookPlayer.Common.Discs /// Load data tracks for playback [CompactDisc only] /// True if the image should be playable immediately, false otherwise /// Instantiated OpticalDisc, if possible - public static OpticalDisc GenerateFromImage(IOpticalMediaImage image, bool generateMissingToc, bool loadHiddenTracks, bool loadDataTracks, bool autoPlay) + public static OpticalDiscBase GenerateFromImage(IOpticalMediaImage image, bool generateMissingToc, bool loadHiddenTracks, bool loadDataTracks, bool autoPlay) { // If the image is not usable, we don't do anything if(!IsUsableImage(image)) return null; // Create the output object - OpticalDisc opticalDisc; + OpticalDiscBase opticalDisc; // Create the proper disc type switch(GetMediaType(image)) diff --git a/RedBookPlayer.Common/Hardware/Player.cs b/RedBookPlayer.Common/Hardware/Player.cs index 8c4c256..4cf76d2 100644 --- a/RedBookPlayer.Common/Hardware/Player.cs +++ b/RedBookPlayer.Common/Hardware/Player.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using Aaru.CommonTypes.Enums; using ReactiveUI; using RedBookPlayer.Common.Discs; +using RedBookPlayer.Common.Factories; namespace RedBookPlayer.Common.Hardware { @@ -179,7 +180,7 @@ namespace RedBookPlayer.Common.Hardware /// /// OpticalDisc object /// - private readonly OpticalDisc _opticalDisc; + private readonly OpticalDiscBase _opticalDisc; /// /// Last volume for mute toggling diff --git a/RedBookPlayer.Common/Hardware/SoundOutput.cs b/RedBookPlayer.Common/Hardware/SoundOutput.cs index b460cee..89f2b8c 100644 --- a/RedBookPlayer.Common/Hardware/SoundOutput.cs +++ b/RedBookPlayer.Common/Hardware/SoundOutput.cs @@ -68,7 +68,7 @@ namespace RedBookPlayer.Common.Hardware /// /// TODO: Can we remove the need for a local reference to OpticalDisc? /// - private OpticalDisc _opticalDisc; + private OpticalDiscBase _opticalDisc; /// /// Data provider for sound output @@ -108,7 +108,7 @@ namespace RedBookPlayer.Common.Hardware /// OpticalDisc to load from /// True if playback should begin immediately, false otherwise /// Default volume between 0 and 100 to use when starting playback - public void Init(OpticalDisc opticalDisc, bool autoPlay = false, int defaultVolume = 100) + public void Init(OpticalDiscBase opticalDisc, bool autoPlay = false, int defaultVolume = 100) { // If we have an unusable disc, just return if(opticalDisc == null || !opticalDisc.Initialized) diff --git a/RedBookPlayer.GUI/PlayerView.xaml.cs b/RedBookPlayer.GUI/PlayerView.xaml.cs index d2af50e..a1b763b 100644 --- a/RedBookPlayer.GUI/PlayerView.xaml.cs +++ b/RedBookPlayer.GUI/PlayerView.xaml.cs @@ -84,45 +84,6 @@ namespace RedBookPlayer.GUI PlayerViewModel.SetLoadHiddenTracks(App.Settings.PlayHiddenTracks); } - /// - /// Generate the digit string to be interpreted by the frontend - /// - /// String representing the digits for the frontend - private string GenerateDigitString() - { - // If the disc isn't initialized, return all '-' characters - if(PlayerViewModel?.Initialized != true) - return string.Empty.PadLeft(20, '-'); - - int usableTrackNumber = PlayerViewModel.CurrentTrackNumber; - if(usableTrackNumber < 0) - usableTrackNumber = 0; - else if(usableTrackNumber > 99) - usableTrackNumber = 99; - - // Otherwise, take the current time into account - ulong sectorTime = GetCurrentSectorTime(); - - int[] numbers = new int[] - { - usableTrackNumber, - PlayerViewModel.CurrentTrackIndex, - - (int)(sectorTime / (75 * 60)), - (int)(sectorTime / 75 % 60), - (int)(sectorTime % 75), - - PlayerViewModel.TotalTracks, - PlayerViewModel.TotalIndexes, - - (int)(PlayerViewModel.TotalTime / (75 * 60)), - (int)(PlayerViewModel.TotalTime / 75 % 60), - (int)(PlayerViewModel.TotalTime % 75), - }; - - return string.Join("", numbers.Select(i => i.ToString().PadLeft(2, '0').Substring(0, 2))); - } - /// /// Load the png image for a given character based on the theme /// @@ -151,21 +112,6 @@ namespace RedBookPlayer.GUI } } - /// - /// Get current sector time, accounting for offsets - /// - /// ulong representing the current sector time - private ulong GetCurrentSectorTime() - { - ulong sectorTime = PlayerViewModel.CurrentSector; - if(PlayerViewModel.SectionStartSector != 0) - sectorTime -= PlayerViewModel.SectionStartSector; - else if (PlayerViewModel.CurrentTrackNumber > 0) - sectorTime += PlayerViewModel.TimeOffset; - - return sectorTime; - } - /// /// Generate a path selection dialog box /// @@ -244,7 +190,7 @@ namespace RedBookPlayer.GUI { Dispatcher.UIThread.InvokeAsync(() => { - string digitString = GenerateDigitString(); + string digitString = PlayerViewModel?.GenerateDigitString() ?? string.Empty.PadLeft(20, '-'); for(int i = 0; i < _digits.Length; i++) { Bitmap digitImage = GetBitmap(digitString[i]); diff --git a/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs b/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs index 2c9d466..a5cad4a 100644 --- a/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs +++ b/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.Linq; using System.Reactive; using ReactiveUI; using RedBookPlayer.Common.Hardware; @@ -421,6 +422,45 @@ namespace RedBookPlayer.GUI.ViewModels #region Helpers + /// + /// Generate the digit string to be interpreted by the frontend + /// + /// String representing the digits for the frontend + public string GenerateDigitString() + { + // If the disc isn't initialized, return all '-' characters + if(Initialized != true) + return string.Empty.PadLeft(20, '-'); + + int usableTrackNumber = CurrentTrackNumber; + if(usableTrackNumber < 0) + usableTrackNumber = 0; + else if(usableTrackNumber > 99) + usableTrackNumber = 99; + + // Otherwise, take the current time into account + ulong sectorTime = GetCurrentSectorTime(); + + int[] numbers = new int[] + { + usableTrackNumber, + CurrentTrackIndex, + + (int)(sectorTime / (75 * 60)), + (int)(sectorTime / 75 % 60), + (int)(sectorTime % 75), + + TotalTracks, + TotalIndexes, + + (int)(TotalTime / (75 * 60)), + (int)(TotalTime / 75 % 60), + (int)(TotalTime % 75), + }; + + return string.Join("", numbers.Select(i => i.ToString().PadLeft(2, '0').Substring(0, 2))); + } + /// /// Set the value for loading data tracks [CompactDisc only] /// @@ -433,6 +473,21 @@ namespace RedBookPlayer.GUI.ViewModels /// True to enable loading hidden tracks, false otherwise public void SetLoadHiddenTracks(bool load) => _player?.SetLoadHiddenTracks(load); + /// + /// Get current sector time, accounting for offsets + /// + /// ulong representing the current sector time + private ulong GetCurrentSectorTime() + { + ulong sectorTime = CurrentSector; + if(SectionStartSector != 0) + sectorTime -= SectionStartSector; + else if(CurrentTrackNumber > 0) + sectorTime += TimeOffset; + + return sectorTime; + } + /// /// Update the view-model from the Player ///