Factories and base class renames

This commit is contained in:
Matt Nadareski
2021-07-12 10:52:50 -07:00
parent 788d10ecd8
commit 29205c953b
7 changed files with 67 additions and 64 deletions

View File

@@ -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

View File

@@ -4,7 +4,7 @@ using ReactiveUI;
namespace RedBookPlayer.Common.Discs
{
public abstract class OpticalDisc : ReactiveObject
public abstract class OpticalDiscBase : ReactiveObject
{
#region Public Fields

View File

@@ -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
/// <param name="loadDataTracks">Load data tracks for playback [CompactDisc only]</param>
/// <param name="autoPlay">True if the image should be playable immediately, false otherwise</param>
/// <returns>Instantiated OpticalDisc, if possible</returns>
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
/// <param name="loadDataTracks">Load data tracks for playback [CompactDisc only]</param>
/// <param name="autoPlay">True if the image should be playable immediately, false otherwise</param>
/// <returns>Instantiated OpticalDisc, if possible</returns>
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))

View File

@@ -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
/// <summary>
/// OpticalDisc object
/// </summary>
private readonly OpticalDisc _opticalDisc;
private readonly OpticalDiscBase _opticalDisc;
/// <summary>
/// Last volume for mute toggling

View File

@@ -68,7 +68,7 @@ namespace RedBookPlayer.Common.Hardware
/// <remarks>
/// TODO: Can we remove the need for a local reference to OpticalDisc?
/// </remarks>
private OpticalDisc _opticalDisc;
private OpticalDiscBase _opticalDisc;
/// <summary>
/// Data provider for sound output
@@ -108,7 +108,7 @@ namespace RedBookPlayer.Common.Hardware
/// <param name="opticalDisc">OpticalDisc to load from</param>
/// <param name="autoPlay">True if playback should begin immediately, false otherwise</param>
/// <param name="defaultVolume">Default volume between 0 and 100 to use when starting playback</param>
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)

View File

@@ -84,45 +84,6 @@ namespace RedBookPlayer.GUI
PlayerViewModel.SetLoadHiddenTracks(App.Settings.PlayHiddenTracks);
}
/// <summary>
/// Generate the digit string to be interpreted by the frontend
/// </summary>
/// <returns>String representing the digits for the frontend</returns>
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)));
}
/// <summary>
/// Load the png image for a given character based on the theme
/// </summary>
@@ -151,21 +112,6 @@ namespace RedBookPlayer.GUI
}
}
/// <summary>
/// Get current sector time, accounting for offsets
/// </summary>
/// <returns>ulong representing the current sector time</returns>
private ulong GetCurrentSectorTime()
{
ulong sectorTime = PlayerViewModel.CurrentSector;
if(PlayerViewModel.SectionStartSector != 0)
sectorTime -= PlayerViewModel.SectionStartSector;
else if (PlayerViewModel.CurrentTrackNumber > 0)
sectorTime += PlayerViewModel.TimeOffset;
return sectorTime;
}
/// <summary>
/// Generate a path selection dialog box
/// </summary>
@@ -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]);

View File

@@ -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
/// <summary>
/// Generate the digit string to be interpreted by the frontend
/// </summary>
/// <returns>String representing the digits for the frontend</returns>
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)));
}
/// <summary>
/// Set the value for loading data tracks [CompactDisc only]
/// </summary>
@@ -433,6 +473,21 @@ namespace RedBookPlayer.GUI.ViewModels
/// <param name="load">True to enable loading hidden tracks, false otherwise</param>
public void SetLoadHiddenTracks(bool load) => _player?.SetLoadHiddenTracks(load);
/// <summary>
/// Get current sector time, accounting for offsets
/// </summary>
/// <returns>ulong representing the current sector time</returns>
private ulong GetCurrentSectorTime()
{
ulong sectorTime = CurrentSector;
if(SectionStartSector != 0)
sectorTime -= SectionStartSector;
else if(CurrentTrackNumber > 0)
sectorTime += TimeOffset;
return sectorTime;
}
/// <summary>
/// Update the view-model from the Player
/// </summary>