Пример #1
0
        public override void LoadPattern(Pattern pattern)
        {
            // Don't unnecessarily reload
            if (pattern.loaded == true)
            {
                return;
            }

            // Parse line-by-line
            _index = 0;
            _line  = "";
            ReadAheadStreamReader reader = new ReadAheadStreamReader(_info.path);

            // Skip to main section
            while (_index < pattern.lineIndex)
            {
                _index++;
                reader.SkipLine();
            }

            // Parsing loop
            while (reader.PeekLine() != null)
            {
                _index++;
                _line = reader.ReadLine().Trim();

                // Empty line
                if (_line.Length == 0)
                {
                    continue;
                    // Comment
                }
                else if (_line[0] == ';' || _line[0] == '/')
                {
                    continue;
                    // Section start
                }
                else if (_line[0] == '[')
                {
                    break;                     // End of pattern data
                    // Pattern data
                }
                else
                {
                    // Parse key-value pair
                    string key, val;
                    if (!this.ParseKeyValuePair(_line, out key, out val))
                    {
                        // Skip if not a key-value pair
                        this.Warning("Unparsed line");
                        continue;
                    }
                    this.ParseNote(pattern, key, val);
                }
            }

            // Sort notes
            this.SortNotes(pattern);

            // Cleanup
            pattern.loaded = true;
            reader.Close();
        }
Пример #2
0
        public override void LoadPattern(Pattern pattern)
        {
            // Don't unnecessarily reload
            if (pattern.loaded == true) {
                return;
            }

            // Parse line-by-line
            _index = 0;
            _line = "";
            ReadAheadStreamReader reader = new ReadAheadStreamReader(_info.path);

            // Skip to main section
            while (_index < pattern.lineIndex) {
                _index++;
                reader.SkipLine();
            }

            // Parsing loop
            while (reader.PeekLine() != null) {
                _index++;
                _line = reader.ReadLine().Trim();

                // Empty line
                if (_line.Length == 0) {
                    continue;
                // Comment
                } else if (_line[0] == ';' || _line[0] == '/') {
                    continue;
                // Section start
                } else if (_line[0] == '[') {
                    break; // End of pattern data
                // Pattern data
                } else {
                    // Parse key-value pair
                    string key, val;
                    if (!this.ParseKeyValuePair(_line, out key, out val)) {
                        // Skip if not a key-value pair
                        this.Warning("Unparsed line");
                        continue;
                    }
                    this.ParseNote(pattern, key, val);
                }
            }

            // Sort notes
            this.SortNotes(pattern);

            // Cleanup
            pattern.loaded = true;
            reader.Close();
        }
Пример #3
0
        public override void LoadPattern(Pattern pattern)
        {
            // Don't unnecessarily reload
            if (pattern.loaded == true)
            {
                return;
            }

            // Parse line-by-line
            _index = 0;
            _line  = "";
            int                   beat    = 0;
            List <string>         measure = new List <string>();
            ReadAheadStreamReader reader  = new ReadAheadStreamReader(_info.path);

            // Skip to main section
            while (_index < pattern.lineIndex)
            {
                _index++;
                reader.SkipLine();
            }

            // Parsing loop
            while (reader.PeekLine() != null)
            {
                _index++;
                _line = reader.ReadLine().Trim();

                // Empty line
                if (_line.Length == 0)
                {
                    continue;
                    // Comment
                }
                else if (_line[0] == '/')
                {
                    continue;
                    // New #NOTES section
                }
                else if (_line[0] == '#')
                {
                    break;                     // End of pattern data
                    // End of measure
                }
                else if (_line[0] == ',' || _line[0] == ';')
                {
                    this.ParseMeasure(pattern, beat, measure);
                    measure = new List <string>();
                    beat   += BEATS_PER_MEASURE;
                    if (_line[0] == ';')
                    {
                        break;                         // End of pattern data,
                    }
                    // Pattern data
                }
                else
                {
                    if (_line.Length != pattern.keyCount)
                    {
                        Warning("Line width does not match expected column count of " + pattern.keyCount);
                    }
                    else
                    {
                        measure.Add(_line);
                    }
                }
            }

            // Add BPM change events
            foreach (Bpm bpm in _bpms)
            {
                Note note = new Note();
                note.type          = NoteType.BPM;
                note.eventTime     = this.CalculateTime(bpm.beat);
                note.eventFloatVal = bpm.bpm;
                this.AddNote(pattern, note);
            }

            // Add Stop events
            foreach (Stop stop in _stops)
            {
                Note note = new Note();
                note.type          = NoteType.STOP;
                note.eventTime     = this.CalculateTime(stop.beat);
                note.eventFloatVal = stop.beat;
                this.AddNote(pattern, note);
            }

            // Add background change events
            foreach (Bg bg in _bgs)
            {
                Note note = new Note();
                note.type           = NoteType.BG;
                note.eventTime      = this.CalculateTime(bg.beat);
                note.eventStringVal = bg.filename;
                this.AddNote(pattern, note);
            }

            // Add Label events
            foreach (Label label in _labels)
            {
                Note note = new Note();
                note.type           = NoteType.LABEL;
                note.eventTime      = this.CalculateTime(label.beat);
                note.eventStringVal = label.text;
                this.AddNote(pattern, note);
            }

            // Sort notes
            this.SortNotes(pattern);

            // Cleanup
            pattern.loaded = true;
            reader.Close();
        }