public static void viewCueFile(FileInfo path)
        {
            //Yeah, this kinda sucks actually, and it's the pinnacle of my hatred for shit which requires multiple files to represent one thing
            //This whole view individual file thing doesn't seem suitable for this... anyway, the most notable problem is that due to the way I wrote all this other code here, it asks you for which track before you select a handler, and that feels kinda weird? Like I think that's kinda weird but anyway whatever who cares nothing matters
            try {
                using (var file = path.OpenRead()) {
                    var cue = CueSheet.create(file, path.Extension);

                    var choices = cue.filenames;
                    var choice  = chooseChoices(choices.Where(c => c.isData), "filename", "Which file do you want to view from this cuesheet?", "File selection");

                    if (choice != null)
                    {
                        FileInfo filename = new FileInfo(Path.Combine(path.DirectoryName, choice.filename));
                        using (ROMFile rom = new NormalROMFile(filename)) {
                            rom.cdSectorSize = choice.sectorSize;
                            viewFile(rom, true);
                        }
                    }
                    //TODO: Include a way for user to view the cuesheet itself or non-data tracks, if they reaaaally wanted to do that
                }
            } catch (Exception ex) {
                MessageBox.Show(ex.ToString(), "Uh oh spaghetti-o", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var cueText = File.ReadAllText("Sample.cue");

            var cueSheet = CueSheet.Parse(cueText);
            var output   = cueSheet.ToString();
        }
Exemple #3
0
        public TimeSpan max(string path)
        {
            CueSheet      cue     = new CueSheet(path);
            List <Marker> markers = openMarkers(path);

            return(markers[markers.Count - 1].Time);
        }
Exemple #4
0
        private static async Task CreateCueFileFromChapters(Video video, string targetMp3File)
        {
            Console.WriteLine("Try getting chapters ... ");
            var chapters = await video.TryGetChaptersAsync(Client);

            if (chapters.Count() == 0)
            {
                var color = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("No chapters found for video.");
                Console.ForegroundColor = color;

                return;
            }

            var filePath = Path.GetDirectoryName(targetMp3File);
            var fileName = Path.GetFileName(targetMp3File);
            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(targetMp3File);

            var cueSheet = new CueSheet
            {
                Performer = "Various Artists",
                Title     = video.Title,
                File      = fileName,
                FileType  = "MP3",
            };

            int trackIndex = 0;

            foreach (var chapter in chapters)
            {
                var artist = chapter.Title;
                var title  = chapter.Title;

                MatchCollection regexResult = Regex.Matches(chapter.Title, "^(.+)(?=-)|(?!<-)([^-]+)$");

                if (regexResult.Count > 1)
                {
                    if (regexResult[0].Success && regexResult[1].Success)
                    {
                        artist = regexResult[0].Groups[0].Value.Trim();
                        title  = regexResult[1].Groups[0].Value.Trim();
                    }
                }

                var duration = TimeSpan.FromMilliseconds(chapter.TimeRangeStart);

                if (cueSheet.Tracks.Count == 0)
                {
                    cueSheet.AddTrack(title, artist);
                    cueSheet.AddIndex(trackIndex++, 1, 0, 0, 0);
                    continue;
                }

                cueSheet.AddTrack(title, artist);
                cueSheet.AddIndex(trackIndex++, 1, (int)Math.Round(duration.TotalMinutes, MidpointRounding.ToEven), duration.Seconds, 0);
            }

            cueSheet.SaveCue(Path.Combine(filePath, fileNameWithoutExtension + ".cue"));
        }
Exemple #5
0
        private void DoConversion(object threadDto)
        {
            ThreadDto     dto = (ThreadDto)threadDto;
            DirectoryInfo workingDirectory = dto.cueFileInfo.Directory;
            CueSheet      cueSheet         = new CueSheet(dto.cueFileInfo.FullName);
            int           currentSector    = 0;
            StringWriter  gdiOutput        = new StringWriter();

            Invoke((MethodInvoker) delegate { progressBar1.Maximum = cueSheet.Tracks.Length; });
            gdiOutput.WriteLine(cueSheet.Tracks.Length.ToString());
            for (int i = 0; i < cueSheet.Tracks.Length; i++)
            {
                Track  currentTrack        = cueSheet.Tracks[i];
                string inputTrackFilePath  = Path.Combine(workingDirectory.FullName, currentTrack.DataFile.Filename);
                bool   canPerformFullCopy  = currentTrack.Indices.Length == 1;
                string outputTrackFileName = string.Format(
                    "track{0}.{1}",
                    currentTrack.TrackNumber,
                    currentTrack.TrackDataType == DataType.AUDIO ? "raw" : "bin");
                string outputTrackFilePath = Path.Combine(workingDirectory.FullName, outputTrackFileName);
                int    sectorAmount;
                if (canPerformFullCopy)
                {
                    File.Copy(inputTrackFilePath, outputTrackFilePath);
                    sectorAmount = (int)(new FileInfo(inputTrackFilePath).Length / 2352);
                }
                else
                {
                    int gapOffset = CountIndexFrames(currentTrack.Indices[1]);
                    sectorAmount   = CopyFileWithGapOffset(inputTrackFilePath, outputTrackFilePath, gapOffset);
                    currentSector += gapOffset;
                }

                int gap = 0;

                gdiOutput.WriteLine("{0} {1} {2} 2352 {3} {4}",
                                    currentTrack.TrackNumber,
                                    currentSector,
                                    currentTrack.TrackDataType == DataType.AUDIO ? "0" : "4",
                                    outputTrackFileName,
                                    gap);

                Invoke((MethodInvoker) delegate { progressBar1.Value++; });
                currentSector += sectorAmount;

                if (currentTrack.Comments.Contains("HIGH-DENSITY AREA"))
                {
                    if (currentSector < 45000)
                    {
                        currentSector = 45000;
                    }
                }
            }

            string gdiOutputPath = Path.Combine(workingDirectory.FullName, "disc.gdi");

            File.WriteAllText(gdiOutputPath, gdiOutput.ToString());
            inProgress = false;
        }
 private FileTag GetAlbum(CueSheet cs)
 {
     return(new FileTag()
     {
         Key = TagMatchingConstants.AlbumTagKey,
         Value = cs.Title
     });
 }
Exemple #7
0
        public void TestCueParser()
        {
            var cuefile   = StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/BCXA-1171.cue")).GetAwaiter().GetResult();
            var cueString = FileIO.ReadTextAsync(cuefile).GetAwaiter().GetResult();
            var cue       = new CueSheet(cueString, null);

            Assert.IsTrue(cue.Tracks.Length == 2);
        }
        public void Can_Parse_Nonstandard_Noncompliant_CueSheet_File()
        {
            using (Stream stream = GetNonstandardNoncompliantCueSheet())
            {
                var      parser   = new CueSheetParser(stream);
                CueSheet cueSheet = parser.Parse();

                Assert.IsNotNull(cueSheet);
            }
        }
        public void Can_Parse_Standard_CueSheet_File()
        {
            using (Stream stream = GetStandardCueSheet())
            {
                var      parser   = new CueSheetParser(stream);
                CueSheet cueSheet = parser.Parse();

                Assert.IsNotNull(cueSheet);
            }
        }
        public void Can_Parse_Nonstandard_Noncompliant_CueSheet_Track_Level_Commands()
        {
            using (Stream stream = GetNonstandardNoncompliantCueSheet())
            {
                var      parser   = new CueSheetParser(stream);
                CueSheet cueSheet = parser.Parse();

                File file1 = cueSheet.Files[0];

                Assert.AreEqual(1, file1.Tracks.Count);

                Track track1 = file1.Tracks[0];

                Assert.AreEqual(1, track1.TrackNum);
                Assert.AreEqual("AUDIO", track1.TrackType);
                Assert.AreEqual("Punish My Heaven", track1.Title);
                Assert.AreEqual("Dark Tranquillity", track1.Performer);
                Assert.AreEqual("DCP", track1.Flags);

                Assert.AreEqual(1, track1.Indexes.Count);

                Index index1 = track1.Indexes[0];

                Assert.AreEqual(1, index1.IndexNum);
                Assert.AreEqual(0, index1.IndexTime.Minutes);
                Assert.AreEqual(0, index1.IndexTime.Seconds);
                Assert.AreEqual(0, index1.IndexTime.Frames);

                File file9 = cueSheet.Files[9];

                track1 = file9.Tracks[0];

                Assert.AreEqual(10, track1.TrackNum);
                Assert.AreEqual("AUDIO", track1.TrackType);
                Assert.AreEqual("Mine Is The Grandeur...", track1.Title);
                Assert.AreEqual("Dark Tranquillity", track1.Performer);
                Assert.AreEqual("DCP", track1.Flags);

                Assert.AreEqual(2, track1.Indexes.Count);

                Index index0 = track1.Indexes[0];

                Assert.AreEqual(0, index0.IndexNum);
                Assert.AreEqual(5, index0.IndexTime.Minutes);
                Assert.AreEqual(41, index0.IndexTime.Seconds);
                Assert.AreEqual(65, index0.IndexTime.Frames);

                index1 = track1.Indexes[1];

                Assert.AreEqual(1, index1.IndexNum);
                Assert.AreEqual(0, index1.IndexTime.Minutes);
                Assert.AreEqual(0, index1.IndexTime.Seconds);
                Assert.AreEqual(0, index1.IndexTime.Frames);
            }
        }
Exemple #11
0
        public void CreateInvalidCueSheet()
        {
            FileHelper.GetNewFile(origFile, newFile);

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

                flac.Metadata.Add(sheet);

                flac.Save();
            }
        }
        public void CreateInvalidCueSheet()
        {
            FileHelper.GetNewFile(origFile, newFile);

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

                flac.Metadata.Add(sheet);

                flac.Save();
            }
        }
