Mercurial > audlegacy-plugins
comparison src/Input/adplug/core/rol.h @ 0:13389e613d67 trunk
[svn] - initial import of audacious-plugins tree (lots to do)
author | nenolod |
---|---|
date | Mon, 18 Sep 2006 01:11:49 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13389e613d67 |
---|---|
1 /* | |
2 * Adplug - Replayer for many OPL2/OPL3 audio file formats. | |
3 * Copyright (C) 1999 - 2004 Simon Peter, <dn.tlp@gmx.net>, et al. | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2.1 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
18 * | |
19 * rol.h - ROL Player by OPLx <oplx@yahoo.com> | |
20 * | |
21 * Visit: http://tenacity.hispeed.com/aomit/oplx/ | |
22 */ | |
23 #ifndef H_ROLPLAYER | |
24 #define H_ROLPLAYER | |
25 | |
26 #include <vector> | |
27 #include <string> | |
28 | |
29 #include "player.h" | |
30 | |
31 class CrolPlayer: public CPlayer | |
32 { | |
33 public: | |
34 static CPlayer *factory(Copl *newopl); | |
35 | |
36 CrolPlayer(Copl *newopl); | |
37 | |
38 ~CrolPlayer(); | |
39 | |
40 bool load (const std::string &filename, const CFileProvider &fp); | |
41 bool update (); | |
42 void rewind (int subsong); // rewinds to specified subsong | |
43 float getrefresh(); // returns needed timer refresh rate | |
44 | |
45 std::string gettype() { return std::string("Adlib Visual Composer"); } | |
46 | |
47 private: | |
48 typedef unsigned short uint16; | |
49 typedef signed short int16; | |
50 #ifdef __x86_64__ | |
51 typedef signed int int32; | |
52 #else | |
53 typedef signed long int int32; | |
54 #endif | |
55 typedef float real32; | |
56 | |
57 typedef struct | |
58 { | |
59 uint16 version_major; | |
60 uint16 version_minor; | |
61 char unused0[40]; | |
62 uint16 ticks_per_beat; | |
63 uint16 beats_per_measure; | |
64 uint16 edit_scale_y; | |
65 uint16 edit_scale_x; | |
66 char unused1; | |
67 char mode; | |
68 char unused2[90]; | |
69 char filler0[38]; | |
70 char filler1[15]; | |
71 real32 basic_tempo; | |
72 } SRolHeader; | |
73 | |
74 typedef struct | |
75 { | |
76 int16 time; | |
77 real32 multiplier; | |
78 } STempoEvent; | |
79 | |
80 typedef struct | |
81 { | |
82 int16 number; | |
83 int16 duration; | |
84 } SNoteEvent; | |
85 | |
86 typedef struct | |
87 { | |
88 int16 time; | |
89 char name[9]; | |
90 int16 ins_index; | |
91 } SInstrumentEvent; | |
92 | |
93 typedef struct | |
94 { | |
95 int16 time; | |
96 real32 multiplier; | |
97 } SVolumeEvent; | |
98 | |
99 typedef struct | |
100 { | |
101 int16 time; | |
102 real32 variation; | |
103 } SPitchEvent; | |
104 | |
105 typedef std::vector<SNoteEvent> TNoteEvents; | |
106 typedef std::vector<SInstrumentEvent> TInstrumentEvents; | |
107 typedef std::vector<SVolumeEvent> TVolumeEvents; | |
108 typedef std::vector<SPitchEvent> TPitchEvents; | |
109 | |
110 #define bit_pos( pos ) (1<<pos) | |
111 | |
112 class CVoiceData | |
113 { | |
114 public: | |
115 enum EEventStatus | |
116 { | |
117 kES_NoteEnd = bit_pos( 0 ), | |
118 kES_PitchEnd = bit_pos( 1 ), | |
119 kES_InstrEnd = bit_pos( 2 ), | |
120 kES_VolumeEnd = bit_pos( 3 ), | |
121 | |
122 kES_None = 0 | |
123 }; | |
124 | |
125 explicit CVoiceData() | |
126 : mForceNote ( true ) | |
127 ,mEventStatus ( kES_None ) | |
128 ,current_note ( 0 ) | |
129 ,current_note_duration( 0 ) | |
130 ,mNoteDuration ( 0 ) | |
131 ,next_instrument_event( 0 ) | |
132 ,next_volume_event ( 0 ) | |
133 ,next_pitch_event ( 0 ) | |
134 { | |
135 } | |
136 | |
137 void Reset() | |
138 { | |
139 mForceNote = true; | |
140 mEventStatus = kES_None; | |
141 current_note = 0; | |
142 current_note_duration = 0; | |
143 mNoteDuration = 0; | |
144 next_instrument_event = 0; | |
145 next_volume_event = 0; | |
146 next_pitch_event = 0; | |
147 } | |
148 | |
149 TNoteEvents note_events; | |
150 TInstrumentEvents instrument_events; | |
151 TVolumeEvents volume_events; | |
152 TPitchEvents pitch_events; | |
153 | |
154 bool mForceNote : 1; | |
155 int mEventStatus; | |
156 unsigned int current_note; | |
157 int current_note_duration; | |
158 int mNoteDuration; | |
159 unsigned int next_instrument_event; | |
160 unsigned int next_volume_event; | |
161 unsigned int next_pitch_event; | |
162 }; | |
163 | |
164 typedef struct | |
165 { | |
166 uint16 index; | |
167 char record_used; | |
168 char name[9]; | |
169 } SInstrumentName; | |
170 | |
171 typedef std::vector<SInstrumentName> TInstrumentNames; | |
172 | |
173 typedef struct | |
174 { | |
175 char version_major; | |
176 char version_minor; | |
177 char signature[6]; | |
178 uint16 number_of_list_entries_used; | |
179 uint16 total_number_of_list_entries; | |
180 int32 abs_offset_of_name_list; | |
181 int32 abs_offset_of_data; | |
182 | |
183 TInstrumentNames ins_name_list; | |
184 } SBnkHeader; | |
185 | |
186 typedef struct | |
187 { | |
188 unsigned char key_scale_level; | |
189 unsigned char freq_multiplier; | |
190 unsigned char feed_back; | |
191 unsigned char attack_rate; | |
192 unsigned char sustain_level; | |
193 unsigned char sustaining_sound; | |
194 unsigned char decay_rate; | |
195 unsigned char release_rate; | |
196 unsigned char output_level; | |
197 unsigned char amplitude_vibrato; | |
198 unsigned char frequency_vibrato; | |
199 unsigned char envelope_scaling; | |
200 unsigned char fm_type; | |
201 } SFMOperator; | |
202 | |
203 typedef struct | |
204 { | |
205 unsigned char ammulti; | |
206 unsigned char ksltl; | |
207 unsigned char ardr; | |
208 unsigned char slrr; | |
209 unsigned char fbc; | |
210 unsigned char waveform; | |
211 } SOPL2Op; | |
212 | |
213 typedef struct | |
214 { | |
215 char mode; | |
216 char voice_number; | |
217 SOPL2Op modulator; | |
218 SOPL2Op carrier; | |
219 } SRolInstrument; | |
220 | |
221 typedef struct | |
222 { | |
223 std::string name; | |
224 SRolInstrument instrument; | |
225 } SUsedList; | |
226 | |
227 void load_tempo_events ( binistream *f ); | |
228 bool load_voice_data ( binistream *f, std::string const &bnk_filename, const CFileProvider &fp ); | |
229 void load_note_events ( binistream *f, CVoiceData &voice ); | |
230 void load_instrument_events( binistream *f, CVoiceData &voice, | |
231 binistream *bnk_file, SBnkHeader const &bnk_header ); | |
232 void load_volume_events ( binistream *f, CVoiceData &voice ); | |
233 void load_pitch_events ( binistream *f, CVoiceData &voice ); | |
234 | |
235 bool load_bnk_info ( binistream *f, SBnkHeader &header ); | |
236 int load_rol_instrument ( binistream *f, SBnkHeader const &header, std::string &name ); | |
237 void read_rol_instrument ( binistream *f, SRolInstrument &ins ); | |
238 void read_fm_operator ( binistream *f, SOPL2Op &opl2_op ); | |
239 int get_ins_index( std::string const &name ) const; | |
240 | |
241 void UpdateVoice( int const voice, CVoiceData &voiceData ); | |
242 void SetNote( int const voice, int const note ); | |
243 void SetNoteMelodic( int const voice, int const note ); | |
244 void SetNotePercussive( int const voice, int const note ); | |
245 void SetFreq ( int const voice, int const note, bool const keyOn=false ); | |
246 void SetPitch ( int const voice, real32 const variation ); | |
247 void SetVolume ( int const voice, int const volume ); | |
248 void SetRefresh( float const multiplier ); | |
249 void send_ins_data_to_chip( int const voice, int const ins_index ); | |
250 void send_operator( int const voice, SOPL2Op const &modulator, SOPL2Op const &carrier ); | |
251 | |
252 class StringCompare | |
253 { | |
254 public: | |
255 bool operator()( SInstrumentName const &lhs, SInstrumentName const &rhs ) const | |
256 { | |
257 return keyLess(lhs.name, rhs.name); | |
258 } | |
259 | |
260 bool operator()( SInstrumentName const &lhs, std::string const &rhs ) const | |
261 { | |
262 return keyLess(lhs.name, rhs.c_str()); | |
263 } | |
264 | |
265 bool operator()( std::string const &lhs, SInstrumentName const &rhs ) const | |
266 { | |
267 return keyLess(lhs.c_str(), rhs.name); | |
268 } | |
269 private: | |
270 bool keyLess( const char *const lhs, const char *const rhs ) const | |
271 { | |
272 return stricmp(lhs, rhs) < 0; | |
273 } | |
274 }; | |
275 | |
276 typedef std::vector<CVoiceData> TVoiceData; | |
277 | |
278 SRolHeader *rol_header; | |
279 std::vector<STempoEvent> mTempoEvents; | |
280 TVoiceData voice_data; | |
281 std::vector<SUsedList> ins_list; | |
282 | |
283 unsigned int mNextTempoEvent; | |
284 int mCurrTick; | |
285 int mTimeOfLastNote; | |
286 float mRefresh; | |
287 unsigned char bdRegister; | |
288 unsigned char bxRegister[9]; | |
289 unsigned char volumeCache[11]; | |
290 uint16 freqCache[11]; | |
291 real32 pitchCache[11]; | |
292 | |
293 static int const kSizeofDataRecord; | |
294 static int const kMaxTickBeat; | |
295 static int const kSilenceNote; | |
296 static int const kNumMelodicVoices; | |
297 static int const kNumPercussiveVoices; | |
298 static int const kBassDrumChannel; | |
299 static int const kSnareDrumChannel; | |
300 static int const kTomtomChannel; | |
301 static int const kTomtomFreq; | |
302 static int const kSnareDrumFreq; | |
303 static float const kDefaultUpdateTme; | |
304 static float const kPitchFactor; | |
305 static uint16 const kNoteTable[12]; | |
306 }; | |
307 | |
308 #endif |