public void ImportVGMFile(BinaryReader reader) { /* TODO: * Make sure that instrument editor is updated * Make sure tracker controls are updated (specifically pattern length) */ instruments.CreateInstrument(); instruments.presets[0].volumeTable = new int[] { 0xF }; instruments.presets[1].volumeTable = new int[] { 0xF }; data.SetPatternLength(128); data.SetData(0, 0, 3, 0xf); data.SetData(0, 0, 4, 0x1); reader.BaseStream.Position = 0x40; data.currentPattern = 0; m_LastVol = new int[4]; bool eof = false; while (reader.BaseStream.Position < reader.BaseStream.Length && !eof) { byte cmd = reader.ReadByte(); switch (cmd) { case 0x50: byte val = reader.ReadByte(); ParsePSGData(val); break; case 0x61: int inc = Mathf.FloorToInt(reader.ReadUInt16() / 735.0f); m_CurrRow += inc; if (m_CurrRow >= data.patternLength) { m_CurrRow -= data.patternLength; data.AddPatternLine(); } break; case 0x62: case 0x63: m_CurrRow++; if (m_CurrRow >= data.patternLength) { m_CurrRow = 0; data.AddPatternLine(); } break; case 0x66: eof = true; break; } } matrix.UpdateMatrix(); view.UpdatePatternData(); }
public void OptimizeSong() { if (!TinyFileDialogs.MessageBox("Optimizing song", "This will erase any unused patterns! Are you sure?", TinyFileDialogs.DialogType.YESNO, TinyFileDialogs.IconType.WARNING, false)) { return; } Dictionary <int, int> sortedIndicies = new Dictionary <int, int> ( ); List <ColumnEntry> sortedData = new List <ColumnEntry> ( ); foreach (int[] row in m_LookupTable) { for (int i = 0; i < 4; i++) { int oldIndex = row [i]; int newIndex = sortedData.Count; if (oldIndex >= 0 && !sortedIndicies.ContainsKey(oldIndex)) { sortedData.Add(m_SongData [row [i]]); sortedIndicies.Add(oldIndex, newIndex); } } } foreach (int [] row in m_LookupTable) { for (int i = 0; i < 4; i++) { if (sortedIndicies.ContainsKey(row [i])) { row [i] = sortedIndicies [row [i]]; } } } m_SongData = sortedData; patternMatrix.UpdateMatrix(); patternView.UpdatePatternData(); }
public void OpenFile() { if (fileModified && !TinyFileDialogs.MessageBox("Opening tune", "Are you sure? You will lose all unsaved progress.", TinyFileDialogs.DialogType.YESNO, TinyFileDialogs.IconType.WARNING, false)) { return; } playback.Stop( ); data.currentPattern = 0; if (m_TuneOpen.ShowDialog()) { IFormatter formatter = new BinaryFormatter( ); Stream fs = m_TuneOpen.OpenFile( ); SongFile open = (SongFile)formatter.Deserialize(fs); fs.Close( ); if (!open.success) { return; } data.SetPatternLength(open.patternLength); data.lookupTable = open.lookupTable; if (open.transposeTable != null && open.transposeTable.Count == open.lookupTable.Count) { data.transposeTable = open.transposeTable; } else { Debug.Log("Transpose table too shourt!!"); data.transposeTable = new List <int []> ( ); for (int i = 0; i < data.lookupTable.Count; i++) { int [] transposeEntry; if (open.transposeTable != null && i < open.transposeTable.Count) { transposeEntry = open.transposeTable [i]; } else { transposeEntry = new int [data.channels]; } data.transposeTable.Add(transposeEntry); } } data.songData = open.songData; SongData.songName = open.songName ?? ""; SongData.artistName = open.artistName ?? ""; keyboard.currentInstrument = 0; int presetCount = open.instruments.Length; Array.Resize(ref instruments.presets, presetCount); Array.Copy(open.instruments, instruments.presets, presetCount); m_OpenFile = m_TuneOpen.filePath; fileModified = false; if (onFileOpen != null) { onFileOpen( ); } patternMatrix.UpdateMatrix(); patternView.UpdatePatternData(); insEditor.UpdateInstruments(); insEditor.UpdateInstrumentInfo(); insEditor.SetSelectedInstrument(0); playback.playbackSpeed = 6; } }