コード例 #1
0
ファイル: Bsd.cs プロジェクト: colerus/MusicBrainz
 protected override TableOfContents ReadTableOfContents(string device, DiscReadFeature features)
 {
     using (var fd = NativeApi.OpenDevice(device)) {
         if (fd.IsInvalid)
         {
             throw new IOException($"Failed to open '{device}'.", new UnixException());
         }
         // Read the TOC itself
         NativeApi.ReadTOC(fd, out var first, out var last, out var rawtracks, this.AddressesAreNative);
         var tracks = new Track[rawtracks.Length];
         var i      = 0;
         if (first > 0)
         {
             for (var trackno = first; trackno <= last; ++trackno, ++i) // Add the regular tracks.
             {
                 if (rawtracks[i].TrackNumber != trackno)
                 {
                     throw new InvalidDataException($"Internal logic error; first track is {first}, but entry at index {i} claims to be track {rawtracks[i].TrackNumber} instead of {trackno}.");
                 }
                 var isrc = ((features & DiscReadFeature.TrackIsrc) != 0) ? NativeApi.GetTrackIsrc(fd, trackno) : null;
                 tracks[trackno] = new Track(rawtracks[i].Address, rawtracks[i].ControlAndADR.Control, isrc);
             }
         }
         // Next entry should be the lead-out (track number 0xAA)
         if (rawtracks[i].TrackNumber != 0xAA)
         {
             throw new InvalidDataException($"Internal logic error; track data ends with a record that reports track number {rawtracks[i].TrackNumber} instead of 0xAA (lead-out).");
         }
         tracks[0] = new Track(rawtracks[i].Address, rawtracks[i].ControlAndADR.Control, null);
         var mcn = ((features & DiscReadFeature.MediaCatalogNumber) != 0) ? NativeApi.GetMediaCatalogNumber(fd) : null;
         // TODO: Find out how to get CD-TEXT data.
         return(new TableOfContents(device, first, last, tracks, mcn, null));
     }
 }
コード例 #2
0
 TableOfContents IPlatform.ReadTableOfContents(string device, DiscReadFeature features)
 {
     if (string.IsNullOrWhiteSpace(device)) // Map null/blanks to the default device
     {
         device = this.DefaultDevice;
     }
     if (device == null) // But we do need a device at this point
     {
         throw new NotSupportedException("No cd-rom device found.");
     }
     // Mask off unsupported features
     features &= this._features;
     return(this.ReadTableOfContents(device, features));
 }
コード例 #3
0
ファイル: Linux.cs プロジェクト: colerus/MusicBrainz
 protected override TableOfContents ReadTableOfContents(string device, DiscReadFeature features)
 {
     using (var fd = NativeApi.OpenDevice(device)) {
         if (fd.IsInvalid)
         {
             throw new IOException($"Failed to open '{device}'.", new UnixException());
         }
         byte    first  = 0;
         byte    last   = 0;
         Track[] tracks = null;
         { // Read the TOC itself
             NativeApi.GetTableOfContents(fd, out MMC.TOCDescriptor rawtoc);
             first  = rawtoc.FirstTrack;
             last   = rawtoc.LastTrack;
             tracks = new Track[last + 1];
             var i = 0;
             for (var trackno = rawtoc.FirstTrack; trackno <= rawtoc.LastTrack; ++trackno, ++i) // Add the regular tracks.
             {
                 if (rawtoc.Tracks[i].TrackNumber != trackno)
                 {
                     throw new InvalidDataException($"Internal logic error; first track is {rawtoc.FirstTrack}, but entry at index {i} claims to be track {rawtoc.Tracks[i].TrackNumber} instead of {trackno}.");
                 }
                 var isrc = ((features & DiscReadFeature.TrackIsrc) != 0) ? NativeApi.GetTrackIsrc(fd, trackno) : null;
                 tracks[trackno] = new Track(rawtoc.Tracks[i].Address, rawtoc.Tracks[i].ControlAndADR.Control, isrc);
             }
             // Next entry should be the lead-out (track number 0xAA)
             if (rawtoc.Tracks[i].TrackNumber != 0xAA)
             {
                 throw new InvalidDataException($"Internal logic error; track data ends with a record that reports track number {rawtoc.Tracks[i].TrackNumber} instead of 0xAA (lead-out).");
             }
             tracks[0] = new Track(rawtoc.Tracks[i].Address, rawtoc.Tracks[i].ControlAndADR.Control, null);
         }
         var mcn = ((features & DiscReadFeature.MediaCatalogNumber) != 0) ? NativeApi.GetMediaCatalogNumber(fd) : null;
         RedBook.CDTextGroup?cdtg = null;
         if ((features & DiscReadFeature.CdText) != 0)
         {
             NativeApi.GetCdTextInfo(fd, out MMC.CDTextDescriptor cdtext);
             if (cdtext.Data.Packs != null)
             {
                 cdtg = cdtext.Data;
             }
         }
         return(new TableOfContents(device, first, last, tracks, mcn, cdtg));
     }
 }
コード例 #4
0
ファイル: Unix.cs プロジェクト: colerus/MusicBrainz
 protected Unix(DiscReadFeature features = DiscReadFeature.TableOfContents) : base(features)
 {
 }
コード例 #5
0
ファイル: Unix.cs プロジェクト: colerus/MusicBrainz
 protected override TableOfContents ReadTableOfContents(string device, DiscReadFeature features)
 {
     throw new NotImplementedException($"CD device access has not been implemented for this platform ({this.GetType().Name} {Environment.OSVersion}).");
 }
コード例 #6
0
 /// <summary>Reads the table of contents for the current disc in the specified device, getting the requested information.</summary>
 /// <param name="device">The name of the device to read from; null to read from <see cref="DefaultDevice"/>.</param>
 /// <param name="features">The features to use (if supported). Note that the table of contents will always be read.</param>
 public static TableOfContents ReadDisc(string device, DiscReadFeature features = DiscReadFeature.All)
 {
     return(TableOfContents.Platform.ReadTableOfContents(device, features));
 }
コード例 #7
0
 /// <summary>Determines whether or not the specified feature is supported for use with <see cref="ReadDisc"/>.</summary>
 /// <param name="feature">The (single) feature to test.</param>
 /// <returns>true if the feature is supported; false otherwise.</returns>
 public static bool HasReadFeature(DiscReadFeature feature) => TableOfContents.Platform.HasFeature(feature);
コード例 #8
0
 protected override TableOfContents ReadTableOfContents(string device, DiscReadFeature features)
 {
     throw new PlatformNotSupportedException($"CD device access is not supported on this platform ({Environment.OSVersion}).");
 }
コード例 #9
0
 protected abstract TableOfContents ReadTableOfContents(string device, DiscReadFeature features);
コード例 #10
0
 public bool HasFeature(DiscReadFeature feature) => (feature & this._features) != 0;
コード例 #11
0
 protected Platform(DiscReadFeature features)
 {
     this._features = features;
 }