aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMarisa-Chan2014-10-22 11:44:49 +0700
committerMarisa-Chan2014-10-22 11:44:49 +0700
commit4bc319441069101a902ed22f48bec40b7e6c9284 (patch)
treede42fc7cb2530ff8e151a6e7ea141611592e7984 /engines
parent0b3a20f645324696e08745a9e8a3fc75e1700cac (diff)
downloadscummvm-rg350-4bc319441069101a902ed22f48bec40b7e6c9284.tar.gz
scummvm-rg350-4bc319441069101a902ed22f48bec40b7e6c9284.tar.bz2
scummvm-rg350-4bc319441069101a902ed22f48bec40b7e6c9284.zip
ZVISION: Implement simple midi support
Diffstat (limited to 'engines')
-rw-r--r--engines/zvision/core/midi.cpp89
-rw-r--r--engines/zvision/core/midi.h59
-rw-r--r--engines/zvision/module.mk1
-rw-r--r--engines/zvision/zvision.cpp4
-rw-r--r--engines/zvision/zvision.h5
5 files changed, 158 insertions, 0 deletions
diff --git a/engines/zvision/core/midi.cpp b/engines/zvision/core/midi.cpp
new file mode 100644
index 0000000000..5cc8cd0402
--- /dev/null
+++ b/engines/zvision/core/midi.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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "common/scummsys.h"
+
+#include "zvision/core/midi.h"
+
+namespace ZVision {
+
+midiManager::midiManager() {
+ MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB);
+ _driver = MidiDriver::createMidi(dev);
+ _driver->open();
+}
+
+midiManager::~midiManager() {
+ stop();
+ _driver->close();
+ delete _driver;
+}
+
+void midiManager::stop() {
+ for (int8 i = 0; i < 16; i++)
+ if (_playChannels[i].playing)
+ noteOff(i);
+}
+
+void midiManager::noteOn(int8 channel, int8 note, int8 velocity) {
+ assert(channel <= 15);
+
+ _playChannels[channel].playing = true;
+ _playChannels[channel].note = note;
+ _driver->send(channel | (velocity << 16) | (note << 8) | 0x90);
+}
+
+void midiManager::noteOff(int8 channel) {
+ assert(channel <= 15);
+
+ if (_playChannels[channel].playing) {
+ _playChannels[channel].playing = false;
+ _driver->send(channel | (_playChannels[channel].note << 8) | 0x80);
+ }
+}
+
+int8 midiManager::getFreeChannel() {
+ for (int8 i = 0; i < 16; i++)
+ if (!_playChannels[i].playing)
+ return i;
+ return -1;
+}
+
+void midiManager::setPan(int8 channel, int8 pan) {
+ assert(channel <= 15);
+
+ _driver->send(channel | (pan << 16) | 0xAB0);
+}
+
+void midiManager::setVolume(int8 channel, int8 volume) {
+ assert(channel <= 15);
+
+ _driver->send(channel | (volume << 16) | 0x7B0);
+}
+
+void midiManager::setProgram(int8 channel, int8 prog) {
+ assert(channel <= 15);
+
+ _driver->send(channel | (prog << 8) | 0xC0);
+}
+
+} // End of namespace ZVision
diff --git a/engines/zvision/core/midi.h b/engines/zvision/core/midi.h
new file mode 100644
index 0000000000..79f8ea3d04
--- /dev/null
+++ b/engines/zvision/core/midi.h
@@ -0,0 +1,59 @@
+/* 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef ZVISION_MIDI_H
+#define ZVISION_MIDI_H
+
+#include "audio/mididrv.h"
+
+namespace ZVision {
+
+class midiManager {
+public:
+ midiManager();
+ ~midiManager();
+
+ void stop();
+ void noteOn(int8 channel, int8 noteNumber, int8 velocity);
+ void noteOff(int8 channel);
+ void setPan(int8 channel, int8 pan);
+ void setVolume(int8 channel, int8 volume);
+ void setProgram(int8 channel, int8 prog);
+
+ int8 getFreeChannel();
+
+protected:
+
+ struct chan {
+ bool playing;
+ int8 note;
+
+ chan() : playing(false), note(0) {};
+ };
+
+ MidiDriver *_driver;
+ chan _playChannels[16];
+};
+
+}
+
+#endif
diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk
index 872b48f775..3f00d67c4c 100644
--- a/engines/zvision/module.mk
+++ b/engines/zvision/module.mk
@@ -7,6 +7,7 @@ MODULE_OBJS := \
core/console.o \
core/events.o \
core/menu.o \
+ core/midi.o \
core/save_manager.o \
core/search_manager.o \
cursors/cursor_manager.o \
diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp
index a534e49c25..a78d68dc8c 100644
--- a/engines/zvision/zvision.cpp
+++ b/engines/zvision/zvision.cpp
@@ -36,6 +36,7 @@
#include "zvision/core/search_manager.h"
#include "zvision/text/text.h"
#include "zvision/fonts/truetype_font.h"
+#include "zvision/core/midi.h"
#include "common/config-manager.h"
#include "common/str.h"
@@ -67,6 +68,7 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc)
_saveManager(nullptr),
_stringManager(nullptr),
_cursorManager(nullptr),
+ _midiManager(nullptr),
_aud_id(0),
_rendDelay(2),
_velocity(0) {
@@ -85,6 +87,7 @@ ZVision::~ZVision() {
delete _renderManager;
delete _scriptManager;
delete _rnd;
+ delete _midiManager;
// Remove all of our debug levels
DebugMan.clearAllDebugChannels();
@@ -156,6 +159,7 @@ void ZVision::initialize() {
_stringManager = new StringManager(this);
_cursorManager = new CursorManager(this, &_pixelFormat);
_textRenderer = new textRenderer(this);
+ _midiManager = new midiManager();
if (_gameDescription->gameId == GID_GRANDINQUISITOR)
_menu = new menuZgi(this);
diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h
index e5d32bf678..cbd10da0d5 100644
--- a/engines/zvision/zvision.h
+++ b/engines/zvision/zvision.h
@@ -55,6 +55,7 @@ class RlfAnimation;
class menuHandler;
class textRenderer;
class Subtitle;
+class midiManager;
class ZVision : public Engine {
public:
@@ -104,6 +105,7 @@ private:
menuHandler *_menu;
sManager *_searchManager;
textRenderer *_textRenderer;
+ midiManager *_midiManager;
// Clock
Clock _clock;
@@ -146,6 +148,9 @@ public:
textRenderer *getTextRenderer() const {
return _textRenderer;
}
+ midiManager *getMidiManager() const {
+ return _midiManager;
+ }
Common::RandomSource *getRandomSource() const {
return _rnd;
}