diff --git a/RedBookPlayer/Discs/OpticalDisc.cs b/RedBookPlayer/Discs/OpticalDisc.cs
index 831deed..701660a 100644
--- a/RedBookPlayer/Discs/OpticalDisc.cs
+++ b/RedBookPlayer/Discs/OpticalDisc.cs
@@ -31,7 +31,11 @@ namespace RedBookPlayer.Discs
///
/// Represents the sector starting the section
///
- public ulong SectionStartSector { get; protected set; }
+ public ulong SectionStartSector
+ {
+ get => _sectionStartSector;
+ protected set => this.RaiseAndSetIfChanged(ref _sectionStartSector, value);
+ }
///
/// Number of bytes per sector for the current track
@@ -68,6 +72,8 @@ namespace RedBookPlayer.Discs
///
public ulong TotalTime { get; protected set; } = 0;
+ private ulong _sectionStartSector;
+
#endregion
#region Protected State Variables
diff --git a/RedBookPlayer/GUI/PlayerView.xaml.cs b/RedBookPlayer/GUI/PlayerView.xaml.cs
index ec749cb..ac975c3 100644
--- a/RedBookPlayer/GUI/PlayerView.xaml.cs
+++ b/RedBookPlayer/GUI/PlayerView.xaml.cs
@@ -4,7 +4,6 @@ using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
-using System.Timers;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
@@ -25,9 +24,6 @@ namespace RedBookPlayer.GUI
///
/// Set of images representing the digits for the UI
///
- ///
- /// TODO: Does it make sense to have this as an array?
- ///
private Image[] _digits;
public PlayerView() => InitializeComponent(null);
@@ -167,7 +163,7 @@ namespace RedBookPlayer.GUI
{
Dispatcher.UIThread.InvokeAsync(() =>
{
- string digitString = PlayerViewModel.GenerateDigitString();
+ string digitString = GenerateDigitString();
for(int i = 0; i < _digits.Length; i++)
{
if(_digits[i] != null)
@@ -176,6 +172,54 @@ namespace RedBookPlayer.GUI
});
}
+ ///
+ /// 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, '-');
+
+ // Otherwise, take the current time into account
+ ulong sectorTime = GetCurrentSectorTime();
+
+ int[] numbers = new int[]
+ {
+ PlayerViewModel.CurrentTrackNumber + 1,
+ 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)));
+ }
+
+ ///
+ /// 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
+ sectorTime += PlayerViewModel.TimeOffset;
+
+ return sectorTime;
+ }
+
#endregion
#region Event Handlers
diff --git a/RedBookPlayer/GUI/PlayerViewModel.cs b/RedBookPlayer/GUI/PlayerViewModel.cs
index 467895b..654d3cd 100644
--- a/RedBookPlayer/GUI/PlayerViewModel.cs
+++ b/RedBookPlayer/GUI/PlayerViewModel.cs
@@ -1,5 +1,4 @@
using System.ComponentModel;
-using System.Linq;
using ReactiveUI;
using RedBookPlayer.Hardware;
@@ -48,6 +47,15 @@ namespace RedBookPlayer.GUI
private set => this.RaiseAndSetIfChanged(ref _currentSector, value);
}
+ ///
+ /// Represents the sector starting the section
+ ///
+ public ulong SectionStartSector
+ {
+ get => _sectionStartSector;
+ protected set => this.RaiseAndSetIfChanged(ref _sectionStartSector, value);
+ }
+
///
/// Represents if the disc has a hidden track
///
@@ -121,6 +129,7 @@ namespace RedBookPlayer.GUI
private int _currentTrackNumber;
private ushort _currentTrackIndex;
private ulong _currentSector;
+ private ulong _sectionStartSector;
private bool _hasHiddenTrack;
private bool _quadChannel;
@@ -245,42 +254,6 @@ namespace RedBookPlayer.GUI
#region Helpers
- ///
- /// Generate the digit string to be interpreted by the frontend
- ///
- /// String representing the digits for the frontend
- ///
- /// TODO: The model shouldn't care about this
- ///
- public string GenerateDigitString()
- {
- // If the disc isn't initialized, return all '-' characters
- if(_player?.Initialized != true)
- return string.Empty.PadLeft(20, '-');
-
- // Otherwise, take the current time into account
- ulong sectorTime = _player.GetCurrentSectorTime();
-
- int[] numbers = new int[]
- {
- _player.CurrentTrackNumber + 1,
- _player.CurrentTrackIndex,
-
- (int)(sectorTime / (75 * 60)),
- (int)(sectorTime / 75 % 60),
- (int)(sectorTime % 75),
-
- _player.TotalTracks,
- _player.TotalIndexes,
-
- (int)(_player.TotalTime / (75 * 60)),
- (int)(_player.TotalTime / 75 % 60),
- (int)(_player.TotalTime % 75),
- };
-
- return string.Join("", numbers.Select(i => i.ToString().PadLeft(2, '0').Substring(0, 2)));
- }
-
///
/// Set de-emphasis status
///
diff --git a/RedBookPlayer/Hardware/Player.cs b/RedBookPlayer/Hardware/Player.cs
index 746729c..870200e 100644
--- a/RedBookPlayer/Hardware/Player.cs
+++ b/RedBookPlayer/Hardware/Player.cs
@@ -42,6 +42,15 @@ namespace RedBookPlayer.Hardware
private set => this.RaiseAndSetIfChanged(ref _currentSector, value);
}
+ ///
+ /// Represents the sector starting the section
+ ///
+ public ulong SectionStartSector
+ {
+ get => _sectionStartSector;
+ protected set => this.RaiseAndSetIfChanged(ref _sectionStartSector, value);
+ }
+
///
/// Represents if the disc has a hidden track
///
@@ -115,6 +124,7 @@ namespace RedBookPlayer.Hardware
private int _currentTrackNumber;
private ushort _currentTrackIndex;
private ulong _currentSector;
+ private ulong _sectionStartSector;
private bool _hasHiddenTrack;
private bool _quadChannel;
@@ -371,21 +381,6 @@ namespace RedBookPlayer.Hardware
#region Helpers
- ///
- /// Get current sector time, accounting for offsets
- ///
- /// ulong representing the current sector time
- public ulong GetCurrentSectorTime()
- {
- ulong sectorTime = _opticalDisc.CurrentSector;
- if (_opticalDisc.SectionStartSector != 0)
- sectorTime -= _opticalDisc.SectionStartSector;
- else
- sectorTime += _opticalDisc.TimeOffset;
-
- return sectorTime;
- }
-
///
/// Set de-emphasis status
///
@@ -415,6 +410,7 @@ namespace RedBookPlayer.Hardware
CurrentTrackNumber = _opticalDisc.CurrentTrackNumber;
CurrentTrackIndex = _opticalDisc.CurrentTrackIndex;
CurrentSector = _opticalDisc.CurrentSector;
+ SectionStartSector = _opticalDisc.SectionStartSector;
HiddenTrack = TimeOffset > 150;