[Scummvm-git-logs] scummvm master -> 78ec6a9c23522397d752338bd12171d857a901db

athrxx noreply at scummvm.org
Thu Sep 15 18:57:20 UTC 2022


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
78ec6a9c23 SCUMM: (IMS) - get rid of instrument static var


Commit: 78ec6a9c23522397d752338bd12171d857a901db
    https://github.com/scummvm/scummvm/commit/78ec6a9c23522397d752338bd12171d857a901db
Author: athrxx (athrxx at scummvm.org)
Date: 2022-09-15T20:56:46+02:00

Commit Message:
SCUMM: (IMS) - get rid of instrument static var

I noticed broken sound when starting DOTT with MT-32
setting, then returning to the launcher and then starting in
GM mode.
Turns out that there was a nasty static var in instrument.cpp
that was not always reset to the correct value.
Instead of just doing that I cleaned it up a bit and got rid of
the static var.

Changed paths:
    engines/scumm/imuse/imuse.cpp
    engines/scumm/imuse/imuse_internal.h
    engines/scumm/imuse/imuse_part.cpp
    engines/scumm/imuse/instrument.cpp
    engines/scumm/imuse/instrument.h


diff --git a/engines/scumm/imuse/imuse.cpp b/engines/scumm/imuse/imuse.cpp
index 2e2f095ba91..93699c49311 100644
--- a/engines/scumm/imuse/imuse.cpp
+++ b/engines/scumm/imuse/imuse.cpp
@@ -333,7 +333,7 @@ void IMuseInternal::init_parts() {
 	int i;
 
 	for (i = 0, part = _parts; i != ARRAYSIZE(_parts); i++, part++) {
-		part->init();
+		part->init(_native_mt32);
 		part->_se = this;
 		part->_slot = i;
 	}
@@ -1439,7 +1439,6 @@ int IMuseInternal::initialize(OSystem *syst, MidiDriver *native_midi, MidiDriver
 
 	if (_midi_native && _soundType != MDT_MACINTOSH && _soundType != MDT_AMIGA) {
 		if (_native_mt32 && !_enable_gs) {
-			Instrument::nativeMT32(_native_mt32);
 			initMT32(_midi_native);
 		} else if (_enable_gs) {
 			initGS(_midi_native);
diff --git a/engines/scumm/imuse/imuse_internal.h b/engines/scumm/imuse/imuse_internal.h
index a5f3ecc9d7e..ba414ce990c 100644
--- a/engines/scumm/imuse/imuse_internal.h
+++ b/engines/scumm/imuse/imuse_internal.h
@@ -354,7 +354,7 @@ struct Part : public Common::Serializable {
 	void allNotesOff();
 
 	void set_param(byte param, int value) { }
-	void init();
+	void init(bool useNativeMT32);
 	void setup(Player *player);
 	void uninit();
 	void off();
diff --git a/engines/scumm/imuse/imuse_part.cpp b/engines/scumm/imuse/imuse_part.cpp
index 2638a9585f1..46e69f1c492 100644
--- a/engines/scumm/imuse/imuse_part.cpp
+++ b/engines/scumm/imuse/imuse_part.cpp
@@ -283,11 +283,12 @@ void Part::noteOff(byte note) {
 	}
 }
 
-void Part::init() {
+void Part::init(bool useNativeMT32) {
 	_player = nullptr;
 	_next = nullptr;
 	_prev = nullptr;
 	_mc = nullptr;
+	_instrument.setNativeMT32Mode(useNativeMT32);
 }
 
 void Part::setup(Player *player) {
diff --git a/engines/scumm/imuse/instrument.cpp b/engines/scumm/imuse/instrument.cpp
index 25b7cfe25cb..476a6448045 100644
--- a/engines/scumm/imuse/instrument.cpp
+++ b/engines/scumm/imuse/instrument.cpp
@@ -25,8 +25,6 @@
 
 namespace Scumm {
 
-static bool _native_mt32 = false;
-
 static struct {
 	const char *name;
 	byte program;
@@ -125,17 +123,18 @@ const byte Instrument::_gmRhythmMap[35] = {
 class Instrument_Program : public InstrumentInternal {
 private:
 	byte _program;
-	bool _mt32;
+	bool _soundTypeMT32;
+	bool _nativeMT32Device;
 
 public:
-	Instrument_Program(byte program, bool mt32);
-	Instrument_Program(Common::Serializer &s);
+	Instrument_Program(byte program, bool soundTypeMT32, bool nativeMT32Device);
+	Instrument_Program(Common::Serializer &s, bool nativeMT32Device);
 	void saveLoadWithSerializer(Common::Serializer &s) override;
 	void send(MidiChannel *mc) override;
-	void copy_to(Instrument *dest) override { dest->program(_program, _mt32); }
+	void copy_to(Instrument *dest) override { dest->program(_program, _soundTypeMT32); }
 	bool is_valid() override {
 		return (_program < 128) &&
-		       ((_native_mt32 == _mt32) || (_native_mt32
+		       ((_nativeMT32Device == _soundTypeMT32) || (_nativeMT32Device
 		        ? (MidiDriver::_gmToMt32[_program] < 128)
 		        : (MidiDriver::_mt32ToGm[_program] < 128)));
 	}
@@ -251,16 +250,17 @@ private:
 	RolandInstrument _instrument;
 
 	char _instrument_name[11];
+	bool _nativeMT32Device;
 
 	uint8 getEquivalentGM();
 
 public:
-	Instrument_Roland(const byte *data);
-	Instrument_Roland(Common::Serializer &s);
+	Instrument_Roland(const byte *data, bool nativeMT32Device);
+	Instrument_Roland(Common::Serializer &s, bool nativeMT32Device);
 	void saveLoadWithSerializer(Common::Serializer &s) override;
 	void send(MidiChannel *mc) override;
 	void copy_to(Instrument *dest) override { dest->roland((byte *)&_instrument); }
-	bool is_valid() override { return (_native_mt32 ? true : (_instrument_name[0] != '\0')); }
+	bool is_valid() override { return (_nativeMT32Device ? true : (_instrument_name[0] != '\0')); }
 };
 
 class Instrument_PcSpk : public InstrumentInternal {
@@ -297,22 +297,18 @@ public:
 //
 ////////////////////////////////////////
 
-void Instrument::nativeMT32(bool native) {
-	_native_mt32 = native;
-}
-
 void Instrument::clear() {
 	delete _instrument;
 	_instrument = nullptr;
 	_type = itNone;
 }
 
-void Instrument::program(byte prog, bool mt32) {
+void Instrument::program(byte prog, bool mt32SoundType) {
 	clear();
 	if (prog > 127)
 		return;
 	_type = itProgram;
-	_instrument = new Instrument_Program(prog, mt32);
+	_instrument = new Instrument_Program(prog, mt32SoundType, _nativeMT32Device);
 }
 
 void Instrument::adlib(const byte *instrument) {
@@ -328,7 +324,7 @@ void Instrument::roland(const byte *instrument) {
 	if (!instrument)
 		return;
 	_type = itRoland;
-	_instrument = new Instrument_Roland(instrument);
+	_instrument = new Instrument_Roland(instrument, _nativeMT32Device);
 }
 
 void Instrument::pcspk(const byte *instrument) {
@@ -359,13 +355,13 @@ void Instrument::saveLoadWithSerializer(Common::Serializer &s) {
 		case itNone:
 			break;
 		case itProgram:
-			_instrument = new Instrument_Program(s);
+			_instrument = new Instrument_Program(s, _nativeMT32Device);
 			break;
 		case itAdLib:
 			_instrument = new Instrument_AdLib(s);
 			break;
 		case itRoland:
-			_instrument = new Instrument_Roland(s);
+			_instrument = new Instrument_Roland(s, _nativeMT32Device);
 			break;
 		case itPcSpk:
 			_instrument = new Instrument_PcSpk(s);
@@ -386,16 +382,18 @@ void Instrument::saveLoadWithSerializer(Common::Serializer &s) {
 //
 ////////////////////////////////////////
 
-Instrument_Program::Instrument_Program(byte program, bool mt32) :
+Instrument_Program::Instrument_Program(byte program, bool soundTypeMT32, bool nativeMT32Device) :
 	_program(program),
-	_mt32(mt32) {
+	_soundTypeMT32(soundTypeMT32),
+	_nativeMT32Device(nativeMT32Device) {
 	if (program > 127)
 		_program = 255;
 }
 
-Instrument_Program::Instrument_Program(Common::Serializer &s) {
+Instrument_Program::Instrument_Program(Common::Serializer &s, bool nativeMT32Device) :
+	_nativeMT32Device(nativeMT32Device) {
 	_program = 255;
-	_mt32 = false;
+	_soundTypeMT32 = false;
 	if (!s.isSaving())
 		saveLoadWithSerializer(s);
 }
@@ -403,11 +401,11 @@ Instrument_Program::Instrument_Program(Common::Serializer &s) {
 void Instrument_Program::saveLoadWithSerializer(Common::Serializer &s) {
 	s.syncAsByte(_program);
 	if (s.isSaving()) {
-		s.syncAsByte(_mt32);
+		s.syncAsByte(_soundTypeMT32);
 	} else {
 		byte tmp;
 		s.syncAsByte(tmp);
-		_mt32 = (tmp > 0);
+		_soundTypeMT32 = (tmp > 0);
 	}
 }
 
@@ -416,8 +414,8 @@ void Instrument_Program::send(MidiChannel *mc) {
 		return;
 
 	byte program = _program;
-	if (_native_mt32 != _mt32)
-		program = _native_mt32 ? MidiDriver::_gmToMt32[program] : MidiDriver::_mt32ToGm[program];
+	if (_nativeMT32Device != _soundTypeMT32)
+		program = _nativeMT32Device ? MidiDriver::_gmToMt32[program] : MidiDriver::_mt32ToGm[program];
 	if (program < 128)
 		mc->programChange(program);
 }
@@ -453,17 +451,17 @@ void Instrument_AdLib::send(MidiChannel *mc) {
 //
 ////////////////////////////////////////
 
-Instrument_Roland::Instrument_Roland(const byte *data) {
+Instrument_Roland::Instrument_Roland(const byte *data, bool nativeMT32Device) : _nativeMT32Device(nativeMT32Device) {
 	memcpy(&_instrument, data, sizeof(_instrument));
 	memcpy(&_instrument_name, &_instrument.common.name, sizeof(_instrument.common.name));
 	_instrument_name[10] = '\0';
-	if (!_native_mt32 && getEquivalentGM() >= 128) {
+	if (!_nativeMT32Device && getEquivalentGM() >= 128) {
 		debug(0, "MT-32 instrument \"%s\" not supported yet", _instrument_name);
 		_instrument_name[0] = '\0';
 	}
 }
 
-Instrument_Roland::Instrument_Roland(Common::Serializer &s) {
+Instrument_Roland::Instrument_Roland(Common::Serializer &s, bool nativeMT32Device) : _nativeMT32Device(nativeMT32Device) {
 	_instrument_name[0] = '\0';
 	if (!s.isSaving())
 		saveLoadWithSerializer(s);
@@ -476,7 +474,7 @@ void Instrument_Roland::saveLoadWithSerializer(Common::Serializer &s) {
 	if (!s.isSaving()) {
 		memcpy(&_instrument_name, &_instrument.common.name, sizeof(_instrument.common.name));
 		_instrument_name[10] = '\0';
-		if (!_native_mt32 && getEquivalentGM() >= 128) {
+		if (!_nativeMT32Device && getEquivalentGM() >= 128) {
 			debug(2, "MT-32 custom instrument \"%s\" not supported", _instrument_name);
 			_instrument_name[0] = '\0';
 		}
@@ -484,7 +482,7 @@ void Instrument_Roland::saveLoadWithSerializer(Common::Serializer &s) {
 }
 
 void Instrument_Roland::send(MidiChannel *mc) {
-	if (_native_mt32) {
+	if (_nativeMT32Device) {
 		if (mc->getNumber() > 8)
 			return;
 		_instrument.device_id = mc->getNumber();
diff --git a/engines/scumm/imuse/instrument.h b/engines/scumm/imuse/instrument.h
index 8b062ed6bb3..43dd2fd290f 100644
--- a/engines/scumm/imuse/instrument.h
+++ b/engines/scumm/imuse/instrument.h
@@ -55,9 +55,9 @@ public:
 		itMacSfx = 5
 	};
 
-	Instrument() : _type(0), _instrument(0) { }
+	Instrument() : _type(0), _instrument(0), _nativeMT32Device(false) { }
 	~Instrument() override { delete _instrument; }
-	static void nativeMT32(bool native);
+	void setNativeMT32Mode(bool isNativeMT32) { _nativeMT32Device = isNativeMT32; }
 	static const byte _gmRhythmMap[35];
 
 	void clear();
@@ -68,7 +68,7 @@ public:
 			dest->clear();
 	}
 
-	void program(byte program, bool mt32);
+	void program(byte program, bool mt32SoundType);
 	void adlib(const byte *instrument);
 	void roland(const byte *instrument);
 	void pcspk(const byte *instrument);
@@ -81,6 +81,8 @@ public:
 		if (_instrument)
 			_instrument->send(mc);
 	}
+
+	bool _nativeMT32Device;
 };
 
 } // End of namespace Scumm




More information about the Scummvm-git-logs mailing list