Set one SoundOutput per disc

This commit is contained in:
Matt Nadareski
2021-10-04 22:26:06 -07:00
parent 6a78fc86e5
commit 34b7fbd790

View File

@@ -229,7 +229,8 @@ namespace RedBookPlayer.Models.Hardware
/// <summary> /// <summary>
/// Sound output handling class /// Sound output handling class
/// </summary> /// </summary>
private readonly SoundOutput _soundOutput; /// <remarks>TODO: Link sound outputs to discs in a 1:1 configuration</remarks>
private readonly SoundOutput[] _soundOutputs = new SoundOutput[5];
/// <summary> /// <summary>
/// OpticalDisc object /// OpticalDisc object
@@ -252,8 +253,11 @@ namespace RedBookPlayer.Models.Hardware
{ {
Initialized = false; Initialized = false;
_currentDisc = 0; _currentDisc = 0;
_soundOutput = new SoundOutput(defaultVolume); for (int i = 0; i < 5; i++)
_soundOutput.SetDeEmphasis(false); {
_soundOutputs[i] = new SoundOutput(defaultVolume);
_soundOutputs[i].SetDeEmphasis(false);
}
} }
/// <summary> /// <summary>
@@ -277,12 +281,12 @@ namespace RedBookPlayer.Models.Hardware
_opticalDiscs[CurrentDisc].PropertyChanged += OpticalDiscStateChanged; _opticalDiscs[CurrentDisc].PropertyChanged += OpticalDiscStateChanged;
// Initialize the sound output // Initialize the sound output
_soundOutput.Init(_opticalDiscs[CurrentDisc], repeatMode, autoPlay); _soundOutputs[CurrentDisc].Init(_opticalDiscs[CurrentDisc], repeatMode, autoPlay);
if(_soundOutput == null || !_soundOutput.Initialized) if(_soundOutputs[CurrentDisc] == null || !_soundOutputs[CurrentDisc].Initialized)
return; return;
// Add event handling for the sound output // Add event handling for the sound output
_soundOutput.PropertyChanged += SoundOutputStateChanged; _soundOutputs[CurrentDisc].PropertyChanged += SoundOutputStateChanged;
// Mark the player as ready // Mark the player as ready
Initialized = true; Initialized = true;
@@ -301,12 +305,12 @@ namespace RedBookPlayer.Models.Hardware
{ {
if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized) if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized)
return; return;
else if(_soundOutput == null) else if(_soundOutputs[CurrentDisc] == null)
return; return;
else if(_soundOutput.PlayerState != PlayerState.Paused && _soundOutput.PlayerState != PlayerState.Stopped) else if(_soundOutputs[CurrentDisc].PlayerState != PlayerState.Paused && _soundOutputs[CurrentDisc].PlayerState != PlayerState.Stopped)
return; return;
_soundOutput.Play(); _soundOutputs[CurrentDisc].Play();
_opticalDiscs[CurrentDisc].SetTotalIndexes(); _opticalDiscs[CurrentDisc].SetTotalIndexes();
PlayerState = PlayerState.Playing; PlayerState = PlayerState.Playing;
} }
@@ -318,12 +322,12 @@ namespace RedBookPlayer.Models.Hardware
{ {
if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized) if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized)
return; return;
else if(_soundOutput == null) else if(_soundOutputs[CurrentDisc] == null)
return; return;
else if(_soundOutput.PlayerState != PlayerState.Playing) else if(_soundOutputs[CurrentDisc].PlayerState != PlayerState.Playing)
return; return;
_soundOutput?.Pause(); _soundOutputs[CurrentDisc]?.Pause();
PlayerState = PlayerState.Paused; PlayerState = PlayerState.Paused;
} }
@@ -355,12 +359,12 @@ namespace RedBookPlayer.Models.Hardware
{ {
if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized) if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized)
return; return;
else if(_soundOutput == null) else if(_soundOutputs[CurrentDisc] == null)
return; return;
else if(_soundOutput.PlayerState != PlayerState.Playing && _soundOutput.PlayerState != PlayerState.Paused) else if(_soundOutputs[CurrentDisc].PlayerState != PlayerState.Playing && _soundOutputs[CurrentDisc].PlayerState != PlayerState.Paused)
return; return;
_soundOutput.Stop(); _soundOutputs[CurrentDisc].Stop();
_opticalDiscs[CurrentDisc].LoadFirstTrack(); _opticalDiscs[CurrentDisc].LoadFirstTrack();
PlayerState = PlayerState.Stopped; PlayerState = PlayerState.Stopped;
} }
@@ -372,11 +376,11 @@ namespace RedBookPlayer.Models.Hardware
{ {
if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized) if(_opticalDiscs[CurrentDisc] == null || !_opticalDiscs[CurrentDisc].Initialized)
return; return;
else if(_soundOutput == null) else if(_soundOutputs[CurrentDisc] == null)
return; return;
Stop(); Stop();
_soundOutput.Eject(); _soundOutputs[CurrentDisc].Eject();
_opticalDiscs[CurrentDisc] = null; _opticalDiscs[CurrentDisc] = null;
PlayerState = PlayerState.NoDisc; PlayerState = PlayerState.NoDisc;
Initialized = false; Initialized = false;
@@ -396,7 +400,7 @@ namespace RedBookPlayer.Models.Hardware
_opticalDiscs[CurrentDisc].NextTrack(); _opticalDiscs[CurrentDisc].NextTrack();
if(_opticalDiscs[CurrentDisc] is CompactDisc compactDisc) if(_opticalDiscs[CurrentDisc] is CompactDisc compactDisc)
_soundOutput.SetDeEmphasis(compactDisc.TrackHasEmphasis); _soundOutputs[CurrentDisc].SetDeEmphasis(compactDisc.TrackHasEmphasis);
if(wasPlaying == PlayerState.Playing) if(wasPlaying == PlayerState.Playing)
Play(); Play();
@@ -416,7 +420,7 @@ namespace RedBookPlayer.Models.Hardware
_opticalDiscs[CurrentDisc].PreviousTrack(); _opticalDiscs[CurrentDisc].PreviousTrack();
if(_opticalDiscs[CurrentDisc] is CompactDisc compactDisc) if(_opticalDiscs[CurrentDisc] is CompactDisc compactDisc)
_soundOutput.SetDeEmphasis(compactDisc.TrackHasEmphasis); _soundOutputs[CurrentDisc].SetDeEmphasis(compactDisc.TrackHasEmphasis);
if(wasPlaying == PlayerState.Playing) if(wasPlaying == PlayerState.Playing)
Play(); Play();
@@ -437,7 +441,7 @@ namespace RedBookPlayer.Models.Hardware
_opticalDiscs[CurrentDisc].NextIndex(changeTrack); _opticalDiscs[CurrentDisc].NextIndex(changeTrack);
if(_opticalDiscs[CurrentDisc] is CompactDisc compactDisc) if(_opticalDiscs[CurrentDisc] is CompactDisc compactDisc)
_soundOutput.SetDeEmphasis(compactDisc.TrackHasEmphasis); _soundOutputs[CurrentDisc].SetDeEmphasis(compactDisc.TrackHasEmphasis);
if(wasPlaying == PlayerState.Playing) if(wasPlaying == PlayerState.Playing)
Play(); Play();
@@ -458,7 +462,7 @@ namespace RedBookPlayer.Models.Hardware
_opticalDiscs[CurrentDisc].PreviousIndex(changeTrack); _opticalDiscs[CurrentDisc].PreviousIndex(changeTrack);
if(_opticalDiscs[CurrentDisc] is CompactDisc compactDisc) if(_opticalDiscs[CurrentDisc] is CompactDisc compactDisc)
_soundOutput.SetDeEmphasis(compactDisc.TrackHasEmphasis); _soundOutputs[CurrentDisc].SetDeEmphasis(compactDisc.TrackHasEmphasis);
if(wasPlaying == PlayerState.Playing) if(wasPlaying == PlayerState.Playing)
Play(); Play();
@@ -504,7 +508,7 @@ namespace RedBookPlayer.Models.Hardware
/// Set the value for the volume /// Set the value for the volume
/// </summary> /// </summary>
/// <param name="volume">New volume value</param> /// <param name="volume">New volume value</param>
public void SetVolume(int volume) => _soundOutput?.SetVolume(volume); public void SetVolume(int volume) => _soundOutputs[CurrentDisc]?.SetVolume(volume);
/// <summary> /// <summary>
/// Temporarily mute playback /// Temporarily mute playback
@@ -546,7 +550,7 @@ namespace RedBookPlayer.Models.Hardware
/// Set de-emphasis status /// Set de-emphasis status
/// </summary> /// </summary>
/// <param name="apply"></param> /// <param name="apply"></param>
private void SetDeEmphasis(bool apply) => _soundOutput?.SetDeEmphasis(apply); private void SetDeEmphasis(bool apply) => _soundOutputs[CurrentDisc]?.SetDeEmphasis(apply);
#endregion #endregion
@@ -588,7 +592,7 @@ namespace RedBookPlayer.Models.Hardware
/// Set repeat mode /// Set repeat mode
/// </summary> /// </summary>
/// <param name="repeatMode">New repeat mode value</param> /// <param name="repeatMode">New repeat mode value</param>
public void SetRepeatMode(RepeatMode repeatMode) => _soundOutput?.SetRepeatMode(repeatMode); public void SetRepeatMode(RepeatMode repeatMode) => _soundOutputs[CurrentDisc]?.SetRepeatMode(repeatMode);
/// <summary> /// <summary>
/// Set the value for session handling [CompactDisc only] /// Set the value for session handling [CompactDisc only]
@@ -633,10 +637,10 @@ namespace RedBookPlayer.Models.Hardware
/// </summary> /// </summary>
private void SoundOutputStateChanged(object sender, PropertyChangedEventArgs e) private void SoundOutputStateChanged(object sender, PropertyChangedEventArgs e)
{ {
PlayerState = _soundOutput.PlayerState; PlayerState = _soundOutputs[CurrentDisc].PlayerState;
RepeatMode = _soundOutput.RepeatMode; RepeatMode = _soundOutputs[CurrentDisc].RepeatMode;
ApplyDeEmphasis = _soundOutput.ApplyDeEmphasis; ApplyDeEmphasis = _soundOutputs[CurrentDisc].ApplyDeEmphasis;
Volume = _soundOutput.Volume; Volume = _soundOutputs[CurrentDisc].Volume;
} }
#endregion #endregion