diff options
author | Neeraj Kumar | 2010-08-11 21:52:28 +0000 |
---|---|---|
committer | Neeraj Kumar | 2010-08-11 21:52:28 +0000 |
commit | f6a1cb991fef5de697d97af1418e719592fbcee6 (patch) | |
tree | 5a2d94486f798ddf73aca4fdab458c3b622db625 /engines/testbed | |
parent | 32553308cffd5d2f936f6143e89db703afeb0036 (diff) | |
download | scummvm-rg350-f6a1cb991fef5de697d97af1418e719592fbcee6.tar.gz scummvm-rg350-f6a1cb991fef5de697d97af1418e719592fbcee6.tar.bz2 scummvm-rg350-f6a1cb991fef5de697d97af1418e719592fbcee6.zip |
TESTBED: enable playing MIDI through testbed
svn-id: r52009
Diffstat (limited to 'engines/testbed')
-rw-r--r-- | engines/testbed/midi.cpp | 98 | ||||
-rw-r--r-- | engines/testbed/midi.h | 4 |
2 files changed, 97 insertions, 5 deletions
diff --git a/engines/testbed/midi.cpp b/engines/testbed/midi.cpp index bdc1314804..57ac1a64d2 100644 --- a/engines/testbed/midi.cpp +++ b/engines/testbed/midi.cpp @@ -22,29 +22,117 @@ * $Id$ */ +#include "common/archive.h" +#include "common/events.h" + +#include "graphics/cursorman.h" + #include "sound/mididrv.h" -#include "sound/midiparser.h" + #include "testbed/midi.h" +#include "testbed/testbed.h" namespace Testbed { +bool MidiTests::loadMusicInMemory(Common::MemoryWriteStreamDynamic *ws) { + Common::SeekableReadStream *midiFile = SearchMan.createReadStreamForMember("music.mid"); + if (!midiFile) { + Testsuite::logPrintf("Error! Can't open Midi music file, check game data directory for file music.mid\n"); + return false; + } + + while (!midiFile->eos()) { + byte data = midiFile->readByte(); + ws->writeByte(data); + } + return true; +} + +void MidiTests::waitForMusicToPlay(MidiParser *parser) { + Common::EventManager *eventMan = g_system->getEventManager(); + bool quitLoop = false; + Common::Event event; + + CursorMan.showMouse(true); + while (!quitLoop) { + while (eventMan->pollEvent(event)) { + // Quit if explicitly requested! + if (Engine::shouldQuit()) { + return; + } + + if (event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_RBUTTONDOWN) { + quitLoop = true; + } else { + Testsuite::writeOnScreen("Playing Midi Music, Click to end", Common::Point(0, 100)); + if (!parser->isPlaying()) { + quitLoop = true; + } + } + } + } + CursorMan.showMouse(false); + return; +} + TestExitStatus MidiTests::playMidiMusic() { + Testsuite::clearScreen(); + Common::String info = "Testing Midi Sound output.\n" + "Here, We generate some Music by using the Midi Driver selected in the GUI.\n" + "You should expect to hear that. The initialization may take some time.\n"; + + if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) { + Testsuite::logPrintf("Info! Skipping test : Play Midi Music\n"); + return kTestSkipped; + } + MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB); // Create a driver instance MidiDriver *driver = MidiDriver::createMidi(dev); // Create a SMF parser MidiParser *smfParser = MidiParser::createParser_SMF(); - smfParser->setMidiDriver(driver); - smfParser->setTimerRate(driver->getBaseTempo()); // Open the driver int errCode = driver->open(); if (errCode) { - Testsuite::logPrintf("Error! %s", driver->getErrorName(errCode)); + Common::String errMsg = driver->getErrorName(errCode); + Testsuite::writeOnScreen(errMsg, Common::Point(0, 100)); + Testsuite::logPrintf("Error! %s", errMsg.c_str()); return kTestFailed; } - Testsuite::logDetailedPrintf("Midi: Succesfully opened the driver\n"); + Testsuite::logDetailedPrintf("Info! Midi: Succesfully opened the driver\n"); + + Common::MemoryWriteStreamDynamic ws(DisposeAfterUse::YES); + loadMusicInMemory(&ws); + + // start playing + if (smfParser->loadMusic(ws.getData(), ws.size())) { + smfParser->setTrack(0); + smfParser->setMidiDriver(driver); + smfParser->setTimerRate(driver->getBaseTempo()); + driver->setTimerCallback(smfParser, MidiParser::timerCallback); + Testsuite::logDetailedPrintf("Info! Midi: Parser Successfully loaded Music data.\n"); + if (smfParser->isPlaying()) { + Testsuite::writeOnScreen("Playing Midi Music, Click to end.", Common::Point(0, 100)); + Testsuite::logDetailedPrintf("Info! Midi: Playing music!\n"); + } + } + + + // Play until track ends or an exit is requested. + waitForMusicToPlay(smfParser); + + // Done. Clean up. + smfParser->unloadMusic(); + driver->setTimerCallback(NULL, NULL); + driver->close(); + delete smfParser; + + if (Testsuite::handleInteractiveInput("Were you able to hear the music as described?", "Yes", "No", kOptionRight)) { + Testsuite::logDetailedPrintf("Error! Midi: Can't play Music\n"); + return kTestFailed; + } return kTestPassed; } diff --git a/engines/testbed/midi.h b/engines/testbed/midi.h index 2443a5e0e0..838d98ca1f 100644 --- a/engines/testbed/midi.h +++ b/engines/testbed/midi.h @@ -25,6 +25,8 @@ #ifndef TESTBED_MIDI_H #define TESTBED_MIDI_H +#include "common/stream.h" +#include "sound/midiparser.h" #include "testbed/testsuite.h" // This file can be used as template for header files of other newer testsuites. @@ -34,6 +36,8 @@ namespace Testbed { namespace MidiTests { // Helper functions for MIDI tests +bool loadMusicInMemory(Common::MemoryWriteStreamDynamic *ws); +void waitForMusicToPlay(MidiParser *parser); // will contain function declarations for MIDI tests // add more here |