ScummVM API documentation
mididrv_ms.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_MIDIDRV_MS_H
23#define AUDIO_MIDIDRV_MS_H
24
25#include "common/mutex.h"
26
27#include "audio/mididrv.h"
28
87public:
92 static const uint8 MAXIMUM_SOURCES = 10;
100 static const uint16 DEFAULT_SOURCE_NEUTRAL_VOLUME = 255;
101
102protected:
103 // Timeout between updates of the channel volume for fades (25ms)
104 static const uint16 FADING_DELAY = 25 * 1000;
105
106public:
123 };
124
141 };
142
148 CONTROLLER_DEFAULT_PROGRAM,
149 CONTROLLER_DEFAULT_INSTRUMENT_BANK,
150 CONTROLLER_DEFAULT_DRUMKIT,
151 CONTROLLER_DEFAULT_CHANNEL_PRESSURE,
152 CONTROLLER_DEFAULT_PITCH_BEND,
153 CONTROLLER_DEFAULT_MODULATION,
154 CONTROLLER_DEFAULT_VOLUME,
155 CONTROLLER_DEFAULT_PANNING,
156 CONTROLLER_DEFAULT_EXPRESSION,
157 CONTROLLER_DEFAULT_SUSTAIN,
158 CONTROLLER_DEFAULT_RPN,
159 CONTROLLER_DEFAULT_PITCH_BEND_SENSITIVITY,
160 CONTROLLER_DEFAULT_REVERB,
161 CONTROLLER_DEFAULT_CHORUS
162 };
163
164protected:
165 // This stores data about a specific source of MIDI data.
166 struct MidiSource {
167 // Whether this source sends music or SFX MIDI data.
168 SourceType type;
169 // The source volume (relative volume for this source as defined by the
170 // game). Default is the default neutral value (255).
171 uint16 volume;
172 // The source volume level at which no scaling is performed (volume as
173 // defined in the MIDI data is used directly). Volume values below this
174 // decrease volume, values above increase volume (up to the maximum MIDI
175 // channel volume). Set this to match the volume values used by the game
176 // engine to avoid having to convert them. Default value is 255; minimum
177 // value is 1.
178 uint16 neutralVolume;
179 // The volume level at which the fade started.
180 uint16 fadeStartVolume;
181 // The target volume level for the fade.
182 uint16 fadeEndVolume;
183 // How much time (microseconds) has passed since the start of the fade.
184 int32 fadePassedTime;
185 // The total duration of the fade (microseconds).
186 int32 fadeDuration;
187
188 MidiSource();
189 };
190
191 // Stores the default values that should be set for each controller.
192 // -1 means no explicit default should be set for that controller.
194 int8 program[16];
195 int8 instrumentBank;
196 int8 drumkit;
197
198 int8 channelPressure;
199 int16 pitchBend;
200
201 int8 modulation;
202 int8 volume;
203 int8 panning;
204 int8 expression;
205 int8 sustain;
206 int8 reverb;
207 int8 chorus;
208 int16 rpn;
209
210 int8 pitchBendSensitivity;
211
213 };
214
215public:
217
218 // MidiDriver functions
220 void send(uint32 b) override;
221 void send(int8 source, uint32 b) override = 0;
222
223 uint32 property(int prop, uint32 param) override;
224
231 virtual void deinitSource(uint8 source);
244 void setSourceType(uint8 source, SourceType type);
250 void setSourceVolume(uint16 volume);
258 void setSourceVolume(uint8 source, uint16 volume);
266 void resetSourceVolume(uint8 source);
273 void setSourceNeutralVolume(uint16 volume);
283 void setSourceNeutralVolume(uint8 source, uint16 volume);
284
292 void startFade(uint16 duration, uint16 targetVolume);
302 void startFade(uint8 source, uint16 duration, uint16 targetVolume);
321 void abortFade(uint8 source, FadeAbortType abortType = FADE_ABORT_TYPE_END_VOLUME);
327 bool isFading();
333 bool isFading(uint8 source);
334
373 void setControllerDefaults(ControllerDefaultType type, const int16 *values);
380
394 void setInstrumentRemapping(const byte *instrumentRemapping);
395
403
416 virtual void stopAllNotes(uint8 source, uint8 channel) = 0;
417
428 void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) override {
429 _timer_param = timer_param;
430 _timer_proc = timer_proc;
431 }
432
433protected:
442 virtual void applySourceVolume(uint8 source) = 0;
451 virtual void onTimer();
452
453 // MIDI source data
454 MidiSource _sources[MAXIMUM_SOURCES];
455
456 // Default values for each controller
457 ControllerDefaults _controllerDefaults;
458
459 // Map for arbitrary instrument remapping.
460 const byte *_instrumentRemapping;
461
462 // True if the driver should scale MIDI channel volume to the user
463 // specified volume settings.
464 bool _userVolumeScaling;
465
466 // User volume settings
467 uint16 _userMusicVolume;
468 uint16 _userSfxVolume;
469 bool _userMute;
470 bool _userMusicMute;
471 bool _userSfxMute;
472
473 Common::Mutex _fadingMutex; // For operations on fades
474
475 // The number of microseconds to wait before the next fading step.
476 uint16 _fadeDelay;
477
478 // The number of microseconds between timer callback invocations.
479 uint32 _timerRate;
480
481 // External timer callback
482 void *_timer_param;
484};
485
487public:
488 int open() override;
489 bool isOpen() const override { return true; }
490 void close() override;
491 uint32 getBaseTempo() override { return 10000; }
492 MidiChannel *allocateChannel() override { return 0; }
493 MidiChannel *getPercussionChannel() override { return 0; }
494
496 void send(int8 source, uint32 b) override { }
498 void stopAllNotes(uint8 source, uint8 channel) override { }
499
500 static void timerCallback(void *data);
501
502protected:
503 void applySourceVolume(uint8 source) override { }
504};
505
506#endif
Definition: mutex.h:67
void(* TimerProc)(void *refCon)
Definition: timer.h:42
Definition: mididrv.h:541
virtual void stopAllNotes(bool stopSustainedNotes=false)
virtual void send(uint32 b)=0
Definition: mididrv_ms.h:86
void setSourceNeutralVolume(uint16 volume)
bool isFading(uint8 source)
void setSourceVolume(uint16 volume)
void setInstrumentRemapping(const byte *instrumentRemapping)
void setControllerDefaults(ControllerDefaultType type, const int16 *values)
void setControllerDefault(ControllerDefaultType type, int16 value)
virtual void onTimer()
void setSourceNeutralVolume(uint8 source, uint16 volume)
void abortFade(uint8 source, FadeAbortType abortType=FADE_ABORT_TYPE_END_VOLUME)
virtual void stopAllNotes(uint8 source, uint8 channel)=0
void startFade(uint8 source, uint16 duration, uint16 targetVolume)
static const uint8 MAXIMUM_SOURCES
Definition: mididrv_ms.h:92
void abortFade(FadeAbortType abortType=FADE_ABORT_TYPE_END_VOLUME)
void setSourceType(SourceType type)
uint32 property(int prop, uint32 param) override
void send(int8 source, uint32 b) override=0
void clearControllerDefault(ControllerDefaultType type)
void setControllerDefault(ControllerDefaultType type)
void setSourceType(uint8 source, SourceType type)
ControllerDefaultType
Definition: mididrv_ms.h:147
void send(uint32 b) override
void setSourceVolume(uint8 source, uint16 volume)
void resetSourceVolume(uint8 source)
void startFade(uint16 duration, uint16 targetVolume)
virtual void deinitSource(uint8 source)
static const uint16 DEFAULT_SOURCE_NEUTRAL_VOLUME
Definition: mididrv_ms.h:100
void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) override
Definition: mididrv_ms.h:428
FadeAbortType
Definition: mididrv_ms.h:128
@ FADE_ABORT_TYPE_START_VOLUME
Definition: mididrv_ms.h:140
@ FADE_ABORT_TYPE_END_VOLUME
Definition: mididrv_ms.h:132
@ FADE_ABORT_TYPE_CURRENT_VOLUME
Definition: mididrv_ms.h:136
virtual void applySourceVolume(uint8 source)=0
SourceType
Definition: mididrv_ms.h:110
@ SOURCE_TYPE_SFX
Definition: mididrv_ms.h:122
@ SOURCE_TYPE_MUSIC
Definition: mididrv_ms.h:118
@ SOURCE_TYPE_UNDEFINED
Definition: mididrv_ms.h:114
Definition: mididrv_ms.h:486
void stopAllNotes(uint8 source, uint8 channel) override
Definition: mididrv_ms.h:498
bool isOpen() const override
Definition: mididrv_ms.h:489
uint32 getBaseTempo() override
Definition: mididrv_ms.h:491
void applySourceVolume(uint8 source) override
Definition: mididrv_ms.h:503
void send(int8 source, uint32 b) override
Definition: mididrv_ms.h:496
Definition: mididrv.h:313
Definition: mididrv_ms.h:193
Definition: mididrv_ms.h:166