コード例 #1
0
        public static NoteChart.TrackType GetInstrument(BaseTrackType type)
        {
            switch (type)
            {
            case BaseTrackType.DoubleGuitar:
            case BaseTrackType.Single:
                return(NoteChart.TrackType.Guitar);

            case BaseTrackType.DoubleBass:
                return(NoteChart.TrackType.Bass);
            }
            return((NoteChart.TrackType)(0xFF));
        }
コード例 #2
0
        public static Chart Create(Stream stream)
        {
            Chart chart = new Chart();

            StreamReader reader = new StreamReader(stream);

            string    line;
            string    section = null;
            TrackType track   = TrackType.Unknown;

            List <NoteChart.Note>[] notes      = null;
            NoteChart.Instrument    instrument = null;
            while ((line = reader.ReadLine()) != null)
            {
                if (line == "}")
                {
                    section = null;
                }
                else if (line == "{")
                {
                    continue;
                }
                Match match = Regex.Match(line, "\\[(?'section'.+)\\]");
                if (match.Success)
                {
                    section = match.Groups["section"].Value;
                    track   = GetTrackType(section);
                    BaseTrackType type = GetBaseTrackType(track);
                    instrument         = chart.CreateInstrument(GetInstrument(type));
                    chart.Tracks[type] = instrument;
                    notes = (instrument as NoteChart.IGems).Gems[GetDifficulty(track)];
                }
                else
                {
                    ulong    time;
                    string[] values = ParseLine(line);
                    switch (section)
                    {
                    case null:
                        throw new FormatException();

                    case "Song":
                        chart.Song[values[0]] = values[1];
                        break;

                    case "SyncTrack":
                        time = ulong.Parse(values[0]);
                        switch (values[1])
                        {
                        case "TS":
                            chart.NoteChart.Signature.Add(new Midi.TimeSignatureEvent(time, byte.Parse(values[2]), 2, 24, 8));
                            break;

                        case "B":
                            chart.NoteChart.BPM.Add(new Midi.TempoEvent(time, (uint)(Mid.MicrosecondsPerMinute / ((float)int.Parse(values[2]) / 1000))));
                            break;

                        default:
                            throw new FormatException();
                        }
                        break;

                    case "Events":
                        time = ulong.Parse(values[0]);
                        switch (values[1])
                        {
                        case "E":
                            chart.EventsTrack.Comments.Add(new Midi.TextEvent(time, "[" + values[2] + "]"));
                            break;

                        default:
                            throw new FormatException();
                        }
                        break;

                    default:
                        if (track == TrackType.Unknown)
                        {
                            throw new FormatException();
                        }
                        time = ulong.Parse(values[0]);
                        ulong duration = ulong.Parse(values[2]);
                        if (duration == 0)
                        {
                            duration = chart.NoteChart.Division.TicksPerBeat / 4U;
                        }
                        switch (values[1])
                        {
                        case "N":
                            int fret = int.Parse(values[1]);
                            notes[fret].Add(new NoteChart.Note(time, duration));
                            break;

                        case "S":
                            NoteChart.Note note        = new NoteChart.Note(time, duration);
                            int            sectiontype = int.Parse(values[1]);
                            switch (sectiontype)
                            {
                            case 0:
                                instrument.Player1.Add(note);
                                break;

                            case 1:
                                instrument.Player2.Add(note);
                                break;

                            case 2:
                                instrument.Overdrive.Add(note);
                                break;

                            default:
                                throw new FormatException();
                            }
                            break;
                        }
                        break;
                    }
                }
            }

            return(chart);
        }