ScummVM API documentation
mididriver.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef DGDS_SOUND_DRIVERS_MIDIDRIVER_H
23#define DGDS_SOUND_DRIVERS_MIDIDRIVER_H
24
25#include "audio/mididrv.h"
26#include "common/platform.h"
27
28namespace Dgds {
29
30// Music patches in SCI games:
31// ===========================
32// 1.pat - MT-32 driver music patch
33// 2.pat - Yamaha FB01 driver music patch
34// 3.pat - Adlib driver music patch
35// 4.pat - Casio MT-540 (in earlier SCI0 games)
36// 4.pat - GM driver music patch (in later games that support GM)
37// 7.pat (newer) / patch.200 (older) - Mac driver music patch / Casio CSM-1
38// 9.pat (newer) / patch.005 (older) - Amiga driver music patch
39// 98.pat - Unknown, found in later SCI1.1 games. A MIDI format patch
40// 101.pat - CMS/PCjr driver music patch.
41// Only later PCjr drivers use this patch, earlier ones don't use a patch
42// bank.001 - older SCI0 Amiga instruments
43
44class ResourceManager;
45
46enum {
47 MIDI_CHANNELS = 16,
48 MIDI_PROP_MASTER_VOLUME = 0
49};
50
51#define MIDI_RHYTHM_CHANNEL 9
52
53/* Special SCI sound stuff */
54
55#define SCI_MIDI_TIME_EXPANSION_PREFIX 0xF8
56#define SCI_MIDI_TIME_EXPANSION_LENGTH 240
57
58#define SCI_MIDI_EOT 0xFC
59#define SCI_MIDI_SET_SIGNAL 0xCF
60#define SCI_MIDI_SET_POLYPHONY 0x4B
61#define SCI_MIDI_RESET_ON_SUSPEND 0x4C
62#define SCI_MIDI_CHANNEL_MUTE 0x4E
63#define SCI_MIDI_SET_REVERB 0x50
64#define SCI_MIDI_HOLD 0x52
65#define SCI_MIDI_CUMULATIVE_CUE 0x60
66#define SCI_MIDI_CHANNEL_SOUND_OFF 0x78 /* all-sound-off for Bn */
67#define SCI_MIDI_CHANNEL_NOTES_OFF 0x7B /* all-notes-off for Bn */
68
69#define SCI_MIDI_SET_SIGNAL_LOOP 0x7F
70/* If this is the parameter of 0xCF, the loop point is set here */
71
72#define SCI_MIDI_CONTROLLER(status) ((status & 0xF0) == 0xB0)
73
75protected:
76 MidiDriver *_driver;
77 int8 _reverb;
78
79public:
80 MidiPlayer() : _driver(nullptr), _reverb(-1) {}
81
82 virtual int open() { return _driver->open(); }
83 virtual void close() { _driver->close(); }
84 void send(uint32 b) override { _driver->send(b); }
85 virtual uint32 getBaseTempo() { return _driver->getBaseTempo(); }
86 virtual bool hasRhythmChannel() const = 0;
87 virtual void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) { _driver->setTimerCallback(timer_param, timer_proc); }
88
89 virtual byte getPlayId() const = 0;
90 virtual int getPolyphony() const = 0;
91 virtual int getFirstChannel() const { return 0; }
92 virtual int getLastChannel() const { return 15; }
93
94 virtual void setVolume(byte volume) {
95 if(_driver)
96 _driver->property(MIDI_PROP_MASTER_VOLUME, volume);
97 }
98
99 virtual int getVolume() {
100 return _driver ? _driver->property(MIDI_PROP_MASTER_VOLUME, 0xffff) : 0;
101 }
102
103 // Returns the current reverb, or -1 when no reverb is active
104 int8 getReverb() const { return _reverb; }
105 // Sets the current reverb, used mainly in MT-32
106 virtual void setReverb(int8 reverb) { _reverb = reverb; }
107
108 virtual void playSwitch(bool play) {
109 if (!play) {
110 // Send "All Sound Off" on all channels
111 for (int i = 0; i < MIDI_CHANNELS; ++i)
112 _driver->send(0xb0 + i, SCI_MIDI_CHANNEL_NOTES_OFF, 0);
113 }
114 }
115};
116
117class SciResource;
118
119extern SciResource *getMidiPatchData(int num);
120
121extern MidiPlayer *MidiPlayer_AdLib_create();
122extern MidiPlayer *MidiPlayer_AmigaMac1_create(Common::Platform platform);
123extern MidiPlayer *MidiPlayer_CMS_create();
124extern MidiPlayer *MidiPlayer_PCJr_create();
125extern MidiPlayer *MidiPlayer_PCSpeaker_create();
126extern MidiPlayer *MidiPlayer_Midi_create();
127
128} // End of namespace Dgds
129
130#endif // DGDS_SOUND_DRIVERS_MIDIDRIVER_H
void(* TimerProc)(void *refCon)
Definition: timer.h:42
Definition: mididriver.h:74
void send(uint32 b) override
Definition: mididriver.h:84
Definition: mididrv.h:114
virtual void send(uint32 b)=0
Definition: mididrv.h:313
virtual int open()=0
virtual void close()=0
virtual uint32 property(int prop, uint32 param)
Definition: mididrv.h:499
virtual uint32 getBaseTempo()=0
Platform
Definition: platform.h:93