mirror of
https://github.com/aaru-dps/RedBookPlayer.git
synced 2025-12-16 19:24:41 +00:00
Port only distinct new feature work
This commit is contained in:
@@ -39,6 +39,15 @@ namespace RedBookPlayer.Models.Hardware
|
||||
private set => this.RaiseAndSetIfChanged(ref _currentTrackIndex, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Current track session
|
||||
/// </summary>
|
||||
public ushort CurrentTrackSession
|
||||
{
|
||||
get => _currentTrackSession;
|
||||
private set => this.RaiseAndSetIfChanged(ref _currentTrackSession, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Current sector number
|
||||
/// </summary>
|
||||
@@ -129,6 +138,7 @@ namespace RedBookPlayer.Models.Hardware
|
||||
|
||||
private int _currentTrackNumber;
|
||||
private ushort _currentTrackIndex;
|
||||
private ushort _currentTrackSession;
|
||||
private ulong _currentSector;
|
||||
private ulong _sectionStartSector;
|
||||
|
||||
@@ -160,6 +170,15 @@ namespace RedBookPlayer.Models.Hardware
|
||||
private set => this.RaiseAndSetIfChanged(ref _dataPlayback, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the repeat mode
|
||||
/// </summary>
|
||||
public RepeatMode RepeatMode
|
||||
{
|
||||
get => _repeatMode;
|
||||
private set => this.RaiseAndSetIfChanged(ref _repeatMode, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if de-emphasis should be applied
|
||||
/// </summary>
|
||||
@@ -180,6 +199,7 @@ namespace RedBookPlayer.Models.Hardware
|
||||
|
||||
private PlayerState _playerState;
|
||||
private DataPlayback _dataPlayback;
|
||||
private RepeatMode _repeatMode;
|
||||
private bool _applyDeEmphasis;
|
||||
private int _volume;
|
||||
|
||||
@@ -220,8 +240,9 @@ namespace RedBookPlayer.Models.Hardware
|
||||
/// </summary>
|
||||
/// <param name="path">Path to the disc image</param>
|
||||
/// <param name="options">Options to pass to the optical disc factory</param>
|
||||
/// <param name="repeatMode">RepeatMode for sound output</param>
|
||||
/// <param name="autoPlay">True if playback should begin immediately, false otherwise</param>
|
||||
public void Init(string path, OpticalDiscOptions options, bool autoPlay)
|
||||
public void Init(string path, OpticalDiscOptions options, RepeatMode repeatMode, bool autoPlay)
|
||||
{
|
||||
// Reset initialization
|
||||
Initialized = false;
|
||||
@@ -235,7 +256,7 @@ namespace RedBookPlayer.Models.Hardware
|
||||
_opticalDisc.PropertyChanged += OpticalDiscStateChanged;
|
||||
|
||||
// Initialize the sound output
|
||||
_soundOutput.Init(_opticalDisc, autoPlay);
|
||||
_soundOutput.Init(_opticalDisc, repeatMode, autoPlay);
|
||||
if(_soundOutput == null || !_soundOutput.Initialized)
|
||||
return;
|
||||
|
||||
@@ -323,6 +344,23 @@ namespace RedBookPlayer.Models.Hardware
|
||||
PlayerState = PlayerState.Stopped;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Eject the currently loaded disc
|
||||
/// </summary>
|
||||
public void Eject()
|
||||
{
|
||||
if(_opticalDisc == null || !_opticalDisc.Initialized)
|
||||
return;
|
||||
else if(_soundOutput == null)
|
||||
return;
|
||||
|
||||
Stop();
|
||||
_soundOutput.Eject();
|
||||
_opticalDisc = null;
|
||||
PlayerState = PlayerState.NoDisc;
|
||||
Initialized = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move to the next playable track
|
||||
/// </summary>
|
||||
@@ -493,6 +531,18 @@ namespace RedBookPlayer.Models.Hardware
|
||||
|
||||
#region Helpers
|
||||
|
||||
/// <summary>
|
||||
/// Extract a single track from the image to WAV
|
||||
/// </summary>
|
||||
/// <param name="trackNumber"></param>
|
||||
/// <param name="outputDirectory">Output path to write data to</param
|
||||
public void ExtractSingleTrackToWav(uint trackNumber, string outputDirectory) => _opticalDisc?.ExtractTrackToWav(trackNumber, outputDirectory);
|
||||
|
||||
/// <summary>
|
||||
/// Extract all tracks from the image to WAV
|
||||
/// <param name="outputDirectory">Output path to write data to</param
|
||||
public void ExtractAllTracksToWav(string outputDirectory) => _opticalDisc?.ExtractAllTracksToWav(outputDirectory);
|
||||
|
||||
/// <summary>
|
||||
/// Set data playback method [CompactDisc only]
|
||||
/// </summary>
|
||||
@@ -513,6 +563,22 @@ namespace RedBookPlayer.Models.Hardware
|
||||
compactDisc.LoadHiddenTracks = load;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set repeat mode
|
||||
/// </summary>
|
||||
/// <param name="repeatMode">New repeat mode value</param>
|
||||
public void SetRepeatMode(RepeatMode repeatMode) => _soundOutput?.SetRepeatMode(repeatMode);
|
||||
|
||||
/// <summary>
|
||||
/// Set the value for session handling [CompactDisc only]
|
||||
/// </summary>
|
||||
/// <param name="sessionHandling">New session handling value</param>
|
||||
public void SetSessionHandling(SessionHandling sessionHandling)
|
||||
{
|
||||
if(_opticalDisc is CompactDisc compactDisc)
|
||||
compactDisc.SessionHandling = sessionHandling;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the player from the current OpticalDisc
|
||||
/// </summary>
|
||||
@@ -547,6 +613,7 @@ namespace RedBookPlayer.Models.Hardware
|
||||
private void SoundOutputStateChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
PlayerState = _soundOutput.PlayerState;
|
||||
RepeatMode = _soundOutput.RepeatMode;
|
||||
ApplyDeEmphasis = _soundOutput.ApplyDeEmphasis;
|
||||
Volume = _soundOutput.Volume;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,15 @@ namespace RedBookPlayer.Models.Hardware
|
||||
private set => this.RaiseAndSetIfChanged(ref _playerState, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the repeat mode
|
||||
/// </summary>
|
||||
public RepeatMode RepeatMode
|
||||
{
|
||||
get => _repeatMode;
|
||||
private set => this.RaiseAndSetIfChanged(ref _repeatMode, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if de-emphasis should be applied
|
||||
/// </summary>
|
||||
@@ -60,6 +69,7 @@ namespace RedBookPlayer.Models.Hardware
|
||||
|
||||
private bool _initialized;
|
||||
private PlayerState _playerState;
|
||||
private RepeatMode _repeatMode;
|
||||
private bool _applyDeEmphasis;
|
||||
private int _volume;
|
||||
|
||||
@@ -117,8 +127,9 @@ namespace RedBookPlayer.Models.Hardware
|
||||
/// Initialize the output with a given image
|
||||
/// </summary>
|
||||
/// <param name="opticalDisc">OpticalDisc to load from</param>
|
||||
/// <param name="repeatMode">RepeatMode for sound output</param>
|
||||
/// <param name="autoPlay">True if playback should begin immediately, false otherwise</param>
|
||||
public void Init(OpticalDiscBase opticalDisc, bool autoPlay)
|
||||
public void Init(OpticalDiscBase opticalDisc, RepeatMode repeatMode, bool autoPlay)
|
||||
{
|
||||
// If we have an unusable disc, just return
|
||||
if(opticalDisc == null || !opticalDisc.Initialized)
|
||||
@@ -137,6 +148,9 @@ namespace RedBookPlayer.Models.Hardware
|
||||
// Setup the audio output
|
||||
SetupAudio();
|
||||
|
||||
// Setup the repeat mode
|
||||
RepeatMode = repeatMode;
|
||||
|
||||
// Initialize playback, if necessary
|
||||
if(autoPlay)
|
||||
_soundOut.Play();
|
||||
@@ -149,6 +163,17 @@ namespace RedBookPlayer.Models.Hardware
|
||||
_source.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset the current internal state
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
_soundOut.Stop();
|
||||
_opticalDisc = null;
|
||||
Initialized = false;
|
||||
PlayerState = PlayerState.NoDisc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fill the current byte buffer with playable data
|
||||
/// </summary>
|
||||
@@ -189,6 +214,11 @@ namespace RedBookPlayer.Models.Hardware
|
||||
int currentTrack = _opticalDisc.CurrentTrackNumber;
|
||||
_opticalDisc.SetCurrentSector(_opticalDisc.CurrentSector + (ulong)(_currentSectorReadPosition / _opticalDisc.BytesPerSector));
|
||||
_currentSectorReadPosition %= _opticalDisc.BytesPerSector;
|
||||
|
||||
if(RepeatMode == RepeatMode.None && _opticalDisc.CurrentTrackNumber < currentTrack)
|
||||
Stop();
|
||||
else if(RepeatMode == RepeatMode.Single && _opticalDisc.CurrentTrackNumber != currentTrack)
|
||||
_opticalDisc.LoadTrack(currentTrack);
|
||||
}
|
||||
|
||||
return count;
|
||||
@@ -229,6 +259,11 @@ namespace RedBookPlayer.Models.Hardware
|
||||
PlayerState = PlayerState.Stopped;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Eject the currently loaded disc
|
||||
/// </summary>
|
||||
public void Eject() => Reset();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
@@ -239,6 +274,12 @@ namespace RedBookPlayer.Models.Hardware
|
||||
/// <param name="apply">New de-emphasis status</param>
|
||||
public void SetDeEmphasis(bool apply) => ApplyDeEmphasis = apply;
|
||||
|
||||
/// <summary>
|
||||
/// Set repeat mode
|
||||
/// </summary>
|
||||
/// <param name="repeatMode">New repeat mode value</param>
|
||||
public void SetRepeatMode(RepeatMode repeatMode) => RepeatMode = repeatMode;
|
||||
|
||||
/// <summary>
|
||||
/// Set the value for the volume
|
||||
/// </summary>
|
||||
@@ -253,8 +294,8 @@ namespace RedBookPlayer.Models.Hardware
|
||||
/// <param name="zeroSectorsAmount">Number of zeroed sectors to concatenate</param>
|
||||
private void DetermineReadAmount(int count, out ulong sectorsToRead, out ulong zeroSectorsAmount)
|
||||
{
|
||||
// Attempt to read 5 more sectors than requested
|
||||
sectorsToRead = ((ulong)count / (ulong)_opticalDisc.BytesPerSector) + 5;
|
||||
// Attempt to read 10 more sectors than requested
|
||||
sectorsToRead = ((ulong)count / (ulong)_opticalDisc.BytesPerSector) + 10;
|
||||
zeroSectorsAmount = 0;
|
||||
|
||||
// Avoid overreads by padding with 0-byte data at the end
|
||||
|
||||
Reference in New Issue
Block a user