diff --git a/RedBookPlayer/GUI/PlayerViewModel.cs b/RedBookPlayer/GUI/PlayerViewModel.cs index 6910ecd..bd285fb 100644 --- a/RedBookPlayer/GUI/PlayerViewModel.cs +++ b/RedBookPlayer/GUI/PlayerViewModel.cs @@ -4,6 +4,37 @@ namespace RedBookPlayer.GUI { public class PlayerViewModel : ReactiveObject { + #region Player Status + + private bool _playing; + public bool Playing + { + get => _playing; + set => this.RaiseAndSetIfChanged(ref _playing, value); + } + + private ulong _currentSector; + public ulong CurrentSector + { + get => _currentSector; + set => this.RaiseAndSetIfChanged(ref _currentSector, value); + } + + public int CurrentFrame => (int)(_currentSector / (75 * 60)); + public int CurrentSecond => (int)(_currentSector / 75 % 60); + public int CurrentMinute => (int)(_currentSector % 75); + + private ulong _totalSectors; + public ulong TotalSectors + { + get => _totalSectors; + set => this.RaiseAndSetIfChanged(ref _totalSectors, value); + } + + public int TotalFrames => (int)(_totalSectors / (75 * 60)); + public int TotalSeconds => (int)(_totalSectors / 75 % 60); + public int TotalMinutes => (int)(_totalSectors % 75); + private int _volume; public int Volume { @@ -11,6 +42,10 @@ namespace RedBookPlayer.GUI set => this.RaiseAndSetIfChanged(ref _volume, value); } + #endregion + + #region Disc Flags + private bool _applyDeEmphasis; public bool ApplyDeEmphasis { @@ -52,5 +87,7 @@ namespace RedBookPlayer.GUI get => _hiddenTrack; set => this.RaiseAndSetIfChanged(ref _hiddenTrack, value); } + + #endregion } } \ No newline at end of file diff --git a/RedBookPlayer/Hardware/Player.cs b/RedBookPlayer/Hardware/Player.cs index edfb8ad..ec7e7e9 100644 --- a/RedBookPlayer/Hardware/Player.cs +++ b/RedBookPlayer/Hardware/Player.cs @@ -233,11 +233,7 @@ namespace RedBookPlayer.Hardware return string.Empty.PadLeft(20, '-'); // Otherwise, take the current time into account - ulong sectorTime = _opticalDisc.CurrentSector; - if(_opticalDisc.SectionStartSector != 0) - sectorTime -= _opticalDisc.SectionStartSector; - else - sectorTime += _opticalDisc.TimeOffset; + ulong sectorTime = GetCurrentSectorTime(); int[] numbers = new int[] { @@ -274,7 +270,11 @@ namespace RedBookPlayer.Hardware if(!Initialized || dataContext == null) return; + dataContext.Playing = Playing; + dataContext.CurrentSector = GetCurrentSectorTime(); + dataContext.TotalSectors = _opticalDisc.TotalTime; dataContext.Volume = App.Settings.Volume; + dataContext.ApplyDeEmphasis = _soundOutput.ApplyDeEmphasis; dataContext.HiddenTrack = _opticalDisc.TimeOffset > 150; @@ -294,6 +294,21 @@ namespace RedBookPlayer.Hardware } } + /// + /// Get current sector time, accounting for offsets + /// + /// ulong representing the current sector time + private ulong GetCurrentSectorTime() + { + ulong sectorTime = _opticalDisc.CurrentSector; + if(_opticalDisc.SectionStartSector != 0) + sectorTime -= _opticalDisc.SectionStartSector; + else + sectorTime += _opticalDisc.TimeOffset; + + return sectorTime; + } + #endregion } } \ No newline at end of file