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 
87 public:
92  static const uint8 MAXIMUM_SOURCES = 10;
100  static const uint16 DEFAULT_SOURCE_NEUTRAL_VOLUME = 255;
101 
102 protected:
103  // Timeout between updates of the channel volume for fades (25ms)
104  static const uint16 FADING_DELAY = 25 * 1000;
105 
106 public:
110  enum SourceType {
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 
164 protected:
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 
215 public:
217 
218  // MidiDriver functions
219  using MidiDriver_BASE::send;
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);
237  void setSourceType(SourceType type);
244  void setSourceType(uint8 source, SourceType type);
250  void setSourceVolume(uint16 volume);
258  void setSourceVolume(uint8 source, uint16 volume);
262  void resetSourceVolume();
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 
359  void setControllerDefault(ControllerDefaultType type, int16 value);
373  void setControllerDefaults(ControllerDefaultType type, const int16 *values);
380 
394  void setInstrumentRemapping(const byte *instrumentRemapping);
395 
402  void syncSoundSettings();
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 
433 protected:
442  virtual void applySourceVolume(uint8 source) = 0;
446  void updateFading();
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 
471  Common::Mutex _fadingMutex; // For operations on fades
472 
473  // The number of microseconds to wait before the next fading step.
474  uint16 _fadeDelay;
475 
476  // The number of microseconds between timer callback invocations.
477  uint32 _timerRate;
478 
479  // External timer callback
480  void *_timer_param;
482 };
483 
485 public:
486  int open() override;
487  bool isOpen() const override { return true; }
488  void close() override;
489  uint32 getBaseTempo() override { return 10000; }
490  MidiChannel *allocateChannel() override { return 0; }
491  MidiChannel *getPercussionChannel() override { return 0; }
492 
494  void send(int8 source, uint32 b) override { }
496  void stopAllNotes(uint8 source, uint8 channel) override { }
497 
498  static void timerCallback(void *data);
499 
500 protected:
501  void applySourceVolume(uint8 source) override { }
502 };
503 
504 #endif
void stopAllNotes(uint8 source, uint8 channel) override
Definition: mididrv_ms.h:496
void setSourceVolume(uint16 volume)
void clearControllerDefault(ControllerDefaultType type)
void send(int8 source, uint32 b) override
Definition: mididrv_ms.h:494
uint32 getBaseTempo() override
Definition: mididrv_ms.h:489
virtual void deinitSource(uint8 source)
Definition: mididrv_ms.h:86
void setSourceNeutralVolume(uint16 volume)
void setControllerDefaults(ControllerDefaultType type, const int16 *values)
void(* TimerProc)(void *refCon)
Definition: timer.h:42
virtual void stopAllNotes(uint8 source, uint8 channel)=0
Definition: mididrv_ms.h:118
virtual void stopAllNotes(bool stopSustainedNotes=false)
Definition: mididrv.h:313
virtual int open()=0
virtual void onTimer()
virtual void close()=0
ControllerDefaultType
Definition: mididrv_ms.h:147
void applySourceVolume(uint8 source) override
Definition: mididrv_ms.h:501
static const uint8 MAXIMUM_SOURCES
Definition: mididrv_ms.h:92
FadeAbortType
Definition: mididrv_ms.h:128
void setControllerDefault(ControllerDefaultType type)
SourceType
Definition: mididrv_ms.h:110
Definition: mididrv_ms.h:484
void startFade(uint16 duration, uint16 targetVolume)
Definition: mutex.h:67
void abortFade(FadeAbortType abortType=FADE_ABORT_TYPE_END_VOLUME)
void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) override
Definition: mididrv_ms.h:428
Definition: mididrv.h:541
uint32 property(int prop, uint32 param) override
void send(uint32 b) override
Definition: mididrv_ms.h:193
static const uint16 DEFAULT_SOURCE_NEUTRAL_VOLUME
Definition: mididrv_ms.h:100
virtual void applySourceVolume(uint8 source)=0
bool isOpen() const override
Definition: mididrv_ms.h:487
Definition: mididrv_ms.h:166
void setInstrumentRemapping(const byte *instrumentRemapping)
virtual void send(uint32 b)=0
Definition: mididrv_ms.h:122
void setSourceType(SourceType type)