2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-08-18 16:21:34 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-08-18 16:21:34 +00:00
|
|
|
*
|
2006-02-11 12:46:41 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2002-08-18 16:21:34 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-09-29 08:14:27 +00:00
|
|
|
#ifndef AGOS_MIDI_H
|
|
|
|
#define AGOS_MIDI_H
|
2002-08-18 16:21:34 +00:00
|
|
|
|
2003-05-18 23:55:53 +00:00
|
|
|
#include "sound/mididrv.h"
|
|
|
|
#include "sound/midiparser.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
#include "common/mutex.h"
|
2002-08-18 16:21:34 +00:00
|
|
|
|
2005-05-10 22:56:25 +00:00
|
|
|
namespace Common {
|
|
|
|
class File;
|
|
|
|
}
|
2002-11-18 09:08:45 +00:00
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
namespace AGOS {
|
2003-10-03 19:42:27 +00:00
|
|
|
|
2003-05-24 01:26:05 +00:00
|
|
|
struct MusicInfo {
|
|
|
|
MidiParser *parser;
|
2006-05-12 08:49:04 +00:00
|
|
|
byte *data;
|
|
|
|
byte num_songs; // For Type 1 SMF resources
|
|
|
|
byte *songs[16]; // For Type 1 SMF resources
|
2003-05-24 03:55:37 +00:00
|
|
|
uint32 song_sizes[16]; // For Type 1 SMF resources
|
2003-08-11 05:25:33 +00:00
|
|
|
|
2003-05-24 03:55:37 +00:00
|
|
|
MidiChannel *channel[16]; // Dynamic remapping of channels to resolve conflicts
|
2003-08-11 05:25:33 +00:00
|
|
|
byte volume[16]; // Current channel volume
|
2003-05-24 01:26:05 +00:00
|
|
|
|
|
|
|
MusicInfo() { clear(); }
|
|
|
|
void clear() {
|
|
|
|
parser = 0; data = 0; num_songs = 0;
|
2006-05-12 08:49:04 +00:00
|
|
|
memset(songs, 0, sizeof(songs));
|
|
|
|
memset(song_sizes, 0, sizeof(song_sizes));
|
|
|
|
memset(channel, 0, sizeof(channel));
|
2003-05-24 01:26:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2003-05-18 23:55:53 +00:00
|
|
|
class MidiPlayer : public MidiDriver {
|
|
|
|
protected:
|
2005-01-28 22:05:51 +00:00
|
|
|
Common::Mutex _mutex;
|
2003-05-18 23:55:53 +00:00
|
|
|
MidiDriver *_driver;
|
2003-07-14 08:29:17 +00:00
|
|
|
bool _map_mt32_to_gm;
|
2004-10-23 00:02:38 +00:00
|
|
|
bool _passThrough;
|
2002-08-18 16:21:34 +00:00
|
|
|
|
2003-05-24 01:26:05 +00:00
|
|
|
MusicInfo _music;
|
|
|
|
MusicInfo _sfx;
|
|
|
|
MusicInfo *_current; // Allows us to establish current context for operations.
|
|
|
|
|
|
|
|
// These are maintained for both music and SFX
|
2002-11-18 09:08:45 +00:00
|
|
|
byte _masterVolume; // 0-255
|
|
|
|
bool _paused;
|
2003-05-24 01:26:05 +00:00
|
|
|
|
|
|
|
// These are only used for music.
|
2003-05-18 23:55:53 +00:00
|
|
|
byte _currentTrack;
|
2003-05-21 04:36:09 +00:00
|
|
|
bool _loopTrack;
|
|
|
|
byte _queuedTrack;
|
|
|
|
bool _loopQueuedTrack;
|
2002-08-18 16:21:34 +00:00
|
|
|
|
2003-08-11 05:25:33 +00:00
|
|
|
protected:
|
2006-05-12 08:49:04 +00:00
|
|
|
static void onTimer(void *data);
|
2003-05-18 23:55:53 +00:00
|
|
|
void clearConstructs();
|
2006-05-12 08:49:04 +00:00
|
|
|
void clearConstructs(MusicInfo &info);
|
2003-08-11 05:25:33 +00:00
|
|
|
void resetVolumeTable();
|
2002-08-18 16:21:34 +00:00
|
|
|
|
2003-05-18 23:55:53 +00:00
|
|
|
public:
|
2003-05-24 01:26:05 +00:00
|
|
|
bool _enable_sfx;
|
2003-05-18 23:55:53 +00:00
|
|
|
|
2003-05-24 01:26:05 +00:00
|
|
|
public:
|
2007-02-16 13:41:38 +00:00
|
|
|
MidiPlayer();
|
2003-05-19 00:24:11 +00:00
|
|
|
virtual ~MidiPlayer();
|
2002-08-18 16:21:34 +00:00
|
|
|
|
2006-05-12 08:49:04 +00:00
|
|
|
void loadSMF(Common::File *in, int song, bool sfx = false);
|
|
|
|
void loadMultipleSMF(Common::File *in, bool sfx = false);
|
|
|
|
void loadXMIDI(Common::File *in, bool sfx = false);
|
|
|
|
void loadS1D(Common::File *in, bool sfx = false);
|
2003-05-21 04:36:09 +00:00
|
|
|
|
2006-05-12 08:49:04 +00:00
|
|
|
void mapMT32toGM(bool map);
|
|
|
|
void setLoop(bool loop);
|
2003-05-21 06:13:47 +00:00
|
|
|
void startTrack(int track);
|
2006-05-12 08:49:04 +00:00
|
|
|
void queueTrack(int track, bool loop);
|
|
|
|
bool isPlaying(bool check_queued = false) { return (_currentTrack != 255 && (_queuedTrack != 255 || !check_queued)); }
|
2003-05-21 04:36:09 +00:00
|
|
|
|
2003-05-18 23:55:53 +00:00
|
|
|
void stop();
|
2006-05-12 08:49:04 +00:00
|
|
|
void pause(bool b);
|
2002-08-18 16:21:34 +00:00
|
|
|
|
2006-10-21 01:51:59 +00:00
|
|
|
int getVolume() { return _masterVolume; }
|
|
|
|
void setVolume(int volume);
|
|
|
|
void setDriver(MidiDriver *md);
|
2003-05-18 23:55:53 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// MidiDriver interface implementation
|
|
|
|
int open();
|
|
|
|
void close();
|
|
|
|
void send(uint32 b);
|
2002-08-18 16:21:34 +00:00
|
|
|
|
2006-05-12 08:49:04 +00:00
|
|
|
void metaEvent(byte type, byte *data, uint16 length);
|
2004-10-23 00:02:38 +00:00
|
|
|
void setPassThrough(bool b) { _passThrough = b; }
|
2002-08-18 16:21:34 +00:00
|
|
|
|
2003-05-18 23:55:53 +00:00
|
|
|
// Timing functions - MidiDriver now operates timers
|
2006-05-12 08:49:04 +00:00
|
|
|
void setTimerCallback(void *timer_param, void (*timer_proc) (void *)) { }
|
|
|
|
uint32 getBaseTempo(void) { return _driver ? _driver->getBaseTempo() : 0; }
|
2002-08-18 16:21:34 +00:00
|
|
|
|
2003-05-18 23:55:53 +00:00
|
|
|
// Channel allocation functions
|
|
|
|
MidiChannel *allocateChannel() { return 0; }
|
|
|
|
MidiChannel *getPercussionChannel() { return 0; }
|
2002-08-18 16:21:34 +00:00
|
|
|
};
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
} // End of namespace AGOS
|
2003-10-03 19:42:27 +00:00
|
|
|
|
2002-08-18 16:21:34 +00:00
|
|
|
#endif
|