2002-04-21 17:46:42 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2001-2006 The ScummVM project
|
2002-04-21 17:46:42 +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.
|
2002-04-21 17:46:42 +00:00
|
|
|
*
|
2006-02-11 10:05:31 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2002-04-21 17:46:42 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2002-09-08 01:08:12 +00:00
|
|
|
#ifndef SOUND_MIDIDRV_H
|
|
|
|
#define SOUND_MIDIDRV_H
|
|
|
|
|
2003-08-01 12:21:04 +00:00
|
|
|
#include "common/scummsys.h"
|
2003-10-18 13:04:59 +00:00
|
|
|
#include "common/timer.h"
|
2002-09-08 01:08:12 +00:00
|
|
|
|
2002-11-26 16:54:58 +00:00
|
|
|
class MidiChannel;
|
2005-05-10 23:48:48 +00:00
|
|
|
namespace Audio {
|
|
|
|
class Mixer;
|
|
|
|
}
|
2003-10-18 00:22:46 +00:00
|
|
|
namespace Common { class String; }
|
2003-10-02 22:52:57 +00:00
|
|
|
|
2005-12-29 16:55:21 +00:00
|
|
|
/**
|
|
|
|
* Music Driver Types, used to uniquely identify each music driver.
|
|
|
|
*
|
|
|
|
* The pseudo drivers are listed first, then all native drivers,
|
|
|
|
* then all other MIDI drivers, and finally the non-MIDI drivers.
|
|
|
|
*
|
|
|
|
* @todo Rename MidiDriverType to MusicDriverType
|
|
|
|
*/
|
2005-12-26 11:18:25 +00:00
|
|
|
enum MidiDriverType {
|
2005-12-29 16:55:21 +00:00
|
|
|
// Pseudo drivers
|
2005-12-26 11:18:25 +00:00
|
|
|
MD_AUTO,
|
|
|
|
MD_NULL,
|
|
|
|
|
|
|
|
// Windows
|
|
|
|
MD_WINDOWS,
|
|
|
|
|
|
|
|
// Linux
|
|
|
|
MD_ALSA,
|
|
|
|
MD_SEQ,
|
|
|
|
|
|
|
|
// Mac OS X
|
|
|
|
MD_QTMUSIC,
|
|
|
|
MD_COREAUDIO,
|
|
|
|
MD_COREMIDI,
|
|
|
|
|
|
|
|
// PalmOS
|
|
|
|
MD_YPA1,
|
|
|
|
MD_ZODIAC,
|
|
|
|
|
|
|
|
// MorphOS
|
|
|
|
MD_ETUDE,
|
|
|
|
|
2005-12-29 16:55:21 +00:00
|
|
|
// MIDI softsynths
|
|
|
|
MD_FLUIDSYNTH,
|
|
|
|
MD_MT32,
|
|
|
|
|
2005-12-26 11:18:25 +00:00
|
|
|
// "Fake" MIDI devices
|
|
|
|
MD_ADLIB,
|
|
|
|
MD_PCSPK,
|
|
|
|
MD_PCJR,
|
2005-12-29 16:55:21 +00:00
|
|
|
MD_TOWNS
|
2003-10-02 22:52:57 +00:00
|
|
|
};
|
|
|
|
|
2005-12-26 11:18:25 +00:00
|
|
|
/**
|
2005-12-29 16:55:21 +00:00
|
|
|
* A set of flags to be passed to detectMusicDriver() which can be used to
|
|
|
|
* specify what kind of music driver is preferred / accepted.
|
|
|
|
*
|
2005-12-30 14:18:21 +00:00
|
|
|
* The flags (except for MDT_PREFER_MIDI) indicate whether a given driver
|
2005-12-29 16:55:21 +00:00
|
|
|
* type is acceptable. E.g. the TOWNS music driver could be returned by
|
|
|
|
* detectMusicDriver if and only if MDT_TOWNS is specified.
|
|
|
|
*
|
|
|
|
* @todo Rename MidiDriverFlags to MusicDriverFlags
|
2005-12-26 11:18:25 +00:00
|
|
|
*/
|
|
|
|
enum MidiDriverFlags {
|
2004-12-02 00:33:42 +00:00
|
|
|
MDT_NONE = 0,
|
2005-12-29 16:55:21 +00:00
|
|
|
MDT_PCSPK = 1 << 0, // PC Speaker: Maps to MD_PCSPK and MD_PCJR
|
|
|
|
MDT_ADLIB = 1 << 1, // Adlib: Maps to MD_ADLIB
|
|
|
|
MDT_TOWNS = 1 << 2, // FM-TOWNS: Maps to MD_TOWNS
|
|
|
|
MDT_MIDI = 1 << 3, // Real MIDI
|
2005-12-30 14:18:21 +00:00
|
|
|
MDT_PREFER_MIDI = 1 << 4 // Real MIDI output is preferred
|
2004-12-02 00:33:42 +00:00
|
|
|
};
|
2003-10-18 00:22:46 +00:00
|
|
|
|
2003-10-02 22:52:57 +00:00
|
|
|
/**
|
|
|
|
* Abstract description of a MIDI driver. Used by the config file and command
|
|
|
|
* line parsing code, and also to be able to give the user a list of available
|
|
|
|
* drivers.
|
2005-12-29 16:55:21 +00:00
|
|
|
*
|
|
|
|
* @todo Rename MidiDriverType to MusicDriverType
|
2003-10-02 22:52:57 +00:00
|
|
|
*/
|
|
|
|
struct MidiDriverDescription {
|
|
|
|
const char *name;
|
|
|
|
const char *description;
|
2005-12-29 16:55:21 +00:00
|
|
|
MidiDriverType id; // A unique ID for each driver
|
|
|
|
int flags; // Capabilities of this driver
|
2003-10-02 22:52:57 +00:00
|
|
|
};
|
|
|
|
|
2005-12-29 16:55:21 +00:00
|
|
|
/**
|
|
|
|
* Abstract MIDI Driver Class
|
|
|
|
*
|
|
|
|
* @todo Rename MidiDriver to MusicDriver
|
|
|
|
*/
|
2002-04-13 18:34:11 +00:00
|
|
|
class MidiDriver {
|
2004-12-02 00:33:42 +00:00
|
|
|
public:
|
2005-12-30 14:18:21 +00:00
|
|
|
/** Find the music driver matching the given driver name/description. */
|
|
|
|
static const MidiDriverDescription &findMusicDriver(const Common::String &str);
|
|
|
|
|
2004-12-02 00:33:42 +00:00
|
|
|
/** Convert a string containing a music driver name into MIDI Driver type. */
|
|
|
|
static int parseMusicDriver(const Common::String &str);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of all available MidiDriver types.
|
|
|
|
* @return list of all available midi drivers, terminated by a zero entry
|
|
|
|
*/
|
|
|
|
static const MidiDriverDescription *getAvailableMidiDrivers();
|
|
|
|
|
|
|
|
static MidiDriver *createMidi(int midiDriver);
|
|
|
|
|
2005-12-30 14:18:21 +00:00
|
|
|
static int detectMusicDriver(int flags);
|
2004-12-02 00:33:42 +00:00
|
|
|
|
|
|
|
|
2002-04-13 18:34:11 +00:00
|
|
|
public:
|
2003-05-23 04:19:47 +00:00
|
|
|
virtual ~MidiDriver() { }
|
|
|
|
|
2005-04-03 22:01:38 +00:00
|
|
|
static const byte _mt32ToGm[128];
|
|
|
|
static const byte _gmToMt32[128];
|
|
|
|
|
2003-10-02 22:52:57 +00:00
|
|
|
/**
|
|
|
|
* Error codes returned by open.
|
|
|
|
* Can be converted to a string with getErrorName().
|
|
|
|
*/
|
2002-04-13 18:34:11 +00:00
|
|
|
enum {
|
|
|
|
MERR_CANNOT_CONNECT = 1,
|
2002-12-11 16:09:58 +00:00
|
|
|
// MERR_STREAMING_NOT_AVAILABLE = 2,
|
2002-04-13 18:34:11 +00:00
|
|
|
MERR_DEVICE_NOT_AVAILABLE = 3,
|
2002-12-25 00:36:04 +00:00
|
|
|
MERR_ALREADY_OPEN = 4
|
2002-04-13 18:34:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2003-05-23 04:19:47 +00:00
|
|
|
// PROP_TIMEDIV = 1,
|
2003-09-25 22:32:05 +00:00
|
|
|
PROP_OLD_ADLIB = 2,
|
|
|
|
PROP_CHANNEL_MASK = 3
|
2002-04-13 18:34:11 +00:00
|
|
|
};
|
|
|
|
|
2003-10-02 22:52:57 +00:00
|
|
|
/**
|
|
|
|
* Open the midi driver.
|
|
|
|
* @return 0 if successful, otherwise an error code.
|
|
|
|
*/
|
2002-12-11 16:09:58 +00:00
|
|
|
virtual int open() = 0;
|
2002-04-13 18:34:11 +00:00
|
|
|
|
2003-10-02 22:52:57 +00:00
|
|
|
/** Close the midi driver. */
|
2002-04-13 18:34:11 +00:00
|
|
|
virtual void close() = 0;
|
|
|
|
|
2003-10-02 22:52:57 +00:00
|
|
|
/** Output a packed midi command to the midi stream. */
|
2002-04-13 18:34:11 +00:00
|
|
|
virtual void send(uint32 b) = 0;
|
|
|
|
|
2003-10-02 22:52:57 +00:00
|
|
|
/** Get or set a property. */
|
2003-05-17 14:27:58 +00:00
|
|
|
virtual uint32 property(int prop, uint32 param) { return 0; }
|
2002-04-13 18:34:11 +00:00
|
|
|
|
2003-10-02 22:52:57 +00:00
|
|
|
/** Retrieve a string representation of an error code. */
|
2002-12-11 16:09:58 +00:00
|
|
|
static const char *getErrorName(int error_code);
|
2002-10-21 09:32:38 +00:00
|
|
|
|
|
|
|
// HIGH-LEVEL SEMANTIC METHODS
|
2005-05-27 12:43:19 +00:00
|
|
|
virtual void setPitchBendRange(byte channel, uint range)
|
2002-11-04 18:29:26 +00:00
|
|
|
{
|
|
|
|
send(( 0 << 16) | (101 << 8) | (0xB0 | channel));
|
|
|
|
send(( 0 << 16) | (100 << 8) | (0xB0 | channel));
|
|
|
|
send((range << 16) | ( 6 << 8) | (0xB0 | channel));
|
|
|
|
send(( 0 << 16) | ( 38 << 8) | (0xB0 | channel));
|
2005-04-13 00:11:49 +00:00
|
|
|
send(( 127 << 16) | (101 << 8) | (0xB0 | channel));
|
|
|
|
send(( 127 << 16) | (100 << 8) | (0xB0 | channel));
|
2002-11-04 18:29:26 +00:00
|
|
|
}
|
2002-11-21 19:06:42 +00:00
|
|
|
|
2006-02-27 01:59:07 +00:00
|
|
|
virtual void sysEx(const byte *msg, uint16 length) { }
|
|
|
|
virtual void sysEx_customInstrument(byte channel, uint32 type, const byte *instr) { }
|
|
|
|
virtual void metaEvent(byte type, byte *data, uint16 length) { }
|
2002-11-21 19:06:42 +00:00
|
|
|
|
|
|
|
// Timing functions - MidiDriver now operates timers
|
2006-06-24 09:34:49 +00:00
|
|
|
virtual void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) = 0;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-10-17 19:39:54 +00:00
|
|
|
/** The time in microseconds between invocations of the timer callback. */
|
2005-05-27 12:43:19 +00:00
|
|
|
virtual uint32 getBaseTempo(void) = 0;
|
2002-11-26 16:54:58 +00:00
|
|
|
|
|
|
|
// Channel allocation functions
|
|
|
|
virtual MidiChannel *allocateChannel() = 0;
|
|
|
|
virtual MidiChannel *getPercussionChannel() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MidiChannel {
|
|
|
|
public:
|
2005-06-20 18:27:33 +00:00
|
|
|
virtual ~MidiChannel() {}
|
|
|
|
|
2002-12-18 07:13:42 +00:00
|
|
|
virtual MidiDriver *device() = 0;
|
2002-12-18 07:48:35 +00:00
|
|
|
virtual byte getNumber() = 0;
|
2002-11-26 16:54:58 +00:00
|
|
|
virtual void release() = 0;
|
|
|
|
|
2005-05-27 12:43:19 +00:00
|
|
|
virtual void send(uint32 b) = 0; // 4-bit channel portion is ignored
|
2003-08-08 11:54:24 +00:00
|
|
|
|
2002-11-26 16:54:58 +00:00
|
|
|
// Regular messages
|
2005-05-27 12:43:19 +00:00
|
|
|
virtual void noteOff(byte note) = 0;
|
|
|
|
virtual void noteOn(byte note, byte velocity) = 0;
|
|
|
|
virtual void programChange(byte program) = 0;
|
|
|
|
virtual void pitchBend(int16 bend) = 0; // -0x2000 to +0x1FFF
|
2002-11-26 16:54:58 +00:00
|
|
|
|
|
|
|
// Control Change messages
|
2005-05-27 12:43:19 +00:00
|
|
|
virtual void controlChange(byte control, byte value) = 0;
|
2006-05-12 12:03:36 +00:00
|
|
|
virtual void modulationWheel(byte value) { controlChange(1, value); }
|
|
|
|
virtual void volume(byte value) { controlChange(7, value); }
|
|
|
|
virtual void panPosition(byte value) { controlChange(10, value); }
|
2005-05-27 12:43:19 +00:00
|
|
|
virtual void pitchBendFactor(byte value) = 0;
|
2006-05-12 12:03:36 +00:00
|
|
|
virtual void detune(byte value) { controlChange(17, value); }
|
2005-05-27 12:43:19 +00:00
|
|
|
virtual void priority(byte value) { }
|
2006-05-12 12:03:36 +00:00
|
|
|
virtual void sustain(bool value) { controlChange(64, value ? 1 : 0); }
|
|
|
|
virtual void effectLevel(byte value) { controlChange(91, value); }
|
|
|
|
virtual void chorusLevel(byte value) { controlChange(93, value); }
|
|
|
|
virtual void allNotesOff() { controlChange(123, 0); }
|
2002-11-26 16:54:58 +00:00
|
|
|
|
|
|
|
// SysEx messages
|
2006-02-27 01:59:07 +00:00
|
|
|
virtual void sysEx_customInstrument(uint32 type, const byte *instr) = 0;
|
2002-04-13 18:34:11 +00:00
|
|
|
};
|
|
|
|
|
2002-03-21 16:12:02 +00:00
|
|
|
|
2002-12-18 07:13:42 +00:00
|
|
|
// Factory functions, for faster compile
|
2002-04-26 13:18:49 +00:00
|
|
|
extern MidiDriver *MidiDriver_NULL_create();
|
2005-05-10 23:48:48 +00:00
|
|
|
extern MidiDriver *MidiDriver_ADLIB_create(Audio::Mixer *mixer);
|
2002-04-26 13:18:49 +00:00
|
|
|
extern MidiDriver *MidiDriver_WIN_create();
|
|
|
|
extern MidiDriver *MidiDriver_SEQ_create();
|
|
|
|
extern MidiDriver *MidiDriver_QT_create();
|
|
|
|
extern MidiDriver *MidiDriver_CORE_create();
|
2005-12-26 11:18:25 +00:00
|
|
|
extern MidiDriver *MidiDriver_CoreMIDI_create();
|
2002-10-02 23:31:40 +00:00
|
|
|
extern MidiDriver *MidiDriver_ETUDE_create();
|
2002-05-16 06:46:50 +00:00
|
|
|
extern MidiDriver *MidiDriver_ALSA_create();
|
2005-05-10 23:48:48 +00:00
|
|
|
extern MidiDriver *MidiDriver_YM2612_create(Audio::Mixer *mixer);
|
2005-04-10 14:33:44 +00:00
|
|
|
#ifdef USE_FLUIDSYNTH
|
2005-05-10 23:48:48 +00:00
|
|
|
extern MidiDriver *MidiDriver_FluidSynth_create(Audio::Mixer *mixer);
|
2005-04-10 14:33:44 +00:00
|
|
|
#endif
|
2004-11-06 01:41:32 +00:00
|
|
|
#ifdef USE_MT32EMU
|
2005-05-10 23:48:48 +00:00
|
|
|
extern MidiDriver *MidiDriver_MT32_create(Audio::Mixer *mixer);
|
2004-11-06 01:41:32 +00:00
|
|
|
#endif
|
2003-04-30 12:51:07 +00:00
|
|
|
extern MidiDriver *MidiDriver_YamahaPa1_create();
|
2004-02-05 13:56:39 +00:00
|
|
|
extern MidiDriver *MidiDriver_Zodiac_create();
|
2002-09-08 01:08:12 +00:00
|
|
|
|
2004-02-06 08:35:24 +00:00
|
|
|
#endif
|