enabled MIDI volume changes

svn-id: r24627
This commit is contained in:
Gregory Montoir 2006-11-05 13:00:20 +00:00
parent 05dcf9c11d
commit 424e9e362e
7 changed files with 25 additions and 48 deletions

View File

@ -21,7 +21,6 @@
*/
#include "common/stdafx.h"
#include "common/mutex.h"
#include "common/stream.h"
#include "sound/midiparser.h"
@ -31,7 +30,7 @@
namespace Touche {
MidiPlayer::MidiPlayer(MidiDriver *driver)
: _masterVolume(255), _isPlaying(false), _driver(driver), _parser(0), _midiData(0) {
: _driver(driver), _parser(0), _midiData(0), _isLooping(false), _isPlaying(false), _masterVolume(0) {
assert(_driver);
memset(_channelsTable, 0, sizeof(_channelsTable));
memset(_channelsVolume, 0, sizeof(_channelsVolume));
@ -75,12 +74,12 @@ void MidiPlayer::updateTimer() {
_mutex.unlock();
}
void MidiPlayer::adjustVolume(int diff) {
setVolume(_masterVolume + diff);
}
void MidiPlayer::setVolume(int volume) {
if (volume < 0) {
volume = 0;
} else if (volume > 255) {
volume = 255;
}
_masterVolume = CLIP(volume, 0, 255);
for (int i = 0; i < NUM_CHANNELS; ++i) {
if (_channelsTable[i]) {
_channelsTable[i]->volume(_channelsVolume[i] * _masterVolume / 255);

View File

@ -24,13 +24,14 @@
#define TOUCHE_MIDI_H
#include "common/util.h"
#include "common/mutex.h"
#include "sound/mididrv.h"
class MidiParser;
namespace Common {
class ReadStream;
class Mutex;
}
namespace Touche {
@ -48,7 +49,9 @@ public:
void play(Common::ReadStream &stream, int size, bool loop = false);
void stop();
void updateTimer();
void adjustVolume(int diff);
void setVolume(int volume);
int getVolume() const { return _masterVolume; }
// MidiDriver interface
int open();
@ -64,14 +67,14 @@ private:
static void timerCallback(void *p);
int _masterVolume;
bool _isLooping;
bool _isPlaying;
MidiDriver *_driver;
MidiParser *_parser;
MidiChannel *_channelsTable[NUM_CHANNELS];
byte _channelsVolume[NUM_CHANNELS];
uint8 *_midiData;
bool _isLooping;
bool _isPlaying;
int _masterVolume;
MidiChannel *_channelsTable[NUM_CHANNELS];
uint8 _channelsVolume[NUM_CHANNELS];
Common::Mutex _mutex;
};

View File

@ -561,7 +561,6 @@ void ToucheEngine::res_loadSound(int priority, int num) {
void ToucheEngine::res_loadMusic(int num) {
debugC(9, kDebugResource, "ToucheEngine::res_loadMusic() num=%d", num);
warning("UNIMPLEMENTED ToucheEngine::res_loadMusic() num=%d", num);
uint32 size;
const uint32 offs = res_getDataOffset(kResourceTypeMusic, num, &size);
_fData.seek(offs);

View File

@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id: $
* $Id$
*
*/
@ -269,7 +269,7 @@ void ToucheEngine::loadGameStateData(Common::ReadStream *stream) {
clearRoomArea();
int16 room_offs_x, room_offs_y;
_currentEpisodeNum = stream->readUint16LE();
_currentMusicNum = stream->readUint16LE();
_newMusicNum = stream->readUint16LE();
_currentRoomNum = stream->readUint16LE();
res_loadRoom(_currentRoomNum);
room_offs_x = stream->readUint16LE();

View File

@ -46,12 +46,7 @@ ToucheEngine::ToucheEngine(OSystem *system, Common::Language language)
clearDirtyRects();
_defaultSoundPriority = 0;
_snd_midiContext.unk2 = 0;
_snd_midiContext.unkA = 1;
_snd_midiContext.unkB = 0;
_snd_midiContext.volume = 0;
_snd_midiContext.unkF = 0;
_snd_midiContext.currentVolume = 175;
_playSoundCounter = 0;
_processRandomPaletteCounter = 0;
@ -1711,15 +1706,10 @@ void ToucheEngine::clearRoomArea() {
}
void ToucheEngine::startNewMusic() {
_snd_midiContext.unkA = _flagsTable[619] & 0xFF;
// bool unkMidiFlag = _flagsTable[619] != 0;
if (_newMusicNum != 0 && _newMusicNum != _currentMusicNum) {
_snd_midiContext.unkB = 3;
if (_snd_midiContext.unkF != 0 && _snd_midiContext.unk2 != 0) {
return;
}
_snd_midiContext.unkB = 0;
res_loadMusic(_newMusicNum);
_snd_midiContext.unk2 = 0;
_currentMusicNum = _newMusicNum;
_newMusicNum = 0;
}
}

View File

@ -197,15 +197,6 @@ struct SpriteData {
uint16 h;
};
struct MidiContext {
uint8 unk2;
uint8 unkA;
uint8 unkB;
uint16 volume;
uint8 unkF;
uint16 currentVolume;
};
struct ProgramPointData {
int16 x, y, z;
int16 priority;
@ -617,7 +608,6 @@ protected:
int _playSoundCounter;
Audio::SoundHandle _sfxHandle;
Audio::SoundHandle _speechHandle;
MidiContext _snd_midiContext;
int16 _inventoryList1[101];
int16 _inventoryList2[101];

View File

@ -25,6 +25,7 @@
#include "common/savefile.h"
#include "touche/graphics.h"
#include "touche/midi.h"
#include "touche/touche.h"
namespace Touche {
@ -63,7 +64,7 @@ void ToucheEngine::setupUIRect() {
Common::Rect(154, 256, 392, 268),
Common::Rect(126, 222, 420, 242)
};
buttonsRectTable1 = inButtonsRectTable1;
buttonsRectTable2 = inButtonsRectTable2;
}
@ -130,7 +131,7 @@ void ToucheEngine::ui_drawButtonBorders(const Common::Rect *r, int count) {
}
void ToucheEngine::ui_drawMusicVolumeBar() {
int volume = _snd_midiContext.volume * 232 / 256;
int volume = _midiPlayer->getVolume() * 232 / 255;
if (volume != 0) {
Graphics::fillRect(_offscreenBuffer, 640, 157, 259, volume, 6, 0xF0);
}
@ -394,14 +395,10 @@ void ToucheEngine::ui_handleOptions(int forceDisplay) {
_talkTextMode = kTalkModeVoiceAndText;
break;
case 26:
if (_snd_midiContext.volume > 0) {
_snd_midiContext.volume -= 16;
}
_midiPlayer->adjustVolume(-16);
break;
case 27:
if (_snd_midiContext.volume < 256) {
_snd_midiContext.volume += 16;
}
_midiPlayer->adjustVolume(+16);
break;
}
}
@ -410,7 +407,6 @@ void ToucheEngine::ui_handleOptions(int forceDisplay) {
if (_flagsTable[611] != 0) {
_flagsTable[611] = ui_displayQuitDialog();
}
_snd_midiContext.currentVolume = _snd_midiContext.volume;
}
}