using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Interfaces; using ReactiveUI; namespace RedBookPlayer.Models.Discs { public abstract class OpticalDiscBase : ReactiveObject { #region Public Fields /// /// Path to the disc image /// public string ImagePath { get; protected set; } /// /// Indicate if the disc is ready to be used /// public bool Initialized { get; protected set; } = false; /// /// Current track number /// public abstract int CurrentTrackNumber { get; protected set; } /// /// Current track index /// public abstract ushort CurrentTrackIndex { get; protected set; } /// /// Current track session /// public abstract ushort CurrentTrackSession { get; protected set; } /// /// Current sector number /// public abstract ulong CurrentSector { get; protected set; } /// /// Represents the sector starting the section /// public ulong SectionStartSector { get => _sectionStartSector; protected set => this.RaiseAndSetIfChanged(ref _sectionStartSector, value); } /// /// Number of bytes per sector for the current track /// public abstract int BytesPerSector { get; } /// /// Represents the track type /// public TrackType TrackType { get; protected set; } /// /// Represents the total tracks on the disc /// public int TotalTracks { get; protected set; } = 0; /// /// Represents the total indices on the disc /// public int TotalIndexes { get; protected set; } = 0; /// /// Total sectors in the image /// public ulong TotalSectors => _image?.Info.Sectors ?? 0; /// /// Represents the time adjustment offset for the disc /// public ulong TimeOffset { get; protected set; } = 0; /// /// Represents the total playing time for the disc /// public ulong TotalTime { get; protected set; } = 0; private ulong _sectionStartSector; #endregion #region Protected State Variables /// /// Currently loaded disc image /// protected IOpticalMediaImage _image; #endregion /// /// Initialize the disc with a given image /// /// Path of the image /// Aaruformat image to load /// True if playback should begin immediately, false otherwise public abstract void Init(string path, IOpticalMediaImage image, bool autoPlay); #region Helpers /// /// Extract a track to WAV /// /// Track number to extract /// Output path to write data to public abstract void ExtractTrackToWav(uint trackNumber, string outputDirectory); /// /// Load the desired track, if possible /// /// Track number to load public abstract void LoadTrack(int track); /// /// Load the desired index, if possible /// /// Index number to load public abstract void LoadIndex(ushort index); /// /// Read sector data from the base image starting from the current sector /// /// Current number of sectors to read /// Byte array representing the read sectors, if possible public virtual byte[] ReadSectors(uint sectorsToRead) => _image.ReadSectors(CurrentSector, sectorsToRead); /// /// Set the total indexes from the current track /// public abstract void SetTotalIndexes(); /// /// Set the current sector /// /// New sector number to use public void SetCurrentSector(ulong sector) => CurrentSector = sector; #endregion } }