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.
|
2003-05-17 14:26:58 +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.
|
2003-05-17 14:26:58 +00:00
|
|
|
*
|
2006-02-11 12:47:47 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2003-05-17 14:26:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Raw output support by Michael Pearce
|
|
|
|
* Alsa support by Nicolas Noble <nicolas@nobis-crew.org> copied from
|
|
|
|
* both the QuickTime support and (vkeybd http://www.alsa-project.org/~iwai/alsa.html)
|
|
|
|
*/
|
|
|
|
|
2010-07-20 08:56:53 +00:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
|
2010-07-20 08:25:13 +00:00
|
|
|
#if defined(USE_SEQ_MIDI)
|
2003-05-17 14:26:58 +00:00
|
|
|
|
2003-09-10 12:23:42 +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"
|
2003-05-17 14:26:58 +00:00
|
|
|
|
2007-03-08 20:42:40 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2003-05-17 14:26:58 +00:00
|
|
|
////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Unix dev/sequencer driver
|
|
|
|
//
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
#define SEQ_MIDIPUTC 5
|
|
|
|
|
|
|
|
class MidiDriver_SEQ : public MidiDriver_MPU401 {
|
|
|
|
public:
|
|
|
|
MidiDriver_SEQ();
|
|
|
|
int open();
|
|
|
|
void close();
|
|
|
|
void send(uint32 b);
|
2006-02-27 01:59:07 +00:00
|
|
|
void sysEx(const byte *msg, uint16 length);
|
2003-05-17 14:26:58 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool _isOpen;
|
|
|
|
int device, _device_num;
|
|
|
|
};
|
|
|
|
|
|
|
|
MidiDriver_SEQ::MidiDriver_SEQ() {
|
|
|
|
_isOpen = false;
|
|
|
|
device = 0;
|
|
|
|
_device_num = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MidiDriver_SEQ::open() {
|
2005-11-06 01:23:40 +00:00
|
|
|
char *device_name;
|
|
|
|
char dev_seq[] = "/dev/sequencer";
|
|
|
|
|
2003-05-17 14:26:58 +00:00
|
|
|
if (_isOpen)
|
|
|
|
return MERR_ALREADY_OPEN;
|
|
|
|
_isOpen = true;
|
|
|
|
device = 0;
|
|
|
|
|
2005-11-06 01:23:40 +00:00
|
|
|
device_name = getenv("SCUMMVM_MIDI");
|
|
|
|
|
|
|
|
if (device_name == NULL) {
|
|
|
|
warning("SCUMMVM_MIDI environment variable not set, using /dev/sequencer");
|
|
|
|
device_name = dev_seq;
|
2003-05-17 14:26:58 +00:00
|
|
|
}
|
2005-11-06 01:23:40 +00:00
|
|
|
|
|
|
|
device = (::open((device_name), O_RDWR, 0));
|
|
|
|
|
2003-05-17 14:26:58 +00:00
|
|
|
if ((device_name == NULL) || (device < 0)) {
|
|
|
|
if (device_name == NULL)
|
|
|
|
warning("Opening /dev/null (no music will be heard) ");
|
|
|
|
else
|
|
|
|
warning("Cannot open rawmidi device %s - using /dev/null (no music will be heard) ",
|
|
|
|
device_name);
|
|
|
|
device = (::open(("/dev/null"), O_RDWR, 0));
|
|
|
|
if (device < 0)
|
|
|
|
error("Cannot open /dev/null to dump midi output");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getenv("SCUMMVM_MIDIPORT"))
|
|
|
|
_device_num = atoi(getenv("SCUMMVM_MIDIPORT"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MidiDriver_SEQ::close() {
|
2003-06-11 05:54:46 +00:00
|
|
|
MidiDriver_MPU401::close();
|
2003-05-17 14:26:58 +00:00
|
|
|
::close(device);
|
|
|
|
_isOpen = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MidiDriver_SEQ::send(uint32 b) {
|
|
|
|
unsigned char buf[256];
|
|
|
|
int position = 0;
|
|
|
|
|
|
|
|
switch (b & 0xF0) {
|
|
|
|
case 0x80:
|
|
|
|
case 0x90:
|
|
|
|
case 0xA0:
|
|
|
|
case 0xB0:
|
|
|
|
case 0xE0:
|
|
|
|
buf[position++] = SEQ_MIDIPUTC;
|
|
|
|
buf[position++] = (unsigned char)b;
|
|
|
|
buf[position++] = _device_num;
|
|
|
|
buf[position++] = 0;
|
|
|
|
buf[position++] = SEQ_MIDIPUTC;
|
|
|
|
buf[position++] = (unsigned char)((b >> 8) & 0x7F);
|
|
|
|
buf[position++] = _device_num;
|
|
|
|
buf[position++] = 0;
|
|
|
|
buf[position++] = SEQ_MIDIPUTC;
|
|
|
|
buf[position++] = (unsigned char)((b >> 16) & 0x7F);
|
|
|
|
buf[position++] = _device_num;
|
|
|
|
buf[position++] = 0;
|
|
|
|
break;
|
|
|
|
case 0xC0:
|
|
|
|
case 0xD0:
|
|
|
|
buf[position++] = SEQ_MIDIPUTC;
|
|
|
|
buf[position++] = (unsigned char)b;
|
|
|
|
buf[position++] = _device_num;
|
|
|
|
buf[position++] = 0;
|
|
|
|
buf[position++] = SEQ_MIDIPUTC;
|
|
|
|
buf[position++] = (unsigned char)((b >> 8) & 0x7F);
|
|
|
|
buf[position++] = _device_num;
|
|
|
|
buf[position++] = 0;
|
|
|
|
break;
|
|
|
|
default:
|
2007-03-08 17:23:19 +00:00
|
|
|
warning("MidiDriver_SEQ::send: unknown : %08x", (int)b);
|
2003-05-17 14:26:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-06-28 19:56:58 +00:00
|
|
|
(void)write(device, buf, position);
|
2003-05-17 14:26:58 +00:00
|
|
|
}
|
|
|
|
|
2006-02-27 01:59:07 +00:00
|
|
|
void MidiDriver_SEQ::sysEx (const byte *msg, uint16 length) {
|
2008-11-30 13:03:43 +00:00
|
|
|
unsigned char buf [266*4];
|
2003-05-17 14:26:58 +00:00
|
|
|
int position = 0;
|
2006-02-27 07:18:49 +00:00
|
|
|
const byte *chr = msg;
|
2003-06-01 01:45:08 +00:00
|
|
|
|
2008-11-30 04:42:30 +00:00
|
|
|
assert(length + 2 <= 266);
|
2007-02-16 13:30:41 +00:00
|
|
|
|
2003-05-17 14:26:58 +00:00
|
|
|
buf[position++] = SEQ_MIDIPUTC;
|
2003-06-01 02:25:07 +00:00
|
|
|
buf[position++] = 0xF0;
|
2003-05-17 14:26:58 +00:00
|
|
|
buf[position++] = _device_num;
|
|
|
|
buf[position++] = 0;
|
2003-05-31 22:16:25 +00:00
|
|
|
for (; length; --length, ++chr) {
|
2003-05-17 14:26:58 +00:00
|
|
|
buf[position++] = SEQ_MIDIPUTC;
|
2003-06-01 01:45:08 +00:00
|
|
|
buf[position++] = (unsigned char) *chr & 0x7F;
|
2003-05-17 14:26:58 +00:00
|
|
|
buf[position++] = _device_num;
|
|
|
|
buf[position++] = 0;
|
|
|
|
}
|
|
|
|
buf[position++] = SEQ_MIDIPUTC;
|
|
|
|
buf[position++] = 0xF7;
|
|
|
|
buf[position++] = _device_num;
|
|
|
|
buf[position++] = 0;
|
2003-05-31 23:14:36 +00:00
|
|
|
|
2009-06-28 19:56:58 +00:00
|
|
|
(void)write(device, buf, position);
|
2003-05-17 14:26:58 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 02:10:05 +00:00
|
|
|
|
|
|
|
// Plugin interface
|
|
|
|
|
2008-06-13 14:30:47 +00:00
|
|
|
class SeqMusicPlugin : 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 "SEQ";
|
|
|
|
}
|
|
|
|
|
2008-06-13 16:04:43 +00:00
|
|
|
const char *getId() const {
|
2008-05-14 14:56:29 +00:00
|
|
|
return "seq";
|
|
|
|
}
|
|
|
|
|
2008-06-13 16:04:43 +00:00
|
|
|
MusicDevices getDevices() const;
|
2010-06-21 21:36:36 +00:00
|
|
|
Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
|
2008-05-11 02:10:05 +00:00
|
|
|
};
|
|
|
|
|
2008-06-13 16:04:43 +00:00
|
|
|
MusicDevices SeqMusicPlugin::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;
|
|
|
|
}
|
|
|
|
|
2010-06-21 21:36:36 +00:00
|
|
|
Common::Error SeqMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
|
2008-05-11 02:10:05 +00:00
|
|
|
*mididriver = new MidiDriver_SEQ();
|
|
|
|
|
2008-11-05 17:24:56 +00:00
|
|
|
return Common::kNoError;
|
2008-05-11 02:10:05 +00:00
|
|
|
}
|
|
|
|
|
2008-05-14 14:56:29 +00:00
|
|
|
//#if PLUGIN_ENABLED_DYNAMIC(SEQ)
|
2008-06-13 14:30:47 +00:00
|
|
|
//REGISTER_PLUGIN_DYNAMIC(SEQ, PLUGIN_TYPE_MUSIC, SeqMusicPlugin);
|
2008-05-14 14:56:29 +00:00
|
|
|
//#else
|
2008-06-13 14:30:47 +00:00
|
|
|
REGISTER_PLUGIN_STATIC(SEQ, PLUGIN_TYPE_MUSIC, SeqMusicPlugin);
|
2008-05-14 14:56:29 +00:00
|
|
|
//#endif
|
|
|
|
|
2003-05-17 14:26:58 +00:00
|
|
|
#endif
|