ScummVM API documentation
towns_euphony.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 TOWNS_EUP_H
23#define TOWNS_EUP_H
24
25#define EUP_USE_MEMPOOL
26
27#include "audio/softsynth/fmtowns_pc98/towns_audio.h"
28#include "common/array.h"
29#include "common/func.h"
30
31#ifdef EUP_USE_MEMPOOL
32#include "common/memorypool.h"
33#endif
34
36public:
38 virtual ~EuphonyBaseDriver() {}
39
40 virtual bool init() { return true; }
41
42 virtual void send(uint8 command) = 0;
43};
44
45class EuphonyPlayer;
46
48public:
51
52 bool init() override;
53 void reset();
54
55 int assignPartToChannel(int chan, int part);
56
57 void send(uint8 command) override;
58
59 void setTimerA(bool enable, int tempo);
60 void setTimerB(bool enable, int tempo);
61
62 void loadInstrument(int chanType, int id, const uint8 *data);
63 void setInstrument(int chan, int instrID);
64 void loadWaveTable(const uint8 *data);
65 void unloadWaveTable(int id);
66
67 void reserveSoundEffectChannels(int num);
68 void playSoundEffect(int chan, int note, int velo, const uint8 *data);
69 void stopSoundEffect(int chan);
70 bool soundEffectIsPlaying(int chan);
71
72 void channelPan(int chan, int mode);
73 void channelPitch(int chan, int pitch);
74 void channelVolume(int chan, int vol);
75
76 void setOutputVolume(int chanType, int volLeft, int volRight);
77 void cdaToggle(int a);
78
79 void setMusicVolume(int volume);
80 void setSoundEffectVolume(int volume);
81
82private:
83 void noteOff();
84 void noteOn();
85 void controlChange_volume();
86 void controlChange_panPos();
87 void controlChange_allNotesOff();
88 void programChange();
89 void pitchWheel();
90
91 Common::Array<uint8> _currentEvent;
92 int8 *_partToChanMapping;
93 int8 *_sustainChannels;
94
95 struct Channel {
96 int8 part;
97 int8 next;
98 uint8 note;
99 uint8 pri;
100 } *_channels;
101
102 TownsAudioInterface *_intf;
103};
104
106public:
108 ~Type0Driver();
109
110 bool init() override;
111
112 void send(uint8 command) override;
113};
114
116public:
118 virtual ~EuphonyPlayer();
119
120 bool init();
121
122 int startTrack(const uint8 *data, int trackSize, int barLen);
123 void stop();
124 void pause();
125 void resume();
126
127 int setTempo(int tempo);
128 void setLoopStatus(bool loop);
129
130 bool isPlaying() {return _playing; }
131
132 int configPart_enable(int part, int val);
133 int configPart_setType(int part, int val);
134 int configPart_remap(int part, int val);
135 int configPart_adjustVolume(int part, int val);
136 int configPart_setTranspose(int part, int val);
137
138 void timerCallback(int timerId) override;
139
140 EuphonyDriver *driver() { return _eupDriver; }
141
142private:
143 void reset();
144 void resetPartConfig();
145 void resetTempo();
146
147 void updatePulseCounters();
148 void updateBeat();
149 void updateParser();
150 void updateCheckEot();
151
152 bool parseEvent();
153 void proceedToNextEvent();
154
155 void updateHangingNotes();
156 void clearHangingNotes();
157
158 void resetAllControls();
159 void allPartsOff();
160
161 uint8 appendEvent(uint8 evt, uint8 chan);
162
163 bool event_notImpl();
164 bool event_noteOn();
165 bool event_polyphonicAftertouch();
166 bool event_controlChange_pitchWheel();
167 bool event_programChange_channelAftertouch();
168
169 bool event_sysex();
170 bool event_advanceBar();
171 bool event_setTempo();
172 bool event_typeOrdrChange();
173
174 uint8 applyTranspose(uint8 in);
175 uint8 applyVolumeAdjust(uint8 in);
176
177 void sendByte(uint8 type, uint8 command);
178 void sendPendingEvent(int type, int evt, int note, int velo);
179 void sendControllerReset(int type, int part);
180 void sendAllNotesOff(int type, int part);
181 void sendTempo(int tempo);
182
183 uint8 *_partConfig_enable;
184 uint8 *_partConfig_type;
185 uint8 *_partConfig_ordr;
186 int8 *_partConfig_volume;
187 int8 *_partConfig_transpose;
188
189 struct PendingEvent {
190 PendingEvent(int ev, int tp, int nt, int vl, int ln, PendingEvent *chain) : evt(ev), type(tp), note(nt), velo(vl), len(ln), next(chain) {}
191 uint8 evt;
192 uint8 type;
193 uint8 note;
194 uint8 velo;
195 uint16 len;
196 PendingEvent *next;
197 };
198
199#ifdef EUP_USE_MEMPOOL
200 Common::ObjectPool<PendingEvent> _pendingEventsPool;
201#endif
202 PendingEvent *_pendingEventsChain;
203
206 EuphonyEventsArray _euphonyEvents;
207
208 uint8 _defaultBarLength;
209 uint8 _barLength;
210 int _playerUpdatesLeft;
211 int _tempoControlMode;
212 int _updatesPerPulseRemainder;
213 int _updatesPerPulse;
214 int _timerSetting;
215 int8 _tempoMode1PulseCounter;
216 int _tempoModifier;
217 uint32 _bar;
218 uint32 _parseToBar;
219 int8 _tempoMode1UpdateF8;
220 uint8 _deltaTicks;
221 uint32 _beat;
222 uint8 _defaultTempo;
223 int _trackTempo;
224
225 bool _loop;
226 bool _playing;
227 bool _endOfTrack;
228 bool _paused;
229
230 const uint8 *_musicStart;
231 const uint8 *_musicPos;
232 uint32 _musicTrackSize;
233
234 EuphonyDriver *_eupDriver;
235 EuphonyBaseDriver *_drivers[3];
236};
237
238#endif
Definition: mixer.h:70
Definition: func.h:389
Definition: towns_euphony.h:35
Definition: towns_euphony.h:47
Definition: towns_euphony.h:115
Definition: towns_audio.h:37
Definition: towns_audio.h:31
Definition: towns_euphony.h:105