aboutsummaryrefslogtreecommitdiff
path: root/simon/midi.h
blob: bbe5bf725c81cf9ed05c0fb6ab97e879ac14d04b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2001-2003 The ScummVM project
 *
 * 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
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header$
 *
 */

#ifndef SIMON_MIDI_H
#define SIMON_MIDI_H

#include "sound/mididrv.h"
#include "sound/midiparser.h"

class File;
class OSystem;

class MidiPlayer : public MidiDriver {
protected:
	OSystem *_system;
	void *_mutex;
	MidiDriver *_driver;
	MidiParser *_parser;

	byte *_data;
	byte _volumeTable[16]; // 0-127
	byte _masterVolume;    // 0-255
	bool _paused;
	byte _currentTrack;
	bool _loopTrack;
	byte _queuedTrack;
	bool _loopQueuedTrack;

	byte _num_songs;
	byte *_songs[16];
	uint32 _song_sizes[16];

	static void onTimer (void *data);
	void clearConstructs();

public:
	bool _midi_sfx_toggle;

	MidiPlayer (OSystem *system);
	virtual ~MidiPlayer();

	void loadSMF (File *in, int song);
	void loadMultipleSMF (File *in);
	void loadXMIDI (File *in);

	void setLoop (bool loop);
	void startTrack(int track);
	void queueTrack (int track, bool loop);
	bool isPlaying (bool check_queued = false) { return (_currentTrack != 255 && (_queuedTrack != 255 || !check_queued)); }

	void stop();
	void pause (bool b);

	int  get_volume() { return _masterVolume; }
	void set_volume (int volume);
	void set_driver (MidiDriver *md);

public:
	// MidiDriver interface implementation
	int open();
	void close();
	void send(uint32 b);

	void metaEvent (byte type, byte *data, uint16 length);

	// Timing functions - MidiDriver now operates timers
	void setTimerCallback (void *timer_param, void (*timer_proc) (void *)) { }
	uint32 getBaseTempo (void) { return _driver ? _driver->getBaseTempo() : 0x4A0000; }

	// Channel allocation functions
	MidiChannel *allocateChannel() { return 0; }
	MidiChannel *getPercussionChannel() { return 0; }
};

#endif