ScummVM API documentation
casio.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 AUDIO_CASIO_H
23 #define AUDIO_CASIO_H
24 
25 #include "audio/mididrv.h"
26 #include "audio/mididrv_ms.h"
27 
57 protected:
58  // Tracks a note currently playing on the device.
59  struct ActiveNote {
60  // The source that played the note (0x7F if no note is tracked).
61  int8 source;
62  // The output MIDI channel on which the note is playing
63  // (0xFF if no note is tracked).
64  uint8 channel;
65  // The MIDI note number of the playing note
66  // (0xFF if no note is tracked).
67  uint8 note;
68  // True if this note is sustained (turned off but held due to the
69  // sustain controller).
70  bool sustained;
71 
72  ActiveNote();
73 
74  // Sets the struct to values indicating no note is currently tracked.
75  void clear();
76  };
77 
78 public:
79  // The maximum polyphony for each output channel.
80  static const int CASIO_CHANNEL_POLYPHONY[4];
81 
82  // Array for remapping instrument numbers from CT-460/CSM-1 to MT-540.
83  static const uint8 INSTRUMENT_REMAPPING_CT460_TO_MT540[30];
84  // Array for remapping instrument numbers from MT-540 to CT-460/CSM-1.
85  static const uint8 INSTRUMENT_REMAPPING_MT540_TO_CT460[30];
86 
87  // The instrument number used for rhythm sounds on the MT-540.
88  static const uint8 RHYTHM_INSTRUMENT_MT540;
89  // The instrument number used for rhythm sounds on the CT-460 and CSM-1.
90  static const uint8 RHYTHM_INSTRUMENT_CT460;
91 
92  // The instrument number used for the bass instruments on the MT-540.
93  static const uint8 BASS_INSTRUMENT_MT540;
94  // The instrument number used for the bass instruments on the CT-460 and
95  // CSM-1.
96  static const uint8 BASS_INSTRUMENT_CT460;
97 
104  MidiDriver_Casio(MusicType midiType);
105  ~MidiDriver_Casio();
106 
107  int open() override;
116  virtual int open(MidiDriver *driver, MusicType deviceType);
117  void close() override;
118  bool isOpen() const override;
119 
120  using MidiDriver_BASE::send;
121  void send(int8 source, uint32 b) override;
122  void metaEvent(int8 source, byte type, byte *data, uint16 length) override;
123 
124  void stopAllNotes(bool stopSustainedNotes = false) override;
125  MidiChannel *allocateChannel() override;
126  MidiChannel *getPercussionChannel() override;
127  uint32 getBaseTempo() override;
128 
129 protected:
142  virtual int8 mapSourceChannel(uint8 source, uint8 dataChannel);
150  virtual void processEvent(int8 source, uint32 b, uint8 outputChannel);
161  virtual void noteOff(byte outputChannel, byte command, byte note, byte velocity, int8 source);
170  virtual void noteOn(byte outputChannel, byte note, byte velocity, int8 source);
180  virtual void programChange(byte outputChannel, byte patchId, int8 source, bool applyRemapping = true);
189  virtual void controlChange(byte outputChannel, byte controllerNumber, byte controllerValue, int8 source);
190 
201  virtual int8 mapNote(byte outputChannel, byte note);
210  virtual byte calculateVelocity(int8 source, byte velocity);
224  virtual byte mapInstrument(byte program, bool applyRemapping = true);
234  virtual bool isRhythmChannel(uint8 outputChannel);
235  // This implementation does nothing, because source volume is applied to
236  // note velocity and cannot be applied immediately.
237  void applySourceVolume(uint8 source) override;
238  void stopAllNotes(uint8 source, uint8 channel) override;
239 
240  // The wrapped MIDI driver.
241  MidiDriver *_driver;
242  // The type of Casio device accessed by the wrapped driver: MT-540 or
243  // CT-460/CSM-1.
244  MusicType _deviceType;
245  // The type of MIDI data supplied to the driver: MT-540 or CT-460/CSM-1.
246  MusicType _midiType;
247  // True if this MIDI driver has been opened.
248  bool _isOpen;
249 
250  // The current instrument on each MIDI output channel. This is the
251  // instrument number as specified in the program change events (before
252  // remapping is applied).
253  byte _instruments[4];
254  // Indicates if each output channel is currently a rhythm channel (i.e. it
255  // has the rhythm instrument set).
256  bool _rhythmChannel[4];
257  // Tracks the notes currently active on the MIDI device.
258  ActiveNote _activeNotes[32];
259  // Tracks the sustain controller status of the output channels.
260  bool _sustain[4];
261 
262  // Optional remapping for rhythm notes. Should point to a 128 byte array
263  // which maps the rhythm note numbers in the input MIDI data to the rhythm
264  // note numbers used by the output device.
265  byte *_rhythmNoteRemapping;
266 
267  // If true the driver will send note off events for notes which are not in
268  // the active note registry. Typically this should be true to prevent
269  // hanging notes in case there are more active notes than can be stored in
270  // the active note registry. Can be set to false if these note offs are not
271  // desirable, f.e. because the driver will be receiving note off events
272  // without corresponding note on events.
273  bool _sendUntrackedNoteOff;
274 
275  // Mutex for operations on active notes.
276  Common::Mutex _mutex;
277 
278 public:
279  static void timerCallback(void *data);
280 };
281 
282 #endif
Definition: casio.h:56
virtual void noteOn(byte outputChannel, byte note, byte velocity, int8 source)
uint32 getBaseTempo() override
virtual byte mapInstrument(byte program, bool applyRemapping=true)
void send(int8 source, uint32 b) override
Definition: mididrv_ms.h:86
MusicType
Definition: mididrv.h:44
virtual int8 mapNote(byte outputChannel, byte note)
void applySourceVolume(uint8 source) override
Definition: mididrv.h:309
void stopAllNotes(bool stopSustainedNotes=false) override
bool isOpen() const override
virtual void processEvent(int8 source, uint32 b, uint8 outputChannel)
virtual byte calculateVelocity(int8 source, byte velocity)
virtual void noteOff(byte outputChannel, byte command, byte note, byte velocity, int8 source)
Definition: mutex.h:67
Definition: casio.h:59
virtual int8 mapSourceChannel(uint8 source, uint8 dataChannel)
Definition: mididrv.h:537
void close() override
MidiDriver_Casio(MusicType midiType)
void metaEvent(int8 source, byte type, byte *data, uint16 length) override
virtual bool isRhythmChannel(uint8 outputChannel)
int open() override
virtual void send(uint32 b)=0
virtual void controlChange(byte outputChannel, byte controllerNumber, byte controllerValue, int8 source)
virtual void programChange(byte outputChannel, byte patchId, int8 source, bool applyRemapping=true)