Exemple #13
0
        /// <summary>
        /// Create a new cuesheet from scratch
        /// </summary>
        static void NewCueSheet()
        {
            CueSheet cue = new CueSheet();

            //Album performer
            cue.Performer = "Rotterdam Philharmonic Orchestra";
            //Album title
            cue.Title = "Edo de Waart / Rachmaninoff: The 3 Symphonies, The Rock - Disc 1";

            //Create 1st track, with a filename that future tracks will inherit
            cue.AddTrack("Symphony No. 2 in E minor, Op. 27: I. Largo - Allegro moderato", "", "CDImage.ape", FileType.WAVE);
            cue.AddIndex(0, 0, 0, 0, 0);
            cue.AddIndex(0, 1, 0, 0, 33);

            //Create 2nd track, with optional 'Performance' field used
            cue.AddTrack("II. Allegro molto", "Fake G. Uy: Timpani");
            cue.AddIndex(1, 0, 18, 39, 33);
            cue.AddIndex(1, 2, 22, 14, 10); //add another index we'll delete later
            cue.AddIndex(1, 1, 18, 44, 25);

            //Create 3rd track
            cue.AddTrack("III. Adagio", "");
            cue.AddIndex(2, 0, 27, 56, 33);
            cue.AddIndex(2, 1, 27, 59, 40);

            //Create 4th track using a method that gives us more control over the data
            Track tempTrack = new Track(4, DataType.AUDIO);

            tempTrack.Title = "IV. Allegro vivace";
            tempTrack.ISRC  = "0000078652395";
            tempTrack.AddFlag(Flags.CH4);
            tempTrack.AddIndex(0, 41, 57, 33);
            tempTrack.AddIndex(1, 42, 00, 60);
            cue.AddTrack(tempTrack);

            //Create 5th track we'll delete later
            cue.AddTrack("Symphony No. Infinity", "Rachmaninoff's Dog");


            //Remove the bad index from the 2nd track
            cue.RemoveIndex(1, 1);//(trackIndex, indexIndex)
            //Notice the index (array-wise) of the Index (cuesheet min/sec/frame) is '1'
            //but the Index Number is 2. This is to show that index and the Index Number are
            //not the same thing and may or may not be equal.

            //Remove the 5th track
            cue.RemoveTrack(4);

            Console.WriteLine(cue.ToString());
            cue.SaveCue("newCDImage.cue");
        }
        public void Can_Parse_Standard_CueSheet_Track_Level_Commands()
        {
            using (Stream stream = GetStandardCueSheet())
            {
                var      parser   = new CueSheetParser(stream);
                CueSheet cueSheet = parser.Parse();

                File file = cueSheet.Files[0];

                Assert.AreEqual(4, file.Tracks.Count);

                Track track1 = file.Tracks[0];

                Assert.AreEqual(1, track1.TrackNum);
                Assert.AreEqual("AUDIO", track1.TrackType);
                Assert.AreEqual("Black winter day", track1.Title);
                Assert.AreEqual("AMORPHIS", track1.Performer);

                Assert.AreEqual(1, track1.Indexes.Count);

                Index index1 = track1.Indexes[0];

                Assert.AreEqual(1, index1.IndexNum);
                Assert.AreEqual(0, index1.IndexTime.Minutes);
                Assert.AreEqual(0, index1.IndexTime.Seconds);
                Assert.AreEqual(0, index1.IndexTime.Frames);

                Track track4 = file.Tracks[3];

                Assert.AreEqual(4, track4.TrackNum);
                Assert.AreEqual("AUDIO", track4.TrackType);
                Assert.AreEqual("Moon and sun Part II: North's son", track4.Title);
                Assert.AreEqual("AMORPHIS", track4.Performer);

                Assert.AreEqual(2, track4.Indexes.Count);

                Index index0 = track4.Indexes[0];

                Assert.AreEqual(0, index0.IndexNum);
                Assert.AreEqual(8, index0.IndexTime.Minutes);
                Assert.AreEqual(45, index0.IndexTime.Seconds);
                Assert.AreEqual(55, index0.IndexTime.Frames);

                index1 = track4.Indexes[1];

                Assert.AreEqual(1, index1.IndexNum);
                Assert.AreEqual(8, index1.IndexTime.Minutes);
                Assert.AreEqual(47, index1.IndexTime.Seconds);
                Assert.AreEqual(0, index1.IndexTime.Frames);
            }
        }
