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  };
161 
162 protected:
163  // This stores data about a specific source of MIDI data.
164  struct MidiSource {
165  // Whether this source sends music or SFX MIDI data.
166  SourceType type;
167  // The source volume (relative volume for this source as defined by the
168  // game). Default is the default neutral value (255).
169  uint16 volume;
170  // The source volume level at which no scaling is performed (volume as
171  // defined in the MIDI data is used directly). Volume values below this
172  // decrease volume, values above increase volume (up to the maximum MIDI
173  // channel volume). Set this to match the volume values used by the game
174  // engine to avoid having to convert them. Default value is 255; minimum
175  // value is 1.
176  uint16 neutralVolume;
177  // The volume level at which the fade started.
178  uint16 fadeStartVolume;
179  // The target volume level for the fade.
180  uint16 fadeEndVolume;
181  // How much time (microseconds) has passed since the start of the fade.
182  int32 fadePassedTime;
183  // The total duration of the fade (microseconds).
184  int32 fadeDuration;
185 
186  MidiSource();
187  };
188 
189  // Stores the default values that should be set for each controller.
190  // -1 means no explicit default should be set for that controller.
192  int8 program[16];
193  int8 instrumentBank;
194  int8 drumkit;
195 
196  int8 channelPressure;
197  int16 pitchBend;
198 
199  int8 modulation;
200  int8 volume;
201  int8 panning;
202  int8 expression;
203  int8 sustain;
204  int16 rpn;
205 
206  int8 pitchBendSensitivity;
207 
209  };
210 
211 public:
213 
214  // MidiDriver functions
215  using MidiDriver_BASE::send;
216  void send(uint32 b) override;
217  void send(int8 source, uint32 b) override = 0;
218 
219  uint32 property(int prop, uint32 param) override;
220 
227  virtual void deinitSource(uint8 source);
233  void setSourceType(SourceType type);
240  void setSourceType(uint8 source, SourceType type);
246  void setSourceVolume(uint16 volume);
254  void setSourceVolume(uint8 source, uint16 volume);
258  void resetSourceVolume();
262  void resetSourceVolume(uint8 source);
269  void setSourceNeutralVolume(uint16 volume);
279  void setSourceNeutralVolume(uint8 source, uint16 volume);
280 
288  void startFade(uint16 duration, uint16 targetVolume);
298  void startFade(uint8 source, uint16 duration, uint16 targetVolume);
317  void abortFade(uint8 source, FadeAbortType abortType = FADE_ABORT_TYPE_END_VOLUME);
323  bool isFading();
329  bool isFading(uint8 source);
330 
355  void setControllerDefault(ControllerDefaultType type, int16 value);
369  void setControllerDefaults(ControllerDefaultType type, int16 *values);
376 
390  void setInstrumentRemapping(const byte *instrumentRemapping);
391 
398  void syncSoundSettings();
399 
412  virtual void stopAllNotes(uint8 source, uint8 channel) = 0;
413 
424  void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) override {
425  _timer_param = timer_param;
426  _timer_proc = timer_proc;
427  }
428 
429 protected:
438  virtual void applySourceVolume(uint8 source) = 0;
442  void updateFading();
447  virtual void onTimer();
448 
449  // MIDI source data
450  MidiSource _sources[MAXIMUM_SOURCES];
451 
452  // Default values for each controller
453  ControllerDefaults _controllerDefaults;
454 
455  // Map for arbitrary instrument remapping.
456  const byte *_instrumentRemapping;
457 
458  // True if the driver should scale MIDI channel volume to the user
459  // specified volume settings.
460  bool _userVolumeScaling;
461 
462  // User volume settings
463  uint16 _userMusicVolume;
464  uint16 _userSfxVolume;
465  bool _userMute;
466 
467  Common::Mutex _fadingMutex; // For operations on fades
468 
469  // The number of microseconds to wait before the next fading step.
470  uint16 _fadeDelay;
471 
472  // The number of microseconds between timer callback invocations.
473  uint32 _timerRate;
474 
475  // External timer callback
476  void *_timer_param;
478 };
479 
481 public:
482  int open() override;
483  bool isOpen() const override { return true; }
484  void close() override;
485  uint32 getBaseTempo() override { return 10000; }
486  MidiChannel *allocateChannel() override { return 0; }
487  MidiChannel *getPercussionChannel() override { return 0; }
488 
490  void send(int8 source, uint32 b) override { }
492  void stopAllNotes(uint8 source, uint8 channel) override { }
493 
494  static void timerCallback(void *data);
495 
496 protected:
497  void applySourceVolume(uint8 source) override { }
498 };
499 
500 #endif
void stopAllNotes(uint8 source, uint8 channel) override
Definition: mididrv_ms.h:492
void setSourceVolume(uint16 volume)
void clearControllerDefault(ControllerDefaultType type)
void send(int8 source, uint32 b) override
Definition: mididrv_ms.h:490
uint32 getBaseTempo() override
Definition: mididrv_ms.h:485
virtual void deinitSource(uint8 source)
Definition: mididrv_ms.h:86
void setSourceNeutralVolume(uint16 volume)
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)
void setControllerDefaults(ControllerDefaultType type, int16 *values)
Definition: mididrv.h:309
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:497
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:480
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:424
Definition: mididrv.h:537
uint32 property(int prop, uint32 param) override
void send(uint32 b) override
Definition: mididrv_ms.h:191
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:483
Definition: mididrv_ms.h:164
void setInstrumentRemapping(const byte *instrumentRemapping)
virtual void send(uint32 b)=0
Definition: mididrv_ms.h:122
void setSourceType(SourceType type)