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 "dgds/sound/scispan.h"
26 #include "dgds/dgds.h"
27 #include "audio/mididrv.h"
28 #include "common/error.h"
29 #include "common/platform.h"
30 
31 namespace Dgds {
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() : _driver(0), _reverb(-1) {}
84 
85  virtual int open() { return _driver->open(); }
86  virtual void close() { _driver->close(); }
87  void send(uint32 b) override { _driver->send(b); }
88  virtual uint32 getBaseTempo() { return _driver->getBaseTempo(); }
89  virtual bool hasRhythmChannel() const = 0;
90  virtual void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) { _driver->setTimerCallback(timer_param, timer_proc); }
91 
92  virtual byte getPlayId() const = 0;
93  virtual int getPolyphony() const = 0;
94  virtual int getFirstChannel() const { return 0; }
95  virtual int getLastChannel() const { return 15; }
96 
97  virtual void setVolume(byte volume) {
98  if(_driver)
99  _driver->property(MIDI_PROP_MASTER_VOLUME, volume);
100  }
101 
102  virtual int getVolume() {
103  return _driver ? _driver->property(MIDI_PROP_MASTER_VOLUME, 0xffff) : 0;
104  }
105 
106  // Returns the current reverb, or -1 when no reverb is active
107  int8 getReverb() const { return _reverb; }
108  // Sets the current reverb, used mainly in MT-32
109  virtual void setReverb(int8 reverb) { _reverb = reverb; }
110 
111  virtual void playSwitch(bool play) {
112  if (!play) {
113  // Send "All Sound Off" on all channels
114  for (int i = 0; i < MIDI_CHANNELS; ++i)
115  _driver->send(0xb0 + i, SCI_MIDI_CHANNEL_NOTES_OFF, 0);
116  }
117  }
118 };
119 
120 class SciResource;
121 
122 extern SciResource *getMidiPatchData(int num);
123 
124 extern MidiPlayer *MidiPlayer_AdLib_create();
125 extern MidiPlayer *MidiPlayer_AmigaMac1_create(Common::Platform platform);
126 extern MidiPlayer *MidiPlayer_CMS_create();
127 extern MidiPlayer *MidiPlayer_PCJr_create();
128 extern MidiPlayer *MidiPlayer_PCSpeaker_create();
129 extern MidiPlayer *MidiPlayer_Midi_create();
130 
131 } // End of namespace Dgds
132 
133 #endif // DGDS_SOUND_DRIVERS_MIDIDRIVER_H
virtual uint32 property(int prop, uint32 param)
Definition: mididrv.h:495
virtual uint32 getBaseTempo()=0
void send(uint32 b) override
Definition: mididriver.h:87
Definition: ads.h:28
void(* TimerProc)(void *refCon)
Definition: timer.h:42
Definition: mididriver.h:77
Definition: mididrv.h:309
virtual int open()=0
virtual void close()=0
Definition: mididrv.h:112
Definition: sci_resource.h:43
virtual void send(uint32 b)=0
Platform
Definition: platform.h:46