Exemple #15
0
        public void OpenFlacFileAndCreateMultipleCueSheets()
        {
            int    cueSheetCount = 0;
            string origFile      = @"Data\testfile4.flac";
            string newFile       = @"Data\testfile4_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    if (flac.CueSheet != null)
                    {
                        cueSheetCount = 1;
                    }

                    // Add a second (empty) cuesheet
                    CueSheet newCueSheet = new CueSheet();
                    newCueSheet.Tracks.Add(new CueSheetTrack()
                    {
                        TrackNumber = CueSheet.CUESHEET_LEADOUT_TRACK_NUMBER_CDDA
                    });
                    flac.Metadata.Add(newCueSheet);
                    // Add a third (empty) cuesheet
                    newCueSheet = new CueSheet();
                    newCueSheet.Tracks.Add(new CueSheetTrack()
                    {
                        TrackNumber = CueSheet.CUESHEET_LEADOUT_TRACK_NUMBER_CDDA
                    });
                    flac.Metadata.Add(newCueSheet);

                    cueSheetCount += 2;

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.AreEqual <int>(cueSheetCount, flac.GetAllCueSheets().Count());
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Exemple #16
0
        /// <summary>
        /// Open an manipulate an existing cuesheet.
        /// </summary>
        static void OpenExistingFile()
        {
            //Incomplete FreeDB feature
            //Console.WriteLine(cue.CalculateCDDBdiscID());
            //Console.Read();

            //open a cuesheet from file with the default encoding.
            CueSheet cue = new CueSheet("CDImage.cue");

            //print out the title from the global section of the cue file
            Console.WriteLine(cue.Title);

            //print out the performer from the global section of the cue file
            Console.WriteLine(cue.Performer);

            //Show how many track there are
            Console.WriteLine("There are " + cue.Tracks.Length.ToString() + "tracks in this cue file.");

            //Write out the first track
            Console.WriteLine(cue[0].ToString());

            Console.WriteLine("------ Start CueSheet -------");
            Console.WriteLine(cue.ToString());
            Console.WriteLine("------  End CueSheet  -------");

            //print out the title of the second track
            Console.WriteLine(cue[1].Title);

            //print out the Minutes, seconds, and frames of the first index of the second track.
            Console.WriteLine(cue[1][0].Minutes);
            Console.WriteLine(cue[1][0].Seconds);
            Console.WriteLine(cue[1][0].Frames);

            //Print out the image filename
            Console.WriteLine("Data file location: " + cue[0].DataFile.Filename);

            //change the title of the cuesheet
            cue.Title = "Great Music";

            //Manipulate the first track
            Track tempTrack = cue[0];               //create a tempTrack to change info

            tempTrack.AddFlag(Flags.CH4);           //add a new flag
            tempTrack.Title = "Wonderful track #1"; //change the title
            cue[0]          = tempTrack;            //Set the 1st track with the newly manipulated track.

            cue.SaveCue("newcue.cue");
        }
Exemple #17
0
        public void CueSheetTest()
        {
            string path = @"..\..\[cue_Sample]\ARCHIVES 2.cue";

            if (!File.Exists(path))
            {
                path = @"..\" + path;
            }
            var cue = new CueSheet(path);
            var ci  = cue.ToChapterInfo();

            foreach (var track in cue.Tracks)
            {
                Console.WriteLine($"{track.Title} {track.Performer} {track.Indices.Last().Time}");
            }
        }
        public void Can_Parse_Standard_CueSheet_File_Level_Commands()
        {
            using (Stream stream = GetStandardCueSheet())
            {
                var      parser   = new CueSheetParser(stream);
                CueSheet cueSheet = parser.Parse();

                Assert.AreEqual("AMORPHIS", cueSheet.Performer);
                Assert.AreEqual("Black winter day", cueSheet.Title);

                Assert.AreEqual(1, cueSheet.Files.Count);

                Assert.AreEqual("AMORPHIS - Black winter day.flac", cueSheet.Files[0].FileName);
                Assert.AreEqual("WAVE", cueSheet.Files[0].FileType);
            }
        }
Exemple #19
0
        public CueSourceItem(string targetFilename, CueSheet cueSheet, int trackIndex)
        {
            this.targetFilename = targetFilename;
            this.cueSheet       = cueSheet;
            this.trackIndex     = trackIndex;

            this.Tag = new AudioFileTag()
            {
                AlbumArtists = this.cueSheet.Performer,
                Artists      = this.cueSheet.Tracks[this.trackIndex].Performer ?? this.cueSheet.Performer,
                Title        = this.cueSheet.Tracks[this.trackIndex].Title,
                Album        = this.cueSheet.Title,
                Track        = this.trackIndex + 1,
                TrackCount   = this.cueSheet.Tracks.Length
            };
        }
        public void Can_Parse_Nonstandard_CueSheet_Track_Level_Commands()
        {
            using (Stream stream = GetNonstandardCueSheet())
            {
                var      parser   = new CueSheetParser(stream);
                CueSheet cueSheet = parser.Parse();

                File file1 = cueSheet.Files[0];

                Assert.AreEqual(1, file1.Tracks.Count);

                Track track1 = file1.Tracks[0];

                Assert.AreEqual(1, track1.TrackNum);
                Assert.AreEqual("AUDIO", track1.TrackType);
                Assert.AreEqual("Mass Hypnosis", track1.Title);
                Assert.AreEqual("Nasum", track1.Performer);

                Assert.AreEqual(1, track1.Indexes.Count);

                Index index1 = track1.Indexes[0];

                Assert.AreEqual(1, index1.IndexNum);
                Assert.AreEqual(0, index1.IndexTime.Minutes);
                Assert.AreEqual(0, index1.IndexTime.Seconds);
                Assert.AreEqual(0, index1.IndexTime.Frames);

                File file25 = cueSheet.Files[24];

                track1 = file25.Tracks[0];

                Assert.AreEqual(25, track1.TrackNum);
                Assert.AreEqual("AUDIO", track1.TrackType);
                Assert.AreEqual("Sometimes Dead is Better", track1.Title);
                Assert.AreEqual("Nasum", track1.Performer);

                Assert.AreEqual(1, track1.Indexes.Count);

                index1 = track1.Indexes[0];

                Assert.AreEqual(1, index1.IndexNum);
                Assert.AreEqual(0, index1.IndexTime.Minutes);
                Assert.AreEqual(0, index1.IndexTime.Seconds);
                Assert.AreEqual(0, index1.IndexTime.Frames);
            }
        }
Exemple #21
0
        public void OverflowCueSheetTracks()
        {
            string flacFile = @"Data\testfile4.flac";

            using (FlacFile file = new FlacFile(flacFile))
            {
                CueSheet sheet = new CueSheet();

                for (int i = 0; i < 100; i++)
                {
                    sheet.Tracks.Add(new CueSheetTrack());
                }

                // This guy should throw an exception ...
                sheet.Tracks.Add(new CueSheetTrack());
            }
        }
        private void WorkerTask()
        {
            while (true)
            {
                string item;
                if (this.shouldCancel || !this.tasks.TryTake(out item, -1))
                {
                    break;
                }

                try
                {
                    if (AudioHelper.IsSupportedAudioSource(item))
                    {
                        this.ProcessAudio(AudioHelper.GetAudioSourceForFile(item), Path.GetDirectoryName(item), Path.GetFileName(item));
                    }
                    else if (item.ToLower().EndsWith(".cue"))
                    {
                        CueSheet sheet = new CueSheet(item);

                        bool   isOriginal;
                        string target = sheet.DiscoverTarget(out isOriginal);
                        if (target == null)
                        {
                            Dialogs.Error("Cue target not found.");
                            continue;
                        }
                        for (int i = 0; i < sheet.Tracks.Length; ++i)
                        {
                            IAudioSource    fullFileSource = AudioHelper.GetAudioSourceForFile(target);
                            AudioSourcePart sourcePart     = new AudioSourcePart(fullFileSource);
                            sourcePart.SetLengthFrames(
                                sheet.GetTrackStartFrame(i),
                                sheet.GetTrackEndFrame(i));
                            this.ProcessAudio(sourcePart, target, (i + 1).ToString("00") + ". " + sheet.Tracks[i].Title);
                        }
                    }
                }
                catch (Exception e)
                {
                    Utility.WriteToErrorLog(e.ToString());
                    Dialogs.Error("Error processing file " + item + ": " + e.Message);
                }
            }
        }
        public void Can_Parse_Nonstandard_CueSheet_File_Level_Commands()
        {
            using (Stream stream = GetNonstandardCueSheet())
            {
                var      parser   = new CueSheetParser(stream);
                CueSheet cueSheet = parser.Parse();

                Assert.AreEqual("Nasum", cueSheet.Performer);
                Assert.AreEqual("Human 2.0", cueSheet.Title);

                Assert.AreEqual(25, cueSheet.Files.Count);

                Assert.AreEqual("01 Nasum - Mass Hypnosis.flac", cueSheet.Files[0].FileName);
                Assert.AreEqual("WAVE", cueSheet.Files[0].FileType);

                Assert.AreEqual("25 Nasum - Sometimes Dead is Better.flac", cueSheet.Files[24].FileName);
                Assert.AreEqual("WAVE", cueSheet.Files[24].FileType);
            }
        }
Exemple #24
0
        public void OverflowCueSheetTrackIndexPoints()
        {
            string flacFile = Path.Combine("Data", "testfile4.flac");

            using (FlacFile file = new FlacFile(flacFile))
            {
                CueSheet sheet = new CueSheet();

                sheet.Tracks.Add(new CueSheetTrack());

                for (int i = 0; i < 100; i++)
                {
                    sheet.Tracks[0].IndexPoints.Add(new CueSheetTrackIndex());
                }

                // This guy should throw an exception ...
                sheet.Tracks[0].IndexPoints.Add(new CueSheetTrackIndex());
            }
        }
        public void Can_Parse_Nonstandard_Noncompliant_CueSheet_File_Level_Commands()
        {
            using (Stream stream = GetNonstandardNoncompliantCueSheet())
            {
                var      parser   = new CueSheetParser(stream);
                CueSheet cueSheet = parser.Parse();

                Assert.AreEqual("Dark Tranquillity", cueSheet.Performer);
                Assert.AreEqual("The Gallery", cueSheet.Title);

                Assert.AreEqual(11, cueSheet.Files.Count);

                Assert.AreEqual("01 Punish My Heaven.flac", cueSheet.Files[0].FileName);
                Assert.AreEqual("WAVE", cueSheet.Files[0].FileType);

                Assert.AreEqual("11 ...Of Melancholy Burning.flac", cueSheet.Files[10].FileName);
                Assert.AreEqual("WAVE", cueSheet.Files[10].FileType);
            }
        }
        public FileTagCollection GetTags(string filePath)
        {
            try
            {
                var cueSheet = new CueSheet(filePath);
                return(new FileTagCollection(GetTags(cueSheet)));
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
            }

            return(new FileTagCollection());

            /*
             *         public static readonly string ArtistTagKey = "ARTIST";
             * public static readonly string AlbumTagKey = "ALBUM";
             * public static readonly string GenreTagKey = "GENRE";*/
        }
        static void CopyOriginalsToOutputPath(string outputPath, string cueFilePath, CueSheet sheet, string coverPath)
        {
            if (string.IsNullOrWhiteSpace(outputPath))
            {
                throw new ArgumentNullException("outputPath");
            }

            if (string.IsNullOrWhiteSpace(cueFilePath))
            {
                throw new ArgumentNullException("cueFilePath");
            }

            if (sheet == null)
            {
                throw new ArgumentNullException("sheet");
            }

            if (!string.IsNullOrWhiteSpace(coverPath))
            {
                IOUtils.FileCopy(coverPath, Path.Combine(outputPath, "cover" + Path.GetExtension(coverPath)));
            }

            DirectoryInfo outputDirInfo = Directory.CreateDirectory(Path.Combine(outputPath, GetOriginalFileDirName(sheet)));

            string cueOutputPath = Path.Combine(outputDirInfo.FullName, Path.GetFileName(cueFilePath));

            IOUtils.FileCopy(cueFilePath, cueOutputPath);

            foreach (var file in sheet.Files)
            {
                string cueDirName = Path.GetDirectoryName(cueFilePath);

                if (cueDirName == null)
                {
                    throw new Exception("Cue file path is missing directory.");
                }

                IOUtils.FileCopy(
                    Path.Combine(cueDirName, file.FileName),
                    Path.Combine(outputDirInfo.FullName, file.FileName));
            }
        }
 private FileTag GetArtist(CueSheet cs)
 {
     if (!String.IsNullOrEmpty(cs.Performer))
     {
         return new FileTag()
                {
                    Key   = TagMatchingConstants.ArtistTagKey,
                    Value = cs.Performer
                }
     }
     ;
     else
     {
         return new FileTag()
                {
                    Key   = TagMatchingConstants.ArtistTagKey,
                    Value = cs.Songwriter
                }
     };
 }
        static string BuildCuesheetTypeStr(CueSheet cueSheet)
        {
            string msg;

            if (cueSheet.IsStandard)
            {
                msg = "standard";
            }
            else
            {
                msg = "nonstandard";

                if (cueSheet.IsNoncompliant)
                {
                    msg += ", noncompliant";
                }
            }

            return(msg);
        }
Exemple #30
0
        public List <Marker> openMarkers(string path)
        {
            CueSheet      cue     = new CueSheet(path);
            List <Marker> markers = new List <Marker>();
            bool          ms      = false;

            if (cue.Comments[0] == "MS")
            {
                ms = true;
            }
            for (int i = 1; i < cue.Tracks.Length; i++)
            {
                TimeSpan fromMins = TimeSpan.FromMinutes(cue[i][0].Minutes);
                markers.Add(new Marker(new TimeSpan(
                                           0, (int)fromMins.TotalHours,
                                           fromMins.Minutes,
                                           cue[i][0].Seconds,
                                           ms ? cue[i][0].Frames : (int)(cue[i][0].Frames * (1000 / 75d)))));
            }
            return(markers);
        }
Exemple #31
0
        private void AddCue(string file)
        {
            CueSheet sheet;

            try
            {
                sheet = new CueSheet(file);
            }
            catch (Exception e)
            {
                Utility.WriteToErrorLog(e.ToString());
                Dialogs.Error("Error reading cue file. Invalid format.");
                return;
            }

            bool   isOriginal;
            string targetFilename = sheet.DiscoverTarget(out isOriginal);

            if (targetFilename == null)
            {
                Dialogs.Error("Cue target was not found!");
                return;
            }
            else if (!isOriginal)
            {
                Dialogs.Inform("Cue target was not found, but successfully discovered.");
            }

            if (!AudioHelper.IsSupportedAudioSource(targetFilename))
            {
                Dialogs.Error("Unsupported audio source!");
                return;
            }

            for (int i = 0; i < sheet.Tracks.Length; ++i)
            {
                CueSourceItem item = new CueSourceItem(targetFilename, sheet, i);
                this.AddItem(item);
            }
        }
        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 OpenFlacFileAndCreateMultipleCueSheets()
        {
            int cueSheetCount = 0;
            string origFile = @"Data\testfile4.flac";
            string newFile = @"Data\testfile4_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    if (flac.CueSheet != null)
                    {
                        cueSheetCount = 1;
                    }

                    // Add a second (empty) cuesheet
                    CueSheet newCueSheet = new CueSheet();
                    newCueSheet.Tracks.Add(new CueSheetTrack() { TrackNumber = CueSheet.CUESHEET_LEADOUT_TRACK_NUMBER_CDDA });
                    flac.Metadata.Add(newCueSheet);
                    // Add a third (empty) cuesheet
                    newCueSheet = new CueSheet();
                    newCueSheet.Tracks.Add(new CueSheetTrack() { TrackNumber = CueSheet.CUESHEET_LEADOUT_TRACK_NUMBER_CDDA });
                    flac.Metadata.Add(newCueSheet);

                    cueSheetCount += 2;

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.AreEqual<int>(cueSheetCount, flac.GetAllCueSheets().Count());
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
        public void OverflowCueSheetTracks()
        {
            string flacFile = @"Data\testfile4.flac";

            using (FlacFile file = new FlacFile(flacFile))
            {
                CueSheet sheet = new CueSheet();

                for (int i = 0; i < 100; i++)
                {
                    sheet.Tracks.Add(new CueSheetTrack());
                }

                // This guy should throw an exception ...
                sheet.Tracks.Add(new CueSheetTrack());
            }
        }