diff options
Diffstat (limited to 'modules/chibi/cp_loader_it_instruments.cpp')
| -rw-r--r-- | modules/chibi/cp_loader_it_instruments.cpp | 252 |
1 files changed, 116 insertions, 136 deletions
diff --git a/modules/chibi/cp_loader_it_instruments.cpp b/modules/chibi/cp_loader_it_instruments.cpp index 446e841c5..cd44d0061 100644 --- a/modules/chibi/cp_loader_it_instruments.cpp +++ b/modules/chibi/cp_loader_it_instruments.cpp @@ -30,189 +30,171 @@ #include "cp_loader_it.h" enum EnvFlags { - ENV_ON=1, - ENV_LOOP=2, - ENV_SUSLOOP=4, - ENV_CARRY=8, - ENV_FILTER=128 + ENV_ON = 1, + ENV_LOOP = 2, + ENV_SUSLOOP = 4, + ENV_CARRY = 8, + ENV_FILTER = 128 }; -void CPLoader_IT::load_envelope(CPEnvelope *p_envelope,bool*p_has_filter_flag) { +void CPLoader_IT::load_envelope(CPEnvelope *p_envelope, bool *p_has_filter_flag) { + + uint8_t flags = file->get_byte(); + uint8_t points = file->get_byte(); + uint8_t begin = file->get_byte(); + uint8_t end = file->get_byte(); + uint8_t susbegin = file->get_byte(); + uint8_t susend = file->get_byte(); - uint8_t flags=file->get_byte(); - uint8_t points=file->get_byte(); - uint8_t begin=file->get_byte(); - uint8_t end=file->get_byte(); - uint8_t susbegin=file->get_byte(); - uint8_t susend=file->get_byte(); - p_envelope->reset(); - - for (int i=0;i<25;i++) { - uint8_t height=file->get_byte(); - int8_t &signed_height=(int8_t&)height; - uint16_t tick=file->get_word(); - - if (i>=points) + for (int i = 0; i < 25; i++) { + + uint8_t height = file->get_byte(); + int8_t &signed_height = (int8_t &)height; + uint16_t tick = file->get_word(); + + if (i >= points) continue; - p_envelope->add_position( tick, signed_height ); - + p_envelope->add_position(tick, signed_height); } - p_envelope->set_enabled( flags & ENV_ON ); - p_envelope->set_carry_enabled( flags & ENV_CARRY); - - p_envelope->set_loop_enabled( flags & ENV_LOOP ); - p_envelope->set_loop_begin( begin ); - p_envelope->set_loop_end( end ); - - p_envelope->set_sustain_loop_enabled( flags & ENV_SUSLOOP ); - p_envelope->set_sustain_loop_begin( susbegin ); - p_envelope->set_sustain_loop_end( susend ); - + p_envelope->set_enabled(flags & ENV_ON); + p_envelope->set_carry_enabled(flags & ENV_CARRY); + + p_envelope->set_loop_enabled(flags & ENV_LOOP); + p_envelope->set_loop_begin(begin); + p_envelope->set_loop_end(end); + + p_envelope->set_sustain_loop_enabled(flags & ENV_SUSLOOP); + p_envelope->set_sustain_loop_begin(susbegin); + p_envelope->set_sustain_loop_end(susend); + if (p_has_filter_flag) - *p_has_filter_flag=flags&ENV_FILTER; - + *p_has_filter_flag = flags & ENV_FILTER; + file->get_byte(); //zerobyte - + //fill with stuff if the envelope hass less than 2 points - while(p_envelope->get_node_count()<2) { - - p_envelope->add_position( 30*p_envelope->get_node_count(), p_envelope->get_min()==0 ? 64 : 0, false ); + while (p_envelope->get_node_count() < 2) { + + p_envelope->add_position(30 * p_envelope->get_node_count(), p_envelope->get_min() == 0 ? 64 : 0, false); } } - -CPLoader::Error CPLoader_IT::load_instrument(CPInstrument *p_instrument,int *p_samples) { - - +CPLoader::Error CPLoader_IT::load_instrument(CPInstrument *p_instrument, int *p_samples) { char aux_header[4]; - - file->get_byte_array((uint8_t*)aux_header,4); - - if ( aux_header[0]!='I' || - aux_header[1]!='M' || - aux_header[2]!='P' || - aux_header[3]!='I') { + file->get_byte_array((uint8_t *)aux_header, 4); + + if (aux_header[0] != 'I' || + aux_header[1] != 'M' || + aux_header[2] != 'P' || + aux_header[3] != 'I') { CP_PRINTERR("IT CPLoader CPInstrument: Failed Identifier"); - + return FILE_UNRECOGNIZED; } - - // Ignore deprecated 8.3 filename field - for (int i=0;i<12;i++) file->get_byte(); - + for (int i = 0; i < 12; i++) + file->get_byte(); + //Ignore zerobyte - file->get_byte(); /* (byte) CPInstrument type (always 0) */ - - switch( file->get_byte() ) { /* New CPNote Action [0,1,2,3] */ - case 0: p_instrument->set_NNA_type( CPInstrument::NNA_NOTE_CUT ) ; break; - case 1: p_instrument->set_NNA_type( CPInstrument::NNA_NOTE_CONTINUE ) ; break; - case 2: p_instrument->set_NNA_type( CPInstrument::NNA_NOTE_OFF ) ; break; - case 3: p_instrument->set_NNA_type( CPInstrument::NNA_NOTE_FADE ) ; break; + file->get_byte(); /* (byte) CPInstrument type (always 0) */ + + switch (file->get_byte()) { /* New CPNote Action [0,1,2,3] */ + case 0: p_instrument->set_NNA_type(CPInstrument::NNA_NOTE_CUT); break; + case 1: p_instrument->set_NNA_type(CPInstrument::NNA_NOTE_CONTINUE); break; + case 2: p_instrument->set_NNA_type(CPInstrument::NNA_NOTE_OFF); break; + case 3: p_instrument->set_NNA_type(CPInstrument::NNA_NOTE_FADE); break; }; - switch( file->get_byte() ) { // Duplicate Check Type - case 0: p_instrument->set_DC_type( CPInstrument::DCT_DISABLED ); break ; - case 1: p_instrument->set_DC_type( CPInstrument::DCT_NOTE ); break ; - case 2: p_instrument->set_DC_type( CPInstrument::DCT_SAMPLE ); break ; - case 3: p_instrument->set_DC_type( CPInstrument::DCT_INSTRUMENT ); break ; + switch (file->get_byte()) { // Duplicate Check Type + case 0: p_instrument->set_DC_type(CPInstrument::DCT_DISABLED); break; + case 1: p_instrument->set_DC_type(CPInstrument::DCT_NOTE); break; + case 2: p_instrument->set_DC_type(CPInstrument::DCT_SAMPLE); break; + case 3: p_instrument->set_DC_type(CPInstrument::DCT_INSTRUMENT); break; } - switch( file->get_byte() ) { //Duplicate Check Action - case 0: p_instrument->set_DC_action( CPInstrument::DCA_NOTE_CUT ); break ; - case 1: p_instrument->set_DC_action( CPInstrument::DCA_NOTE_OFF ); break ; - case 2: p_instrument->set_DC_action( CPInstrument::DCA_NOTE_FADE ); break ; + switch (file->get_byte()) { //Duplicate Check Action + case 0: p_instrument->set_DC_action(CPInstrument::DCA_NOTE_CUT); break; + case 1: p_instrument->set_DC_action(CPInstrument::DCA_NOTE_OFF); break; + case 2: p_instrument->set_DC_action(CPInstrument::DCA_NOTE_FADE); break; } - + int fade = file->get_word(); //intf("AFADE: %i\n",fade); - if (fade>CPInstrument::MAX_FADEOUT) //needs to be clipped because of horrible modplug doings - fade=CPInstrument::MAX_FADEOUT; - - p_instrument->set_volume_fadeout( fade ); - p_instrument->set_pan_pitch_separation( file->get_byte() ); - p_instrument->set_pan_pitch_center( file->get_byte() ); - p_instrument->set_volume_global_amount( file->get_byte() ); - uint8_t pan=file->get_byte(); - p_instrument->set_pan_default_amount(pan&0x7F); - p_instrument->set_pan_default_enabled( !(pan&0x80) ); - p_instrument->set_volume_random_variation( file->get_byte() ); - p_instrument->set_pan_random_variation( file->get_byte() ); - - - + if (fade > CPInstrument::MAX_FADEOUT) //needs to be clipped because of horrible modplug doings + fade = CPInstrument::MAX_FADEOUT; + + p_instrument->set_volume_fadeout(fade); + p_instrument->set_pan_pitch_separation(file->get_byte()); + p_instrument->set_pan_pitch_center(file->get_byte()); + p_instrument->set_volume_global_amount(file->get_byte()); + uint8_t pan = file->get_byte(); + p_instrument->set_pan_default_amount(pan & 0x7F); + p_instrument->set_pan_default_enabled(!(pan & 0x80)); + p_instrument->set_volume_random_variation(file->get_byte()); + p_instrument->set_pan_random_variation(file->get_byte()); + file->get_word(); //empty (version) - uint8_t samples=file->get_byte(); + uint8_t samples = file->get_byte(); if (p_samples) - *p_samples=samples; + *p_samples = samples; file->get_byte(); //empty - char aux_name[26]; - file->get_byte_array((uint8_t*)aux_name,26); + char aux_name[26]; + file->get_byte_array((uint8_t *)aux_name, 26); p_instrument->set_name(aux_name); - - uint8_t cutoff=file->get_byte(); - - p_instrument->set_filter_default_cutoff(cutoff&0x7F); - p_instrument->set_filter_use_default_cutoff(cutoff&0x80); - - uint8_t resonance=file->get_byte(); - - p_instrument->set_filter_default_resonance(resonance&0x7F); - p_instrument->set_filter_use_default_resonance(resonance&0x80); - + + uint8_t cutoff = file->get_byte(); + + p_instrument->set_filter_default_cutoff(cutoff & 0x7F); + p_instrument->set_filter_use_default_cutoff(cutoff & 0x80); + + uint8_t resonance = file->get_byte(); + + p_instrument->set_filter_default_resonance(resonance & 0x7F); + p_instrument->set_filter_use_default_resonance(resonance & 0x80); + file->get_dword(); //MIDI, IGNORED! - + /* CPNote -> CPSample table */ - for (uint8_t i=0;i<CPNote::NOTES;i++) { - - - uint8_t note=file->get_byte(); - if (note>=CPNote::NOTES) - note=0; - p_instrument->set_note_number(i,note); - - uint8_t samp=file->get_byte(); - if (samp==0 || samp>99) - samp=CPNote::EMPTY; - else + for (uint8_t i = 0; i < CPNote::NOTES; i++) { + + uint8_t note = file->get_byte(); + if (note >= CPNote::NOTES) + note = 0; + p_instrument->set_note_number(i, note); + + uint8_t samp = file->get_byte(); + if (samp == 0 || samp > 99) + samp = CPNote::EMPTY; + else samp--; - - - p_instrument->set_sample_number(i,samp); - + p_instrument->set_sample_number(i, samp); } - - load_envelope( p_instrument->get_volume_envelope() ); - load_envelope( p_instrument->get_pan_envelope() ); + load_envelope(p_instrument->get_volume_envelope()); + load_envelope(p_instrument->get_pan_envelope()); bool use_as_filter; - load_envelope( p_instrument->get_pitch_filter_envelope(), &use_as_filter ); - p_instrument->set_pitch_use_as_filter( use_as_filter ); + load_envelope(p_instrument->get_pitch_filter_envelope(), &use_as_filter); + p_instrument->set_pitch_use_as_filter(use_as_filter); return FILE_OK; - } - CPLoader::Error CPLoader_IT::load_instruments() { + for (int i = 0; i < header.insnum; i++) { - for (int i=0;i<header.insnum;i++) { + file->seek(0xC0 + header.ordnum + i * 4); + uint32_t final_location = file->get_dword(); + file->seek(final_location); - - file->seek(0xC0+header.ordnum+i*4); - uint32_t final_location=file->get_dword(); - file->seek( final_location ); - - Error err=load_instrument( song->get_instrument( i ) ); + Error err = load_instrument(song->get_instrument(i)); if (err) return err; - } return FILE_OK; @@ -220,5 +202,3 @@ CPLoader::Error CPLoader_IT::load_instruments() { if (file->eof_reached() || file->get_error()) return FILE_CORRUPTED; } - - |
