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)); }
internal void Run() { var musicSheet = new MidiParser().Parse(_options.InputMidi); var rawMusicSheet = new MusicSheetSerializer(new ChordOffsetSerializer(new ChordSerializer(new NoteSerializer(), _options.IncludeChordDuration))).Serialize(musicSheet); new XmlMusicSheetWriter().SaveToFile(rawMusicSheet, _options.OutputXml); }
/// <summary> /// Loads a <see cref="Pattern"/> from a MIDI file /// </summary> /// <param name="filePath">Path to the MIDI file</param> /// <returns>Loaded pattern</returns> public static Pattern LoadPatternFromMidi(string filePath) { var midiParser = new MidiParser(); var patternBuilder = new StaccatoPatternBuilder(midiParser); midiParser.Parse(new Sequence(filePath)); return(patternBuilder.Pattern); }
public Song readSong(string band, string file) { string path = "Songs/" + band + "/" + file + "/"; List <SongNote> notes = MidiParser.readMidi(basePath + path + "player.mid"); AudioClip songBackground = Resources.Load <AudioClip>(path + "backing"); AudioClip hitNoise = Resources.Load <AudioClip>(path + "instrument"); return(new Song(notes, songBackground, hitNoise)); }
public static void MidiToJSON() { string dataPath = Application.dataPath.Replace('/', '\\'); string midiFilePath = dataPath + @"\UnityTools\song.mid"; FileStream fileStream = File.OpenRead(midiFilePath); string midiJSON = MidiParser.Parse(fileStream); }
public void it_parses() { var midiParser = new MidiParser(); var musicSheet = midiParser.Parse(TestMidiFilePath); Assert.That(musicSheet.MetronomeMark.Metronome, Is.EqualTo(120)); Assert.That(musicSheet.Melody, Is.Not.Null.And.Not.Empty); }
public void SaveOrLoad(Serializer ser) { var playerEntries = new [] { LoadAndSaveEntry.Create(r => _active = r.ReadBoolean(), w => w.Write(_active), 8), LoadAndSaveEntry.Create(r => _id = r.ReadUInt16(), w => w.WriteUInt16(_id), 8), LoadAndSaveEntry.Create(r => _priority = r.ReadByte(), w => w.WriteByte(_priority), 8), LoadAndSaveEntry.Create(r => _volume = r.ReadByte(), w => w.WriteByte(_volume), 8), LoadAndSaveEntry.Create(r => _pan = r.ReadSByte(), w => w.Write(_pan), 8), LoadAndSaveEntry.Create(r => _transpose = r.ReadSByte(), w => w.Write(_transpose), 8), LoadAndSaveEntry.Create(r => _detune = r.ReadSByte(), w => w.Write(_detune), 8), LoadAndSaveEntry.Create(r => VolChan = r.ReadUInt16(), w => w.WriteUInt16(VolChan), 8), LoadAndSaveEntry.Create(r => _vol_eff = r.ReadByte(), w => w.WriteByte(_vol_eff), 8), LoadAndSaveEntry.Create(r => _speed = r.ReadByte(), w => w.WriteByte(_speed), 8), LoadAndSaveEntry.Create(r => r.ReadUInt16(), w => w.WriteUInt16(0), 8, 19), //_song_index LoadAndSaveEntry.Create(r => _track_index = r.ReadUInt16(), w => w.WriteUInt16(_track_index), 8), LoadAndSaveEntry.Create(r => r.ReadUInt16(), w => w.WriteUInt16(0), 8, 17), //_timer_counter LoadAndSaveEntry.Create(r => _loop_to_beat = r.ReadUInt16(), w => w.WriteUInt16(_loop_to_beat), 8), LoadAndSaveEntry.Create(r => _loop_from_beat = r.ReadUInt16(), w => w.WriteUInt16(_loop_from_beat), 8), LoadAndSaveEntry.Create(r => _loop_counter = r.ReadUInt16(), w => w.WriteUInt16(_loop_counter), 8), LoadAndSaveEntry.Create(r => _loop_to_tick = r.ReadUInt16(), w => w.WriteUInt16(_loop_to_tick), 8), LoadAndSaveEntry.Create(r => _loop_from_tick = r.ReadUInt16(), w => w.WriteUInt16(_loop_from_tick), 8), LoadAndSaveEntry.Create(r => r.ReadUInt32(), w => w.WriteUInt32(0), 8, 19), //_tempo LoadAndSaveEntry.Create(r => r.ReadUInt32(), w => w.WriteUInt32(0), 8, 17), //_cur_pos LoadAndSaveEntry.Create(r => r.ReadUInt32(), w => w.WriteUInt32(0), 8, 17), //_next_pos LoadAndSaveEntry.Create(r => r.ReadUInt32(), w => w.WriteUInt32(0), 8, 17), //_song_offset LoadAndSaveEntry.Create(r => r.ReadUInt16(), w => w.WriteUInt16(0), 8, 17), //_tick_index LoadAndSaveEntry.Create(r => r.ReadUInt16(), w => w.WriteUInt16(0), 8, 17), //_beat_index LoadAndSaveEntry.Create(r => r.ReadUInt16(), w => w.WriteUInt16(0), 8, 17), // _ticks_per_beat LoadAndSaveEntry.Create(r => _music_tick = r.ReadUInt32(), w => w.WriteUInt32(_music_tick), 19), }; if (ser.IsLoading && _parser != null) { _parser = null; } _music_tick = _parser != null ? (uint)_parser.Tick : 0; int num; if (!ser.IsLoading) { num = _parts != null?Array.IndexOf(_se._parts, _parts) + 1 : 0; ser.Writer.WriteUInt16(num); } else { num = ser.Reader.ReadUInt16(); _parts = num != 0 ? _se._parts[num - 1] : null; } playerEntries.ForEach(e => e.Execute(ser)); _hook.SaveOrLoad(ser); _parameterFaders.ForEach(pf => pf.SaveOrLoad(ser)); }
public void LoadSong(byte[] midiData) { data = new MidiData(); if (midiData == null) { return; } MidiParser.ParseNotesData(midiData, ref data); notesData = data.notesData[0]; BuildNoteData(); }
public Song readSong(string file) { string path = "Songs/" + file + "/"; List <SongNote> notes = MidiParser.readMidi(basePath + path + "notes.mid"); Debug.Log(MidiParser.readMidi(basePath + path + "notes.mid")); AudioClip songBackground = Resources.Load <AudioClip>(path + "background"); AudioClip hitNoise = Resources.Load <AudioClip>(path + "instrument"); //Song test = Song(notes, songBackground, hitNoise); return(new Song(notes, songBackground, hitNoise, getDifficulty(notes))); }
void Start() { song = MidiParser.readMidi("Assets/Resources/Songs/HotCrossBunsLow.mid"); songBackground = Resources.Load <AudioClip>("Songs/Megalovania"); audio.clip = songBackground; audio.Play(); SongSetup songSetup = gameObject.GetComponent <SongSetup>(); lanes = songSetup.setupLanes(); songStartTime = Time.time; }
public IParser CreateParser(string type) { IParser parser; switch (type) { case ".mid": parser = new MidiParser(); break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } return(parser); }
private void InitMetaData() { var rootText = Resources.Load <TextAsset>("meta/root" + SceneManager.GetActiveScene().name); var docStream = new StringReader(rootText.text); RootGraph root = RootGraph.Construct(docStream); foreach (var clip in root.Clips) { //load clip var clipText = Resources.Load <TextAsset>("meta/" + clip.Path); var clipDocStream = new StringReader(clipText.text); ClipTree clipGraph = ClipTree.Construct(clipDocStream); var ser = new YamlDotNet.Serialization.Serializer(); clipGraphs.Add(clip.Name, clipGraph); var midiFile = Resources.Load <TextAsset>("clips/" + clipGraph.Midi); Debug.Log(clipGraph.Midi); AudioSource audioSource = AddAudioSourceToScene(clipGraph.Audio); //parse midi Midi midi = new MidiParser().Parse(midiFile.bytes); //debug Debug.Log(midi.Tracks[2].Bpm); foreach (var msg in midi.Tracks[2].Messages) { Debug.Log(msg); } Debug.Log(ser.Serialize(clipGraph)); clips.Add(clip.Name, new Assets.Core.Clip(audioSource, midi)); } foreach (var graph in root.Scriptgraphs) { var graphText = Resources.Load <TextAsset>("meta/" + graph.Path); Debug.Log(graphText); var graphDocStream = new StringReader(graphText.text); ScriptTree scriptGraph = ScriptTree.Construct(graphDocStream); var ser = new YamlDotNet.Serialization.Serializer(); scriptGraphs.Add(graph.Name, scriptGraph); Debug.Log("Constructed a script graph : " + graph.Name); Debug.Log(ser.Serialize(scriptGraph)); } }
public static QbcParser LoadMidiSong(string fileName, bool forceRb3) { QbcParser qbc = null; Song song = null; try { song = MidReader.ReadMidi(fileName); var chartFile = ChartWriter.writeChart(song, "", false, forceRb3).ToString(); var chartParser = new ChartParser(chartFile, false); qbc = chartParser.ConvertToQbc(); } catch (Exception e) { MessageBox.Show("Error using the new MIDI importer.\nReverting to original GHTCP method. \n\n" + e, "MIDI Error", MessageBoxButtons.OK, MessageBoxIcon.Information); qbc = new MidiParser(fileName).LoadMidi().ConvertToQbc(); } return(qbc); }
public void Clear() { if (!_active) { return; } Debug.WriteLine("Stopping music {0}", _id); if (_parser != null) { _parser.UnloadMusic(); _parser = null; } UninitParts(); _se.ImFireAllTriggers(_id); _active = false; _midi = null; _id = 0; _note_offset = 0; }
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); //} }
public void LateUpdate() { if (uiFont is null && SceneManager.GetActiveScene().name.Equals("Main Menu")) { uiFont = GameObject.Find("Profile Title").GetComponent <Text>().font; } if (sceneChanged) { sceneChanged = false; if (SceneManager.GetActiveScene().name.Equals("Gameplay")) { var gameManagerObject = GameObject.Find("Game Manager"); gameManager = GameManagerWrapper.Wrap(GameObject.Find("Game Manager")?.GetComponent <GameManager>()); if (gameManager.GlobalVariables.SongEntry.SongEntry.lyrics && gameManager.GlobalVariables.SongEntry.SongEntry.chartPath.EndsWith("notes.mid")) { string file = gameManager.GlobalVariables.SongEntry.SongEntry.chartPath; MidiParser parser = new MidiParser(file); List <List <ChartCommand> > coms = parser.ParseMidi(); commands0 = coms[0]; commands1 = coms[1]; commands2 = coms[2]; Logger.LogDebug(commands2.Count); foreach (ChartCommand com in commands2) { Logger.LogDebug($"{com.TimeInMs} {com.Command} {com.Parameter}"); } index0 = 0; index1 = 0; index2 = 0; //Logger.LogDebug(gameManager.GlobalVariables.SongEntry.SongEntry.chartPath); lyricsTransform = GameObject.Find("Lyrics").transform; altLyrics0 = CreateTmpText(lyricsTransform, "AltLyrics1", 3); altLyrics1 = CreateTmpText(lyricsTransform, "AltLyrics2", 2); altLyrics2 = CreateTmpText(lyricsTransform, "AltLyrics3", 1); altLyrics0.fontSize = 44f; altLyrics1.fontSize = 44f; altLyrics2.fontSize = 44f; altLyrics0.transform.localPosition = new Vector2(0, 460); altLyrics1.transform.localPosition = new Vector2(0, 300); altLyrics2.transform.localPosition = new Vector2(0, 240); altLyrics0.horizontalAlignment = HorizontalAlignmentOptions.Center; altLyrics1.horizontalAlignment = HorizontalAlignmentOptions.Center; altLyrics2.horizontalAlignment = HorizontalAlignmentOptions.Center; altLyrics0.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width / 2, altLyrics0.preferredHeight); altLyrics1.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width / 2, altLyrics1.preferredHeight); altLyrics2.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width / 2, altLyrics2.preferredHeight); indexes0 = new List <int>(); indexes1 = new List <int>(); indexes2 = new List <int>(); ClearLyric0(); ClearLyric1(); ClearLyric2(); } else if (gameManager.GlobalVariables.SongEntry.SongEntry.lyrics && gameManager.GlobalVariables.SongEntry.SongEntry.chartPath.EndsWith("notes.chart")) { string file = gameManager.GlobalVariables.SongEntry.SongEntry.chartPath; LyricsParser parser = new LyricsParser(file); commands0 = parser.ParseLyrics()[0]; index0 = 0; Logger.LogDebug(gameManager.GlobalVariables.SongEntry.SongEntry.chartPath); lyricsTransform = GameObject.Find("Lyrics").transform; altLyrics0 = CreateTmpText(lyricsTransform, "AltLyrics1", 1); altLyrics0.fontSize = 44f; altLyrics0.transform.localPosition = new Vector2(0, 460); altLyrics0.horizontalAlignment = HorizontalAlignmentOptions.Center; altLyrics0.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width / 2, altLyrics0.preferredHeight); indexes0 = new List <int>(); ClearLyric0(); ClearLyric1(); ClearLyric2(); } else { commands0 = new List <ChartCommand>(); } //UpdateTextButton(altLyrics, "TEST", 40, Color.white); } } if (SceneManager.GetActiveScene().name.Equals("Gameplay")) { if (index0 < commands0.Count) { if (TimeSpan.FromSeconds(gameManager.SongTime).TotalMilliseconds >= commands0[index0].TimeInMs) { ChartCommand curCommand = commands0[index0++]; if (curCommand.Command == "phrase_start") { ClearLyric0(); int i = 0; ChartCommand x; while ((index0 + i) < commands0.Count && (x = commands0[index0 + i++]).Command == "lyric") { altLyricText0 += x.Parameter; if (altLyricText0.EndsWith("=")) { altLyricText0 = altLyricText0.TrimEnd('=') + "-"; } else if (altLyricText0.EndsWith("$") || altLyricText0.EndsWith("#")) { altLyricText0 = altLyricText0.TrimEnd(new char[] { '$', '#' }); } else if (altLyricText0.EndsWith("-")) { altLyricText0 = altLyricText0.TrimEnd('-'); } else { altLyricText0 += " "; } indexes0.Add(altLyricText0.Length); } altLyrics0.text = altLyricText0; } else if (curCommand.Command == "phrase_end") { ClearLyric0(); } else { altLyrics0.text = "<color=#47a9ea>" + altLyricText0.Substring(0, indexes0[colorIndex0]) + "</color>" + altLyricText0.Substring(indexes0[colorIndex0++]); } //altLyrics.text = $"{curCommand.Command} {curCommand.Parameter}"; } } if (index1 < commands1.Count) { if (TimeSpan.FromSeconds(gameManager.SongTime).TotalMilliseconds >= commands1[index1].TimeInMs) { ChartCommand curCommand = commands1[index1++]; if (curCommand.Command == "phrase_start") { ClearLyric1(); int i = 0; ChartCommand x; while ((index1 + i) < commands1.Count && (x = commands1[index1 + i++]).Command == "lyric") { altLyricText1 += x.Parameter; if (altLyricText1.EndsWith("=")) { altLyricText1 = altLyricText1.TrimEnd('=') + "-"; } else if (altLyricText1.EndsWith("$") || altLyricText1.EndsWith("#")) { altLyricText1 = altLyricText1.TrimEnd(new char[] { '$', '#' }); } else if (altLyricText1.EndsWith("-")) { altLyricText1 = altLyricText1.TrimEnd('-'); } else { altLyricText1 += " "; } indexes1.Add(altLyricText1.Length); } altLyrics1.text = altLyricText1; } else if (curCommand.Command == "phrase_end") { ClearLyric1(); } else { altLyrics1.text = "<color=#e59b2b>" + altLyricText1.Substring(0, indexes1[colorIndex1]) + "</color>" + altLyricText1.Substring(indexes1[colorIndex1++]); } //altLyrics.text = $"{curCommand.Command} {curCommand.Parameter}"; } } if (index2 < commands2.Count) { if (TimeSpan.FromSeconds(gameManager.SongTime).TotalMilliseconds >= commands2[index2].TimeInMs) { Logger.LogDebug("TEST0"); ChartCommand curCommand = commands2[index2++]; Logger.LogDebug("TEST1"); if (curCommand.Command == "phrase_start") { ClearLyric2(); int i = 0; ChartCommand x; while ((index2 + i) < commands2.Count && (x = commands2[index2 + i++]).Command == "lyric") { Logger.LogDebug("TEST2"); altLyricText2 += x.Parameter; if (altLyricText2.EndsWith("=")) { altLyricText2 = altLyricText2.TrimEnd('=') + "-"; } else if (altLyricText2.EndsWith("$") || altLyricText2.EndsWith("#")) { altLyricText2 = altLyricText2.TrimEnd(new char[] { '$', '#' }); } else if (altLyricText2.EndsWith("-")) { altLyricText2 = altLyricText2.TrimEnd('-'); } else { altLyricText2 += " "; } indexes2.Add(altLyricText2.Length); } altLyrics2.text = altLyricText2; } else if (curCommand.Command == "phrase_end") { ClearLyric2(); } else { altLyrics2.text = "<color=#af3e1c>" + altLyricText2.Substring(0, indexes2[colorIndex2]) + "</color>" + altLyricText2.Substring(indexes2[colorIndex2++]); } //altLyrics.text = $"{curCommand.Command} {curCommand.Parameter}"; } } } }
// Sequencer part protected int StartSeqSound(int sound, bool resetVars = true) { if (resetVars) { _loop_to_beat = 1; _loop_from_beat = 1; _track_index = 0; _loop_counter = 0; _loop_to_tick = 0; _loop_from_tick = 0; } var ptr = _se.FindStartOfSound(sound); if (ptr == null) { return(-1); } if (Encoding.UTF8.GetString(ptr, 0, 2) == "RO") { // Old style 'RO' resource _parser = MidiParser.CreateRO(); } else if (Encoding.UTF8.GetString(ptr, 0, 4) == "FORM") { // Humongous Games XMIDI resource _parser = MidiParser.CreateXMidiParser(); } else { // SCUMM SMF resource _parser = MidiParser.CreateSmfParser(); } _parser.MidiDriver = this; _parser.Property(MidiParserProperty.SmartJump, 1); _parser.LoadMusic(ptr); _parser.ActiveTrack = _track_index; ptr = _se.FindStartOfSound(sound, IMuseInternal.ChunkType.MDhd); var speed = 128; if (resetVars) { if (ptr != null) { using (var br = new BinaryReader(new MemoryStream(ptr))) { br.BaseStream.Seek(4, SeekOrigin.Begin); speed = br.ReadUInt32BigEndian() != 0 && ptr[15] != 0 ? ptr[15] : 128; } } } else { speed = _speed; } SetSpeed((byte)speed); return(0); }