From 2463b4580436b41a46500e53b4868789c9c7b21e Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Tue, 16 Dec 2014 01:05:01 +0200 Subject: ZVISION: Move the MIDI code together with the rest of the sound code --- engines/zvision/core/midi.cpp | 89 ------------------------- engines/zvision/core/midi.h | 59 ---------------- engines/zvision/module.mk | 2 +- engines/zvision/scripting/sidefx/music_node.cpp | 2 +- engines/zvision/sound/midi.cpp | 89 +++++++++++++++++++++++++ engines/zvision/sound/midi.h | 59 ++++++++++++++++ engines/zvision/zvision.cpp | 2 +- 7 files changed, 151 insertions(+), 151 deletions(-) delete mode 100644 engines/zvision/core/midi.cpp delete mode 100644 engines/zvision/core/midi.h create mode 100644 engines/zvision/sound/midi.cpp create mode 100644 engines/zvision/sound/midi.h diff --git a/engines/zvision/core/midi.cpp b/engines/zvision/core/midi.cpp deleted file mode 100644 index 736be1311d..0000000000 --- a/engines/zvision/core/midi.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* 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 deleted file mode 100644 index a3bac19636..0000000000 --- a/engines/zvision/core/midi.h +++ /dev/null @@ -1,59 +0,0 @@ -/* 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 604b697ec7..c9a1cb7187 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -4,7 +4,6 @@ MODULE_OBJS := \ core/console.o \ core/events.o \ core/menu.o \ - core/midi.o \ core/save_manager.o \ core/search_manager.o \ detection.o \ @@ -39,6 +38,7 @@ MODULE_OBJS := \ scripting/sidefx/syncsound_node.o \ scripting/sidefx/timer_node.o \ scripting/sidefx/ttytext_node.o \ + sound/midi.o \ sound/zork_raw.o \ text/string_manager.o \ text/text.o \ diff --git a/engines/zvision/scripting/sidefx/music_node.cpp b/engines/zvision/scripting/sidefx/music_node.cpp index 8316c1a76b..c79dd0296d 100644 --- a/engines/zvision/scripting/sidefx/music_node.cpp +++ b/engines/zvision/scripting/sidefx/music_node.cpp @@ -25,9 +25,9 @@ #include "zvision/scripting/sidefx/music_node.h" #include "zvision/zvision.h" -#include "zvision/core/midi.h" #include "zvision/scripting/script_manager.h" #include "zvision/graphics/render_manager.h" +#include "zvision/sound/midi.h" #include "zvision/sound/zork_raw.h" #include "common/stream.h" diff --git a/engines/zvision/sound/midi.cpp b/engines/zvision/sound/midi.cpp new file mode 100644 index 0000000000..920002c7c3 --- /dev/null +++ b/engines/zvision/sound/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/sound/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/sound/midi.h b/engines/zvision/sound/midi.h new file mode 100644 index 0000000000..a3bac19636 --- /dev/null +++ b/engines/zvision/sound/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/zvision.cpp b/engines/zvision/zvision.cpp index 34fe0794bd..45dc124b58 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -34,7 +34,7 @@ #include "zvision/core/search_manager.h" #include "zvision/text/text.h" #include "zvision/graphics/truetype_font.h" -#include "zvision/core/midi.h" +#include "zvision/sound/midi.h" #include "zvision/utility/zfs_archive.h" #include "common/config-manager.h" -- cgit v1.2.3