Start building out multi-disc framework

This commit is contained in:
Matt Nadareski
2021-10-04 21:58:59 -07:00
parent 93a38ec9e9
commit 6a78fc86e5

View File

@@ -17,7 +17,26 @@ namespace RedBookPlayer.Models.Hardware
private set => this.RaiseAndSetIfChanged(ref _initialized, value); private set => this.RaiseAndSetIfChanged(ref _initialized, value);
} }
/// <summary>
/// Currently selected disc
/// </summary>
public int CurrentDisc
{
get => _currentDisc;
private set
{
int temp = value;
if (temp < 4)
temp = 0;
else if (temp >= 5)
temp = 0;
this.RaiseAndSetIfChanged(ref _currentDisc, temp);
}
}
private bool _initialized; private bool _initialized;
private int _currentDisc;
#region OpticalDisc Passthrough #region OpticalDisc Passthrough
@@ -114,27 +133,27 @@ namespace RedBookPlayer.Models.Hardware
/// <summary> /// <summary>
/// Represents the total tracks on the disc /// Represents the total tracks on the disc
/// </summary> /// </summary>
public int TotalTracks => _opticalDisc?.TotalTracks ?? 0; public int TotalTracks => _opticalDiscs[CurrentDisc]?.TotalTracks ?? 0;
/// <summary> /// <summary>
/// Represents the total indices on the disc /// Represents the total indices on the disc
/// </summary> /// </summary>
public int TotalIndexes => _opticalDisc?.TotalIndexes ?? 0; public int TotalIndexes => _opticalDiscs[CurrentDisc]?.TotalIndexes ?? 0;
/// <summary> /// <summary>
/// Total sectors in the image /// Total sectors in the image
/// </summary> /// </summary>
public ulong TotalSectors => _opticalDisc?.TotalSectors ?? 0; public ulong TotalSectors => _opticalDiscs[CurrentDisc]?.TotalSectors ?? 0;
/// <summary> /// <summary>
/// Represents the time adjustment offset for the disc /// Represents the time adjustment offset for the disc
/// </summary> /// </summary>
public ulong TimeOffset => _opticalDisc?.TimeOffset ?? 0; public ulong TimeOffset => _opticalDiscs[CurrentDisc]?.TimeOffset ?? 0;
/// <summary> /// <summary>
/// Represents the total playing time for the disc /// Represents the total playing time for the disc
/// </summary> /// </summary>
public ulong TotalTime => _opticalDisc?.TotalTime ?? 0; public ulong TotalTime => _opticalDiscs[CurrentDisc]?.TotalTime ?? 0;
private int _currentTrackNumber; private int _currentTrackNumber;
private ushort _currentTrackIndex; private ushort _currentTrackIndex;
@@ -215,7 +234,8 @@ namespace RedBookPlayer.Models.Hardware
/// <summary> /// <summary>
/// OpticalDisc object /// OpticalDisc object
/// </summary> /// </summary>
private OpticalDiscBase _opticalDisc; /// <remarks>TODO: Make the number of discs in the changer configurable</remarks>
private OpticalDiscBase[] _opticalDiscs = new OpticalDiscBase[5];
/// <summary> /// <summary>
/// Last volume for mute toggling /// Last volume for mute toggling
@@ -231,6 +251,7 @@ namespace RedBookPlayer.Models.Hardware
public Player(int defaultVolume) public Player(int defaultVolume)
{ {
Initialized = false; Initialized = false;
_currentDisc = 0;
_soundOutput = new SoundOutput(defaultVolume); _soundOutput = new SoundOutput(defaultVolume);
_soundOutput.SetDeEmphasis(false); _soundOutput.SetDeEmphasis(false);
} }
@@ -248,15 +269,15 @@ namespace RedBookPlayer.Models.Hardware
Initialized = false; Initialized = false;
// Initalize the disc // Initalize the disc
_opticalDisc = OpticalDiscFactory.GenerateFromPath(path, options, autoPlay); _opticalDiscs[CurrentDisc] = OpticalDiscFactory.GenerateFromPath(path, options, autoPlay);
if(_opticalDisc == null || !_opticalDisc.Initialized) if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized)
return; return;
// Add event handling for the optical disc // Add event handling for the optical disc
_opticalDisc.PropertyChanged += OpticalDiscStateChanged; _opticalDiscs[CurrentDisc].PropertyChanged += OpticalDiscStateChanged;
// Initialize the sound output // Initialize the sound output
_soundOutput.Init(_opticalDisc, repeatMode, autoPlay); _soundOutput.Init(_opticalDiscs[CurrentDisc], repeatMode, autoPlay);
if(_soundOutput == null || !_soundOutput.Initialized) if(_soundOutput == null || !_soundOutput.Initialized)
return; return;
@@ -278,7 +299,7 @@ namespace RedBookPlayer.Models.Hardware
/// </summary> /// </summary>
public void Play() public void Play()
{ {
if(_opticalDisc == null || !_opticalDisc.Initialized) if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized)
return; return;
else if(_soundOutput == null) else if(_soundOutput == null)
return; return;
@@ -286,7 +307,7 @@ namespace RedBookPlayer.Models.Hardware
return; return;
_soundOutput.Play(); _soundOutput.Play();
_opticalDisc.SetTotalIndexes(); _opticalDiscs[CurrentDisc].SetTotalIndexes();
PlayerState = PlayerState.Playing; PlayerState = PlayerState.Playing;
} }
@@ -295,7 +316,7 @@ namespace RedBookPlayer.Models.Hardware
/// </summary> /// </summary>
public void Pause() public void Pause()
{ {
if(_opticalDisc == null || !_opticalDisc.Initialized) if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized)
return; return;
else if(_soundOutput == null) else if(_soundOutput == null)
return; return;
@@ -332,7 +353,7 @@ namespace RedBookPlayer.Models.Hardware
/// </summary> /// </summary>
public void Stop() public void Stop()
{ {
if(_opticalDisc == null || !_opticalDisc.Initialized) if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized)
return; return;
else if(_soundOutput == null) else if(_soundOutput == null)
return; return;
@@ -340,7 +361,7 @@ namespace RedBookPlayer.Models.Hardware
return; return;
_soundOutput.Stop(); _soundOutput.Stop();
_opticalDisc.LoadFirstTrack(); _opticalDiscs[CurrentDisc].LoadFirstTrack();
PlayerState = PlayerState.Stopped; PlayerState = PlayerState.Stopped;
} }
@@ -349,14 +370,14 @@ namespace RedBookPlayer.Models.Hardware
/// </summary> /// </summary>
public void Eject() public void Eject()
{ {
if(_opticalDisc == null || !_opticalDisc.Initialized) if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized)
return; return;
else if(_soundOutput == null) else if(_soundOutput == null)
return; return;
Stop(); Stop();
_soundOutput.Eject(); _soundOutput.Eject();
_opticalDisc = null; _opticalDiscs[CurrentDisc] = null;
PlayerState = PlayerState.NoDisc; PlayerState = PlayerState.NoDisc;
Initialized = false; Initialized = false;
} }
@@ -366,15 +387,15 @@ namespace RedBookPlayer.Models.Hardware
/// </summary> /// </summary>
public void NextTrack() public void NextTrack()
{ {
if(_opticalDisc == null || !_opticalDisc.Initialized) if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized)
return; return;
PlayerState wasPlaying = PlayerState; PlayerState wasPlaying = PlayerState;
if(wasPlaying == PlayerState.Playing) if(wasPlaying == PlayerState.Playing)
Pause(); Pause();
_opticalDisc.NextTrack(); _opticalDiscs[CurrentDisc].NextTrack();
if(_opticalDisc is CompactDisc compactDisc) if(_opticalDiscs[CurrentDisc] is CompactDisc compactDisc)
_soundOutput.SetDeEmphasis(compactDisc.TrackHasEmphasis); _soundOutput.SetDeEmphasis(compactDisc.TrackHasEmphasis);
if(wasPlaying == PlayerState.Playing) if(wasPlaying == PlayerState.Playing)
@@ -386,15 +407,15 @@ namespace RedBookPlayer.Models.Hardware
/// </summary> /// </summary>
public void PreviousTrack() public void PreviousTrack()
{ {
if(_opticalDisc == null || !_opticalDisc.Initialized) if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized)
return; return;
PlayerState wasPlaying = PlayerState; PlayerState wasPlaying = PlayerState;
if(wasPlaying == PlayerState.Playing) if(wasPlaying == PlayerState.Playing)
Pause(); Pause();
_opticalDisc.PreviousTrack(); _opticalDiscs[CurrentDisc].PreviousTrack();
if(_opticalDisc is CompactDisc compactDisc) if(_opticalDiscs[CurrentDisc] is CompactDisc compactDisc)
_soundOutput.SetDeEmphasis(compactDisc.TrackHasEmphasis); _soundOutput.SetDeEmphasis(compactDisc.TrackHasEmphasis);
if(wasPlaying == PlayerState.Playing) if(wasPlaying == PlayerState.Playing)
@@ -407,15 +428,15 @@ namespace RedBookPlayer.Models.Hardware
/// <param name="changeTrack">True if index changes can trigger a track change, false otherwise</param> /// <param name="changeTrack">True if index changes can trigger a track change, false otherwise</param>
public void NextIndex(bool changeTrack) public void NextIndex(bool changeTrack)
{ {
if(_opticalDisc == null || !_opticalDisc.Initialized) if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized)
return; return;
PlayerState wasPlaying = PlayerState; PlayerState wasPlaying = PlayerState;
if(wasPlaying == PlayerState.Playing) if(wasPlaying == PlayerState.Playing)
Pause(); Pause();
_opticalDisc.NextIndex(changeTrack); _opticalDiscs[CurrentDisc].NextIndex(changeTrack);
if(_opticalDisc is CompactDisc compactDisc) if(_opticalDiscs[CurrentDisc] is CompactDisc compactDisc)
_soundOutput.SetDeEmphasis(compactDisc.TrackHasEmphasis); _soundOutput.SetDeEmphasis(compactDisc.TrackHasEmphasis);
if(wasPlaying == PlayerState.Playing) if(wasPlaying == PlayerState.Playing)
@@ -428,15 +449,15 @@ namespace RedBookPlayer.Models.Hardware
/// <param name="changeTrack">True if index changes can trigger a track change, false otherwise</param> /// <param name="changeTrack">True if index changes can trigger a track change, false otherwise</param>
public void PreviousIndex(bool changeTrack) public void PreviousIndex(bool changeTrack)
{ {
if(_opticalDisc == null || !_opticalDisc.Initialized) if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized)
return; return;
PlayerState wasPlaying = PlayerState; PlayerState wasPlaying = PlayerState;
if(wasPlaying == PlayerState.Playing) if(wasPlaying == PlayerState.Playing)
Pause(); Pause();
_opticalDisc.PreviousIndex(changeTrack); _opticalDiscs[CurrentDisc].PreviousIndex(changeTrack);
if(_opticalDisc is CompactDisc compactDisc) if(_opticalDiscs[CurrentDisc] is CompactDisc compactDisc)
_soundOutput.SetDeEmphasis(compactDisc.TrackHasEmphasis); _soundOutput.SetDeEmphasis(compactDisc.TrackHasEmphasis);
if(wasPlaying == PlayerState.Playing) if(wasPlaying == PlayerState.Playing)
@@ -448,10 +469,10 @@ namespace RedBookPlayer.Models.Hardware
/// </summary> /// </summary>
public void FastForward() public void FastForward()
{ {
if(_opticalDisc == null || !_opticalDisc.Initialized) if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized)
return; return;
_opticalDisc.SetCurrentSector(_opticalDisc.CurrentSector + 75); _opticalDiscs[CurrentDisc].SetCurrentSector(_opticalDiscs[CurrentDisc].CurrentSector + 75);
} }
/// <summary> /// <summary>
@@ -459,10 +480,10 @@ namespace RedBookPlayer.Models.Hardware
/// </summary> /// </summary>
public void Rewind() public void Rewind()
{ {
if(_opticalDisc == null || !_opticalDisc.Initialized) if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized)
return; return;
_opticalDisc.SetCurrentSector(_opticalDisc.CurrentSector - 75); _opticalDiscs[CurrentDisc].SetCurrentSector(_opticalDiscs[CurrentDisc].CurrentSector - 75);
} }
#endregion #endregion
@@ -536,12 +557,12 @@ namespace RedBookPlayer.Models.Hardware
/// </summary> /// </summary>
/// <param name="trackNumber"></param> /// <param name="trackNumber"></param>
/// <param name="outputDirectory">Output path to write data to</param> /// <param name="outputDirectory">Output path to write data to</param>
public void ExtractSingleTrackToWav(uint trackNumber, string outputDirectory) => _opticalDisc?.ExtractTrackToWav(trackNumber, outputDirectory); public void ExtractSingleTrackToWav(uint trackNumber, string outputDirectory) => _opticalDiscs[CurrentDisc]?.ExtractTrackToWav(trackNumber, outputDirectory);
/// <summary> /// <summary>
/// Extract all tracks from the image to WAV /// Extract all tracks from the image to WAV
/// <param name="outputDirectory">Output path to write data to</param> /// <param name="outputDirectory">Output path to write data to</param>
public void ExtractAllTracksToWav(string outputDirectory) => _opticalDisc?.ExtractAllTracksToWav(outputDirectory); public void ExtractAllTracksToWav(string outputDirectory) => _opticalDiscs[CurrentDisc]?.ExtractAllTracksToWav(outputDirectory);
/// <summary> /// <summary>
/// Set data playback method [CompactDisc only] /// Set data playback method [CompactDisc only]
@@ -549,7 +570,7 @@ namespace RedBookPlayer.Models.Hardware
/// <param name="dataPlayback">New playback value</param> /// <param name="dataPlayback">New playback value</param>
public void SetDataPlayback(DataPlayback dataPlayback) public void SetDataPlayback(DataPlayback dataPlayback)
{ {
if(_opticalDisc is CompactDisc compactDisc) if(_opticalDiscs[CurrentDisc] is CompactDisc compactDisc)
compactDisc.DataPlayback = dataPlayback; compactDisc.DataPlayback = dataPlayback;
} }
@@ -559,7 +580,7 @@ namespace RedBookPlayer.Models.Hardware
/// <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) public void SetLoadHiddenTracks(bool load)
{ {
if(_opticalDisc is CompactDisc compactDisc) if(_opticalDiscs[CurrentDisc] is CompactDisc compactDisc)
compactDisc.LoadHiddenTracks = load; compactDisc.LoadHiddenTracks = load;
} }
@@ -575,7 +596,7 @@ namespace RedBookPlayer.Models.Hardware
/// <param name="sessionHandling">New session handling value</param> /// <param name="sessionHandling">New session handling value</param>
public void SetSessionHandling(SessionHandling sessionHandling) public void SetSessionHandling(SessionHandling sessionHandling)
{ {
if(_opticalDisc is CompactDisc compactDisc) if(_opticalDiscs[CurrentDisc] is CompactDisc compactDisc)
compactDisc.SessionHandling = sessionHandling; compactDisc.SessionHandling = sessionHandling;
} }
@@ -584,14 +605,14 @@ namespace RedBookPlayer.Models.Hardware
/// </summary> /// </summary>
private void OpticalDiscStateChanged(object sender, PropertyChangedEventArgs e) private void OpticalDiscStateChanged(object sender, PropertyChangedEventArgs e)
{ {
CurrentTrackNumber = _opticalDisc.CurrentTrackNumber; CurrentTrackNumber = _opticalDiscs[CurrentDisc].CurrentTrackNumber;
CurrentTrackIndex = _opticalDisc.CurrentTrackIndex; CurrentTrackIndex = _opticalDiscs[CurrentDisc].CurrentTrackIndex;
CurrentSector = _opticalDisc.CurrentSector; CurrentSector = _opticalDiscs[CurrentDisc].CurrentSector;
SectionStartSector = _opticalDisc.SectionStartSector; SectionStartSector = _opticalDiscs[CurrentDisc].SectionStartSector;
HiddenTrack = TimeOffset > 150; HiddenTrack = TimeOffset > 150;
if(_opticalDisc is CompactDisc compactDisc) if(_opticalDiscs[CurrentDisc] is CompactDisc compactDisc)
{ {
QuadChannel = compactDisc.QuadChannel; QuadChannel = compactDisc.QuadChannel;
IsDataTrack = compactDisc.IsDataTrack; IsDataTrack = compactDisc.IsDataTrack;
@@ -601,7 +622,7 @@ namespace RedBookPlayer.Models.Hardware
else else
{ {
QuadChannel = false; QuadChannel = false;
IsDataTrack = _opticalDisc.TrackType != TrackType.Audio; IsDataTrack = _opticalDiscs[CurrentDisc].TrackType != TrackType.Audio;
CopyAllowed = false; CopyAllowed = false;
TrackHasEmphasis = false; TrackHasEmphasis = false;
} }