private static bool ParseSummary(string command2, string strParam1, string strParam2, HashSet <int> channels, out int combos) { if (!int.TryParse(command2, out _)) { combos = 0; return(false); } int channel = GetChannelNumberById(strParam2); if ((channel > 10 && channel < 30) || (channel > 50 && channel < 70)) { channels.Add(channel); int lCombos = 0; for (int i = 0, length = strParam1.Length / 2; i < length; i++) { int value = Base36.Decode(strParam1.Substring(i * 2, 2)); if (value > 0) { lCombos++; } } combos = lCombos; return(true); } combos = 0; return(false); }
KeyObject parseKeyObject(int measure, int channel, string rawData) { var data = new int[rawData.Length / 2]; for (var i = 0; i < rawData.Length / 2; i++) { var chunkedData = rawData.Substring(i * 2, 2); data[i] = (int)Base36.Decode(chunkedData); } return(new KeyObject(measure, channel, data)); }
/* * Special mapping for channels * 01 = 1, 02 = 2, ..., 09 = 9, * 0A = 1010, 0B = 1011, ... 0Z = 1035, * 11 = 11, 12 = 12, ... 19 = 19, * 1A = 1110, 1B = 1111, ..., 1Z = 1135, * ..., * 2A = 1210, 2B = 1211, ..., 2Z = 1235, * ..., * Z1 = 351, Z2 = 352, ..., Z9 = 359, * ZA = 4510, ZB = 4511, ..., ZZ = 4535 * Illegal channel format: -99 */ private static int GetChannelNumberById(string channel) { if (string.IsNullOrEmpty(channel) || channel.Length > 2) { return(-99); } int channelRaw = Base36.Decode(channel); if (channelRaw < 0) { return(-99); } int digit1 = channelRaw % 36, digit2 = channelRaw / 36; int result = digit1 > 9 ? (digit2 * 100 + digit1 + 1000) : (digit2 * 10 + digit1); return(result); }
private bool ParseResourceLine(string command2, string strParam1, string strParam2) { switch (command2) { case "wav": AddResource(ResourceType.wav, Base36.Decode(strParam2), strParam1); break; case "bmp": AddResource(ResourceType.bmp, Base36.Decode(strParam2), strParam1); break; case "bga": string[] strParams = strParam1.Split(' '); AddResource(ResourceType.bga, Base36.Decode(strParam2), string.Empty, new object[] { Base36.Decode(strParams[0]), // index float.Parse(strParams[1]), // x1 float.Parse(strParams[2]), // x2 float.Parse(strParams[3]), // y1 float.Parse(strParams[4]), // y2 float.Parse(strParams[5]), // dx float.Parse(strParams[6]) // dy }); break; case "bpm": AddResource(ResourceType.bpm, Base36.Decode(strParam2), string.Empty, float.Parse(strParam1)); break; case "stop": AddResource(ResourceType.stop, Base36.Decode(strParam2), string.Empty, float.Parse(strParam1)); break; default: return(false); } return(true); }
void parseDef(BMSData bmsData, string def) { Match m; m = DefPlayer.Match(def); if (m.Success) { var value = int.Parse(m.Groups[1].Value); bmsData.Player = (Player)value; return; } m = DefGenre.Match(def); if (m.Success) { bmsData.Genre = m.Groups[1].Value; return; } m = DefTitle.Match(def); if (m.Success) { bmsData.Title = m.Groups[1].Value; return; } m = DefArtist.Match(def); if (m.Success) { bmsData.Artist = m.Groups[1].Value; return; } m = DefBPM.Match(def); if (m.Success) { var value = int.Parse(m.Groups[1].Value); bmsData.BPM = value; return; } m = DefMidiFile.Match(def); if (m.Success) { bmsData.MidiFile = m.Groups[1].Value; return; } m = DefPlayLevel.Match(def); if (m.Success) { var value = int.Parse(m.Groups[1].Value); bmsData.PlayLevel = value; return; } m = DefRank.Match(def); if (m.Success) { var value = int.Parse(m.Groups[1].Value); bmsData.Rank = (Rank)value; return; } m = DefVolWav.Match(def); if (m.Success) { var value = int.Parse(m.Groups[1].Value); bmsData.VolWav = value; return; } m = DefTotal.Match(def); if (m.Success) { var value = double.Parse(m.Groups[1].Value); bmsData.Total = value; return; } m = DefWav.Match(def); if (m.Success) { var key = (int)Base36.Decode(m.Groups[1].Value); var value = m.Groups[2].Value; bmsData.Wav.Add(key, value); return; } m = DefBmp.Match(def); if (m.Success) { var key = (int)Base36.Decode(m.Groups[1].Value); var value = m.Groups[2].Value; bmsData.Bmp.Add(key, value); return; } m = DefObj.Match(def); if (m.Success) { var measure = int.Parse(m.Groups[1].Value); var channel = int.Parse(m.Groups[2].Value); var rawData = m.Groups[3].Value; var obj = this.parseObject(measure, channel, rawData); if (obj == null) { return; } bmsData.Objects.Add(obj); return; } }
private void PostProcessContent(ExtendedSortedSet <BMSEvent> bmev) { Dictionary <int, BMSEvent> lnMarker = new Dictionary <int, BMSEvent>(); double bpm = initialBPM, beatOffset = 0, beatPerMeas = 1; TimeSpan referenceTimePoint = TimeSpan.Zero; TimeSpan stopTimePoint = TimeSpan.Zero; float stopMeasBeat = 0; EnsureCapacity(bmev.Count + 1); AddEvent(new BMSEvent { measure = 0, beat = 0, type = BMSEventType.BPM, Data2F = bpm }); foreach (BMSEvent ev in bmev) { BMSEvent converted = new BMSEvent { measure = ev.measure, beat = (float)(ev.beat * beatPerMeas), }; if (ev.measure + ev.beat == stopMeasBeat) { converted.time = stopTimePoint; } else { converted.time = referenceTimePoint + MeasureBeatToTimeSpan(ev.measure + ev.beat - beatOffset, beatPerMeas, bpm); } switch (ev.type) { case BMSEventType.BPM: double newBpm; if (ev.data1 == 8 && TryGetResourceData(ResourceType.bpm, ev.data2, out BMSResourceData bpmData)) // Extended BPM { newBpm = Convert.ToDouble(bpmData.additionalData); } else if (ev.data1 == 3 && int.TryParse(Base36.Encode((int)ev.data2), NumberStyles.HexNumber, null, out int bpmInt)) // BPM { newBpm = bpmInt; } else { continue; } if (newBpm == bpm) { continue; } converted.type = BMSEventType.BPM; converted.Data2F = newBpm; referenceTimePoint = converted.time; beatOffset = ev.measure + ev.beat; bpm = newBpm; minBpm = Math.Min(minBpm, (float)newBpm); break; case BMSEventType.BeatReset: double newBeatPerMeas = ev.Data2F; if (newBeatPerMeas == beatPerMeas) { continue; } converted.type = BMSEventType.BeatReset; converted.Data2F = ev.Data2F * 4; beatOffset = ev.measure; beatPerMeas = newBeatPerMeas; referenceTimePoint = converted.time; break; case BMSEventType.STOP: if (!TryGetResourceData(ResourceType.stop, ev.data2, out BMSResourceData stopData)) { continue; } double stopSeconds = Convert.ToDouble(stopData.additionalData) / bpm * 1.25; if (stopSeconds <= 0) { continue; } converted.type = BMSEventType.STOP; stopTimePoint = converted.time; stopMeasBeat = ev.measure + ev.beat; TimeSpan stopTime = new TimeSpan((long)Math.Round(stopSeconds * TimeSpan.TicksPerSecond)); converted.data2 = stopTime.Ticks; referenceTimePoint += stopTime; break; case BMSEventType.BMP: converted.type = BMSEventType.BMP; switch (ev.data1) { case 4: converted.data1 = 0; break; case 6: converted.data1 = -1; break; case 7: converted.data1 = 1; break; default: continue; } converted.data2 = ev.data2; break; case BMSEventType.LongNoteStart: converted.data1 = ev.data1 - 40; converted.data2 = ev.data2; converted.sliceStart = TimeSpan.Zero; converted.sliceEnd = TimeSpan.MaxValue; if (lnMarker.TryGetValue(ev.data1, out BMSEvent lnStart)) { converted.type = BMSEventType.LongNoteEnd; int index = FindEventIndex(lnStart); lnStart.time2 = converted.time; ReplaceEvent(index, lnStart); lnMarker.Remove(ev.data1); } else { converted.type = BMSEventType.LongNoteStart; lnMarker[ev.data1] = converted; } break; case BMSEventType.Unknown: continue; default: if ((ev.data1 >= 30 && ev.data1 <= 50) || ev.data1 >= 70) { continue; } converted.type = ev.type; converted.data1 = ev.data1; converted.data2 = ev.data2; converted.sliceStart = TimeSpan.Zero; converted.sliceEnd = TimeSpan.MaxValue; break; } AddEvent(converted); } }
private static bool ParseContentLine(string command2, string strParam1, string strParam2, ExtendedSortedSet <BMSEvent> bmev) { if (!int.TryParse(command2, out int verse)) { return(false); } int channel = GetChannelNumberById(strParam2); if (channel < 0) { return(false); } strParam1 = spaceMatcher.Replace(strParam1, string.Empty); int length = strParam1.Length / 2; BMSEventType evType; switch (channel) { case 1: evType = BMSEventType.WAV; break; case 2: bmev.Add(new BMSEvent { measure = verse, beat = 0, Data2F = double.Parse(strParam1), type = BMSEventType.BeatReset }, InsertMode.OldFirst); return(true); case 3: evType = BMSEventType.BPM; break; case 4: case 6: case 7: evType = BMSEventType.BMP; break; case 8: evType = BMSEventType.BPM; break; case 9: evType = BMSEventType.STOP; break; default: if (channel > 10 && channel < 30) { evType = BMSEventType.Note; } else if (channel > 50 && channel < 70) { evType = BMSEventType.LongNoteStart; } else { evType = BMSEventType.Unknown; } break; } for (int i = 0; i < length; i++) { int value = Base36.Decode(strParam1.Substring(i * 2, 2)); if (value > 0) { bmev.Add(new BMSEvent { measure = verse, beat = (float)i / length, type = evType, data1 = channel, data2 = value }, InsertMode.OldFirst); } } return(true); }