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; }
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)); }
// 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; }