Esempio n. 1
0
        public static void Write(CueFile cueFile, string file)
        {
            using (var stream = new FileStream(file, FileMode.Create))
            {
                using (var writer = new StreamWriter(stream))
                {
                    foreach (var entry in cueFile.FileEntries)
                    {
                        writer.WriteLine($"FILE \"{entry.FileName}\" {entry.FileType}");
                        foreach (var cueTrack in entry.Tracks)
                        {
                            writer.WriteLine($"  TRACK {cueTrack.Number:00} {cueTrack.DataType}");

                            foreach (var cueIndex in cueTrack.Indexes)
                            {
                                writer.WriteLine($"    INDEX {cueIndex.Number:00} {cueIndex.Position.ToString()}");
                            }
                        }
                    }

                    writer.Flush();
                }
            }
        }
Esempio n. 2
0
        public static CueFile Read(string file)
        {
            var cueFile = new CueFile();

            CueFileEntry cueFileEntry = null;
            CueTrack     cueTrack     = null;
            var          cueLines     = File.ReadAllLines(file);

            foreach (var line in cueLines)
            {
                var fileMatch  = FileRegex.Match(line);
                var trackMatch = TrackRegex.Match(line);
                var indexMatch = IndexRegex.Match(line);

                if (fileMatch.Success)
                {
                    cueFileEntry = new CueFileEntry
                    {
                        FileName = fileMatch.Groups[1].Value,
                        FileType = fileMatch.Groups[2].Value,
                        Tracks   = new List <CueTrack>()
                    };
                    cueFile.FileEntries.Add(cueFileEntry);
                }
                else if (trackMatch.Success)
                {
                    //Define the numberth track, whose type is data - type.The value number is a strictly positive integer and must be one greater than the last one supplied to a previous TRACK command,
                    //notwithstanding number can be greater than 1 in the first occurrence of TRACK command; however, it cannot exceed 99 in any case. Usually number is padded with a 0 on the left when smaller than 10,
                    //in order to keep track numbers two digit wide uniformly throughout the CUE sheet.The data-type argument is one of those described at MODE(Compact Disc fields).

                    cueTrack = new CueTrack
                    {
                        Number   = int.Parse(trackMatch.Groups[1].Value),
                        DataType = trackMatch.Groups[2].Value,
                        Indexes  = new List <CueIndex>()
                    };
                    cueFileEntry.Tracks.Add(cueTrack);
                }
                else if (indexMatch.Success)
                {
                    //If number is 0, then consider the time specified by the next INDEX command as the track pre-gap length present in the file declared by the current FILE command context.
                    //If number is 1, then define the starting time of the index of this track as mm minutes plus ss seconds plus ff frames.This index specify the starting time of track data and is the only stored in the table-of - contents of the disc.
                    //If number is 2 or more, then define the starting time of the(number-1)th sub-index within this track as mm minutes plus ss seconds plus ff frames.
                    //If this is the first INDEX command of the current TRACK command context, then it must start at 00:00:00 and number must be either 0 or 1.
                    //If this is not the first INDEX command of the current TRACK command context, then number must be one greater than that of the last TRACK command.
                    //The value number cannot be greater than 99 and is usually padded with a 0 on the left when smaller than 10, in order to keep index and sub-index numbers two digit wide uniformly throughout the CUE sheet.
                    //The time mm: ss: ff is an offset relative to the beginning of the file specified by the current FILE command context.
                    //The values mm, ss and ff must be non-negative integers.
                    //There are 75 frames per second.

                    var positionMatch = indexMatch.Groups[2].Value.Split(new char[] { ':' });

                    var cueIndex = new CueIndex
                    {
                        Number   = int.Parse(indexMatch.Groups[1].Value),
                        Position = new IndexPosition()
                        {
                            Minutes = int.Parse(positionMatch[0]),
                            Seconds = int.Parse(positionMatch[1]),
                            Frames  = int.Parse(positionMatch[2]),
                        }
                    };
                    cueTrack.Indexes.Add(cueIndex);
                }
            }

            return(cueFile);
        }