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 SCI_SOUND_DRIVERS_MIDIDRIVER_H
23 #define SCI_SOUND_DRIVERS_MIDIDRIVER_H
24 
25 #include "sci/sci.h"
26 #include "sci/util.h"
27 #include "audio/mididrv.h"
28 #include "common/error.h"
29 #include "common/platform.h"
30 
31 namespace Sci {
32 
33 // Music patches in SCI games:
34 // ===========================
35 // 1.pat - MT-32 driver music patch
36 // 2.pat - Yamaha FB01 driver music patch
37 // 3.pat - Adlib driver music patch
38 // 4.pat - Casio MT-540 (in earlier SCI0 games)
39 // 4.pat - GM driver music patch (in later games that support GM)
40 // 7.pat (newer) / patch.200 (older) - Mac driver music patch / Casio CSM-1
41 // 9.pat (newer) / patch.005 (older) - Amiga driver music patch
42 // 98.pat - Unknown, found in later SCI1.1 games. A MIDI format patch
43 // 101.pat - CMS/PCjr driver music patch.
44 // Only later PCjr drivers use this patch, earlier ones don't use a patch
45 // bank.001 - older SCI0 Amiga instruments
46 
47 class ResourceManager;
48 
49 enum {
50  MIDI_CHANNELS = 16,
51  MIDI_PROP_MASTER_VOLUME = 0
52 };
53 
54 #define MIDI_RHYTHM_CHANNEL 9
55 
56 /* Special SCI sound stuff */
57 
58 #define SCI_MIDI_TIME_EXPANSION_PREFIX 0xF8
59 #define SCI_MIDI_TIME_EXPANSION_LENGTH 240
60 
61 #define SCI_MIDI_EOT 0xFC
62 #define SCI_MIDI_SET_SIGNAL 0xCF
63 #define SCI_MIDI_SET_POLYPHONY 0x4B
64 #define SCI_MIDI_RESET_ON_SUSPEND 0x4C
65 #define SCI_MIDI_CHANNEL_MUTE 0x4E
66 #define SCI_MIDI_SET_REVERB 0x50
67 #define SCI_MIDI_HOLD 0x52
68 #define SCI_MIDI_CUMULATIVE_CUE 0x60
69 #define SCI_MIDI_CHANNEL_SOUND_OFF 0x78 /* all-sound-off for Bn */
70 #define SCI_MIDI_CHANNEL_NOTES_OFF 0x7B /* all-notes-off for Bn */
71 
72 #define SCI_MIDI_SET_SIGNAL_LOOP 0x7F
73 /* If this is the parameter of 0xCF, the loop point is set here */
74 
75 #define SCI_MIDI_CONTROLLER(status) ((status & 0xF0) == 0xB0)
76 
77 class MidiPlayer : public MidiDriver_BASE {
78 protected:
79  MidiDriver *_driver;
80  int8 _reverb;
81 
82 public:
83  MidiPlayer(SciVersion version) : _driver(0), _reverb(-1), _version(version) { }
84 
85  int open() {
86  ResourceManager *resMan = g_sci->getResMan(); // HACK
87  return open(resMan);
88  }
89  virtual int open(ResourceManager *resMan) { return _driver->open(); }
90  virtual void close() { _driver->close(); }
91  void send(uint32 b) override { _driver->send(b); }
92  virtual uint32 getBaseTempo() { return _driver->getBaseTempo(); }
93  virtual bool hasRhythmChannel() const = 0;
94  virtual void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) { _driver->setTimerCallback(timer_param, timer_proc); }
95 
96  virtual byte getPlayId() const = 0;
97  virtual int getPolyphony() const = 0;
98  virtual int getFirstChannel() const { return 0; }
99  virtual int getLastChannel() const { return 15; }
100 
101  virtual void setVolume(byte volume) {
102  if(_driver)
103  _driver->property(MIDI_PROP_MASTER_VOLUME, volume);
104  }
105 
106  virtual int getVolume() {
107  return _driver ? _driver->property(MIDI_PROP_MASTER_VOLUME, 0xffff) : 0;
108  }
109 
110  // Returns the current reverb, or -1 when no reverb is active
111  int8 getReverb() const { return _reverb; }
112  // Sets the current reverb, used mainly in MT-32
113  virtual void setReverb(int8 reverb) { _reverb = reverb; }
114 
115  virtual void playSwitch(bool play) {
116  if (!play) {
117  // Send "All Sound Off" on all channels
118  for (int i = 0; i < MIDI_CHANNELS; ++i)
119  _driver->send(0xb0 + i, SCI_MIDI_CHANNEL_NOTES_OFF, 0);
120  }
121  }
122 
123  // Prepares the driver for the playback of SCI0 midi tracks.
124  // The main purpose is the assignment of voices ("hardware" sound channels) to the 16 midi parts.
125  // This is basically the predecessor of the 0x4B midi event.
126  // Some drivers also do other things in here.
127  virtual void initTrack(SciSpan<const byte> &) {}
128 
129  // There are several sound drivers which weren' part of the
130  // original game setup and came in the form of aftermarket patches.
131  // This method allows each driver to report missing patch or other
132  // required files which will then be displayed in an error dialog box.
133  // The method returns only a single string (instead of a string list),
134  // because no more than two files will be required.
135  virtual const char *reportMissingFiles() { return 0; }
136 
137 protected:
138  SciVersion _version;
139 };
140 
141 extern MidiPlayer *MidiPlayer_AdLib_create(SciVersion version);
142 extern MidiPlayer *MidiPlayer_AmigaMac0_create(SciVersion version, Common::Platform platform);
143 extern MidiPlayer *MidiPlayer_AmigaMac1_create(SciVersion version, Common::Platform platform);
144 extern MidiPlayer *MidiPlayer_PCJr_create(SciVersion version);
145 extern MidiPlayer *MidiPlayer_PCSpeaker_create(SciVersion version);
146 extern MidiPlayer *MidiPlayer_CMS_create(SciVersion version);
147 extern MidiPlayer *MidiPlayer_MacSci0_create(SciVersion version);
148 extern MidiPlayer *MidiPlayer_Midi_create(SciVersion version);
149 extern MidiPlayer *MidiPlayer_Fb01_create(SciVersion version);
150 extern MidiPlayer *MidiPlayer_Casio_create(SciVersion version, MusicType midiType);
151 extern MidiPlayer *MidiPlayer_FMTowns_create(SciVersion version);
152 extern MidiPlayer *MidiPlayer_PC9801_create(SciVersion version);
153 
154 } // End of namespace Sci
155 
156 #endif // SCI_SOUND_DRIVERS_MIDIDRIVER_H
void send(uint32 b) override
Definition: mididriver.h:91
virtual uint32 property(int prop, uint32 param)
Definition: mididrv.h:495
virtual uint32 getBaseTempo()=0
SciVersion
Definition: detection.h:134
SciEngine * g_sci
MusicType
Definition: mididrv.h:44
void(* TimerProc)(void *refCon)
Definition: timer.h:42
Definition: mididrv.h:309
virtual int open()=0
Definition: resource.h:327
virtual void close()=0
Definition: mididrv.h:112
Definition: console.h:28
Definition: mididriver.h:77
virtual void send(uint32 b)=0
Platform
Definition: platform.h:46