Exemple #1
0
        public void SaveCueSheetWithoutCorrectLeadOutTrack()
        {
            string origFile = @"Data\testfile4.flac";
            string newFile  = @"Data\testfile4_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

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

                    CueSheetTrack newTrack = new CueSheetTrack();
                    newTrack.IsAudioTrack  = true;
                    newTrack.IsPreEmphasis = false;
                    newTrack.TrackNumber   = (byte)(55); // a non-lead-out track

                    flac.CueSheet.Tracks.Add(newTrack);  // Add the track as last track ...

                    // The save should not allow this.
                    flac.Save();
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Exemple #2
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);
            }
        }
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 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 SaveCueSheetWithoutCorrectLeadOutTrack()
        {
            string origFile = @"Data\testfile4.flac";
            string newFile = @"Data\testfile4_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

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

                    CueSheetTrack newTrack = new CueSheetTrack();
                    newTrack.IsAudioTrack = true;
                    newTrack.IsPreEmphasis = false;
                    newTrack.TrackNumber = (byte)(55); // a non-lead-out track

                    flac.CueSheet.Tracks.Add(newTrack); // Add the track as last track ...

                    // The save should not allow this.
                    flac.Save();
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Parse and store cue sheet. But how to handle comments... they should be stored in the corresponding section so that
        /// writing the cue sheet will still have all remarks at the right place.
        /// But should we remove remarks to note other creation programs?
        /// </summary>
        /// <param name="Filename"></param>
        /// <returns></returns>
        public CueSheet ParseCueSheet(string Filename)
        {
            CueSheet        cueSheet   = new CueSheet();
            CueSheetFile    cueFile    = new CueSheetFile();
            CueSheetTrack   cueTrack   = new CueSheetTrack();
            CueSheetIndex   cueIndex   = new CueSheetIndex();
            CueSheetContext cueContext = CueSheetContext.NONE;

            int Temp;

            string[] lines = System.IO.File.ReadAllLines(Filename);

            foreach (var item in lines)
            {
                if (cueContext == CueSheetContext.FILE)
                {
                    if (item.TrimStart(' ').StartsWith("TRACK", true, System.Globalization.CultureInfo.CurrentCulture))
                    {
                        cueContext = CueSheetContext.TRACK;
                        if (cueTrack.TrackNumber > 0)
                        {
                            cueFile.Tracks.Add(cueTrack);
                        }
                        cueTrack.Reset();
                        int Start = item.IndexOf(' ', item.IndexOf("TRACK"));
                        int End   = item.LastIndexOf(' ');
                        int.TryParse(item.Substring(Start, End - Start), out Temp);
                        cueTrack.TrackNumber = Temp;
                    }
                    if (item.TrimStart(' ').StartsWith("INDEX", true, System.Globalization.CultureInfo.CurrentCulture))
                    {
                        if (cueIndex.IndexNumber > 0)
                        {
                            cueTrack.Indexes.Add(cueIndex);
                        }
                        cueIndex.Reset();
                        int Start = item.IndexOf(' ', item.IndexOf("INDEX"));
                        int End   = item.LastIndexOf(' ');
                        int.TryParse(item.Substring(Start, End - Start), out Temp);
                        cueIndex.IndexNumber = Temp;
                        cueIndex.Time.Parse(item.Substring(End));
                    }
                    if (item.TrimStart(' ').StartsWith("PERFORMER", true, System.Globalization.CultureInfo.CurrentCulture))
                    {
                        int Start = item.IndexOf(' ', item.IndexOf("PERFORMER"));
                    }
                }
                if (item.StartsWith("rem ", true, System.Globalization.CultureInfo.CurrentCulture))
                {
                    string[] words = item.Split(' ');
                    switch (words[1].ToUpper())
                    {
                    case "DISCID":
                        cueSheet.DiscID = words[2];
                        break;

                    case "DISCNUMBER":
                        int.TryParse(words[2], out Temp);
                        cueSheet.Discnumber = Temp;
                        break;

                    case "TOTALDISCS":
                        int.TryParse(words[2], out Temp);
                        cueSheet.TotalDiscs = Temp;
                        break;

                    default:
                        break;
                    }
                }
                if (item.StartsWith("PERFORMER ", true, System.Globalization.CultureInfo.CurrentCulture))
                {
                    cueSheet.Performer = item.Substring(item.IndexOf(' '));
                }
                if (item.StartsWith("TITLE ", true, System.Globalization.CultureInfo.CurrentCulture))
                {
                    cueSheet.Title = item.Substring(item.IndexOf(' '));
                }
                if (item.StartsWith("FILE ", true, System.Globalization.CultureInfo.CurrentCulture))
                {
                    if (!string.IsNullOrEmpty(cueFile.Filename))
                    {
                        cueSheet.Files.Add(cueFile);
                    }
                    cueFile.Reset();
                    cueFile.Filename = item.Substring(item.IndexOf(' '));
                    cueContext       = CueSheetContext.FILE;
                }
            }
            //Add the final file
            if (cueIndex.IndexNumber > 0)
            {
                cueTrack.Indexes.Add(cueIndex);
            }
            if (cueTrack.TrackNumber > 0)
            {
                cueFile.Tracks.Add(cueTrack);
            }
            if (!string.IsNullOrEmpty(cueFile.Filename))
            {
                cueSheet.Files.Add(cueFile);
            }
            return(cueSheet);
        }
        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);
            }
        }