mirror of
https://github.com/aaru-dps/RedBookPlayer.git
synced 2025-12-16 19:24:41 +00:00
Factories and base class renames
This commit is contained in:
@@ -11,7 +11,7 @@ using static Aaru.Decoders.CD.FullTOC;
|
|||||||
|
|
||||||
namespace RedBookPlayer.Common.Discs
|
namespace RedBookPlayer.Common.Discs
|
||||||
{
|
{
|
||||||
public class CompactDisc : OpticalDisc, IReactiveObject
|
public class CompactDisc : OpticalDiscBase, IReactiveObject
|
||||||
{
|
{
|
||||||
#region Public Fields
|
#region Public Fields
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using ReactiveUI;
|
|||||||
|
|
||||||
namespace RedBookPlayer.Common.Discs
|
namespace RedBookPlayer.Common.Discs
|
||||||
{
|
{
|
||||||
public abstract class OpticalDisc : ReactiveObject
|
public abstract class OpticalDiscBase : ReactiveObject
|
||||||
{
|
{
|
||||||
#region Public Fields
|
#region Public Fields
|
||||||
|
|
||||||
@@ -3,8 +3,9 @@ using Aaru.CommonTypes.Interfaces;
|
|||||||
using Aaru.CommonTypes.Metadata;
|
using Aaru.CommonTypes.Metadata;
|
||||||
using Aaru.DiscImages;
|
using Aaru.DiscImages;
|
||||||
using Aaru.Filters;
|
using Aaru.Filters;
|
||||||
|
using RedBookPlayer.Common.Discs;
|
||||||
|
|
||||||
namespace RedBookPlayer.Common.Discs
|
namespace RedBookPlayer.Common.Factories
|
||||||
{
|
{
|
||||||
public static class OpticalDiscFactory
|
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="loadDataTracks">Load data tracks for playback [CompactDisc only]</param>
|
||||||
/// <param name="autoPlay">True if the image should be playable immediately, false otherwise</param>
|
/// <param name="autoPlay">True if the image should be playable immediately, false otherwise</param>
|
||||||
/// <returns>Instantiated OpticalDisc, if possible</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -51,14 +52,14 @@ namespace RedBookPlayer.Common.Discs
|
|||||||
/// <param name="loadDataTracks">Load data tracks for playback [CompactDisc only]</param>
|
/// <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>
|
/// <param name="autoPlay">True if the image should be playable immediately, false otherwise</param>
|
||||||
/// <returns>Instantiated OpticalDisc, if possible</returns>
|
/// <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 the image is not usable, we don't do anything
|
||||||
if(!IsUsableImage(image))
|
if(!IsUsableImage(image))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// Create the output object
|
// Create the output object
|
||||||
OpticalDisc opticalDisc;
|
OpticalDiscBase opticalDisc;
|
||||||
|
|
||||||
// Create the proper disc type
|
// Create the proper disc type
|
||||||
switch(GetMediaType(image))
|
switch(GetMediaType(image))
|
||||||
@@ -3,6 +3,7 @@ using System.ComponentModel;
|
|||||||
using Aaru.CommonTypes.Enums;
|
using Aaru.CommonTypes.Enums;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using RedBookPlayer.Common.Discs;
|
using RedBookPlayer.Common.Discs;
|
||||||
|
using RedBookPlayer.Common.Factories;
|
||||||
|
|
||||||
namespace RedBookPlayer.Common.Hardware
|
namespace RedBookPlayer.Common.Hardware
|
||||||
{
|
{
|
||||||
@@ -179,7 +180,7 @@ namespace RedBookPlayer.Common.Hardware
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// OpticalDisc object
|
/// OpticalDisc object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly OpticalDisc _opticalDisc;
|
private readonly OpticalDiscBase _opticalDisc;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Last volume for mute toggling
|
/// Last volume for mute toggling
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ namespace RedBookPlayer.Common.Hardware
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// TODO: Can we remove the need for a local reference to OpticalDisc?
|
/// TODO: Can we remove the need for a local reference to OpticalDisc?
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
private OpticalDisc _opticalDisc;
|
private OpticalDiscBase _opticalDisc;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Data provider for sound output
|
/// Data provider for sound output
|
||||||
@@ -108,7 +108,7 @@ namespace RedBookPlayer.Common.Hardware
|
|||||||
/// <param name="opticalDisc">OpticalDisc to load from</param>
|
/// <param name="opticalDisc">OpticalDisc to load from</param>
|
||||||
/// <param name="autoPlay">True if playback should begin immediately, false otherwise</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>
|
/// <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 we have an unusable disc, just return
|
||||||
if(opticalDisc == null || !opticalDisc.Initialized)
|
if(opticalDisc == null || !opticalDisc.Initialized)
|
||||||
|
|||||||
@@ -84,45 +84,6 @@ namespace RedBookPlayer.GUI
|
|||||||
PlayerViewModel.SetLoadHiddenTracks(App.Settings.PlayHiddenTracks);
|
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>
|
/// <summary>
|
||||||
/// Load the png image for a given character based on the theme
|
/// Load the png image for a given character based on the theme
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Generate a path selection dialog box
|
/// Generate a path selection dialog box
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -244,7 +190,7 @@ namespace RedBookPlayer.GUI
|
|||||||
{
|
{
|
||||||
Dispatcher.UIThread.InvokeAsync(() =>
|
Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
{
|
{
|
||||||
string digitString = GenerateDigitString();
|
string digitString = PlayerViewModel?.GenerateDigitString() ?? string.Empty.PadLeft(20, '-');
|
||||||
for(int i = 0; i < _digits.Length; i++)
|
for(int i = 0; i < _digits.Length; i++)
|
||||||
{
|
{
|
||||||
Bitmap digitImage = GetBitmap(digitString[i]);
|
Bitmap digitImage = GetBitmap(digitString[i]);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
using System.Reactive;
|
using System.Reactive;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using RedBookPlayer.Common.Hardware;
|
using RedBookPlayer.Common.Hardware;
|
||||||
@@ -421,6 +422,45 @@ namespace RedBookPlayer.GUI.ViewModels
|
|||||||
|
|
||||||
#region Helpers
|
#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>
|
/// <summary>
|
||||||
/// Set the value for loading data tracks [CompactDisc only]
|
/// Set the value for loading data tracks [CompactDisc only]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -433,6 +473,21 @@ namespace RedBookPlayer.GUI.ViewModels
|
|||||||
/// <param name="load">True to enable loading hidden tracks, false otherwise</param>
|
/// <param name="load">True to enable loading hidden tracks, false otherwise</param>
|
||||||
public void SetLoadHiddenTracks(bool load) => _player?.SetLoadHiddenTracks(load);
|
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>
|
/// <summary>
|
||||||
/// Update the view-model from the Player
|
/// Update the view-model from the Player
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user