Exemplo n.º 1
0
        /// <summary>
        /// Reads in the song information from the directory in which a midi file
        /// and its supporting files are stored.  Since this function never
        /// actually accesses the midi file itself (just song.ini), it does not
        /// need to be merged with the midi parsing function.
        /// </summary>
        /// <param name="inputPath">
        /// The path to the midi file (which also contains song.ini)
        /// </param>
        /// <returns>
        /// A filled out ChartInfo instance.
        /// </returns>
        public static Info AddSongInfoFromMidi(string inputPath)
        {
            Info chartInfoToReturn = new Info();

            chartInfoToReturn.offset = 0;

            if (File.Exists(inputPath + "\\song.ogg"))
            {
                chartInfoToReturn.musicStream = "song.ogg";
            }

            if (File.Exists(inputPath + "\\guitar.ogg"))
            {
                chartInfoToReturn.guitarStream = "guitar.ogg";
            }

            if (File.Exists(inputPath + "\\rhythm.ogg"))
            {
                chartInfoToReturn.bassStream = "rhythm.ogg";
            }

            if (File.Exists(inputPath + "\\drums.ogg"))
            {
                chartInfoToReturn.drumStream = "drums.ogg";
            }

            if (File.Exists(inputPath + "\\song.ini"))
            {
                StreamReader inputStream  = new StreamReader(inputPath + "\\Song.ini");
                string       inputFile    = inputStream.ReadToEnd();
                StringReader stringReader = new StringReader(inputFile);
                string       currentLine  = "";
                string[]     parsedLine;

                while ((currentLine = stringReader.ReadLine()) != null)
                {
                    // Trim and split the line to retrieve information
                    currentLine = currentLine.Trim();
                    parsedLine  = currentLine.Split(' ');

                    if ((parsedLine[0] == "artist") || (parsedLine[0] == "Artist"))
                    {
                        chartInfoToReturn.artistName = ProperStringCreator.createProperString(parsedLine.SubArray(2, parsedLine.Length));
                    }
                    else if ((parsedLine[0] == "name") || (parsedLine[0] == "Name"))
                    {
                        chartInfoToReturn.songName = ProperStringCreator.createProperString(parsedLine.SubArray(2, parsedLine.Length));
                    }
                    else if (parsedLine[0] == "hopo_note")
                    {
                        chartInfoToReturn.HOPOThreshold = int.Parse(parsedLine[2]);
                    }
                }
            }

            return(chartInfoToReturn);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Opens a specified chart and reads in all the valid events
        /// (i.e 14208 = E "section Verse 1a") and returns a populated list.
        /// </summary>
        /// <param name="input_string">
        /// The whole *.chart file stored in one massive string.
        /// </param>
        /// <returns>
        /// A list containing every valid event from the chart.  Due to the nature
        /// of the *.chart specification, these events will be in proper order.
        /// </returns>
        public static List <Event> AddEventsFromChart(string input_string)
        {
            List <Event> eventListToReturn = new List <Event>();

            // Single out the event section via regular expressions
            string pattern         = Regex.Escape("[") + "Events]\\s*" + Regex.Escape("{") + "[^}]*";
            Match  matched_section = Regex.Match(input_string, pattern);

            // Create the stream from the singled out section of the input string
            StringReader pattern_stream = new StringReader(matched_section.ToString());
            string       current_line   = "";

            string[] parsed_line;

            while ((current_line = pattern_stream.ReadLine()) != null)
            {
                // Trim and split the line to retrieve information
                current_line = current_line.Trim();
                parsed_line  = current_line.Split(' ');

                // If a valid event is found, add it to the list
                if (parsed_line.Length >= 4)
                {
                    if (parsed_line[2] == "E")
                    {
                        eventListToReturn.Add(new Event(Convert.ToUInt32(parsed_line[0]),
                                                        ProperStringCreator.createProperString(parsed_line.SubArray(3, parsed_line.Length))));
                    }
                }
            }

            // Close the string stream
            pattern_stream.Close();

            return(eventListToReturn);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Opens a specified chart and reads in the usable chart information
        /// (i.e. Artist = "Bullet for my Valentine")
        /// </summary>
        /// <param name="inputFile">
        /// The whole *.chart file stored in one massive string.
        /// </param>
        /// <returns>
        /// A filled out ChartInfo instance.
        /// </returns>
        public static Info AddSongInfoFromChart(string inputFile)
        {
            Info chartInfoToReturn = new Info();

            // Single out the song section via regular expressions
            string pattern         = Regex.Escape("[") + "Song]\\s*" + Regex.Escape("{") + "[^}]*";
            Match  matched_section = Regex.Match(inputFile, pattern);

            // Create the stream from the singled out section of the input string
            StringReader stringReader = new StringReader(matched_section.ToString());
            string       currentLine  = "";

            string[] parsedLine;

            while ((currentLine = stringReader.ReadLine()) != null)
            {
                // Trim and split the line to retrieve information
                currentLine = currentLine.Trim();
                parsedLine  = currentLine.Split(' ');

                // Check for various song infos and parse accordingly
                if (parsedLine[0] == "Name")
                {
                    chartInfoToReturn.songName = ProperStringCreator.createProperString(parsedLine.SubArray(2, parsedLine.Length));
                }

                else if (parsedLine[0] == "Artist")
                {
                    chartInfoToReturn.artistName = ProperStringCreator.createProperString(parsedLine.SubArray(2, parsedLine.Length));
                }

                else if (parsedLine[0] == "Offset")
                {
                    chartInfoToReturn.offset = float.Parse(parsedLine[2]);
                }

                else if (parsedLine[0] == "Resolution")
                {
                    chartInfoToReturn.resolution = int.Parse(parsedLine[2]);
                }

                else if (parsedLine[0] == "hopo_note")
                {
                    chartInfoToReturn.HOPOThreshold = int.Parse(parsedLine[2]);
                }

                else if (parsedLine[0] == "MusicStream")
                {
                    chartInfoToReturn.musicStream = ProperStringCreator.createProperString(parsedLine.SubArray(2, parsedLine.Length));
                }

                else if (parsedLine[0] == "GuitarStream")
                {
                    chartInfoToReturn.guitarStream = ProperStringCreator.createProperString(parsedLine.SubArray(2, parsedLine.Length));
                }

                else if (parsedLine[0] == "BassStream")
                {
                    chartInfoToReturn.bassStream = ProperStringCreator.createProperString(parsedLine.SubArray(2, parsedLine.Length));
                }
            }

            // Close the string stream
            stringReader.Close();

            return(chartInfoToReturn);
        }