]> 4ch.mooo.com Git - 16.git/blob - 16/adplug/adplug/src/rol.h
renamed: 16/adplug/adplug-2.2.1/.DS_Store -> 16/adplug/adplug/.DS_Store
[16.git] / 16 / adplug / adplug / src / rol.h
1 /*
2  * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3  * Copyright (C) 1999 - 2008 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 #include <strings.h>
29
30 #include "player.h"
31
32 class CrolPlayer: public CPlayer
33 {
34 public:
35   static CPlayer *factory(Copl *newopl);
36
37     CrolPlayer(Copl *newopl);
38
39     ~CrolPlayer();
40
41     bool  load      (const std::string &filename, const CFileProvider &fp);
42     bool  update    ();
43     void  rewind    (int subsong);      // rewinds to specified subsong
44     float getrefresh();                 // returns needed timer refresh rate
45
46     std::string gettype() { return std::string("Adlib Visual Composer"); }
47
48 private:
49     typedef unsigned short    uint16;
50     typedef signed   short    int16;
51 #ifdef __x86_64__
52     typedef signed   int      int32;
53 #else
54     typedef signed long int   int32;
55 #endif
56     typedef float             real32;
57
58     typedef struct
59     {
60         uint16 version_major;
61         uint16 version_minor;
62         char   unused0[40];
63         uint16 ticks_per_beat;
64         uint16 beats_per_measure;
65         uint16 edit_scale_y;
66         uint16 edit_scale_x;
67         char   unused1;
68         char   mode;
69         char   unused2[90];
70         char   filler0[38];
71         char   filler1[15];
72         real32 basic_tempo;
73     } SRolHeader;
74
75     typedef struct
76     {
77         int16  time;
78         real32 multiplier;
79     } STempoEvent;
80
81     typedef struct
82     {
83         int16 number;
84         int16 duration;
85     } SNoteEvent;
86
87     typedef struct
88     {
89         int16 time;
90         char  name[9];
91         int16 ins_index;
92     } SInstrumentEvent;
93
94     typedef struct
95     {
96         int16  time;
97         real32 multiplier;
98     } SVolumeEvent;
99
100     typedef struct
101     {
102         int16  time;
103         real32 variation;
104     } SPitchEvent;
105
106     typedef std::vector<SNoteEvent>       TNoteEvents;
107     typedef std::vector<SInstrumentEvent> TInstrumentEvents;
108     typedef std::vector<SVolumeEvent>     TVolumeEvents;
109     typedef std::vector<SPitchEvent>      TPitchEvents;
110
111 #define bit_pos( pos ) (1<<pos)
112
113     class CVoiceData
114     {
115     public:
116         enum EEventStatus
117         {
118             kES_NoteEnd   = bit_pos( 0 ),
119             kES_PitchEnd  = bit_pos( 1 ),
120             kES_InstrEnd  = bit_pos( 2 ),
121             kES_VolumeEnd = bit_pos( 3 ),
122
123             kES_None     = 0
124         };
125
126         explicit CVoiceData()
127             :   mForceNote           ( true )
128                ,mEventStatus         ( kES_None )
129                ,current_note         ( 0 )
130                ,current_note_duration( 0 )
131                ,mNoteDuration        ( 0 )
132                ,next_instrument_event( 0 )
133                ,next_volume_event    ( 0 )
134                ,next_pitch_event     ( 0 )
135         {
136         }
137
138         void Reset()
139         {
140             mForceNote            = true;
141             mEventStatus          = kES_None;
142             current_note          = 0;
143             current_note_duration = 0;
144             mNoteDuration         = 0;
145             next_instrument_event = 0;
146             next_volume_event     = 0;
147             next_pitch_event      = 0;
148         }
149
150         TNoteEvents       note_events;
151         TInstrumentEvents instrument_events;
152         TVolumeEvents     volume_events;
153         TPitchEvents      pitch_events;
154
155         bool              mForceNote : 1;
156         int               mEventStatus;
157         unsigned int      current_note;
158         int               current_note_duration;
159         int               mNoteDuration;
160         unsigned int      next_instrument_event;
161         unsigned int      next_volume_event;
162         unsigned int      next_pitch_event;
163     };
164
165     typedef struct
166     {
167         uint16 index;
168         char   record_used;
169         char   name[9];
170     } SInstrumentName;
171
172     typedef std::vector<SInstrumentName> TInstrumentNames;
173
174     typedef struct
175     {
176         char   version_major;
177         char   version_minor;
178         char   signature[6];
179         uint16 number_of_list_entries_used;
180         uint16 total_number_of_list_entries;
181         int32  abs_offset_of_name_list;
182         int32  abs_offset_of_data;
183
184         TInstrumentNames ins_name_list;
185     } SBnkHeader;
186
187     typedef struct
188     {
189         unsigned char key_scale_level;
190         unsigned char freq_multiplier;
191         unsigned char feed_back;
192         unsigned char attack_rate;
193         unsigned char sustain_level;
194         unsigned char sustaining_sound;
195         unsigned char decay_rate;
196         unsigned char release_rate;
197         unsigned char output_level;
198         unsigned char amplitude_vibrato;
199         unsigned char frequency_vibrato;
200         unsigned char envelope_scaling;
201         unsigned char fm_type;
202     } SFMOperator;
203
204     typedef struct
205     {
206         unsigned char ammulti;
207         unsigned char ksltl;
208         unsigned char ardr;  
209         unsigned char slrr;
210         unsigned char fbc;
211         unsigned char waveform;
212     } SOPL2Op;
213
214     typedef struct
215     {
216         char        mode;
217         char        voice_number;
218         SOPL2Op     modulator;
219         SOPL2Op     carrier;
220     } SRolInstrument;
221
222     typedef struct
223     {
224         std::string    name;
225         SRolInstrument instrument;
226     } SUsedList;
227
228     void load_tempo_events     ( binistream *f );
229     bool load_voice_data       ( binistream *f, std::string const &bnk_filename, const CFileProvider &fp );
230     void load_note_events      ( binistream *f, CVoiceData &voice );
231     void load_instrument_events( binistream *f, CVoiceData &voice,
232                                  binistream *bnk_file, SBnkHeader const &bnk_header );
233     void load_volume_events    ( binistream *f, CVoiceData &voice );
234     void load_pitch_events     ( binistream *f, CVoiceData &voice );
235
236     bool load_bnk_info         ( binistream *f, SBnkHeader &header );
237     int  load_rol_instrument   ( binistream *f, SBnkHeader const &header, std::string &name );
238     void read_rol_instrument   ( binistream *f, SRolInstrument &ins );
239     void read_fm_operator      ( binistream *f, SOPL2Op &opl2_op );
240     int  get_ins_index( std::string const &name ) const;
241
242     void UpdateVoice( int const voice, CVoiceData &voiceData );
243     void SetNote( int const voice, int const note );
244     void SetNoteMelodic(  int const voice, int const note  );
245     void SetNotePercussive( int const voice, int const note );
246     void SetFreq   ( int const voice, int const note, bool const keyOn=false );
247     void SetPitch  ( int const voice, real32 const variation );
248     void SetVolume ( int const voice, int const volume );
249     void SetRefresh( float const multiplier );
250     void send_ins_data_to_chip( int const voice, int const ins_index );
251     void send_operator( int const voice, SOPL2Op const &modulator, SOPL2Op const &carrier );
252
253     class StringCompare
254     {
255     public:
256         bool operator()( SInstrumentName const &lhs, SInstrumentName const &rhs ) const
257         {
258             return keyLess(lhs.name, rhs.name);
259         }
260
261         bool operator()( SInstrumentName const &lhs, std::string const &rhs ) const
262         {
263             return keyLess(lhs.name, rhs.c_str());
264         }
265
266         bool operator()( std::string const &lhs, SInstrumentName const &rhs ) const
267         {
268             return keyLess(lhs.c_str(), rhs.name);
269         }
270     private:
271         bool keyLess( const char *const lhs, const char *const rhs ) const
272         {
273             return stricmp(lhs, rhs) < 0;
274         }
275     };
276
277     typedef std::vector<CVoiceData> TVoiceData;
278
279     SRolHeader *rol_header;
280     std::vector<STempoEvent>    mTempoEvents;
281     TVoiceData                  voice_data;
282     std::vector<SUsedList>      ins_list;
283
284     unsigned int                mNextTempoEvent;
285     int                         mCurrTick;
286     int                         mTimeOfLastNote;
287     float                       mRefresh;
288     unsigned char               bdRegister;
289     unsigned char               bxRegister[9];
290     unsigned char               volumeCache[11];
291     uint16                      freqCache[11];
292     real32                      pitchCache[11];
293
294     static int    const kSizeofDataRecord;
295     static int    const kMaxTickBeat;
296     static int    const kSilenceNote;
297     static int    const kNumMelodicVoices;
298     static int    const kNumPercussiveVoices;
299     static int    const kBassDrumChannel;
300     static int    const kSnareDrumChannel;
301     static int    const kTomtomChannel;
302     static int    const kTomtomFreq;
303     static int    const kSnareDrumFreq;
304     static float  const kDefaultUpdateTme;
305     static float  const kPitchFactor;
306     static uint16 const kNoteTable[12];
307 };
308
309 #endif