aboutsummaryrefslogtreecommitdiff
path: root/engines/agos/drivers/simon1/adlib.h
blob: 6057bf1b16aec8b9c2c5bd1d2577882ceee18878 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* 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.
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#ifndef AGOS_SIMON1_ADLIB_H
#define AGOS_SIMON1_ADLIB_H

#include "audio/mididrv.h"
#include "audio/fmopl.h"

namespace AGOS {

class MidiDriver_Simon1_AdLib : public MidiDriver {
public:
	MidiDriver_Simon1_AdLib(const byte *instrumentData);
	virtual ~MidiDriver_Simon1_AdLib();

	// MidiDriver API
	virtual int open();
	virtual bool isOpen() const;
	virtual void close();

	virtual void send(uint32 b);

	virtual void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc);
	virtual uint32 getBaseTempo();

	virtual MidiChannel *allocateChannel() { return 0; }
	virtual MidiChannel *getPercussionChannel() { return 0; }
private:
	bool _isOpen;

	OPL::OPL *_opl;

	Common::TimerManager::TimerProc _timerProc;
	void *_timerParam;
	void onTimer();

	void reset();
	void resetOPLVoices();

	void resetRhythm();
	int _melodyVoices;
	uint8 _amvdrBits;
	bool _rhythmEnabled;

	enum {
		kNumberOfVoices = 11,
		kNumberOfMidiChannels = 16
	};

	struct Voice {
		Voice();

		uint channel;
		uint note;
		uint instrTotalLevel;
		uint instrScalingLevel;
		uint frequency;
	};

	void resetVoices();
	int allocateVoice(uint channel);

	Voice _voices[kNumberOfVoices];
	uint _midiPrograms[kNumberOfMidiChannels];

	void noteOff(uint channel, uint note);
	void noteOn(uint channel, uint note, uint velocity);
	void noteOnRhythm(uint channel, uint note, uint velocity);
	void controlChange(uint channel, uint controller, uint value);
	void programChange(uint channel, uint program);

	void setupInstrument(uint voice, uint instrument);
	const byte *_instruments;

	static const int _operatorMap[9];
	static const int _operatorDefaults[8];

	static const int _rhythmOperatorMap[5];
	static const uint _rhythmInstrumentMask[5];
	static const int _rhythmVoiceMap[5];

	static const int _frequencyIndexAndOctaveTable[128];
	static const int _frequencyTable[16];

	struct RhythmMap {
		int channel;
		int program;
		int note;
	};

	static const RhythmMap _rhythmMap[39];
};

MidiDriver *createMidiDriverSimon1AdLib(const char *instrumentFilename);

} // End of namespace AGOS

#endif