1
/* ScummVM - Graphic Adventure Engine
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.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
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.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26
#ifndef SOUND_MIDIPLAYER_H
27
#define SOUND_MIDIPLAYER_H
29
#include "common/scummsys.h"
30
#include "common/mutex.h"
31
#include "audio/mididrv.h"
38
* Simple MIDI playback class.
40
* @note Currently incomplete, as it lacks play() methods. This is just a
41
* start of the real thing, which tries to include code replicated between
42
* several of our engines.
44
* Eventually, this should offer ways to start playback of SMF and XMIDI
45
* data (and possibly make it easy to add further playback methods),
46
* should be able to automatically instantiate _driver as needed,
47
* should perform memory management on the MidiParser object(s) being
48
* used, and possibly more.
50
* Also, pause/resume handling should be unified (we provide an implementation,
51
* but several subclasses use different ones).
53
* Also, care should be taken to ensure that mutex locking is done right.
55
* @todo Document origin of this class. It is based on code shared by
56
* several engines (e.g. DRACI says it copied it from MADE, which took
59
class MidiPlayer : public MidiDriver_BASE {
64
// TODO: Implement ways to actually play stuff
65
//virtual void play(TODO);
67
// TODO: Document these
70
virtual void resume();
73
* Return whether there is currently any MIDI music playing.
75
* @todo There is a subtle difference between the semantics of this in
76
* various subclasses, related to paused music: Namely, should this
77
* function return true or false if a MIDI song is currently loaded,
78
* but paused? In the base implementation of pause/resume, "false"
79
* will be returned (that is, it is not possible to distinguish between
80
* nothing being played, and an active but paused MIDI tune).
81
* But in several subclasses (e.g. in HUGO), there is a separate _paused
82
* variable, which is used to pause playback, and for these, "true"
84
* And in SAGA, isPlaying is overwritten to return the value
85
* of _parser->isPlaying() (which should amount to "true" in the
86
* described situation).
87
* We really should unify this and clearly define the desired
88
* semantics of this method.
90
bool isPlaying() const { return _isPlaying; }
93
* Return the currently active master volume, in the range 0-255.
95
int getVolume() const { return _masterVolume; }
98
* Set the master volume to the specified value in the range 0-255.
99
* (values outside this range are automatically clipped).
100
* This may cause suitable MIDI events to be sent to active channels.
102
* @todo This method currently does not do anything if the new volume
103
* matches the old volume. But some engines always update the
104
* volume (Parallaction, Tinsel, Touche, ...). This is why
105
* this method is currently virtual. We really should figure
106
* which way to do it, and then make this the default, and make
107
* this method non-virtual again.
109
virtual void setVolume(int volume);
112
* Update the volume according to the ConfMan's 'music_volume'
113
* setting. also respects the 'mute' setting.
117
// TODO: Document this
118
bool hasNativeMT32() const { return _nativeMT32; }
120
// MidiDriver_BASE implementation
121
virtual void send(uint32 b);
122
virtual void metaEvent(byte type, byte *data, uint16 length);
126
* This method is invoked by the default send() implementation,
127
* after suitably filtering the message b.
129
virtual void sendToChannel(byte ch, uint32 b);
132
* This method is invoked by metaEvent when an end-of-track
133
* event arrives. By default, this tells the parser
134
* to jump to the start (if looping is enabled) resp.
136
* Overload this to customize behavior.
138
virtual void endOfTrack();
140
// TODO: Document this
141
virtual void onTimer();
143
static void timerCallback(void *data);
145
void createDriver(int flags = MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM);
150
* The number of MIDI channels supported.
155
Common::Mutex _mutex;
159
* A MidiParser instances, to be created by methods of a MidiPlayer
161
* @note The stop() method (and hence the destructor) invoke the
162
* unloadMusic() method of _parser and then delete it.
167
* This is an (optional) pointer to a malloc'ed buffer containing
168
* MIDI data used by _parser. The stop() method (and hence the
169
* destructor) will free this if set.
170
* Subclasses of this class may use _midiData, but don't have to
174
MidiChannel *_channelsTable[kNumChannels];
175
uint8 _channelsVolume[kNumChannels];
181
* The master volume, in the range 0-255.
183
int _masterVolume; // FIXME: byte or int ?
189
} // End of namespace Audio