ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

mididrv.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef AUDIO_MIDIDRV_H
00024 #define AUDIO_MIDIDRV_H
00025 
00026 #include "common/scummsys.h"
00027 #include "common/str.h"
00028 #include "common/timer.h"
00029 
00030 class MidiChannel;
00031 
00035 enum MusicType {
00036     MT_INVALID = -1,    // Invalid output
00037     MT_AUTO = 0,        // Auto
00038     MT_NULL,            // Null
00039     MT_PCSPK,           // PC Speaker
00040     MT_PCJR,            // PCjr
00041     MT_CMS,             // CMS
00042     MT_ADLIB,           // AdLib
00043     MT_C64,             // C64
00044     MT_AMIGA,           // Amiga
00045     MT_APPLEIIGS,       // Apple IIGS
00046     MT_TOWNS,           // FM-TOWNS
00047     MT_PC98,            // PC98
00048     MT_GM,              // General MIDI
00049     MT_MT32,            // MT-32
00050     MT_GS               // Roland GS
00051 };
00052 
00068 enum MidiDriverFlags {
00069     MDT_NONE        = 0,
00070     MDT_PCSPK       = 1 << 0,       // PC Speaker: Maps to MT_PCSPK and MT_PCJR
00071     MDT_CMS         = 1 << 1,       // Creative Music System / Gameblaster: Maps to MT_CMS
00072     MDT_PCJR        = 1 << 2,       // Tandy/PC Junior driver
00073     MDT_ADLIB       = 1 << 3,       // AdLib: Maps to MT_ADLIB
00074     MDT_C64         = 1 << 4,
00075     MDT_AMIGA       = 1 << 5,
00076     MDT_APPLEIIGS   = 1 << 6,
00077     MDT_TOWNS       = 1 << 7,       // FM-TOWNS: Maps to MT_TOWNS
00078     MDT_PC98        = 1 << 8,       // FM-TOWNS: Maps to MT_PC98
00079     MDT_MIDI        = 1 << 9,       // Real MIDI
00080     MDT_PREFER_MT32 = 1 << 10,      // MT-32 output is preferred
00081     MDT_PREFER_GM   = 1 << 11       // GM output is preferred
00082 };
00083 
00087 class MidiDriver_BASE {
00088 public:
00089     virtual ~MidiDriver_BASE() { }
00090 
00097     virtual void send(uint32 b) = 0;
00098 
00106     void send(byte status, byte firstOp, byte secondOp) {
00107         send(status | ((uint32)firstOp << 8) | ((uint32)secondOp << 16));
00108     }
00109 
00120     virtual void sysEx(const byte *msg, uint16 length) { }
00121 
00122     // TODO: Document this.
00123     virtual void metaEvent(byte type, byte *data, uint16 length) { }
00124 };
00125 
00131 class MidiDriver : public MidiDriver_BASE {
00132 public:
00140     typedef uint32 DeviceHandle;
00141 
00142     enum DeviceStringType {
00143         kDriverName,
00144         kDriverId,
00145         kDeviceName,
00146         kDeviceId
00147     };
00148 
00149     static Common::String musicType2GUIO(uint32 musicType);
00150 
00152     static MidiDriver *createMidi(DeviceHandle handle);
00153 
00155     static DeviceHandle detectDevice(int flags);
00156 
00158     static DeviceHandle getDeviceHandle(const Common::String &identifier);
00159 
00161     static bool checkDevice(DeviceHandle handle);
00162 
00164     static MusicType getMusicType(DeviceHandle handle);
00165 
00167     static Common::String getDeviceString(DeviceHandle handle, DeviceStringType type);
00168 
00169 private:
00170     // If detectDevice() detects MT32 and we have a preferred MT32 device
00171     // we use this to force getMusicType() to return MT_MT32 so that we don't
00172     // have to rely on the 'True Roland MT-32' config manager setting (since nobody
00173     // would possibly think about activating 'True Roland MT-32' when he has set
00174     // 'Music Driver' to '<default>')
00175     static bool _forceTypeMT32;
00176 
00177 public:
00178     virtual ~MidiDriver() { }
00179 
00180     static const byte _mt32ToGm[128];
00181     static const byte _gmToMt32[128];
00182 
00187     enum {
00188         MERR_CANNOT_CONNECT = 1,
00189 //      MERR_STREAMING_NOT_AVAILABLE = 2,
00190         MERR_DEVICE_NOT_AVAILABLE = 3,
00191         MERR_ALREADY_OPEN = 4
00192     };
00193 
00194     enum {
00195 //      PROP_TIMEDIV = 1,
00196         PROP_OLD_ADLIB = 2,
00197         PROP_CHANNEL_MASK = 3,
00198         // HACK: Not so nice, but our SCUMM AdLib code is in audio/
00199         PROP_SCUMM_OPL3 = 4
00200     };
00201 
00206     virtual int open() = 0;
00207 
00211     virtual bool isOpen() const = 0;
00212 
00214     virtual void close() = 0;
00215 
00217     virtual uint32 property(int prop, uint32 param) { return 0; }
00218 
00220     static const char *getErrorName(int error_code);
00221 
00222     // HIGH-LEVEL SEMANTIC METHODS
00223     virtual void setPitchBendRange(byte channel, uint range) {
00224         send(0xB0 | channel, 101, 0);
00225         send(0xB0 | channel, 100, 0);
00226         send(0xB0 | channel,   6, range);
00227         send(0xB0 | channel,  38, 0);
00228         send(0xB0 | channel, 101, 127);
00229         send(0xB0 | channel, 100, 127);
00230     }
00231 
00235     void sendMT32Reset();
00236 
00240     void sendGMReset();
00241 
00242     virtual void sysEx_customInstrument(byte channel, uint32 type, const byte *instr) { }
00243 
00244     // Timing functions - MidiDriver now operates timers
00245     virtual void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) = 0;
00246 
00248     virtual uint32 getBaseTempo() = 0;
00249 
00250     // Channel allocation functions
00251     virtual MidiChannel *allocateChannel() = 0;
00252     virtual MidiChannel *getPercussionChannel() = 0;
00253 };
00254 
00255 class MidiChannel {
00256 public:
00257     virtual ~MidiChannel() {}
00258 
00259     virtual MidiDriver *device() = 0;
00260     virtual byte getNumber() = 0;
00261     virtual void release() = 0;
00262 
00263     virtual void send(uint32 b) = 0; // 4-bit channel portion is ignored
00264 
00265     // Regular messages
00266     virtual void noteOff(byte note) = 0;
00267     virtual void noteOn(byte note, byte velocity) = 0;
00268     virtual void programChange(byte program) = 0;
00269     virtual void pitchBend(int16 bend) = 0; // -0x2000 to +0x1FFF
00270 
00271     // Control Change messages
00272     virtual void controlChange(byte control, byte value) = 0;
00273     virtual void modulationWheel(byte value) { controlChange(1, value); }
00274     virtual void volume(byte value) { controlChange(7, value); }
00275     virtual void panPosition(byte value) { controlChange(10, value); }
00276     virtual void pitchBendFactor(byte value) = 0;
00277     virtual void detune(byte value) { controlChange(17, value); }
00278     virtual void priority(byte value) { }
00279     virtual void sustain(bool value) { controlChange(64, value ? 1 : 0); }
00280     virtual void effectLevel(byte value) { controlChange(91, value); }
00281     virtual void chorusLevel(byte value) { controlChange(93, value); }
00282     virtual void allNotesOff() { controlChange(123, 0); }
00283 
00284     // SysEx messages
00285     virtual void sysEx_customInstrument(uint32 type, const byte *instr) = 0;
00286 };
00287 
00288 #endif


Generated on Sat Feb 16 2019 05:00:58 for ResidualVM by doxygen 1.7.1
curved edge   curved edge