2007-05-30 21:56:52 +00:00
|
|
|
/* 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.
|
2004-02-05 13:56:39 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-02-05 13:56:39 +00:00
|
|
|
*
|
2006-02-11 12:47:47 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-02-05 13:56:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/util.h"
|
2008-06-13 14:30:47 +00:00
|
|
|
#include "sound/musicplugin.h"
|
2008-05-11 02:10:05 +00:00
|
|
|
#include "sound/mpu401.h"
|
2004-02-05 13:56:39 +00:00
|
|
|
|
|
|
|
#ifndef DISABLE_TAPWAVE
|
2004-09-12 11:14:14 +00:00
|
|
|
|
2007-05-01 09:58:44 +00:00
|
|
|
#include <tapwave.h>
|
2004-09-12 11:14:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MidiDriver_Zodiac:public MidiDriver_MPU401 {
|
|
|
|
public:
|
|
|
|
MidiDriver_Zodiac();
|
|
|
|
int open();
|
|
|
|
void close();
|
|
|
|
void send(uint32 b);
|
2006-02-27 01:59:07 +00:00
|
|
|
void sysEx(const byte *msg, uint16 length);
|
2004-09-12 11:14:14 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
TwMidiHandle _midiHandle;
|
|
|
|
Boolean _isOpen;
|
|
|
|
Int32 _oldVol;
|
|
|
|
};
|
|
|
|
|
|
|
|
MidiDriver_Zodiac::MidiDriver_Zodiac() {
|
|
|
|
_isOpen = false;
|
|
|
|
_midiHandle = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MidiDriver_Zodiac::open() {
|
|
|
|
Err e;
|
|
|
|
|
|
|
|
if (e = TwMidiOpen(&_midiHandle))
|
2008-01-28 00:14:17 +00:00
|
|
|
return MERR_DEVICE_NOT_AVAILABLE;
|
2004-09-12 11:14:14 +00:00
|
|
|
|
|
|
|
TwMidiGetMasterVolume(&_oldVol);
|
2006-09-17 10:08:16 +00:00
|
|
|
TwMidiSetMasterVolume(twMidiMaxVolume); // TODO : set volume based on gVars
|
2004-09-12 11:14:14 +00:00
|
|
|
|
|
|
|
_isOpen = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MidiDriver_Zodiac::close() {
|
|
|
|
if (_isOpen) {
|
|
|
|
_isOpen = false;
|
|
|
|
MidiDriver_MPU401::close();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-09-12 11:14:14 +00:00
|
|
|
TwMidiSetMasterVolume(_oldVol);
|
|
|
|
TwMidiClose(_midiHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MidiDriver_Zodiac::send(uint32 b) {
|
|
|
|
if (!_isOpen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
UInt8 midiCmd[4];
|
|
|
|
UInt8 chanID,mdCmd;
|
|
|
|
|
|
|
|
midiCmd[3] = (b & 0xFF000000) >> 24;
|
|
|
|
midiCmd[2] = (b & 0x00FF0000) >> 16;
|
|
|
|
midiCmd[1] = (b & 0x0000FF00) >> 8;
|
|
|
|
midiCmd[0] = (b & 0x000000FF);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-09-12 11:14:14 +00:00
|
|
|
chanID = (midiCmd[0] & 0x0F) ;
|
|
|
|
mdCmd = midiCmd[0] & 0xF0;
|
|
|
|
|
|
|
|
switch (mdCmd) {
|
|
|
|
case 0x80: // note off
|
|
|
|
TwMidiNoteOff(_midiHandle, chanID, midiCmd[1], 0);
|
|
|
|
break;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-09-12 11:14:14 +00:00
|
|
|
case 0x90: // note on
|
|
|
|
TwMidiNoteOn(_midiHandle, chanID, midiCmd[1], midiCmd[2]);
|
|
|
|
break;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-09-12 11:14:14 +00:00
|
|
|
case 0xB0: // control change
|
|
|
|
TwMidiControlChange(_midiHandle, chanID, midiCmd[1], midiCmd[2]);
|
|
|
|
break;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-09-12 11:14:14 +00:00
|
|
|
case 0xC0: // progam change
|
|
|
|
TwMidiProgramChange(_midiHandle, chanID, midiCmd[1]);
|
|
|
|
break;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-09-12 11:14:14 +00:00
|
|
|
case 0xE0: // pitchBend
|
|
|
|
TwMidiPitchBend(_midiHandle, chanID, (short)(midiCmd[1] | (midiCmd[2] << 8)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-27 01:59:07 +00:00
|
|
|
void MidiDriver_Zodiac::sysEx(const byte *msg, uint16 length) {
|
2008-11-30 04:42:30 +00:00
|
|
|
unsigned char buf[266];
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-05-01 09:51:53 +00:00
|
|
|
buf[0] = 0xF0;
|
|
|
|
memcpy(buf + 1, msg, length);
|
|
|
|
buf[length + 1] = 0xF7;
|
2007-02-16 13:30:41 +00:00
|
|
|
|
2007-05-01 09:51:53 +00:00
|
|
|
TwMidiSysEx(_midiHandle, 0, (byte *)buf, length + 2);
|
2004-09-12 11:14:14 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 02:10:05 +00:00
|
|
|
|
|
|
|
// Plugin interface
|
|
|
|
|
2008-06-13 14:30:47 +00:00
|
|
|
class ZodiacMusicPlugin : public MusicPluginObject {
|
2008-05-11 02:10:05 +00:00
|
|
|
public:
|
2008-06-13 16:04:43 +00:00
|
|
|
const char *getName() const {
|
2008-05-11 02:10:05 +00:00
|
|
|
return "Tapwave Zodiac";
|
|
|
|
}
|
|
|
|
|
2008-06-13 16:04:43 +00:00
|
|
|
const char *getId() const {
|
2008-05-14 14:56:29 +00:00
|
|
|
return "zodiac";
|
|
|
|
}
|
|
|
|
|
2008-06-13 16:04:43 +00:00
|
|
|
MusicDevices getDevices() const;
|
2008-11-05 17:24:56 +00:00
|
|
|
Common::Error createInstance(Audio::Mixer *mixer, MidiDriver **mididriver) const;
|
2008-05-11 02:10:05 +00:00
|
|
|
};
|
|
|
|
|
2008-06-13 16:04:43 +00:00
|
|
|
MusicDevices ZodiacMusicPlugin::getDevices() const {
|
|
|
|
MusicDevices devices;
|
|
|
|
// TODO: Return a different music type depending on the configuration
|
|
|
|
// TODO: List the available devices
|
|
|
|
devices.push_back(MusicDevice(this, "", MT_GM));
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
2008-11-05 17:24:56 +00:00
|
|
|
Common::Error ZodiacMusicPlugin::createInstance(Audio::Mixer *mixer, MidiDriver **mididriver) const {
|
2008-05-11 02:10:05 +00:00
|
|
|
*mididriver = new MidiDriver_Zodiac();
|
|
|
|
|
2008-11-05 17:24:56 +00:00
|
|
|
return Common::kNoError;
|
2008-05-11 02:10:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MidiDriver *MidiDriver_Zodiac_create(Audio::Mixer *mixer) {
|
|
|
|
MidiDriver *mididriver;
|
|
|
|
|
2008-06-13 14:30:47 +00:00
|
|
|
ZodiacMusicPlugin p;
|
2008-05-11 02:10:05 +00:00
|
|
|
p.createInstance(mixer, &mididriver);
|
|
|
|
|
|
|
|
return mididriver;
|
2004-09-12 11:14:14 +00:00
|
|
|
}
|
|
|
|
|
2008-05-14 14:56:29 +00:00
|
|
|
//#if PLUGIN_ENABLED_DYNAMIC(ZODIAC)
|
2008-06-13 14:30:47 +00:00
|
|
|
//REGISTER_PLUGIN_DYNAMIC(ZODIAC, PLUGIN_TYPE_MUSIC, ZodiacMusicPlugin);
|
2008-05-14 14:56:29 +00:00
|
|
|
//#else
|
2008-06-13 14:30:47 +00:00
|
|
|
REGISTER_PLUGIN_STATIC(ZODIAC, PLUGIN_TYPE_MUSIC, ZodiacMusicPlugin);
|
2008-05-14 14:56:29 +00:00
|
|
|
//#endif
|
|
|
|
|
2004-02-05 13:56:39 +00:00
|
|
|
#endif
|