From a82ca9de5cd207e9c00b41277e8a3e1e3869e254 Mon Sep 17 00:00:00 2001 From: Martin Kiewitz Date: Tue, 22 Jun 2010 15:05:09 +0000 Subject: SCI: change midi queue to Common::Array and make it resize itself if needed instead of error() svn-id: r50143 --- engines/sci/sound/music.cpp | 20 ++++++++++++-------- engines/sci/sound/music.h | 5 +++-- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'engines/sci') diff --git a/engines/sci/sound/music.cpp b/engines/sci/sound/music.cpp index 38d4968fee..8ee43fea64 100644 --- a/engines/sci/sound/music.cpp +++ b/engines/sci/sound/music.cpp @@ -47,7 +47,8 @@ SciMusic::SciMusic(SciVersion soundVersion) for (int i = 0; i < 16; i++) _usedChannel[i] = 0; - _queuedCommandCount = 0; + _queuedCommandCapacity = 1000; + _queuedCommands.reserve(_queuedCommandCapacity); } SciMusic::~SciMusic() { @@ -125,23 +126,26 @@ void SciMusic::putMidiCommandInQueue(byte status, byte firstOp, byte secondOp) { } void SciMusic::putMidiCommandInQueue(uint32 midi) { - if (_queuedCommandCount >= 1000) - error("driver queue is full"); - _queuedCommands[_queuedCommandCount] = midi; - _queuedCommandCount++; + if (_queuedCommands.size() == _queuedCommandCapacity) { + // We need more space + _queuedCommandCapacity *= 2; + _queuedCommands.reserve(_queuedCommandCapacity); + } + _queuedCommands.push_back(midi); } // This sends the stored commands from queue to driver (is supposed to get called only during onTimer()) // at least mt32 emulation doesn't like getting note-on commands from main thread (if we directly send, we would get // a crash during piano scene in lsl5) void SciMusic::sendMidiCommandsFromQueue() { - int curCommand = 0; + uint curCommand = 0; + uint commandCount = _queuedCommands.size(); - while (curCommand < _queuedCommandCount) { + while (curCommand < commandCount) { _pMidiDrv->send(_queuedCommands[curCommand]); curCommand++; } - _queuedCommandCount = 0; + _queuedCommands.clear(); } void SciMusic::clearPlayList() { diff --git a/engines/sci/sound/music.h b/engines/sci/sound/music.h index 0a461cf76e..0a6662a7ce 100644 --- a/engines/sci/sound/music.h +++ b/engines/sci/sound/music.h @@ -120,6 +120,7 @@ public: }; typedef Common::Array MusicList; +typedef Common::Array MidiCommandQueue; class SciMusic #ifndef USE_OLD_MUSIC_FUNCTIONS @@ -224,8 +225,8 @@ private: byte _masterVolume; MusicEntry *_usedChannel[16]; - int _queuedCommandCount; - uint32 _queuedCommands[1000]; + uint _queuedCommandCapacity; + MidiCommandQueue _queuedCommands; int _driverFirstChannel; }; -- cgit v1.2.3