2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-04-12 21:26:59 +00:00
|
|
|
*
|
2021-12-26 18:47:58 +01:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2014-02-18 02:34:17 +01:00
|
|
|
*
|
2002-04-12 21:26:59 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-02-18 02:34:17 +01:00
|
|
|
*
|
2002-04-12 21:26:59 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 18:47:58 +01:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2002-04-12 21:26:59 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-03-23 16:14:39 +01:00
|
|
|
#include "common/config-manager.h"
|
2002-11-10 15:24:17 +00:00
|
|
|
#include "common/file.h"
|
2011-04-24 11:34:27 +03:00
|
|
|
#include "common/textconsole.h"
|
2015-07-04 01:50:07 +02:00
|
|
|
#include "common/memstream.h"
|
2006-04-29 14:23:16 +00:00
|
|
|
|
2006-09-29 08:14:27 +00:00
|
|
|
#include "agos/agos.h"
|
2011-08-05 11:16:03 +01:00
|
|
|
#include "agos/midi.h"
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2022-01-27 22:29:39 +01:00
|
|
|
#include "agos/midiparser_gmf.h"
|
|
|
|
#include "agos/midiparser_simonwin.h"
|
|
|
|
|
2015-06-21 00:45:45 +02:00
|
|
|
#include "agos/drivers/accolade/mididriver.h"
|
2019-06-03 19:35:48 +01:00
|
|
|
#include "agos/drivers/accolade/adlib.h"
|
|
|
|
#include "agos/drivers/accolade/mt32.h"
|
2015-07-23 22:33:56 +02:00
|
|
|
#include "agos/drivers/simon1/adlib.h"
|
2022-01-27 22:29:39 +01:00
|
|
|
#include "agos/drivers/simon1/adlib_win.h"
|
2015-07-01 12:40:16 +02:00
|
|
|
// Miles Audio for Simon 2
|
|
|
|
#include "audio/miles.h"
|
2022-02-15 22:31:26 +01:00
|
|
|
#include "audio/midiparser.h"
|
2015-06-21 00:45:45 +02:00
|
|
|
|
2015-07-04 01:50:07 +02:00
|
|
|
// PKWARE data compression library decompressor required for Simon 2
|
|
|
|
#include "common/dcl.h"
|
2020-07-04 03:13:05 +05:30
|
|
|
#include "common/translation.h"
|
2015-07-04 01:50:07 +02:00
|
|
|
|
2015-06-21 10:06:12 +02:00
|
|
|
#include "gui/message.h"
|
2022-01-27 22:29:39 +01:00
|
|
|
#include <engines/agos/intern_detection.h>
|
2015-06-21 10:06:12 +02:00
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
namespace AGOS {
|
2003-10-03 19:42:27 +00:00
|
|
|
|
|
|
|
|
2003-05-25 03:19:21 +00:00
|
|
|
// MidiParser_S1D is not considered part of the standard
|
|
|
|
// MidiParser suite, but we still try to mask its details
|
|
|
|
// and just provide a factory function.
|
|
|
|
extern MidiParser *MidiParser_createS1D();
|
|
|
|
|
2022-02-18 23:16:22 +01:00
|
|
|
// This instrument remapping has been constructed by checking how the GM
|
|
|
|
// instruments correspond to MT-32 instruments in other tracks (f.e. track 10-3
|
|
|
|
// is similar to track 11).
|
|
|
|
byte MidiPlayer::SIMON2_TRACK10_GM_MT32_INSTRUMENT_REMAPPING[] {
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x1D, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x54, 0x00, 0x56, 0x53, 0x4B, 0x00, 0x4B, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
|
|
|
};
|
|
|
|
|
2022-01-27 22:29:39 +01:00
|
|
|
MidiPlayer::MidiPlayer(AGOSEngine *vm) {
|
2002-11-18 09:08:45 +00:00
|
|
|
// Since initialize() is called every time the music changes,
|
|
|
|
// this is where we'll initialize stuff that must persist
|
|
|
|
// between songs.
|
2022-01-27 22:29:39 +01:00
|
|
|
_vm = vm;
|
2021-11-13 23:40:15 +02:00
|
|
|
_driver = nullptr;
|
2022-01-27 22:29:39 +01:00
|
|
|
_driverMsMusic = nullptr;
|
|
|
|
_driverMsSfx = nullptr;
|
2003-07-14 08:29:17 +00:00
|
|
|
_map_mt32_to_gm = false;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2021-11-13 23:40:15 +02:00
|
|
|
_current = nullptr;
|
2003-05-24 01:26:05 +00:00
|
|
|
|
2008-07-14 22:10:04 +00:00
|
|
|
_musicVolume = 255;
|
|
|
|
_sfxVolume = 255;
|
|
|
|
|
2003-08-11 05:25:33 +00:00
|
|
|
resetVolumeTable();
|
2003-05-20 13:20:18 +00:00
|
|
|
_paused = false;
|
2003-05-24 01:26:05 +00:00
|
|
|
|
2003-05-18 23:55:53 +00:00
|
|
|
_currentTrack = 255;
|
2015-07-05 10:58:35 +10:00
|
|
|
_loopTrack = 0;
|
2003-05-21 04:36:09 +00:00
|
|
|
_queuedTrack = 255;
|
|
|
|
_loopQueuedTrack = 0;
|
2015-06-21 00:45:45 +02:00
|
|
|
|
2015-07-01 12:40:16 +02:00
|
|
|
_musicMode = kMusicModeDisabled;
|
2022-02-15 22:31:26 +01:00
|
|
|
_deviceType = MT_NULL;
|
|
|
|
_dataType = MT_NULL;
|
2022-01-27 22:29:39 +01:00
|
|
|
|
|
|
|
_parserMusic = nullptr;
|
|
|
|
_parserSfx = nullptr;
|
|
|
|
_musicData = nullptr;
|
|
|
|
_sfxData = nullptr;
|
2002-11-18 09:08:45 +00:00
|
|
|
}
|
|
|
|
|
2003-05-18 23:55:53 +00:00
|
|
|
MidiPlayer::~MidiPlayer() {
|
2011-03-23 16:14:39 +01:00
|
|
|
stop();
|
2022-01-27 22:29:39 +01:00
|
|
|
stopSfx();
|
2011-03-23 16:14:39 +01:00
|
|
|
|
2022-02-15 22:31:26 +01:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
2022-01-27 22:29:39 +01:00
|
|
|
if (_driverMsSfx && _driverMsSfx != _driverMsMusic) {
|
|
|
|
_driverMsSfx->setTimerCallback(nullptr, nullptr);
|
|
|
|
_driverMsSfx->close();
|
|
|
|
delete _driverMsSfx;
|
|
|
|
_driverMsSfx = nullptr;
|
|
|
|
}
|
|
|
|
if (_driverMsMusic) {
|
|
|
|
_driverMsMusic->setTimerCallback(nullptr, nullptr);
|
|
|
|
_driverMsMusic->close();
|
|
|
|
delete _driverMsMusic;
|
|
|
|
_driverMsMusic = nullptr;
|
|
|
|
} else if (_driver) {
|
2021-11-13 23:40:15 +02:00
|
|
|
_driver->setTimerCallback(nullptr, nullptr);
|
2011-03-23 16:14:39 +01:00
|
|
|
_driver->close();
|
|
|
|
delete _driver;
|
2022-01-27 22:29:39 +01:00
|
|
|
_driver = nullptr;
|
2011-03-23 16:14:39 +01:00
|
|
|
}
|
2021-06-11 17:42:26 +02:00
|
|
|
|
2022-01-27 22:29:39 +01:00
|
|
|
if (_parserMusic)
|
|
|
|
delete _parserMusic;
|
|
|
|
if (_parserSfx)
|
|
|
|
delete _parserSfx;
|
|
|
|
|
|
|
|
if (_musicData)
|
|
|
|
delete[] _musicData;
|
|
|
|
if (_sfxData)
|
|
|
|
delete[] _sfxData;
|
|
|
|
|
2011-03-23 16:14:39 +01:00
|
|
|
clearConstructs();
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2021-01-12 17:52:14 +01:00
|
|
|
int MidiPlayer::open(int gameType, Common::Platform platform, bool isDemo) {
|
2011-03-23 16:14:39 +01:00
|
|
|
// Don't call open() twice!
|
|
|
|
assert(!_driver);
|
|
|
|
|
2015-07-03 00:52:36 +02:00
|
|
|
Common::String accoladeDriverFilename;
|
2022-02-15 22:31:26 +01:00
|
|
|
// All games have MT-32 data, except Simon 2, which has both GM and MT-32
|
|
|
|
// data for DOS, or only GM for Windows. Some of the GM tracks have extra
|
|
|
|
// instruments compared to the MT-32 tracks, so we prefer GM.
|
|
|
|
int devFlags = MDT_MIDI | MDT_ADLIB | (_vm->getGameType() == GType_SIMON2 ? MDT_PREFER_GM : MDT_PREFER_MT32);
|
2015-06-21 00:45:45 +02:00
|
|
|
|
2022-01-27 22:29:39 +01:00
|
|
|
if (_vm->getGameType() == GType_SIMON1) {
|
|
|
|
// Check the type of device that the user has configured.
|
|
|
|
MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(devFlags);
|
2022-02-15 22:31:26 +01:00
|
|
|
_deviceType = MidiDriver::getMusicType(dev);
|
|
|
|
if (_deviceType == MT_GM && ConfMan.getBool("native_mt32"))
|
|
|
|
_deviceType = MT_MT32;
|
2022-01-27 22:29:39 +01:00
|
|
|
|
|
|
|
// All versions of Simon 1 that use MIDI have data that targets the
|
|
|
|
// MT-32 (even the Windows and Acorn versions).
|
2022-02-15 22:31:26 +01:00
|
|
|
_dataType = MT_MT32;
|
2022-01-27 22:29:39 +01:00
|
|
|
|
2022-02-15 22:31:26 +01:00
|
|
|
if (_dataType == MT_MT32 && _deviceType == MT_GM) {
|
2022-01-27 22:29:39 +01:00
|
|
|
// Not a real MT32 / no MUNT
|
|
|
|
::GUI::MessageDialog dialog(_(
|
|
|
|
"You appear to be using a General MIDI device,\n"
|
|
|
|
"but your game only supports Roland MT32 MIDI.\n"
|
|
|
|
"We try to map the Roland MT32 instruments to\n"
|
|
|
|
"General MIDI ones. It is still possible that\n"
|
|
|
|
"some tracks sound incorrect."));
|
|
|
|
dialog.runModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_vm->getPlatform() == Common::kPlatformDOS &&
|
|
|
|
(_vm->getFeatures() & GF_DEMO) && !(_vm->getFeatures() & GF_TALKIE)) {
|
|
|
|
// DOS floppy demo uses the older Accolade music drivers.
|
|
|
|
_musicMode = kMusicModeAccolade;
|
|
|
|
accoladeDriverFilename = "MUSIC.DRV";
|
|
|
|
|
2022-02-15 22:31:26 +01:00
|
|
|
switch (_deviceType) {
|
2022-01-27 22:29:39 +01:00
|
|
|
case MT_ADLIB:
|
|
|
|
_driver = MidiDriver_Accolade_AdLib_create(accoladeDriverFilename);
|
|
|
|
break;
|
|
|
|
case MT_MT32:
|
|
|
|
_driver = MidiDriver_Accolade_MT32_create(accoladeDriverFilename);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_driver = new MidiDriver_NULL_Multisource();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the MIDI parser for the MUS format used by this version.
|
|
|
|
_parserMusic = MidiParser_createS1D();
|
2022-02-15 22:31:26 +01:00
|
|
|
_parserMusic->property(MidiParser::mpDisableAutoStartPlayback, true);
|
2022-01-27 22:29:39 +01:00
|
|
|
|
|
|
|
// Open the MIDI driver.
|
|
|
|
int returnCode = _driver->open();
|
|
|
|
if (returnCode != 0)
|
|
|
|
error("MidiPlayer::open - Failed to open MIDI music driver - error code %d.", returnCode);
|
|
|
|
|
|
|
|
// Connect the driver and the parser.
|
|
|
|
_parserMusic->setMidiDriver(_driver);
|
|
|
|
_parserMusic->setTimerRate(_driver->getBaseTempo());
|
|
|
|
|
|
|
|
_driver->setTimerCallback(_parserMusic, &_parserMusic->timerCallback);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
// Create the correct driver(s) for the device type and platform.
|
2022-02-15 22:31:26 +01:00
|
|
|
switch (_deviceType) {
|
2022-01-27 22:29:39 +01:00
|
|
|
case MT_ADLIB:
|
|
|
|
if (_vm->getPlatform() == Common::kPlatformDOS) {
|
|
|
|
// DOS versions use a specific AdLib driver implementation
|
|
|
|
// that needs an instrument bank file.
|
|
|
|
_driverMsMusic = createMidiDriverSimon1AdLib("MT_FM.IBK");
|
|
|
|
if (!(_vm->getFeatures() & GF_TALKIE)) {
|
|
|
|
// DOS floppy version has MIDI SFX for AdLib.
|
|
|
|
_driverMsSfx = _driverMsMusic;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Windows and Acorn CD
|
|
|
|
// TODO Acorn does not use an OPL chip, but we don't have
|
|
|
|
// an implementation for the Acorn audio. It has the same
|
|
|
|
// music data has the DOS CD version, but it does not have
|
|
|
|
// the MT_FM.IBK instrument bank, so we use the standard
|
|
|
|
// OPL MIDI driver.
|
|
|
|
_driverMsMusic = new MidiDriver_Simon1_AdLib_Windows();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MT_MT32:
|
|
|
|
case MT_GM:
|
2022-02-15 22:31:26 +01:00
|
|
|
_driverMsMusic = new MidiDriver_MT32GM(_dataType);
|
2022-01-27 22:29:39 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformDOS && !(_vm->getFeatures() & GF_TALKIE) &&
|
|
|
|
ConfMan.getBool("multi_midi")) {
|
|
|
|
// DOS floppy version uses AdLib MIDI SFX if mixed MIDI
|
|
|
|
// mode is active.
|
|
|
|
_driverMsSfx = createMidiDriverSimon1AdLib("MT_FM.IBK");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_driverMsMusic = new MidiDriver_NULL_Multisource();
|
|
|
|
break;
|
|
|
|
}
|
2022-02-15 22:31:26 +01:00
|
|
|
_driver = _driverMsMusic;
|
|
|
|
|
|
|
|
// WORKAROUND The Simon 1 MIDI data does not always set a value for
|
|
|
|
// program, volume or panning before it starts playing notes on a
|
|
|
|
// MIDI channel. This can cause settings for these parameters from
|
|
|
|
// a previous track to be used unintentionally. To correct this,
|
|
|
|
// default values for these parameters are set when a new track is
|
|
|
|
// started.
|
|
|
|
_driverMsMusic->setControllerDefault(MidiDriver_Multisource::CONTROLLER_DEFAULT_PROGRAM);
|
|
|
|
_driverMsMusic->setControllerDefault(MidiDriver_Multisource::CONTROLLER_DEFAULT_VOLUME);
|
|
|
|
_driverMsMusic->setControllerDefault(MidiDriver_Multisource::CONTROLLER_DEFAULT_PANNING);
|
|
|
|
_driverMsMusic->property(MidiDriver::PROP_USER_VOLUME_SCALING, true);
|
2022-01-27 22:29:39 +01:00
|
|
|
|
|
|
|
// Create the MIDI parser(s) for the format used by the platform.
|
|
|
|
if (_vm->getPlatform() == Common::kPlatformWindows) {
|
|
|
|
// Windows version uses a specific SMF variant.
|
2022-02-15 22:31:26 +01:00
|
|
|
_parserMusic = new MidiParser_SimonWin(0, true);
|
2022-01-27 22:29:39 +01:00
|
|
|
} else {
|
|
|
|
// DOS floppy & CD and Acorn CD use GMF (also an SMF variant).
|
|
|
|
_parserMusic = new MidiParser_GMF(0);
|
|
|
|
|
|
|
|
if (_driverMsSfx) {
|
|
|
|
// DOS floppy needs a second parser for AdLib SFX.
|
|
|
|
_parserSfx = new MidiParser_GMF(1);
|
|
|
|
_parserMusic->property(MidiParser::mpDisableAllNotesOffMidiEvents, true);
|
|
|
|
_parserSfx->property(MidiParser::mpDisableAllNotesOffMidiEvents, true);
|
2022-02-15 22:31:26 +01:00
|
|
|
_parserSfx->property(MidiParser::mpDisableAutoStartPlayback, true);
|
2022-01-27 22:29:39 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-15 22:31:26 +01:00
|
|
|
_parserMusic->property(MidiParser::mpDisableAutoStartPlayback, true);
|
2022-01-27 22:29:39 +01:00
|
|
|
|
|
|
|
// Open the MIDI driver(s).
|
|
|
|
int returnCode = _driverMsMusic->open();
|
|
|
|
if (returnCode != 0)
|
|
|
|
error("MidiPlayer::open - Failed to open MIDI music driver - error code %d.", returnCode);
|
|
|
|
_driverMsMusic->syncSoundSettings();
|
|
|
|
if (_driverMsSfx && _driverMsMusic != _driverMsSfx) {
|
|
|
|
_driverMsSfx->property(MidiDriver::PROP_USER_VOLUME_SCALING, true);
|
|
|
|
returnCode = _driverMsSfx->open();
|
|
|
|
if (returnCode != 0)
|
|
|
|
error("MidiPlayer::open - Failed to open MIDI SFX driver - error code %d.", returnCode);
|
|
|
|
_driverMsSfx->syncSoundSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Connect the driver(s) and parser(s).
|
|
|
|
_parserMusic->setMidiDriver(_driverMsMusic);
|
|
|
|
_parserMusic->setTimerRate(_driverMsMusic->getBaseTempo());
|
|
|
|
if (_parserSfx) {
|
|
|
|
_parserSfx->setMidiDriver(_driverMsSfx);
|
|
|
|
_parserSfx->setTimerRate(_driverMsSfx->getBaseTempo());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_driverMsSfx == _driverMsMusic) {
|
|
|
|
// Use MidiPlayer::onTimer to trigger both parsers from the
|
|
|
|
// single driver (it can only have one timer callback).
|
|
|
|
_driverMsMusic->setTimerCallback(this, &onTimer);
|
|
|
|
} else {
|
|
|
|
// Trigger each parser callback from the corresponding driver.
|
|
|
|
_driverMsMusic->setTimerCallback(_parserMusic, &_parserMusic->timerCallback);
|
|
|
|
if (_driverMsSfx) {
|
|
|
|
_driverMsSfx->setTimerCallback(_parserSfx, &_parserSfx->timerCallback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2022-02-15 22:31:26 +01:00
|
|
|
} else if (_vm->getGameType() == GType_SIMON2) {
|
|
|
|
// Check the type of device that the user has configured.
|
|
|
|
MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(devFlags);
|
|
|
|
_deviceType = MidiDriver::getMusicType(dev);
|
|
|
|
if (_deviceType == MT_GM && ConfMan.getBool("native_mt32"))
|
|
|
|
_deviceType = MT_MT32;
|
|
|
|
|
|
|
|
// DOS version has both MT-32 and GM tracks; Windows is GM only.
|
|
|
|
_dataType = (_vm->getPlatform() == Common::kPlatformDOS && _deviceType == MT_MT32) ? MT_MT32 : MT_GM;
|
|
|
|
|
|
|
|
switch (_deviceType) {
|
|
|
|
case MT_ADLIB:
|
|
|
|
if (_vm->getPlatform() == Common::kPlatformDOS) {
|
|
|
|
if (Common::File::exists("MIDPAK.AD")) {
|
|
|
|
// if there is a file called MIDPAK.AD, use it directly
|
|
|
|
warning("MidiPlayer::open - SIMON 2: using MIDPAK.AD");
|
|
|
|
_driverMsMusic = Audio::MidiDriver_Miles_AdLib_create("MIDPAK.AD", "");
|
|
|
|
} else {
|
|
|
|
// if there is no file called MIDPAK.AD, try to extract it from the file SETUP.SHR
|
|
|
|
// if we didn't do this, the user would be forced to "install" the game instead of simply
|
|
|
|
// copying all files from CD-ROM.
|
|
|
|
Common::SeekableReadStream *midpakAdLibStream = simon2SetupExtractFile("MIDPAK.AD");
|
|
|
|
if (!midpakAdLibStream)
|
|
|
|
error("MidiPlayer::open - Could not extract MIDPAK.AD from SETUP.SHR");
|
|
|
|
|
|
|
|
// Pass this extracted data to the driver
|
|
|
|
warning("MidiPlayer::open - SIMON 2: using MIDPAK.AD extracted from SETUP.SHR");
|
|
|
|
_driverMsMusic = Audio::MidiDriver_Miles_AdLib_create("", "", midpakAdLibStream);
|
|
|
|
delete midpakAdLibStream;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Windows
|
|
|
|
_driverMsMusic = new MidiDriver_ADLIB_Multisource(OPL::Config::kOpl3);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MT_MT32:
|
|
|
|
case MT_GM:
|
|
|
|
if (_vm->getPlatform() == Common::kPlatformDOS) {
|
|
|
|
_driverMsMusic = Audio::MidiDriver_Miles_MIDI_create(_dataType, "");
|
|
|
|
} else {
|
|
|
|
// Windows
|
|
|
|
_driverMsMusic = new MidiDriver_MT32GM(_dataType);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_driverMsMusic = new MidiDriver_NULL_Multisource();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
_driver = _driverMsMusic;
|
|
|
|
_driverMsMusic->property(MidiDriver::PROP_USER_VOLUME_SCALING, true);
|
|
|
|
|
|
|
|
// Create the MIDI parser(s) for the format used by the platform.
|
|
|
|
if (_vm->getPlatform() == Common::kPlatformDOS) {
|
|
|
|
_parserMusic = MidiParser::createParser_XMIDI(MidiParser::defaultXMidiCallback, 0, 0);
|
|
|
|
} else {
|
|
|
|
// Windows version uses a specific SMF variant.
|
|
|
|
_parserMusic = new MidiParser_SimonWin(0);
|
|
|
|
}
|
|
|
|
_parserMusic->property(MidiParser::mpDisableAutoStartPlayback, true);
|
|
|
|
|
|
|
|
// Open the MIDI driver.
|
|
|
|
int returnCode = _driverMsMusic->open();
|
|
|
|
if (returnCode != 0)
|
|
|
|
error("MidiPlayer::open - Failed to open MIDI music driver - error code %d.", returnCode);
|
|
|
|
_driverMsMusic->syncSoundSettings();
|
|
|
|
|
|
|
|
// Connect the driver and parser.
|
|
|
|
_parserMusic->setMidiDriver(_driverMsMusic);
|
|
|
|
_parserMusic->setTimerRate(_driverMsMusic->getBaseTempo());
|
|
|
|
_driverMsMusic->setTimerCallback(this, &onTimer);
|
|
|
|
|
|
|
|
return 0;
|
2022-01-27 22:29:39 +01:00
|
|
|
}
|
|
|
|
|
2022-02-15 22:31:26 +01:00
|
|
|
// TODO Old code below is no longer used for Simon 1 and 2.
|
|
|
|
_deviceType = MT_INVALID;
|
2022-01-27 22:29:39 +01:00
|
|
|
|
2015-06-21 00:45:45 +02:00
|
|
|
switch (gameType) {
|
|
|
|
case GType_ELVIRA1:
|
2021-01-12 17:52:14 +01:00
|
|
|
if (platform == Common::kPlatformPC98) {
|
2021-01-17 14:26:06 +01:00
|
|
|
_musicMode = kMusicModePC98;
|
2021-01-12 17:52:14 +01:00
|
|
|
devFlags = (devFlags & ~MDT_ADLIB) | MDT_PC98;
|
|
|
|
} else {
|
|
|
|
_musicMode = kMusicModeAccolade;
|
|
|
|
accoladeDriverFilename = "INSTR.DAT";
|
|
|
|
}
|
2015-06-21 00:45:45 +02:00
|
|
|
break;
|
2015-06-21 01:20:21 +02:00
|
|
|
case GType_ELVIRA2:
|
2015-06-21 00:45:45 +02:00
|
|
|
case GType_WW:
|
2015-06-21 01:22:57 +02:00
|
|
|
// Attention: Elvira 2 shipped with INSTR.DAT and MUSIC.DRV
|
|
|
|
// MUSIC.DRV is the correct one. INSTR.DAT seems to be a left-over
|
2015-07-01 12:40:16 +02:00
|
|
|
_musicMode = kMusicModeAccolade;
|
2015-07-03 00:52:36 +02:00
|
|
|
accoladeDriverFilename = "MUSIC.DRV";
|
2015-06-21 00:45:45 +02:00
|
|
|
break;
|
|
|
|
case GType_SIMON1:
|
|
|
|
if (isDemo) {
|
2015-07-01 12:40:16 +02:00
|
|
|
_musicMode = kMusicModeAccolade;
|
2015-07-03 00:52:36 +02:00
|
|
|
accoladeDriverFilename = "MUSIC.DRV";
|
2015-07-23 22:33:56 +02:00
|
|
|
} else if (Common::File::exists("MT_FM.IBK")) {
|
|
|
|
_musicMode = kMusicModeSimon1;
|
2015-06-21 00:45:45 +02:00
|
|
|
}
|
|
|
|
break;
|
2015-07-01 12:40:16 +02:00
|
|
|
case GType_SIMON2:
|
2015-07-03 00:59:17 +02:00
|
|
|
//_musicMode = kMusicModeMilesAudio;
|
2015-07-01 12:40:16 +02:00
|
|
|
// currently disabled, because there are a few issues
|
2015-07-01 20:39:00 +02:00
|
|
|
// MT32 seems to work fine now, AdLib seems to use bad instruments and is also outputting music on
|
|
|
|
// the right speaker only. The original driver did initialize the panning to 0 and the Simon2 XMIDI
|
|
|
|
// tracks don't set panning at all. We can reset panning to be centered, which would solve this
|
|
|
|
// issue, but we still don't know who's setting it in the original interpreter.
|
2015-07-01 12:40:16 +02:00
|
|
|
break;
|
2015-06-21 00:45:45 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-07-01 12:40:16 +02:00
|
|
|
MidiDriver::DeviceHandle dev;
|
|
|
|
int ret = 0;
|
|
|
|
|
2021-01-17 14:26:06 +01:00
|
|
|
if (_musicMode == kMusicModePC98) {
|
|
|
|
dev = MidiDriver::detectDevice(devFlags);
|
|
|
|
_driver = MidiDriverPC98_create(dev);
|
|
|
|
if (_driver && !_driver->open()) {
|
|
|
|
_driver->setTimerCallback(this, &onTimer);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else if (_musicMode != kMusicModeDisabled) {
|
2021-01-12 17:52:14 +01:00
|
|
|
dev = MidiDriver::detectDevice(devFlags);
|
2022-02-15 22:31:26 +01:00
|
|
|
_deviceType = MidiDriver::getMusicType(dev);
|
2015-06-21 00:45:45 +02:00
|
|
|
|
2022-02-15 22:31:26 +01:00
|
|
|
switch (_deviceType) {
|
2015-06-21 00:45:45 +02:00
|
|
|
case MT_ADLIB:
|
|
|
|
case MT_MT32:
|
|
|
|
break;
|
|
|
|
case MT_GM:
|
2015-06-21 10:06:12 +02:00
|
|
|
if (!ConfMan.getBool("native_mt32")) {
|
|
|
|
// Not a real MT32 / no MUNT
|
2020-07-04 03:13:05 +05:30
|
|
|
::GUI::MessageDialog dialog(_(
|
2020-06-22 23:29:25 +05:30
|
|
|
"You appear to be using a General MIDI device,\n"
|
2015-06-21 10:06:12 +02:00
|
|
|
"but your game only supports Roland MT32 MIDI.\n"
|
|
|
|
"We try to map the Roland MT32 instruments to\n"
|
|
|
|
"General MIDI ones. It is still possible that\n"
|
2020-07-04 03:13:05 +05:30
|
|
|
"some tracks sound incorrect."));
|
2015-06-21 10:06:12 +02:00
|
|
|
dialog.runModal();
|
2015-06-21 00:45:45 +02:00
|
|
|
}
|
2015-06-21 10:06:12 +02:00
|
|
|
// Switch to MT32 driver in any case
|
2022-02-15 22:31:26 +01:00
|
|
|
_deviceType = MT_MT32;
|
2015-06-21 00:45:45 +02:00
|
|
|
break;
|
|
|
|
default:
|
2015-07-01 12:40:16 +02:00
|
|
|
_musicMode = kMusicModeDisabled;
|
|
|
|
break;
|
|
|
|
}
|
2015-06-21 00:45:45 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 12:40:16 +02:00
|
|
|
switch (_musicMode) {
|
|
|
|
case kMusicModeAccolade: {
|
2015-06-21 00:45:45 +02:00
|
|
|
// Setup midi driver
|
2022-02-15 22:31:26 +01:00
|
|
|
switch (_deviceType) {
|
2015-06-21 00:45:45 +02:00
|
|
|
case MT_ADLIB:
|
2015-07-03 00:52:36 +02:00
|
|
|
_driver = MidiDriver_Accolade_AdLib_create(accoladeDriverFilename);
|
2015-06-21 00:45:45 +02:00
|
|
|
break;
|
|
|
|
case MT_MT32:
|
2015-07-03 00:52:36 +02:00
|
|
|
_driver = MidiDriver_Accolade_MT32_create(accoladeDriverFilename);
|
2015-06-21 00:45:45 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!_driver)
|
|
|
|
return 255;
|
|
|
|
|
2015-07-01 12:40:16 +02:00
|
|
|
ret = _driver->open();
|
2015-06-21 00:45:45 +02:00
|
|
|
if (ret == 0) {
|
|
|
|
// Reset is done inside our MIDI driver
|
|
|
|
_driver->setTimerCallback(this, &onTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
//setTimerRate(_driver->getBaseTempo());
|
|
|
|
return 0;
|
|
|
|
}
|
2016-10-09 14:59:58 +02:00
|
|
|
|
2015-07-01 12:40:16 +02:00
|
|
|
case kMusicModeMilesAudio: {
|
2022-02-15 22:31:26 +01:00
|
|
|
switch (_deviceType) {
|
2015-07-01 12:40:16 +02:00
|
|
|
case MT_ADLIB: {
|
2015-07-03 21:02:13 +02:00
|
|
|
Common::File instrumentDataFile;
|
|
|
|
if (instrumentDataFile.exists("MIDPAK.AD")) {
|
|
|
|
// if there is a file called MIDPAK.AD, use it directly
|
|
|
|
warning("SIMON 2: using MIDPAK.AD");
|
|
|
|
_driver = Audio::MidiDriver_Miles_AdLib_create("MIDPAK.AD", "MIDPAK.AD");
|
|
|
|
} else {
|
|
|
|
// if there is no file called MIDPAK.AD, try to extract it from the file SETUP.SHR
|
|
|
|
// if we didn't do this, the user would be forced to "install" the game instead of simply
|
|
|
|
// copying all files from CD-ROM.
|
2015-07-04 12:55:49 +02:00
|
|
|
Common::SeekableReadStream *midpakAdLibStream;
|
|
|
|
midpakAdLibStream = simon2SetupExtractFile("MIDPAK.AD");
|
|
|
|
if (!midpakAdLibStream)
|
2015-07-03 21:02:13 +02:00
|
|
|
error("MidiPlayer: could not extract MIDPAK.AD from SETUP.SHR");
|
|
|
|
|
|
|
|
// Pass this extracted data to the driver
|
|
|
|
warning("SIMON 2: using MIDPAK.AD extracted from SETUP.SHR");
|
2015-07-04 12:55:49 +02:00
|
|
|
_driver = Audio::MidiDriver_Miles_AdLib_create("", "", midpakAdLibStream);
|
|
|
|
delete midpakAdLibStream;
|
2015-07-03 21:02:13 +02:00
|
|
|
}
|
2015-07-01 20:39:00 +02:00
|
|
|
// TODO: not sure what's going wrong with AdLib
|
|
|
|
// it doesn't seem to matter if we use the regular XMIDI tracks or the 2nd set meant for MT32
|
2015-07-01 12:40:16 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MT_MT32:
|
|
|
|
_driver = Audio::MidiDriver_Miles_MT32_create("");
|
2015-07-01 20:39:00 +02:00
|
|
|
_nativeMT32 = true; // use 2nd set of XMIDI tracks
|
2015-07-01 12:40:16 +02:00
|
|
|
break;
|
|
|
|
case MT_GM:
|
|
|
|
if (ConfMan.getBool("native_mt32")) {
|
|
|
|
_driver = Audio::MidiDriver_Miles_MT32_create("");
|
2015-07-01 20:39:00 +02:00
|
|
|
_nativeMT32 = true; // use 2nd set of XMIDI tracks
|
2015-07-01 12:40:16 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!_driver)
|
|
|
|
return 255;
|
|
|
|
|
|
|
|
ret = _driver->open();
|
|
|
|
if (ret == 0) {
|
|
|
|
// Reset is done inside our MIDI driver
|
|
|
|
_driver->setTimerCallback(this, &onTimer);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-23 22:33:56 +02:00
|
|
|
case kMusicModeSimon1: {
|
|
|
|
// This only handles the original AdLib driver of Simon1.
|
2022-02-15 22:31:26 +01:00
|
|
|
if (_deviceType == MT_ADLIB) {
|
2015-07-23 22:33:56 +02:00
|
|
|
_map_mt32_to_gm = false;
|
|
|
|
_nativeMT32 = false;
|
|
|
|
|
2015-07-23 22:33:56 +02:00
|
|
|
_driver = createMidiDriverSimon1AdLib("MT_FM.IBK");
|
|
|
|
if (_driver && _driver->open() == 0) {
|
|
|
|
_driver->setTimerCallback(this, &onTimer);
|
|
|
|
// Like the original, we enable the rhythm support by default.
|
|
|
|
_driver->send(0xB0, 0x67, 0x01);
|
|
|
|
return 0;
|
2015-07-23 22:33:56 +02:00
|
|
|
}
|
2015-07-23 22:33:56 +02:00
|
|
|
|
|
|
|
delete _driver;
|
|
|
|
_driver = nullptr;
|
2015-07-23 22:33:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_musicMode = kMusicModeDisabled;
|
|
|
|
}
|
|
|
|
|
2015-07-01 12:40:16 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-06-21 00:45:45 +02:00
|
|
|
|
2015-07-01 12:40:16 +02:00
|
|
|
dev = MidiDriver::detectDevice(MDT_ADLIB | MDT_MIDI | (gameType == GType_SIMON1 ? MDT_PREFER_MT32 : MDT_PREFER_GM));
|
2011-03-23 16:14:39 +01:00
|
|
|
_nativeMT32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"));
|
|
|
|
|
|
|
|
_driver = MidiDriver::createMidi(dev);
|
2003-05-18 23:55:53 +00:00
|
|
|
if (!_driver)
|
|
|
|
return 255;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2011-03-23 16:14:39 +01:00
|
|
|
if (_nativeMT32)
|
|
|
|
_driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
|
|
|
|
|
|
|
|
_map_mt32_to_gm = (gameType != GType_SIMON2 && !_nativeMT32);
|
|
|
|
|
2015-07-01 12:40:16 +02:00
|
|
|
ret = _driver->open();
|
2003-05-18 23:55:53 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2003-09-24 06:33:59 +00:00
|
|
|
_driver->setTimerCallback(this, &onTimer);
|
2007-02-16 13:41:38 +00:00
|
|
|
|
MIDI: Send a reset MIDI device signal on startup.
This is currently done in the engine code. I adapted AGI, AGOS, DRACI,
GROOVIE, LURE, MADE, QUEEN, SAGA, SKY, TINSEL and TOUCHE to send a reset
device on startup. The sound output still works fine (started up a game
from every engine), so this should hopefully not introduce any regressions.
As far as I can tell it seems that SCUMM does send a proper device reset, so
I did not touch it. KYRA only sends a proper reset for MT-32 currently. I am
not sure about SCI though.
This fixes bug #3066826 "SIMON: MIDI notes off when using RTL after SCI".
svn-id: r52736
2010-09-15 22:00:20 +00:00
|
|
|
if (_nativeMT32)
|
|
|
|
_driver->sendMT32Reset();
|
|
|
|
else
|
|
|
|
_driver->sendGMReset();
|
2007-02-16 13:41:38 +00:00
|
|
|
|
2003-05-18 23:55:53 +00:00
|
|
|
return 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-09-24 06:33:59 +00:00
|
|
|
void MidiPlayer::send(uint32 b) {
|
2003-05-24 01:26:05 +00:00
|
|
|
if (!_current)
|
|
|
|
return;
|
|
|
|
|
2015-07-01 12:40:16 +02:00
|
|
|
if (_musicMode != kMusicModeDisabled) {
|
2015-07-23 22:33:57 +02:00
|
|
|
// Handle volume control for Simon1 output.
|
|
|
|
if (_musicMode == kMusicModeSimon1) {
|
|
|
|
// The driver does not support any volume control, thus we simply
|
|
|
|
// scale the velocities on note on for now.
|
|
|
|
// TODO: We should probably handle this at output level at some
|
|
|
|
// point. Then we can allow volume changes to affect already
|
|
|
|
// playing notes too. For now this simple change allows us to
|
|
|
|
// have some simple volume control though.
|
|
|
|
if ((b & 0xF0) == 0x90) {
|
|
|
|
byte volume = (b >> 16) & 0x7F;
|
|
|
|
|
|
|
|
if (_current == &_sfx) {
|
|
|
|
volume = volume * _sfxVolume / 255;
|
|
|
|
} else if (_current == &_music) {
|
|
|
|
volume = volume * _musicVolume / 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
b = (b & 0xFF00FFFF) | (volume << 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send directly to Accolade/Miles/Simon1 Audio driver
|
2015-06-21 00:45:45 +02:00
|
|
|
_driver->send(b);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-12 08:49:04 +00:00
|
|
|
byte channel = (byte)(b & 0x0F);
|
2003-05-18 23:55:53 +00:00
|
|
|
if ((b & 0xFFF0) == 0x07B0) {
|
2008-07-14 22:10:04 +00:00
|
|
|
// Adjust volume changes by master music and master sfx volume.
|
2006-05-12 08:49:04 +00:00
|
|
|
byte volume = (byte)((b >> 16) & 0x7F);
|
2003-09-24 06:33:59 +00:00
|
|
|
_current->volume[channel] = volume;
|
2008-07-14 22:10:04 +00:00
|
|
|
if (_current == &_sfx)
|
|
|
|
volume = volume * _sfxVolume / 255;
|
|
|
|
else if (_current == &_music)
|
|
|
|
volume = volume * _musicVolume / 255;
|
2003-05-18 23:55:53 +00:00
|
|
|
b = (b & 0xFF00FFFF) | (volume << 16);
|
2015-07-23 22:33:56 +02:00
|
|
|
} else if ((b & 0xF0) == 0xC0 && _map_mt32_to_gm) {
|
|
|
|
b = (b & 0xFFFF00FF) | (MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8);
|
2003-05-24 01:26:05 +00:00
|
|
|
} else if ((b & 0xFFF0) == 0x007BB0) {
|
|
|
|
// Only respond to an All Notes Off if this channel
|
2003-05-24 04:39:47 +00:00
|
|
|
// has already been allocated.
|
2003-09-24 06:33:59 +00:00
|
|
|
if (!_current->channel[b & 0x0F])
|
2003-05-24 01:26:05 +00:00
|
|
|
return;
|
2006-05-12 10:29:58 +00:00
|
|
|
} else if ((b & 0xFFF0) == 0x79B0) {
|
2006-05-15 12:39:53 +00:00
|
|
|
// "Reset All Controllers". There seems to be some confusion
|
|
|
|
// about what this message should do to the volume controller.
|
|
|
|
// See http://www.midi.org/about-midi/rp15.shtml for more
|
|
|
|
// information.
|
|
|
|
//
|
|
|
|
// If I understand it correctly, the current standard indicates
|
|
|
|
// that the volume should be reset, but the next revision will
|
|
|
|
// exclude it. On my system, both ALSA and FluidSynth seem to
|
2010-01-12 21:07:56 +00:00
|
|
|
// reset it, while AdLib does not. Let's follow the majority.
|
2006-05-15 12:39:53 +00:00
|
|
|
|
|
|
|
_current->volume[channel] = 127;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2015-06-21 00:45:45 +02:00
|
|
|
// Allocate channels if needed
|
2003-09-24 06:33:59 +00:00
|
|
|
if (!_current->channel[channel])
|
2003-05-24 03:55:37 +00:00
|
|
|
_current->channel[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
|
2015-06-21 00:45:45 +02:00
|
|
|
|
2003-10-12 14:31:21 +00:00
|
|
|
if (_current->channel[channel]) {
|
2008-07-14 22:10:04 +00:00
|
|
|
if (channel == 9) {
|
|
|
|
if (_current == &_sfx)
|
|
|
|
_current->channel[9]->volume(_current->volume[9] * _sfxVolume / 255);
|
|
|
|
else if (_current == &_music)
|
|
|
|
_current->channel[9]->volume(_current->volume[9] * _musicVolume / 255);
|
|
|
|
}
|
2015-07-23 22:33:56 +02:00
|
|
|
_current->channel[channel]->send(b);
|
2006-05-15 12:39:53 +00:00
|
|
|
if ((b & 0xFFF0) == 0x79B0) {
|
|
|
|
// We have received a "Reset All Controllers" message
|
|
|
|
// and passed it on to the MIDI driver. This may or may
|
|
|
|
// not have affected the volume controller. To ensure
|
2011-05-25 10:31:37 -04:00
|
|
|
// consistent behavior, explicitly set the volume to
|
2006-05-15 12:39:53 +00:00
|
|
|
// what we think it should be.
|
|
|
|
|
2008-07-14 22:10:04 +00:00
|
|
|
if (_current == &_sfx)
|
|
|
|
_current->channel[channel]->volume(_current->volume[channel] * _sfxVolume / 255);
|
|
|
|
else if (_current == &_music)
|
|
|
|
_current->channel[channel]->volume(_current->volume[channel] * _musicVolume / 255);
|
2006-05-15 12:39:53 +00:00
|
|
|
}
|
2003-10-12 14:31:21 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2006-05-12 08:49:04 +00:00
|
|
|
void MidiPlayer::metaEvent(byte type, byte *data, uint16 length) {
|
2003-05-18 23:55:53 +00:00
|
|
|
// Only thing we care about is End of Track.
|
2003-07-24 04:19:42 +00:00
|
|
|
if (!_current || type != 0x2F) {
|
2003-05-18 23:55:53 +00:00
|
|
|
return;
|
2003-07-24 04:19:42 +00:00
|
|
|
} else if (_current == &_sfx) {
|
2003-09-24 06:33:59 +00:00
|
|
|
clearConstructs(_sfx);
|
2015-07-05 10:58:35 +10:00
|
|
|
} else if (_loopTrack) {
|
2003-09-24 06:33:59 +00:00
|
|
|
_current->parser->jumpToTick(0);
|
2003-05-21 04:36:09 +00:00
|
|
|
} else if (_queuedTrack != 255) {
|
|
|
|
_currentTrack = 255;
|
|
|
|
byte destination = _queuedTrack;
|
|
|
|
_queuedTrack = 255;
|
2015-07-05 10:58:35 +10:00
|
|
|
_loopTrack = _loopQueuedTrack;
|
2003-05-21 04:36:09 +00:00
|
|
|
_loopQueuedTrack = false;
|
|
|
|
|
|
|
|
// Remember, we're still inside the locked mutex.
|
|
|
|
// Have to unlock it before calling jump()
|
|
|
|
// (which locks it itself), and then relock it
|
|
|
|
// upon returning.
|
2005-01-28 22:05:51 +00:00
|
|
|
_mutex.unlock();
|
2006-05-12 08:49:04 +00:00
|
|
|
startTrack(destination);
|
2005-01-28 22:05:51 +00:00
|
|
|
_mutex.lock();
|
2003-05-21 04:36:09 +00:00
|
|
|
} else {
|
|
|
|
stop();
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2006-05-12 08:49:04 +00:00
|
|
|
void MidiPlayer::onTimer(void *data) {
|
|
|
|
MidiPlayer *p = (MidiPlayer *)data;
|
2004-09-04 00:04:36 +00:00
|
|
|
Common::StackLock lock(p->_mutex);
|
|
|
|
|
2022-02-15 22:31:26 +01:00
|
|
|
if (p->_parserMusic) {
|
2022-01-27 22:29:39 +01:00
|
|
|
p->_parserMusic->onTimer();
|
2022-02-15 22:31:26 +01:00
|
|
|
if (!p->_parserMusic->isPlaying() && p->_queuedTrack != 255) {
|
|
|
|
// Music is no longer playing and there is a track queued up.
|
|
|
|
// Play the queued track.
|
|
|
|
p->setLoop(p->_loopQueuedTrack);
|
|
|
|
p->play(p->_queuedTrack, false, false, true);
|
|
|
|
p->_queuedTrack = 255;
|
|
|
|
p->_loopQueuedTrack = false;
|
|
|
|
}
|
|
|
|
}
|
2022-01-27 22:29:39 +01:00
|
|
|
if (p->_parserSfx)
|
|
|
|
p->_parserSfx->onTimer();
|
|
|
|
|
2003-05-24 01:26:05 +00:00
|
|
|
if (!p->_paused) {
|
|
|
|
if (p->_music.parser && p->_currentTrack != 255) {
|
|
|
|
p->_current = &p->_music;
|
|
|
|
p->_music.parser->onTimer();
|
|
|
|
}
|
|
|
|
}
|
2003-07-14 12:15:17 +00:00
|
|
|
if (p->_sfx.parser) {
|
|
|
|
p->_current = &p->_sfx;
|
|
|
|
p->_sfx.parser->onTimer();
|
|
|
|
}
|
2021-11-13 23:40:15 +02:00
|
|
|
p->_current = nullptr;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2022-02-15 22:31:26 +01:00
|
|
|
bool MidiPlayer::usesMT32Data() const {
|
|
|
|
return _dataType == MT_MT32;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MidiPlayer::hasAdLibSfx() const {
|
|
|
|
return _parserSfx != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MidiPlayer::isPlaying(bool checkQueued) {
|
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
|
|
|
return _parserMusic->isPlaying() && (!checkQueued || _queuedTrack != 255);
|
|
|
|
}
|
|
|
|
|
2006-05-12 08:49:04 +00:00
|
|
|
void MidiPlayer::startTrack(int track) {
|
2011-03-23 11:50:37 +01:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
2003-05-20 17:10:15 +00:00
|
|
|
if (track == _currentTrack)
|
2003-05-18 23:55:53 +00:00
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-05-24 01:26:05 +00:00
|
|
|
if (_music.num_songs > 0) {
|
|
|
|
if (track >= _music.num_songs)
|
2003-05-18 23:55:53 +00:00
|
|
|
return;
|
2002-11-18 09:08:45 +00:00
|
|
|
|
2003-05-24 01:26:05 +00:00
|
|
|
if (_music.parser) {
|
2003-05-24 04:39:47 +00:00
|
|
|
_current = &_music;
|
2003-05-24 01:26:05 +00:00
|
|
|
delete _music.parser;
|
2021-11-13 23:40:15 +02:00
|
|
|
_current = nullptr;
|
|
|
|
_music.parser = nullptr;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-05-18 23:55:53 +00:00
|
|
|
MidiParser *parser = MidiParser::createParser_SMF();
|
2003-05-19 05:00:13 +00:00
|
|
|
parser->property (MidiParser::mpMalformedPitchBends, 1);
|
2006-05-12 08:49:04 +00:00
|
|
|
parser->setMidiDriver(this);
|
|
|
|
parser->setTimerRate(_driver->getBaseTempo());
|
|
|
|
if (!parser->loadMusic(_music.songs[track], _music.song_sizes[track])) {
|
2010-11-01 21:37:47 +00:00
|
|
|
warning("Error reading track %d", track);
|
2003-05-18 23:55:53 +00:00
|
|
|
delete parser;
|
2021-11-13 23:40:15 +02:00
|
|
|
parser = nullptr;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2006-05-12 08:49:04 +00:00
|
|
|
_currentTrack = (byte)track;
|
2003-05-24 01:26:05 +00:00
|
|
|
_music.parser = parser; // That plugs the power cord into the wall
|
|
|
|
} else if (_music.parser) {
|
2003-09-24 06:33:59 +00:00
|
|
|
if (!_music.parser->setTrack(track)) {
|
2003-05-21 06:13:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-05-12 08:49:04 +00:00
|
|
|
_currentTrack = (byte)track;
|
2003-05-24 04:39:47 +00:00
|
|
|
_current = &_music;
|
2003-09-24 06:33:59 +00:00
|
|
|
_music.parser->jumpToTick(0);
|
2021-11-13 23:40:15 +02:00
|
|
|
_current = nullptr;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-18 23:55:53 +00:00
|
|
|
void MidiPlayer::stop() {
|
2004-09-04 00:04:36 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
2022-02-15 22:31:26 +01:00
|
|
|
// Clear the queued track to prevent it from starting when the current
|
|
|
|
// track is stopped.
|
|
|
|
_queuedTrack = 255;
|
|
|
|
|
2022-01-27 22:29:39 +01:00
|
|
|
if (_parserMusic) {
|
|
|
|
_parserMusic->stopPlaying();
|
|
|
|
if (_driverMsMusic)
|
|
|
|
_driverMsMusic->deinitSource(0);
|
|
|
|
}
|
|
|
|
|
2003-05-24 04:39:47 +00:00
|
|
|
if (_music.parser) {
|
|
|
|
_current = &_music;
|
2003-05-24 01:26:05 +00:00
|
|
|
_music.parser->jumpToTick(0);
|
2003-05-24 04:39:47 +00:00
|
|
|
}
|
2021-11-13 23:40:15 +02:00
|
|
|
_current = nullptr;
|
2003-05-18 23:55:53 +00:00
|
|
|
_currentTrack = 255;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2022-01-27 22:29:39 +01:00
|
|
|
void MidiPlayer::stopSfx() {
|
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
|
|
|
if (_parserSfx) {
|
|
|
|
_parserSfx->stopPlaying();
|
|
|
|
if (_driverMsSfx)
|
|
|
|
_driverMsSfx->deinitSource(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-12 08:49:04 +00:00
|
|
|
void MidiPlayer::pause(bool b) {
|
2003-05-20 16:42:25 +00:00
|
|
|
if (_paused == b || !_driver)
|
2003-05-18 23:55:53 +00:00
|
|
|
return;
|
|
|
|
_paused = b;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2004-09-04 00:04:36 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
2022-01-27 22:29:39 +01:00
|
|
|
|
|
|
|
if (_paused) {
|
|
|
|
if (_parserMusic)
|
|
|
|
_parserMusic->pausePlaying();
|
|
|
|
if (_parserSfx)
|
|
|
|
_parserSfx->pausePlaying();
|
|
|
|
} else {
|
|
|
|
if (_parserMusic)
|
|
|
|
_parserMusic->resumePlaying();
|
|
|
|
if (_parserSfx)
|
|
|
|
_parserSfx->resumePlaying();
|
|
|
|
}
|
|
|
|
|
2019-05-02 20:24:41 +03:00
|
|
|
// if using the driver Accolade_AdLib call setVolume() to turn off\on the volume on all channels
|
2022-02-15 22:31:26 +01:00
|
|
|
if (_deviceType == MT_ADLIB && _musicMode == kMusicModeAccolade) {
|
2021-11-01 09:05:11 +01:00
|
|
|
static_cast <MidiDriver_Accolade_AdLib*> (_driver)->setVolume(_paused ? 0 : ConfMan.getInt("music_volume"));
|
2021-01-17 14:26:06 +01:00
|
|
|
} else if (_musicMode == kMusicModePC98) {
|
|
|
|
_driver->property(0x30, _paused ? 1 : 0);
|
2019-05-02 20:24:41 +03:00
|
|
|
}
|
2021-01-17 14:26:06 +01:00
|
|
|
|
2003-08-11 05:25:33 +00:00
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
if (_music.channel[i])
|
2008-07-14 22:10:04 +00:00
|
|
|
_music.channel[i]->volume(_paused ? 0 : (_music.volume[i] * _musicVolume / 255));
|
2003-08-11 05:25:33 +00:00
|
|
|
if (_sfx.channel[i])
|
2008-07-14 22:10:04 +00:00
|
|
|
_sfx.channel[i]->volume(_paused ? 0 : (_sfx.volume[i] * _sfxVolume / 255));
|
2003-08-11 05:25:33 +00:00
|
|
|
}
|
2003-05-18 23:55:53 +00:00
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2022-02-15 22:31:26 +01:00
|
|
|
void MidiPlayer::fadeOut() {
|
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
|
|
|
if (!_parserMusic->isPlaying())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// 1 second fade-out to silence.
|
|
|
|
_driverMsMusic->startFade(0, 1000, 0);
|
|
|
|
}
|
|
|
|
|
2008-07-14 22:10:04 +00:00
|
|
|
void MidiPlayer::setVolume(int musicVol, int sfxVol) {
|
2018-05-03 21:54:58 +02:00
|
|
|
musicVol = CLIP(musicVol, 0, 255);
|
|
|
|
sfxVol = CLIP(sfxVol, 0, 255);
|
2008-07-14 22:10:04 +00:00
|
|
|
|
|
|
|
if (_musicVolume == musicVol && _sfxVolume == sfxVol)
|
2003-05-18 23:55:53 +00:00
|
|
|
return;
|
2008-07-14 22:10:04 +00:00
|
|
|
|
|
|
|
_musicVolume = musicVol;
|
2018-05-03 21:54:58 +02:00
|
|
|
_sfxVolume = sfxVol;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2021-01-17 14:26:06 +01:00
|
|
|
if (_musicMode == kMusicModePC98) {
|
|
|
|
_driver->property(0x10, _musicVolume);
|
|
|
|
_driver->property(0x20, _sfxVolume);
|
2022-02-15 22:31:26 +01:00
|
|
|
} else if (_musicMode == kMusicModeAccolade && _deviceType == MT_ADLIB) {
|
2021-11-01 09:05:11 +01:00
|
|
|
static_cast <MidiDriver_Accolade_AdLib*> (_driver)->setVolume(_musicVolume);
|
2021-01-17 14:26:06 +01:00
|
|
|
}
|
|
|
|
|
2003-05-18 23:55:53 +00:00
|
|
|
// Now tell all the channels this.
|
2004-09-04 00:04:36 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
2003-05-18 23:55:53 +00:00
|
|
|
if (_driver && !_paused) {
|
2003-08-11 05:25:33 +00:00
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
if (_music.channel[i])
|
2008-07-14 22:10:04 +00:00
|
|
|
_music.channel[i]->volume(_music.volume[i] * _musicVolume / 255);
|
2003-08-11 05:25:33 +00:00
|
|
|
if (_sfx.channel[i])
|
2008-07-14 22:10:04 +00:00
|
|
|
_sfx.channel[i]->volume(_sfx.volume[i] * _sfxVolume / 255);
|
2003-05-18 23:55:53 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-27 22:29:39 +01:00
|
|
|
void MidiPlayer::syncSoundSettings() {
|
|
|
|
if (_driverMsMusic)
|
|
|
|
_driverMsMusic->syncSoundSettings();
|
|
|
|
if (_driverMsSfx)
|
|
|
|
_driverMsSfx->syncSoundSettings();
|
|
|
|
|
|
|
|
// Sync code for non-multisource drivers.
|
|
|
|
// TODO Remove when no longer necessary
|
|
|
|
bool mute = false;
|
|
|
|
if (ConfMan.hasKey("mute"))
|
|
|
|
mute = ConfMan.getBool("mute");
|
|
|
|
|
|
|
|
// Sync the engine with the config manager
|
|
|
|
int soundVolumeMusic = ConfMan.getInt("music_volume");
|
|
|
|
int soundVolumeSFX = ConfMan.getInt("sfx_volume");
|
|
|
|
|
|
|
|
setVolume(mute ? 0 : soundVolumeMusic, mute ? 0 : soundVolumeSFX);
|
|
|
|
}
|
|
|
|
|
2006-05-12 08:49:04 +00:00
|
|
|
void MidiPlayer::setLoop(bool loop) {
|
2004-09-04 00:04:36 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
2015-07-05 10:58:35 +10:00
|
|
|
_loopTrack = loop;
|
2022-01-27 22:29:39 +01:00
|
|
|
|
|
|
|
if (_parserMusic)
|
|
|
|
_parserMusic->property(MidiParser::mpAutoLoop, loop);
|
2003-05-21 04:36:09 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 23:16:22 +01:00
|
|
|
void MidiPlayer::setSimon2Remapping(bool remap) {
|
|
|
|
if (_driverMsMusic)
|
|
|
|
_driverMsMusic->setInstrumentRemapping(remap ? SIMON2_TRACK10_GM_MT32_INSTRUMENT_REMAPPING : nullptr);
|
|
|
|
}
|
|
|
|
|
2006-05-12 08:49:04 +00:00
|
|
|
void MidiPlayer::queueTrack(int track, bool loop) {
|
2022-02-15 22:31:26 +01:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
|
|
|
if (!_parserMusic->isPlaying()) {
|
|
|
|
// There is no music playing right now, so immediately play the track.
|
2003-09-24 06:33:59 +00:00
|
|
|
setLoop(loop);
|
2022-02-15 22:31:26 +01:00
|
|
|
play(track);
|
2003-05-21 04:36:09 +00:00
|
|
|
} else {
|
2022-02-15 22:31:26 +01:00
|
|
|
// Queue up the track for playback at the end of the current track.
|
2003-05-21 04:36:09 +00:00
|
|
|
_queuedTrack = track;
|
|
|
|
_loopQueuedTrack = loop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-18 23:55:53 +00:00
|
|
|
void MidiPlayer::clearConstructs() {
|
2003-09-24 06:33:59 +00:00
|
|
|
clearConstructs(_music);
|
|
|
|
clearConstructs(_sfx);
|
2003-05-24 01:26:05 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2003-09-24 06:33:59 +00:00
|
|
|
void MidiPlayer::clearConstructs(MusicInfo &info) {
|
2003-05-24 01:42:57 +00:00
|
|
|
int i;
|
2003-05-24 01:26:05 +00:00
|
|
|
if (info.num_songs > 0) {
|
|
|
|
for (i = 0; i < info.num_songs; ++i)
|
2006-05-12 08:49:04 +00:00
|
|
|
free(info.songs[i]);
|
2003-07-24 04:19:42 +00:00
|
|
|
info.num_songs = 0;
|
2003-05-18 23:55:53 +00:00
|
|
|
}
|
2003-07-24 04:19:42 +00:00
|
|
|
|
2010-07-16 03:35:44 +00:00
|
|
|
free(info.data);
|
2021-11-13 23:40:15 +02:00
|
|
|
info.data = nullptr;
|
2010-07-16 03:35:44 +00:00
|
|
|
|
|
|
|
delete info.parser;
|
2021-11-13 23:40:15 +02:00
|
|
|
info.parser = nullptr;
|
2003-07-24 04:19:42 +00:00
|
|
|
|
2003-05-24 01:42:57 +00:00
|
|
|
if (_driver) {
|
|
|
|
for (i = 0; i < 16; ++i) {
|
2003-05-24 03:55:37 +00:00
|
|
|
if (info.channel[i]) {
|
2003-08-11 05:25:33 +00:00
|
|
|
info.channel[i]->allNotesOff();
|
2003-05-24 03:55:37 +00:00
|
|
|
info.channel[i]->release();
|
|
|
|
}
|
2003-05-24 01:42:57 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-24 01:26:05 +00:00
|
|
|
info.clear();
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-08-11 05:25:33 +00:00
|
|
|
void MidiPlayer::resetVolumeTable() {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 16; ++i) {
|
|
|
|
_music.volume[i] = _sfx.volume[i] = 127;
|
|
|
|
if (_driver)
|
2008-07-14 22:10:04 +00:00
|
|
|
_driver->send(((_musicVolume >> 1) << 16) | 0x7B0 | i);
|
2003-08-11 05:25:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-27 22:29:39 +01:00
|
|
|
void MidiPlayer::loadMusic(Common::SeekableReadStream *in, int32 size, bool sfx) {
|
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
|
|
|
MidiParser *parser = sfx ? _parserSfx : _parserMusic;
|
|
|
|
|
|
|
|
if (size < 0) {
|
|
|
|
// Use the parser to determine the size of the MIDI data.
|
|
|
|
int64 startPos = in->pos();
|
|
|
|
size = parser->determineDataSize(in);
|
|
|
|
if (size < 0) {
|
|
|
|
warning("MidiPlayer::loadMusic - Could not determine size of music data");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// determineDataSize might move the stream position, so return it to
|
|
|
|
// the original position.
|
|
|
|
in->seek(startPos, SEEK_SET);
|
|
|
|
}
|
|
|
|
|
|
|
|
parser->unloadMusic();
|
|
|
|
|
|
|
|
// Copy the data into _musicData or _sfxData.
|
|
|
|
byte **dataPtr = sfx ? &_sfxData : &_musicData;
|
|
|
|
if (*dataPtr) {
|
|
|
|
delete[] *dataPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dataPtr = new byte[size];
|
|
|
|
in->read(*dataPtr, size);
|
|
|
|
|
|
|
|
// Finally, load the data into the parser.
|
|
|
|
parser->loadMusic(*dataPtr, size);
|
|
|
|
}
|
|
|
|
|
2022-02-15 22:31:26 +01:00
|
|
|
void MidiPlayer::play(int track, bool sfx, bool sfxUsesRhythm, bool queued) {
|
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
2022-01-27 22:29:39 +01:00
|
|
|
MidiParser *parser = sfx ? _parserSfx : _parserMusic;
|
|
|
|
|
|
|
|
if (parser->setTrack(track)) {
|
|
|
|
if (sfx && sfxUsesRhythm) {
|
|
|
|
// This sound effect uses OPL rhythm instruments. Disable music
|
|
|
|
// rhythm notes while this sound effect is playing to prevent
|
|
|
|
// conflicts.
|
|
|
|
// Note that if AdLib music is used, _driverMsMusic and
|
|
|
|
// _driverMsSfx point to the same object. If AdLib music is not
|
|
|
|
// used, the disableMusicRhythmNotes call will do nothing.
|
|
|
|
MidiDriver_Simon1_AdLib *adLibSfxDriver = dynamic_cast<MidiDriver_Simon1_AdLib *>(_driverMsSfx);
|
|
|
|
if (adLibSfxDriver)
|
|
|
|
adLibSfxDriver->disableMusicRhythmNotes();
|
|
|
|
}
|
|
|
|
|
2022-02-15 22:31:26 +01:00
|
|
|
if (!sfx && !queued && _driverMsMusic)
|
|
|
|
// Reset the volume to neutral (in case the previous track was
|
|
|
|
// faded out).
|
|
|
|
_driverMsMusic->resetSourceVolume(0);
|
2022-01-27 22:29:39 +01:00
|
|
|
parser->startPlaying();
|
|
|
|
} else {
|
2022-02-15 22:31:26 +01:00
|
|
|
// Original interpreter stops playing when an invalid track is
|
|
|
|
// requested (f.e. Simon 2 MT-32 intro).
|
|
|
|
parser->stopPlaying();
|
2022-01-27 22:29:39 +01:00
|
|
|
warning("MidiPlayer::play - Could not play %s track %i", sfx ? "SFX" : "music", track);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Remove dead code
|
|
|
|
|
2006-10-08 00:21:40 +00:00
|
|
|
static const int simon1_gmf_size[] = {
|
2003-05-19 05:00:13 +00:00
|
|
|
8900, 12166, 2848, 3442, 4034, 4508, 7064, 9730, 6014, 4742, 3138,
|
|
|
|
6570, 5384, 8909, 6457, 16321, 2742, 8968, 4804, 8442, 7717,
|
|
|
|
9444, 5800, 1381, 5660, 6684, 2456, 4744, 2455, 1177, 1232,
|
|
|
|
17256, 5103, 8794, 4884, 16
|
|
|
|
};
|
|
|
|
|
2021-01-12 17:52:14 +01:00
|
|
|
void MidiPlayer::loadSMF(Common::SeekableReadStream *in, int song, bool sfx) {
|
2004-09-04 00:04:36 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
2003-05-24 01:26:05 +00:00
|
|
|
MusicInfo *p = sfx ? &_sfx : &_music;
|
2006-05-12 08:49:04 +00:00
|
|
|
clearConstructs(*p);
|
2003-05-20 16:50:16 +00:00
|
|
|
|
2003-07-24 04:19:42 +00:00
|
|
|
uint32 startpos = in->pos();
|
|
|
|
byte header[4];
|
2003-09-24 06:33:59 +00:00
|
|
|
in->read(header, 4);
|
2006-05-12 08:49:04 +00:00
|
|
|
bool isGMF = !memcmp(header, "GMF\x1", 4);
|
2003-09-24 06:33:59 +00:00
|
|
|
in->seek(startpos, SEEK_SET);
|
2003-07-24 04:19:42 +00:00
|
|
|
|
2003-05-20 17:23:15 +00:00
|
|
|
uint32 size = in->size() - in->pos();
|
2003-07-24 04:19:42 +00:00
|
|
|
if (isGMF) {
|
|
|
|
if (sfx) {
|
|
|
|
// Multiple GMF resources are stored in the SFX files,
|
|
|
|
// but each one is referenced by a pointer at the
|
|
|
|
// beginning of the file. Those pointers can be used
|
|
|
|
// to determine file size.
|
2003-09-24 06:33:59 +00:00
|
|
|
in->seek(0, SEEK_SET);
|
2003-07-24 04:19:42 +00:00
|
|
|
uint16 value = in->readUint16LE() >> 2; // Number of resources
|
|
|
|
if (song != value - 1) {
|
2003-09-24 06:33:59 +00:00
|
|
|
in->seek(song * 2 + 2, SEEK_SET);
|
2003-07-24 04:19:42 +00:00
|
|
|
value = in->readUint16LE();
|
|
|
|
size = value - startpos;
|
|
|
|
}
|
2003-09-24 06:33:59 +00:00
|
|
|
in->seek(startpos, SEEK_SET);
|
2003-07-24 04:19:42 +00:00
|
|
|
} else if (size >= 64000) {
|
|
|
|
// For GMF resources not in separate
|
|
|
|
// files, we're going to have to use
|
|
|
|
// hardcoded size tables.
|
2003-09-24 06:33:59 +00:00
|
|
|
size = simon1_gmf_size[song];
|
2003-07-24 04:19:42 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-20 17:23:15 +00:00
|
|
|
|
|
|
|
// When allocating space, add 4 bytes in case
|
|
|
|
// this is a GMF and we have to tack on our own
|
|
|
|
// End of Track event.
|
2006-05-12 08:49:04 +00:00
|
|
|
p->data = (byte *)calloc(size + 4, 1);
|
2003-09-24 06:33:59 +00:00
|
|
|
in->read(p->data, size);
|
2003-05-18 23:55:53 +00:00
|
|
|
|
2006-06-03 16:55:17 +00:00
|
|
|
uint32 timerRate = _driver->getBaseTempo();
|
|
|
|
|
2014-08-18 13:45:20 +02:00
|
|
|
if (isGMF) {
|
2006-06-01 12:23:08 +00:00
|
|
|
// The GMF header
|
2003-05-24 03:55:37 +00:00
|
|
|
// 3 BYTES: 'GMF'
|
2006-06-01 12:23:08 +00:00
|
|
|
// 1 BYTE : Major version
|
|
|
|
// 1 BYTE : Minor version
|
|
|
|
// 1 BYTE : Ticks (Ranges from 2 - 8, always 2 for SFX)
|
2015-07-24 20:34:52 +10:00
|
|
|
// 1 BYTE : Loop control. 0 = no loop, 1 = loop (Music only)
|
|
|
|
if (!sfx) {
|
|
|
|
// In the original, the ticks value indicated how many
|
|
|
|
// times the music timer was called before it actually
|
|
|
|
// did something. The larger the value the slower the
|
|
|
|
// music.
|
|
|
|
//
|
|
|
|
// We, on the other hand, have a timer rate which is
|
|
|
|
// used to control by how much the music advances on
|
|
|
|
// each onTimer() call. The larger the value, the
|
|
|
|
// faster the music.
|
|
|
|
//
|
|
|
|
// It seems that 4 corresponds to our base tempo, so
|
|
|
|
// this should be the right way to calculate it.
|
|
|
|
timerRate = (4 * _driver->getBaseTempo()) / p->data[5];
|
|
|
|
|
2021-02-28 01:28:23 -08:00
|
|
|
// According to bug #1706 calling setLoop() from
|
2015-07-24 20:34:52 +10:00
|
|
|
// within a lock causes a lockup, though I have no
|
|
|
|
// idea when this actually happens.
|
|
|
|
_loopTrack = (p->data[6] != 0);
|
|
|
|
}
|
2003-05-24 03:10:14 +00:00
|
|
|
}
|
2003-05-19 05:00:13 +00:00
|
|
|
|
2003-05-18 23:55:53 +00:00
|
|
|
MidiParser *parser = MidiParser::createParser_SMF();
|
2003-09-24 06:33:59 +00:00
|
|
|
parser->property(MidiParser::mpMalformedPitchBends, 1);
|
|
|
|
parser->setMidiDriver(this);
|
2006-06-03 16:55:17 +00:00
|
|
|
parser->setTimerRate(timerRate);
|
2003-09-24 06:33:59 +00:00
|
|
|
if (!parser->loadMusic(p->data, size)) {
|
2010-11-01 21:37:47 +00:00
|
|
|
warning("Error reading track");
|
2003-05-18 23:55:53 +00:00
|
|
|
delete parser;
|
2021-11-13 23:40:15 +02:00
|
|
|
parser = nullptr;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-05-24 01:26:05 +00:00
|
|
|
if (!sfx) {
|
|
|
|
_currentTrack = 255;
|
2003-08-11 05:25:33 +00:00
|
|
|
resetVolumeTable();
|
2003-05-24 01:26:05 +00:00
|
|
|
}
|
|
|
|
p->parser = parser; // That plugs the power cord into the wall
|
2002-04-13 10:41:27 +00:00
|
|
|
}
|
|
|
|
|
2021-01-12 17:52:14 +01:00
|
|
|
void MidiPlayer::loadMultipleSMF(Common::SeekableReadStream *in, bool sfx) {
|
2003-05-18 23:55:53 +00:00
|
|
|
// This is a special case for Simon 2 Windows.
|
|
|
|
// Instead of having multiple sequences as
|
|
|
|
// separate tracks in a Type 2 file, simon2win
|
|
|
|
// has multiple songs, each of which is a Type 1
|
|
|
|
// file. Thus, preceding the songs is a single
|
|
|
|
// byte specifying how many songs are coming.
|
|
|
|
// We need to load ALL the songs and then
|
|
|
|
// treat them as separate tracks -- for the
|
|
|
|
// purpose of jumps, anyway.
|
2004-09-04 00:04:36 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
2003-05-24 01:26:05 +00:00
|
|
|
MusicInfo *p = sfx ? &_sfx : &_music;
|
2003-09-24 06:33:59 +00:00
|
|
|
clearConstructs(*p);
|
2003-05-24 01:26:05 +00:00
|
|
|
|
|
|
|
p->num_songs = in->readByte();
|
|
|
|
if (p->num_songs > 16) {
|
2010-11-01 21:37:47 +00:00
|
|
|
warning("playMultipleSMF: %d is too many songs to keep track of", (int)p->num_songs);
|
2002-11-18 09:08:45 +00:00
|
|
|
return;
|
2003-05-18 23:55:53 +00:00
|
|
|
}
|
2002-11-18 09:08:45 +00:00
|
|
|
|
2003-05-18 23:55:53 +00:00
|
|
|
byte i;
|
2003-05-24 01:26:05 +00:00
|
|
|
for (i = 0; i < p->num_songs; ++i) {
|
2003-05-18 23:55:53 +00:00
|
|
|
byte buf[5];
|
|
|
|
uint32 pos = in->pos();
|
|
|
|
|
|
|
|
// Make sure there's a MThd
|
2003-09-24 06:33:59 +00:00
|
|
|
in->read(buf, 4);
|
2011-11-02 22:55:58 +00:00
|
|
|
if (memcmp(buf, "MThd", 4) != 0) {
|
2010-11-01 21:37:47 +00:00
|
|
|
warning("Expected MThd but found '%c%c%c%c' instead", buf[0], buf[1], buf[2], buf[3]);
|
2003-05-18 23:55:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-07-11 16:51:10 +00:00
|
|
|
in->seek(in->readUint32BE(), SEEK_CUR);
|
2003-05-18 23:55:53 +00:00
|
|
|
|
|
|
|
// Now skip all the MTrk blocks
|
|
|
|
while (true) {
|
2006-05-12 08:49:04 +00:00
|
|
|
in->read(buf, 4);
|
2011-11-02 22:55:58 +00:00
|
|
|
if (memcmp(buf, "MTrk", 4) != 0)
|
2003-05-18 23:55:53 +00:00
|
|
|
break;
|
2006-07-11 16:51:10 +00:00
|
|
|
in->seek(in->readUint32BE(), SEEK_CUR);
|
2003-05-18 23:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32 pos2 = in->pos() - 4;
|
|
|
|
uint32 size = pos2 - pos;
|
2006-05-12 08:49:04 +00:00
|
|
|
p->songs[i] = (byte *)calloc(size, 1);
|
2003-09-24 06:33:59 +00:00
|
|
|
in->seek(pos, SEEK_SET);
|
|
|
|
in->read(p->songs[i], size);
|
2003-05-24 01:26:05 +00:00
|
|
|
p->song_sizes[i] = size;
|
2002-11-18 09:08:45 +00:00
|
|
|
}
|
2002-11-17 17:15:29 +00:00
|
|
|
|
2003-05-24 01:26:05 +00:00
|
|
|
if (!sfx) {
|
|
|
|
_currentTrack = 255;
|
2003-08-11 05:25:33 +00:00
|
|
|
resetVolumeTable();
|
2003-05-24 01:26:05 +00:00
|
|
|
}
|
2002-11-17 17:15:29 +00:00
|
|
|
}
|
|
|
|
|
2021-01-12 17:52:14 +01:00
|
|
|
void MidiPlayer::loadXMIDI(Common::SeekableReadStream *in, bool sfx) {
|
2004-09-04 00:04:36 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
2003-05-24 01:26:05 +00:00
|
|
|
MusicInfo *p = sfx ? &_sfx : &_music;
|
2003-09-24 06:33:59 +00:00
|
|
|
clearConstructs(*p);
|
2003-05-18 23:55:53 +00:00
|
|
|
|
|
|
|
char buf[4];
|
|
|
|
uint32 pos = in->pos();
|
|
|
|
uint32 size = 4;
|
2003-09-24 06:33:59 +00:00
|
|
|
in->read(buf, 4);
|
|
|
|
if (!memcmp(buf, "FORM", 4)) {
|
2003-05-20 16:42:25 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < 16; ++i) {
|
2003-09-24 06:33:59 +00:00
|
|
|
if (!memcmp(buf, "CAT ", 4))
|
2003-05-20 16:42:25 +00:00
|
|
|
break;
|
|
|
|
size += 2;
|
2003-09-24 06:33:59 +00:00
|
|
|
memcpy(buf, &buf[2], 2);
|
|
|
|
in->read(&buf[2], 2);
|
2003-05-20 16:42:25 +00:00
|
|
|
}
|
2011-11-02 22:55:58 +00:00
|
|
|
if (memcmp(buf, "CAT ", 4) != 0) {
|
2006-08-27 05:02:48 +00:00
|
|
|
error("Could not find 'CAT ' tag to determine resource size");
|
2003-05-20 16:42:25 +00:00
|
|
|
}
|
2003-05-18 23:55:53 +00:00
|
|
|
size += 4 + in->readUint32BE();
|
2003-09-24 06:33:59 +00:00
|
|
|
in->seek(pos, 0);
|
2006-05-12 08:49:04 +00:00
|
|
|
p->data = (byte *)calloc(size, 1);
|
2003-09-24 06:33:59 +00:00
|
|
|
in->read(p->data, size);
|
2003-05-18 23:55:53 +00:00
|
|
|
} else {
|
2006-08-27 05:02:48 +00:00
|
|
|
error("Expected 'FORM' tag but found '%c%c%c%c' instead", buf[0], buf[1], buf[2], buf[3]);
|
2003-05-18 23:55:53 +00:00
|
|
|
}
|
2002-11-18 09:08:45 +00:00
|
|
|
|
2008-08-10 17:59:42 +00:00
|
|
|
// In the DOS version of Simon the Sorcerer 2, the music contains lots
|
|
|
|
// of XMIDI callback controller events. As far as we know, they aren't
|
|
|
|
// actually used, so we disable the callback handler explicitly.
|
|
|
|
|
2021-11-13 23:40:15 +02:00
|
|
|
MidiParser *parser = MidiParser::createParser_XMIDI(nullptr);
|
2003-09-24 06:33:59 +00:00
|
|
|
parser->setMidiDriver(this);
|
|
|
|
parser->setTimerRate(_driver->getBaseTempo());
|
2006-08-27 05:02:48 +00:00
|
|
|
if (!parser->loadMusic(p->data, size))
|
|
|
|
error("Error reading track");
|
2002-04-13 10:41:27 +00:00
|
|
|
|
2003-05-24 01:26:05 +00:00
|
|
|
if (!sfx) {
|
|
|
|
_currentTrack = 255;
|
2003-08-11 05:25:33 +00:00
|
|
|
resetVolumeTable();
|
2003-05-24 01:26:05 +00:00
|
|
|
}
|
|
|
|
p->parser = parser; // That plugs the power cord into the wall
|
2002-04-13 18:34:11 +00:00
|
|
|
}
|
2003-05-25 03:19:21 +00:00
|
|
|
|
2021-01-12 17:52:14 +01:00
|
|
|
void MidiPlayer::loadS1D(Common::SeekableReadStream *in, bool sfx) {
|
2004-09-04 00:04:36 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
2003-05-25 03:19:21 +00:00
|
|
|
MusicInfo *p = sfx ? &_sfx : &_music;
|
2003-09-24 06:33:59 +00:00
|
|
|
clearConstructs(*p);
|
2003-05-25 03:19:21 +00:00
|
|
|
|
2003-05-25 21:32:11 +00:00
|
|
|
uint16 size = in->readUint16LE();
|
2003-05-25 03:19:21 +00:00
|
|
|
if (size != in->size() - 2) {
|
2006-10-15 05:59:22 +00:00
|
|
|
error("Size mismatch in MUS file (%ld versus reported %d)", (long)in->size() - 2, (int)size);
|
2003-05-25 03:19:21 +00:00
|
|
|
}
|
|
|
|
|
2006-05-12 08:49:04 +00:00
|
|
|
p->data = (byte *)calloc(size, 1);
|
2003-09-24 06:33:59 +00:00
|
|
|
in->read(p->data, size);
|
2003-05-25 03:19:21 +00:00
|
|
|
|
|
|
|
MidiParser *parser = MidiParser_createS1D();
|
2003-09-24 06:33:59 +00:00
|
|
|
parser->setMidiDriver(this);
|
|
|
|
parser->setTimerRate(_driver->getBaseTempo());
|
2006-08-27 05:02:48 +00:00
|
|
|
if (!parser->loadMusic(p->data, size))
|
|
|
|
error("Error reading track");
|
2003-05-25 03:19:21 +00:00
|
|
|
|
|
|
|
if (!sfx) {
|
|
|
|
_currentTrack = 255;
|
2003-08-11 05:25:33 +00:00
|
|
|
resetVolumeTable();
|
2003-05-25 03:19:21 +00:00
|
|
|
}
|
|
|
|
p->parser = parser; // That plugs the power cord into the wall
|
|
|
|
}
|
2003-10-03 19:42:27 +00:00
|
|
|
|
2015-07-03 21:02:13 +02:00
|
|
|
#define MIDI_SETUP_BUNDLE_HEADER_SIZE 56
|
|
|
|
#define MIDI_SETUP_BUNDLE_FILEHEADER_SIZE 48
|
|
|
|
#define MIDI_SETUP_BUNDLE_FILENAME_MAX_SIZE 12
|
|
|
|
|
2015-07-04 01:50:07 +02:00
|
|
|
// PKWARE data compression library (called "DCL" in ScummVM) was used for storing files within SETUP.SHR
|
2015-07-03 21:02:13 +02:00
|
|
|
// we need it to be able to get the file MIDPAK.AD, otherwise we would have to require the user
|
|
|
|
// to "install" the game before being able to actually play it, when using AdLib.
|
|
|
|
//
|
|
|
|
// SETUP.SHR file format:
|
|
|
|
// [bundle file header]
|
|
|
|
// [compressed file header] [compressed file data]
|
|
|
|
// * compressed file count
|
2015-07-04 12:55:49 +02:00
|
|
|
Common::SeekableReadStream *MidiPlayer::simon2SetupExtractFile(const Common::String &requestedFileName) {
|
2015-07-03 21:02:13 +02:00
|
|
|
Common::File *setupBundleStream = new Common::File();
|
|
|
|
uint32 bundleSize = 0;
|
|
|
|
uint32 bundleBytesLeft = 0;
|
|
|
|
byte bundleHeader[MIDI_SETUP_BUNDLE_HEADER_SIZE];
|
|
|
|
byte bundleFileHeader[MIDI_SETUP_BUNDLE_FILEHEADER_SIZE];
|
|
|
|
uint16 bundleFileCount = 0;
|
|
|
|
uint16 bundleFileNr = 0;
|
|
|
|
|
|
|
|
Common::String fileName;
|
|
|
|
uint32 fileCompressedSize = 0;
|
|
|
|
byte *fileCompressedDataPtr = nullptr;
|
|
|
|
|
2015-07-04 12:55:49 +02:00
|
|
|
Common::SeekableReadStream *extractedStream = nullptr;
|
2015-07-03 21:02:13 +02:00
|
|
|
|
|
|
|
if (!setupBundleStream->open("setup.shr"))
|
|
|
|
error("MidiPlayer: could not open setup.shr");
|
|
|
|
|
|
|
|
bundleSize = setupBundleStream->size();
|
|
|
|
bundleBytesLeft = bundleSize;
|
|
|
|
|
|
|
|
if (bundleSize < MIDI_SETUP_BUNDLE_HEADER_SIZE)
|
|
|
|
error("MidiPlayer: unexpected EOF in setup.shr");
|
|
|
|
|
|
|
|
if (setupBundleStream->read(bundleHeader, MIDI_SETUP_BUNDLE_HEADER_SIZE) != MIDI_SETUP_BUNDLE_HEADER_SIZE)
|
|
|
|
error("MidiPlayer: setup.shr read error");
|
|
|
|
bundleBytesLeft -= MIDI_SETUP_BUNDLE_HEADER_SIZE;
|
|
|
|
|
|
|
|
// Verify header byte
|
|
|
|
if (bundleHeader[13] != 't')
|
|
|
|
error("MidiPlayer: setup.shr bundle header data mismatch");
|
|
|
|
|
|
|
|
bundleFileCount = READ_LE_UINT16(&bundleHeader[14]);
|
|
|
|
|
|
|
|
// Search for requested file
|
|
|
|
while (bundleFileNr < bundleFileCount) {
|
|
|
|
if (bundleBytesLeft < sizeof(bundleFileHeader))
|
|
|
|
error("MidiPlayer: unexpected EOF in setup.shr");
|
|
|
|
|
|
|
|
if (setupBundleStream->read(bundleFileHeader, sizeof(bundleFileHeader)) != sizeof(bundleFileHeader))
|
|
|
|
error("MidiPlayer: setup.shr read error");
|
|
|
|
bundleBytesLeft -= MIDI_SETUP_BUNDLE_FILEHEADER_SIZE;
|
|
|
|
|
|
|
|
// Extract filename from file-header
|
|
|
|
fileName.clear();
|
|
|
|
for (byte curPos = 0; curPos < MIDI_SETUP_BUNDLE_FILENAME_MAX_SIZE; curPos++) {
|
|
|
|
if (!bundleFileHeader[curPos]) // terminating NUL
|
|
|
|
break;
|
|
|
|
fileName.insertChar(bundleFileHeader[curPos], curPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get compressed
|
|
|
|
fileCompressedSize = READ_LE_UINT32(&bundleFileHeader[20]);
|
|
|
|
if (!fileCompressedSize)
|
|
|
|
error("MidiPlayer: compressed file is 0 bytes, data corruption?");
|
|
|
|
if (bundleBytesLeft < fileCompressedSize)
|
|
|
|
error("MidiPlayer: unexpected EOF in setup.shr");
|
|
|
|
|
|
|
|
if (fileName == requestedFileName) {
|
|
|
|
// requested file found
|
|
|
|
fileCompressedDataPtr = new byte[fileCompressedSize];
|
2015-07-04 01:50:07 +02:00
|
|
|
|
2015-07-03 21:02:13 +02:00
|
|
|
if (setupBundleStream->read(fileCompressedDataPtr, fileCompressedSize) != fileCompressedSize)
|
|
|
|
error("MidiPlayer: setup.shr read error");
|
|
|
|
|
2015-07-04 01:50:07 +02:00
|
|
|
Common::MemoryReadStream *compressedStream = nullptr;
|
|
|
|
|
|
|
|
compressedStream = new Common::MemoryReadStream(fileCompressedDataPtr, fileCompressedSize);
|
|
|
|
// we don't know the unpacked size, let decompressor figure it out
|
|
|
|
extractedStream = Common::decompressDCL(compressedStream);
|
|
|
|
delete compressedStream;
|
2015-07-03 21:02:13 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip compressed size
|
|
|
|
setupBundleStream->skip(fileCompressedSize);
|
|
|
|
bundleBytesLeft -= fileCompressedSize;
|
|
|
|
|
|
|
|
bundleFileNr++;
|
|
|
|
}
|
|
|
|
setupBundleStream->close();
|
|
|
|
delete setupBundleStream;
|
|
|
|
|
2015-07-04 12:55:49 +02:00
|
|
|
return extractedStream;
|
2015-07-03 21:02:13 +02:00
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
} // End of namespace AGOS
|