public void ParseMidiSong(byte[] midiSong, SongDataModel songModel) { //read midi file var data = new MidiData(); MidiParser.ParseNotesData(midiSong, ref data); LevelDataModel lv = new LevelDataModel(); lv.noteData = data.notesData[NoteTrack]; lv.playbackData = data.notesData[PlaybackTrack]; lv.playbackData.Sort((x, y) => (x.timeAppear.CompareTo(y.timeAppear))); lv.noteData.Sort((x, y) => (x.timeAppear.CompareTo(y.timeAppear))); lv.BPM = data.beatsPerMinute; lv.denominator = data.denominator; lv.tickPerQuarterNote = (int)data.deltaTickPerQuarterNote; var ticksPerTile = songModel.tickPerTile; var minTickPerTile = Mathf.FloorToInt(ticksPerTile * (1 - tickTolerance)); var maxTickPerTile = Mathf.CeilToInt(ticksPerTile * (1 + tickTolerance)); StartCoroutine(PrepareTileData(lv, minTickPerTile, maxTickPerTile, songModel)); }
public void LoadSong(byte[] midiData) { data = new MidiData(); if (midiData == null) { return; } MidiParser.ParseNotesData(midiData, ref data); notesData = data.notesData[0]; BuildNoteData(); }
private void OnLevelDownloadCompleted(WWW midi) { //try { byte[] midiData = midi.bytes; var data = new MidiData(); MidiParser.ParseNotesData(midiData, ref data); //LevelDataModel levelData = new LevelDataModel(); m_levelData.BPM = data.beatsPerMinute; m_levelData.denominator = data.denominator; m_levelData.tickPerQuarterNote = (int)data.deltaTickPerQuarterNote; //this.Print("Ticks per quarter note: " + data.deltaTickPerQuarterNote); m_levelData.noteData = data.notesData[NoteTrack]; m_levelData.playbackData = data.notesData[PlaybackTrack]; if (m_levelData.noteData == null || m_levelData.playbackData == null) { Helpers.CallbackWithValue(OnSongParsed, false, null); } else { Helpers.CallbackWithValue(OnSongParsed, true, m_levelData); } //} //catch(Exception ex) { // this.Print(ex.ToString()); // Helpers.CallbackWithValue(OnSongParsed, false, null); //} //string notedata = midiData.text; //string[] data = notedata.Split('_'); //if (OnTemporarySongParsed != null) { // OnTemporarySongParsed(true, data); //} }