diff --git a/engines/bagel/bagel.cpp b/engines/bagel/bagel.cpp index df1260c3a04..9bf387ab719 100644 --- a/engines/bagel/bagel.cpp +++ b/engines/bagel/bagel.cpp @@ -26,6 +26,7 @@ #include "graphics/palette.h" #include "bagel/bagel.h" #include "bagel/detection.h" +#include "bagel/music.h" #include "bagel/baglib/bagel.h" #include "bagel/baglib/character_object.h" @@ -93,6 +94,7 @@ BagelEngine::BagelEngine(OSystem *syst, const ADGameDescription *gameDesc) : Eng } BagelEngine::~BagelEngine() { + delete _midi; delete _screen; } diff --git a/engines/bagel/bagel.h b/engines/bagel/bagel.h index 1d070859916..9b1eff8c021 100644 --- a/engines/bagel/bagel.h +++ b/engines/bagel/bagel.h @@ -35,6 +35,7 @@ #include "graphics/screen.h" #include "bagel/detection.h" +#include "bagel/music.h" #include "bagel/baglib/master_win.h" #include "bagel/boflib/stdinc.h" #include "bagel/boflib/bit_buf.h" @@ -55,6 +56,7 @@ protected: public: Graphics::Screen *_screen = nullptr; + MusicPlayer *_midi = nullptr; bool _useOriginalSaveLoad = false; ZIPGLOBAL _zg; diff --git a/engines/bagel/boflib/sound.cpp b/engines/bagel/boflib/sound.cpp index 6773d950e55..cd9d77555d1 100644 --- a/engines/bagel/boflib/sound.cpp +++ b/engines/bagel/boflib/sound.cpp @@ -119,6 +119,12 @@ CBofSound::CBofSound(CBofWindow *pWnd, const CHAR *pszPathName, WORD wFlags, con m_wFlags |= SOUND_ASYNCH; } + if (m_wFlags & SOUND_MIDI) { + m_chType = SOUND_TYPE_XM; + } else { + m_chType = SOUND_TYPE_WAV; + } + if (pszPathName != nullptr) { if ((m_szDrivePath[0] != '\0') && (*pszPathName == '.')) @@ -210,6 +216,8 @@ VOID CBofSound::SetVolume(INT nVolume) { m_nVol = nLocalVolume; g_system->getMixer()->setChannelVolume(m_handle, VOLUME_SVM(m_nVol)); + + // TODO: MIDI volume } @@ -299,29 +307,13 @@ BOOL CBofSound::Play(DWORD dwBeginHere, DWORD TimeFormatFlag) { } if (m_wFlags & SOUND_MIDI) { -#if 0 - HMDIDRIVER hMidiDriver; - if ((hMidiDriver = CBofApp::GetApp()->GetMidiDriver()) != nullptr) { - - if ((m_hSequence = AIL_allocate_sequence_handle(hMidiDriver)) != nullptr) { - INT nError; - - nError = AIL_init_sequence(m_hSequence, m_pFileBuf, 0); - AIL_set_sequence_volume(m_hSequence, m_nVol * 10, 0); - AIL_set_sequence_loop_count(m_hSequence, m_wLoops); - AIL_start_sequence(m_hSequence); - m_bPlaying = TRUE; - - } else { - ReportError(ERR_UNKNOWN, "Could not allocate an HSEQUENCE. (%s)", AIL_last_error()); - } - } -#endif + g_engine->_midi->play(this); + m_bPlaying = TRUE; } else if (m_wFlags & SOUND_WAVE) { - PlayMSS(); + PlayWAV(); if (m_bPlaying) { @@ -339,7 +331,7 @@ BOOL CBofSound::Play(DWORD dwBeginHere, DWORD TimeFormatFlag) { if (!(m_wFlags & SOUND_QUEUE)) { - PlayMSS(); + PlayWAV(); } else { Assert(m_iQSlot >= 0 && m_iQSlot < NUM_QUEUES); @@ -406,9 +398,12 @@ BOOL CBofSound::Pause() { // must be playing to be paused and not already paused // if (Playing() && (m_bPaused == FALSE)) { - - g_system->getMixer()->pauseHandle(m_handle, true); - + bSuccess = TRUE; + if (m_wFlags & SOUND_MIDI) { + g_engine->_midi->pause(); + } else { + g_system->getMixer()->pauseHandle(m_handle, true); + } } if (bSuccess) @@ -445,9 +440,12 @@ BOOL CBofSound::Resume() { BOOL bSuccess = FALSE; if (m_bPaused) { // must be paused to resume - - g_system->getMixer()->pauseHandle(m_handle, false); - + bSuccess = TRUE; + if (m_wFlags & SOUND_MIDI) { + g_engine->_midi->resume(); + } else { + g_system->getMixer()->pauseHandle(m_handle, false); + } } @@ -535,8 +533,12 @@ BOOL CBofSound::Stop() { // if this sound is currently playing // - g_system->getMixer()->stopHandle(m_handle); - m_handle = {}; + if (m_wFlags & SOUND_MIDI) { + g_engine->_midi->stop(); + } else { + g_system->getMixer()->stopHandle(m_handle); + m_handle = {}; + } if (m_bInQueue) { Assert(m_iQSlot >= 0 && m_iQSlot < NUM_QUEUES); @@ -994,24 +996,24 @@ VOID CBofSound::AudioTask() { // if ((CBofSound *)m_cQueue[pSound->m_iQSlot].GetQItem() == pSound) { - pSound->PlayMSS(); + pSound->PlayWAV(); } } } } else if (pSound->m_wFlags & SOUND_MIDI) { -#if 0 - if (pSound->m_hSequence != nullptr) { + + if (pSound->m_bPlaying) { // And, Is it done? // - if (AIL_sequence_status(pSound->m_hSequence) != SEQ_PLAYING) { + if (!g_engine->_midi->isPlaying()) { // Kill it pSound->Stop(); } } -#endif + } } @@ -1021,7 +1023,7 @@ VOID CBofSound::AudioTask() { bAlready = FALSE; } -ERROR_CODE CBofSound::PlayMSS() { +ERROR_CODE CBofSound::PlayWAV() { Assert(IsValidObject(this)); if (!ErrorOccurred()) { diff --git a/engines/bagel/boflib/sound.h b/engines/bagel/boflib/sound.h index c2f2b5581c4..f0673371e0e 100644 --- a/engines/bagel/boflib/sound.h +++ b/engines/bagel/boflib/sound.h @@ -73,6 +73,8 @@ namespace Bagel { class CBofSound : public CBofError, public CBofObject, public CLList { public: + friend class MusicPlayer; + CBofSound(CBofWindow *pWnd, const CHAR *pszPathName, WORD wFlags, const INT nLoops = 1); virtual ~CBofSound(); @@ -153,7 +155,7 @@ public: static VOID SetQVol(INT nSlot, INT nVol); - ERROR_CODE PlayMSS(); + ERROR_CODE PlayWAV(); static ERROR_CODE FlushQueue(INT nSlot); diff --git a/engines/bagel/detection.cpp b/engines/bagel/detection.cpp index 28e8f3c725f..726572815e3 100644 --- a/engines/bagel/detection.cpp +++ b/engines/bagel/detection.cpp @@ -40,7 +40,7 @@ const DebugChannelDef BagelMetaEngineDetection::debugFlagList[] = { BagelMetaEngineDetection::BagelMetaEngineDetection() : AdvancedMetaEngineDetection(Bagel::gameDescriptions, sizeof(ADGameDescription), Bagel::bagelGames) { - _guiOptions = GUIO1(GAMEOPTION_ORIGINAL_SAVELOAD); + _guiOptions = GUIO2(GUIO_NOSPEECH, GAMEOPTION_ORIGINAL_SAVELOAD); } REGISTER_PLUGIN_STATIC(BAGEL_DETECTION, PLUGIN_TYPE_ENGINE_DETECTION, BagelMetaEngineDetection); diff --git a/engines/bagel/module.mk b/engines/bagel/module.mk index 5b96b496f7b..905395311b0 100644 --- a/engines/bagel/module.mk +++ b/engines/bagel/module.mk @@ -4,6 +4,7 @@ MODULE_OBJS = \ bagel.o \ console.o \ metaengine.o \ + music.o \ baglib/bagel.o \ baglib/base_pda.o \ baglib/bmp_object.o \ diff --git a/engines/bagel/music.cpp b/engines/bagel/music.cpp new file mode 100644 index 00000000000..60594c00457 --- /dev/null +++ b/engines/bagel/music.cpp @@ -0,0 +1,89 @@ +/* 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. + * + * 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. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "audio/mididrv.h" +#include "audio/midiparser.h" + +#include "bagel/music.h" +#include "bagel/boflib/sound.h" + +namespace Bagel { + +MusicPlayer::MusicPlayer() { + + MidiPlayer::createDriver(); + + int ret = _driver->open(); + if (ret == 0) { + if (_nativeMT32) + _driver->sendMT32Reset(); + else + _driver->sendGMReset(); + + _driver->setTimerCallback(this, &timerCallback); + } +} + +void MusicPlayer::play(CBofSound *sound) { + Common::StackLock lock(_mutex); + + if (_isPlaying && sound == _sound) { + // Already playing + return; + } + + MidiParser *parser = nullptr; + if (sound->m_chType == SOUND_TYPE_XM) { + parser = MidiParser::createParser_XMIDI(); + } else if (sound->m_chType == SOUND_TYPE_QT) { + parser = MidiParser::createParser_QT(); + } else { + warning("Invalid sound %s passed to MusicPlayer", sound->m_szFileName); + return; + } + + if (parser->loadMusic(sound->m_pFileBuf, sound->m_iFileSize)) { + stop(); + parser->setTrack(0); + parser->setMidiDriver(this); + parser->setTimerRate(_driver->getBaseTempo()); + parser->property(MidiParser::mpCenterPitchWheelOnUnload, 1); + + _parser = parser; + + // TODO: Set channel volume + syncVolume(); + + _isLooping = (sound->m_wLoops == 0); + _isPlaying = true; + _sound = sound; + } else { + warning("Failed to play %s", sound->m_szFileName); + delete parser; + } +} + +void MusicPlayer::stop() { + Audio::MidiPlayer::stop(); + _sound = nullptr; +} + +} // End of namespace Bagel diff --git a/engines/bagel/music.h b/engines/bagel/music.h new file mode 100644 index 00000000000..37a612d30e0 --- /dev/null +++ b/engines/bagel/music.h @@ -0,0 +1,43 @@ +/* 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. + * + * 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. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef BAGEL_MUSIC_H +#define BAGEL_MUSIC_H + +#include "audio/midiplayer.h" +#include "bagel/boflib/sound.h" + +namespace Bagel { + +class MusicPlayer : public Audio::MidiPlayer { +private: + CBofSound *_sound = nullptr; + +public: + MusicPlayer(); + + void play(CBofSound *sound); + void stop() override; +}; + +} // End of namespace Bagel + +#endif diff --git a/engines/bagel/spacebar/spacebar.cpp b/engines/bagel/spacebar/spacebar.cpp index 2a8dbf3cd4f..ddeef6cdb73 100644 --- a/engines/bagel/spacebar/spacebar.cpp +++ b/engines/bagel/spacebar/spacebar.cpp @@ -23,6 +23,7 @@ #include "common/config-manager.h" #include "engines/util.h" #include "bagel/console.h" +#include "bagel/music.h" #include "bagel/spacebar/spacebar.h" #include "bagel/spacebar/master_win.h" #include "bagel/spacebar/bib_odds_wnd.h" @@ -223,7 +224,10 @@ Common::Error SpaceBarEngine::run() { Graphics::PixelFormat format(2, 5, 6, 5, 0, 11, 5, 0, 0); initGraphics(640, 480, &format); + // Initialize systems _screen = new Graphics::Screen(); + _midi = new MusicPlayer(); + syncSoundSettings(); // Set the engine's debugger console setDebugger(new Console());