Exemple #1
0
        public void CreateValidCueSheet()
        {
            string anISRC = "JMK401400212";

            byte  firstIndexPointNr      = 4;
            ulong firstIndexPointOffset  = 356;
            byte  secondIndexPointNr     = 5;
            ulong secondIndexPointOffset = 1000;

            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile flac = new FlacFile(newFile))
            {
                CueSheet cueSheet = new CueSheet();

                CueSheetTrack newTrack = new CueSheetTrack();
                newTrack.IsAudioTrack  = true;
                newTrack.IsPreEmphasis = false;
                newTrack.ISRC          = anISRC;
                newTrack.TrackNumber   = 1;
                newTrack.TrackOffset   = 0;

                CueSheetTrackIndex indexPoint = new CueSheetTrackIndex();
                indexPoint.IndexPointNumber = firstIndexPointNr;
                indexPoint.Offset           = firstIndexPointOffset;
                newTrack.IndexPoints.Add(indexPoint);
                indexPoint = new CueSheetTrackIndex();
                indexPoint.IndexPointNumber = secondIndexPointNr;
                indexPoint.Offset           = secondIndexPointOffset;
                newTrack.IndexPoints.Add(indexPoint);

                cueSheet.Tracks.Add(newTrack);

                // Create the lead-out track

                CueSheetTrack leadOut = new CueSheetTrack();
                leadOut.IsAudioTrack = false;
                leadOut.TrackNumber  = CueSheet.CUESHEET_LEADOUT_TRACK_NUMBER_CDDA;
                cueSheet.Tracks.Add(leadOut);

                flac.Metadata.Add(cueSheet);

                flac.Save();
            }

            using (FlacFile flac = new FlacFile(newFile))
            {
                CueSheet cueSheet = flac.CueSheet;
                Assert.IsNotNull(cueSheet);

                Assert.AreEqual <byte>(2, cueSheet.TrackCount);

                CueSheetTrack track = cueSheet.Tracks[0];

                Assert.AreEqual <bool>(true, track.IsAudioTrack);
                Assert.AreEqual <bool>(false, track.IsPreEmphasis);
                Assert.AreEqual <string>(anISRC, track.ISRC);
                Assert.AreEqual <byte>(1, track.TrackNumber);
                Assert.AreEqual <ulong>(0, track.TrackOffset);

                Assert.AreEqual <byte>(2, track.IndexPointCount);
                Assert.AreEqual <byte>(firstIndexPointNr, track.IndexPoints[0].IndexPointNumber);
                Assert.AreEqual <ulong>(firstIndexPointOffset, track.IndexPoints[0].Offset);
                Assert.AreEqual <byte>(secondIndexPointNr, track.IndexPoints[1].IndexPointNumber);
                Assert.AreEqual <ulong>(secondIndexPointOffset, track.IndexPoints[1].Offset);
            }
        }
        public void CopyOpenAddAndSaveCueSheetTracks()
        {
            string origFile = @"Data\testfile4.flac";
            string newFile = @"Data\testfile4_temp.flac";

            byte oldTrackCount = 0;
            ulong oldOffset = 0;
            ulong newOffset = 1000;
            string anISRC = "JMK401400212";

            byte firstIndexPointNr = 4;
            ulong firstIndexPointOffset = 356;
            byte secondIndexPointNr = 5;
            ulong secondIndexPointOffset = 1000;

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    var cueSheet = flac.CueSheet;
                    Assert.IsNotNull(cueSheet);

                    oldTrackCount = cueSheet.TrackCount;

                    CueSheetTrack newTrack = new CueSheetTrack();
                    newTrack.IsAudioTrack = true;
                    newTrack.IsPreEmphasis = false;
                    newTrack.ISRC = anISRC;
                    newTrack.TrackNumber = (byte)(oldTrackCount + 1);
                    oldOffset = cueSheet.Tracks[cueSheet.Tracks.Count - 2].TrackOffset;
                    newOffset += oldOffset;
                    newTrack.TrackOffset = newOffset;

                    CueSheetTrackIndex indexPoint = new CueSheetTrackIndex();
                    indexPoint.IndexPointNumber = firstIndexPointNr;
                    indexPoint.Offset = firstIndexPointOffset;
                    newTrack.IndexPoints.Add(indexPoint);
                    indexPoint = new CueSheetTrackIndex();
                    indexPoint.IndexPointNumber = secondIndexPointNr;
                    indexPoint.Offset = secondIndexPointOffset;
                    newTrack.IndexPoints.Add(indexPoint);

                    // Insert the track just before the lead-out track ...
                    flac.CueSheet.Tracks.Insert(flac.CueSheet.Tracks.Count - 1, newTrack);

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.IsNotNull(flac.CueSheet);

                    // first verify that the last track is our track (ignoring the lead-out track ...)
                    var lastTrack = flac.CueSheet.Tracks[flac.CueSheet.TrackCount - 2];

                    Assert.AreEqual<bool>(true, lastTrack.IsAudioTrack);
                    Assert.AreEqual<bool>(false, lastTrack.IsPreEmphasis);
                    Assert.AreEqual<string>(anISRC, lastTrack.ISRC);
                    Assert.AreEqual<byte>(flac.CueSheet.TrackCount, lastTrack.TrackNumber);
                    Assert.AreEqual<ulong>(newOffset, lastTrack.TrackOffset);

                    // Now check if our two index points are still there as well
                    Assert.AreEqual<byte>(2, lastTrack.IndexPointCount);
                    Assert.AreEqual<byte>(firstIndexPointNr, lastTrack.IndexPoints[0].IndexPointNumber);
                    Assert.AreEqual<ulong>(firstIndexPointOffset, lastTrack.IndexPoints[0].Offset);
                    Assert.AreEqual<byte>(secondIndexPointNr, lastTrack.IndexPoints[1].IndexPointNumber);
                    Assert.AreEqual<ulong>(secondIndexPointOffset, lastTrack.IndexPoints[1].Offset);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Exemple #3
0
        public void CopyOpenAddAndSaveCueSheetTracks()
        {
            string origFile = @"Data\testfile4.flac";
            string newFile  = @"Data\testfile4_temp.flac";

            byte   oldTrackCount = 0;
            ulong  oldOffset     = 0;
            ulong  newOffset     = 1000;
            string anISRC        = "JMK401400212";

            byte  firstIndexPointNr      = 4;
            ulong firstIndexPointOffset  = 356;
            byte  secondIndexPointNr     = 5;
            ulong secondIndexPointOffset = 1000;

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    var cueSheet = flac.CueSheet;
                    Assert.IsNotNull(cueSheet);

                    oldTrackCount = cueSheet.TrackCount;

                    CueSheetTrack newTrack = new CueSheetTrack();
                    newTrack.IsAudioTrack  = true;
                    newTrack.IsPreEmphasis = false;
                    newTrack.ISRC          = anISRC;
                    newTrack.TrackNumber   = (byte)(oldTrackCount + 1);
                    oldOffset            = cueSheet.Tracks[cueSheet.Tracks.Count - 2].TrackOffset;
                    newOffset           += oldOffset;
                    newTrack.TrackOffset = newOffset;

                    CueSheetTrackIndex indexPoint = new CueSheetTrackIndex();
                    indexPoint.IndexPointNumber = firstIndexPointNr;
                    indexPoint.Offset           = firstIndexPointOffset;
                    newTrack.IndexPoints.Add(indexPoint);
                    indexPoint = new CueSheetTrackIndex();
                    indexPoint.IndexPointNumber = secondIndexPointNr;
                    indexPoint.Offset           = secondIndexPointOffset;
                    newTrack.IndexPoints.Add(indexPoint);

                    // Insert the track just before the lead-out track ...
                    flac.CueSheet.Tracks.Insert(flac.CueSheet.Tracks.Count - 1, newTrack);

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.IsNotNull(flac.CueSheet);

                    // first verify that the last track is our track (ignoring the lead-out track ...)
                    var lastTrack = flac.CueSheet.Tracks[flac.CueSheet.TrackCount - 2];

                    Assert.AreEqual <bool>(true, lastTrack.IsAudioTrack);
                    Assert.AreEqual <bool>(false, lastTrack.IsPreEmphasis);
                    Assert.AreEqual <string>(anISRC, lastTrack.ISRC);
                    Assert.AreEqual <byte>(flac.CueSheet.TrackCount, lastTrack.TrackNumber);
                    Assert.AreEqual <ulong>(newOffset, lastTrack.TrackOffset);

                    // Now check if our two index points are still there as well
                    Assert.AreEqual <byte>(2, lastTrack.IndexPointCount);
                    Assert.AreEqual <byte>(firstIndexPointNr, lastTrack.IndexPoints[0].IndexPointNumber);
                    Assert.AreEqual <ulong>(firstIndexPointOffset, lastTrack.IndexPoints[0].Offset);
                    Assert.AreEqual <byte>(secondIndexPointNr, lastTrack.IndexPoints[1].IndexPointNumber);
                    Assert.AreEqual <ulong>(secondIndexPointOffset, lastTrack.IndexPoints[1].Offset);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
        public void CreateValidCueSheet()
        {
            string anISRC = "JMK401400212";

            byte firstIndexPointNr = 4;
            ulong firstIndexPointOffset = 356;
            byte secondIndexPointNr = 5;
            ulong secondIndexPointOffset = 1000;

            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile flac = new FlacFile(newFile))
            {
                CueSheet cueSheet = new CueSheet();

                CueSheetTrack newTrack = new CueSheetTrack();
                newTrack.IsAudioTrack = true;
                newTrack.IsPreEmphasis = false;
                newTrack.ISRC = anISRC;
                newTrack.TrackNumber = 1;
                newTrack.TrackOffset = 0;

                CueSheetTrackIndex indexPoint = new CueSheetTrackIndex();
                indexPoint.IndexPointNumber = firstIndexPointNr;
                indexPoint.Offset = firstIndexPointOffset;
                newTrack.IndexPoints.Add(indexPoint);
                indexPoint = new CueSheetTrackIndex();
                indexPoint.IndexPointNumber = secondIndexPointNr;
                indexPoint.Offset = secondIndexPointOffset;
                newTrack.IndexPoints.Add(indexPoint);

                cueSheet.Tracks.Add(newTrack);

                // Create the lead-out track

                CueSheetTrack leadOut = new CueSheetTrack();
                leadOut.IsAudioTrack = false;
                leadOut.TrackNumber = CueSheet.CUESHEET_LEADOUT_TRACK_NUMBER_CDDA;
                cueSheet.Tracks.Add(leadOut);

                flac.Metadata.Add(cueSheet);

                flac.Save();
            }

            using (FlacFile flac = new FlacFile(newFile))
            {
                CueSheet cueSheet = flac.CueSheet;
                Assert.IsNotNull(cueSheet);

                Assert.AreEqual<byte>(2, cueSheet.TrackCount);

                CueSheetTrack track = cueSheet.Tracks[0];

                Assert.AreEqual<bool>(true, track.IsAudioTrack);
                Assert.AreEqual<bool>(false, track.IsPreEmphasis);
                Assert.AreEqual<string>(anISRC, track.ISRC);
                Assert.AreEqual<byte>(1, track.TrackNumber);
                Assert.AreEqual<ulong>(0, track.TrackOffset);

                Assert.AreEqual<byte>(2, track.IndexPointCount);
                Assert.AreEqual<byte>(firstIndexPointNr, track.IndexPoints[0].IndexPointNumber);
                Assert.AreEqual<ulong>(firstIndexPointOffset, track.IndexPoints[0].Offset);
                Assert.AreEqual<byte>(secondIndexPointNr, track.IndexPoints[1].IndexPointNumber);
                Assert.AreEqual<ulong>(secondIndexPointOffset, track.IndexPoints[1].Offset);
            }
        }