Example #1
0
        /// <summary>
        /// Fill a TRACK from an array of lines
        /// </summary>
        /// <param name="number">Number to set</param>
        /// <param name="dataType">Data type to set</param>
        /// <param name="cueLines">Lines array to pull from</param>
        /// <param name="i">Reference to index in array</param>
        /// <param name="throwOnError">True if errors throw an exception, false otherwise</param>
        public CueTrack(string number, string dataType, string[] cueLines, ref int i, bool throwOnError = false)
        {
            if (cueLines == null)
            {
                if (throwOnError)
                {
                    throw new ArgumentNullException(nameof(cueLines));
                }

                return;
            }
            else if (i < 0 || i > cueLines.Length)
            {
                if (throwOnError)
                {
                    throw new IndexOutOfRangeException();
                }

                return;
            }

            // Set the current fields
            if (!int.TryParse(number, out int parsedNumber))
            {
                if (throwOnError)
                {
                    throw new ArgumentException($"Number was not a number: {number}");
                }

                return;
            }
            else if (parsedNumber < 1 || parsedNumber > 99)
            {
                if (throwOnError)
                {
                    throw new IndexOutOfRangeException($"Index must be between 1 and 99: {parsedNumber}");
                }

                return;
            }

            this.Number   = parsedNumber;
            this.DataType = GetDataType(dataType);

            // Increment to start
            i++;

            for (; i < cueLines.Length; i++)
            {
                string   line      = cueLines[i].Trim();
                string[] splitLine = line.Split(' ');

                // If we have an empty line, we skip
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                switch (splitLine[0])
                {
                // Read comments
                case "REM":
                    // We ignore all comments for now
                    break;

                // Read flag information
                case "FLAGS":
                    if (splitLine.Length < 2)
                    {
                        if (throwOnError)
                        {
                            throw new FormatException($"FLAGS line malformed: {line}");
                        }

                        continue;
                    }

                    this.Flags = GetFlags(splitLine);
                    break;

                // Read International Standard Recording Code
                case "ISRC":
                    if (splitLine.Length < 2)
                    {
                        if (throwOnError)
                        {
                            throw new FormatException($"ISRC line malformed: {line}");
                        }

                        continue;
                    }

                    this.ISRC = splitLine[1];
                    break;

                // Read CD-Text enhanced performer
                case "PERFORMER":
                    if (splitLine.Length < 2)
                    {
                        if (throwOnError)
                        {
                            throw new FormatException($"PERFORMER line malformed: {line}");
                        }

                        continue;
                    }

                    this.Performer = splitLine[1];
                    break;

                // Read CD-Text enhanced songwriter
                case "SONGWRITER":
                    if (splitLine.Length < 2)
                    {
                        if (throwOnError)
                        {
                            throw new FormatException($"SONGWRITER line malformed: {line}");
                        }

                        continue;
                    }

                    this.Songwriter = splitLine[1];
                    break;

                // Read CD-Text enhanced title
                case "TITLE":
                    if (splitLine.Length < 2)
                    {
                        if (throwOnError)
                        {
                            throw new FormatException($"TITLE line malformed: {line}");
                        }

                        continue;
                    }

                    this.Title = splitLine[1];
                    break;

                // Read pregap information
                case "PREGAP":
                    if (splitLine.Length < 2)
                    {
                        if (throwOnError)
                        {
                            throw new FormatException($"PREGAP line malformed: {line}");
                        }

                        continue;
                    }

                    var pregap = new PreGap(splitLine[1]);
                    if (pregap == default)
                    {
                        if (throwOnError)
                        {
                            throw new FormatException($"PREGAP line malformed: {line}");
                        }

                        continue;
                    }

                    this.PreGap = pregap;
                    break;

                // Read index information
                case "INDEX":
                    if (splitLine.Length < 3)
                    {
                        if (throwOnError)
                        {
                            throw new FormatException($"INDEX line malformed: {line}");
                        }

                        continue;
                    }

                    if (this.Indices == null)
                    {
                        this.Indices = new List <CueIndex>();
                    }

                    var index = new CueIndex(splitLine[1], splitLine[2]);
                    if (index == default)
                    {
                        if (throwOnError)
                        {
                            throw new FormatException($"INDEX line malformed: {line}");
                        }

                        continue;
                    }

                    this.Indices.Add(index);
                    break;

                // Read postgap information
                case "POSTGAP":
                    if (splitLine.Length < 2)
                    {
                        if (throwOnError)
                        {
                            throw new FormatException($"POSTGAP line malformed: {line}");
                        }

                        continue;
                    }

                    var postgap = new PostGap(splitLine[1]);
                    if (postgap == default)
                    {
                        if (throwOnError)
                        {
                            throw new FormatException($"POSTGAP line malformed: {line}");
                        }

                        continue;
                    }

                    this.PostGap = postgap;
                    break;

                // Default means return
                default:
                    i--;
                    return;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Fill a TRACK from an array of lines
        /// </summary>
        /// <param name="number">Number to set</param>
        /// <param name="dataType">Data type to set</param>
        /// <param name="cueLines">Lines array to pull from</param>
        /// <param name="i">Reference to index in array</param>
        public CueTrack(string number, string dataType, string[] cueLines, ref int i)
        {
            if (cueLines == null || i < 0 || i > cueLines.Length)
            {
                return; // TODO: Make this throw an exception
            }
            // Set the current fields
            if (!int.TryParse(number, out int parsedNumber))
            {
                return; // TODO: Make this throw an exception
            }
            else if (parsedNumber < 1 || parsedNumber > 99)
            {
                return; // TODO: Make this throw an exception
            }
            this.Number   = parsedNumber;
            this.DataType = GetDataType(dataType);

            // Increment to start
            i++;

            for (; i < cueLines.Length; i++)
            {
                string   line      = cueLines[i].Trim();
                string[] splitLine = line.Split(' ');

                // If we have an empty line, we skip
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                switch (splitLine[0])
                {
                // Read comments
                case "REM":
                    // We ignore all comments for now
                    break;

                // Read flag information
                case "FLAGS":
                    if (splitLine.Length < 2)
                    {
                        continue;     // TODO: Make this throw an exception
                    }
                    this.Flags = GetFlags(splitLine);
                    break;

                // Read International Standard Recording Code
                case "ISRC":
                    if (splitLine.Length < 2)
                    {
                        continue;     // TODO: Make this throw an exception
                    }
                    this.ISRC = splitLine[1];
                    break;

                // Read CD-Text enhanced performer
                case "PERFORMER":
                    if (splitLine.Length < 2)
                    {
                        continue;     // TODO: Make this throw an exception
                    }
                    this.Performer = splitLine[1];
                    break;

                // Read CD-Text enhanced songwriter
                case "SONGWRITER":
                    if (splitLine.Length < 2)
                    {
                        continue;     // TODO: Make this throw an exception
                    }
                    this.Songwriter = splitLine[1];
                    break;

                // Read CD-Text enhanced title
                case "TITLE":
                    if (splitLine.Length < 2)
                    {
                        continue;     // TODO: Make this throw an exception
                    }
                    this.Title = splitLine[1];
                    break;

                // Read pregap information
                case "PREGAP":
                    if (splitLine.Length < 2)
                    {
                        continue;     // TODO: Make this throw an exception
                    }
                    var pregap = new PreGap(splitLine[1]);
                    if (pregap == default)
                    {
                        continue;     // TODO: Make this throw an exception
                    }
                    this.PreGap = pregap;
                    break;

                // Read index information
                case "INDEX":
                    if (splitLine.Length < 3)
                    {
                        continue;     // TODO: Make this throw an exception
                    }
                    if (this.Indices == null)
                    {
                        this.Indices = new List <CueIndex>();
                    }

                    var index = new CueIndex(splitLine[1], splitLine[2]);
                    if (index == default)
                    {
                        continue;     // TODO: Make this throw an exception
                    }
                    this.Indices.Add(index);
                    break;

                // Read postgap information
                case "POSTGAP":
                    if (splitLine.Length < 2)
                    {
                        continue;     // TODO: Make this throw an exception
                    }
                    var postgap = new PostGap(splitLine[1]);
                    if (postgap == default)
                    {
                        continue;     // TODO: Make this throw an exception
                    }
                    this.PostGap = postgap;
                    break;

                // Default means return
                default:
                    i--;
                    return;
                }
            }
        }