[Scummvm-cvs-logs] SF.net SVN: scummvm:[52009] scummvm/branches/gsoc2010-testbed
sud03r at users.sourceforge.net
sud03r at users.sourceforge.net
Wed Aug 11 23:52:28 CEST 2010
Revision: 52009
http://scummvm.svn.sourceforge.net/scummvm/?rev=52009&view=rev
Author: sud03r
Date: 2010-08-11 21:52:28 +0000 (Wed, 11 Aug 2010)
Log Message:
-----------
TESTBED: enable playing MIDI through testbed
Modified Paths:
--------------
scummvm/branches/gsoc2010-testbed/engines/testbed/midi.cpp
scummvm/branches/gsoc2010-testbed/engines/testbed/midi.h
Added Paths:
-----------
scummvm/branches/gsoc2010-testbed/dists/engine-data/testbed-audiocd-files/music.mid
Added: scummvm/branches/gsoc2010-testbed/dists/engine-data/testbed-audiocd-files/music.mid
===================================================================
(Binary files differ)
Property changes on: scummvm/branches/gsoc2010-testbed/dists/engine-data/testbed-audiocd-files/music.mid
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/midi.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/midi.cpp 2010-08-11 21:51:34 UTC (rev 52008)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/midi.cpp 2010-08-11 21:52:28 UTC (rev 52009)
@@ -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;
}
Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/midi.h
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/midi.h 2010-08-11 21:51:34 UTC (rev 52008)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/midi.h 2010-08-11 21:52:28 UTC (rev 52009)
@@ -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 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
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list