diff --git a/RedBookPlayer.Models/Hardware/Player.cs b/RedBookPlayer.Models/Hardware/Player.cs index eed7163..517e51f 100644 --- a/RedBookPlayer.Models/Hardware/Player.cs +++ b/RedBookPlayer.Models/Hardware/Player.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; @@ -292,10 +293,15 @@ namespace RedBookPlayer.Models.Hardware private readonly SoundOutput _soundOutput; /// - /// OpticalDisc object + /// OpticalDisc objects /// private OpticalDiscBase[] _opticalDiscs; + /// + /// List of available tracks + /// + private Dictionary> _trackList; + /// /// Last volume for mute toggling /// @@ -337,6 +343,12 @@ namespace RedBookPlayer.Models.Hardware _filterStage = new FilterStage(); _soundOutput = new SoundOutput(defaultVolume); + _trackList = new Dictionary>(); + for(int i = 0; i < _numberOfDiscs; i++) + { + _trackList.Add(i, new List()); + } + PropertyChanged += HandlePlaybackModes; } @@ -378,6 +390,9 @@ namespace RedBookPlayer.Models.Hardware // Add event handling for the sound output _soundOutput.PropertyChanged += SoundOutputStateChanged; + // Load in the track list for the current disc + LoadTrackList(); + // Mark the player as ready Initialized = true; @@ -386,6 +401,18 @@ namespace RedBookPlayer.Models.Hardware SoundOutputStateChanged(this, null); } + /// + /// Load the track list into the track dictionary for the current disc + /// + private void LoadTrackList() + { + OpticalDiscBase opticalDisc = _opticalDiscs[CurrentDisc]; + if (opticalDisc is CompactDisc compactDisc) + _trackList[CurrentDisc] = compactDisc.Tracks.Select(t => (int)t.TrackSequence).OrderBy(s => s).ToList(); + else + _trackList[CurrentDisc] = Enumerable.Range(1, opticalDisc.TotalTracks).ToList(); + } + #region Playback (UI) ///