CPLoader::Error CPLoader_IT::load_samples() { for (int i=0;i<header.smpnum;i++) { //seek to sample file->seek(0xC0+header.ordnum+header.insnum*4+i*4); uint32_t final_location=file->get_dword(); file->seek( final_location ); Error err=load_sample(song->get_sample(i)); CP_ERR_COND_V(err,err); } if (file->eof_reached() || file->get_error()) return FILE_CORRUPTED; return FILE_OK; }
uint8_t CPInstrument::get_note_number(uint8_t p_note) { CP_ERR_COND_V(p_note>=CPNote::NOTES,0); return data.note_number[p_note]; }
CPLoader::Error CPLoader_IT::load_header(bool p_dont_set) { char aux_songname[26]; file->get_byte_array((uint8_t *)aux_songname, 26); if (!p_dont_set) song->set_name(aux_songname); uint8_t aux_hlmin = file->get_byte(); uint8_t aux_hlmaj = file->get_byte(); if (aux_hlmin == 0) aux_hlmin = 4; if (aux_hlmaj == 0) aux_hlmaj = 16; if (!p_dont_set) { song->set_row_highlight_minor(aux_hlmin); song->set_row_highlight_major(aux_hlmaj); } header.ordnum = file->get_word(); header.insnum = file->get_word(); header.smpnum = file->get_word(); header.patnum = file->get_word(); header.cwt = file->get_word(); /* Created with tracker (y.xx = 0x0yxx) */ header.cmwt = file->get_word(); /* Compatible with tracker ver > than val. */ header.flags = file->get_word(); if (!p_dont_set) { song->set_stereo(header.flags & 1); song->set_linear_slides(header.flags & 8); song->set_old_effects(header.flags & 16); song->set_compatible_gxx(header.flags & 32); song->set_instruments(header.flags & 4); } header.special = file->get_word(); if (!p_dont_set) { song->set_global_volume(file->get_byte()); song->set_mixing_volume(file->get_byte()); song->set_speed(file->get_byte()); song->set_tempo(file->get_byte()); song->set_stereo_separation(file->get_byte()); } else { file->get_byte(); // skip file->get_byte(); // skip file->get_byte(); // skip file->get_byte(); // skip file->get_byte(); // skip } file->get_byte(); // ZERO Byte header.msglength = file->get_word(); header.msgoffset = file->get_dword(); char chibi[4]; file->get_byte_array((uint8_t *)chibi, 4); header.is_chibi = (chibi[0] == 'C' && chibi[1] == 'H' && chibi[2] == 'B' && chibi[3] == 'I'); for (int i = 0; i < 64; i++) { uint8_t panbyte = file->get_byte(); uint8_t pan_dst = (panbyte < 65) ? panbyte : 32; bool surround_dst = (panbyte == 100); bool mute_dst = (panbyte >= 128); if (!p_dont_set) { song->set_channel_pan(i, pan_dst); song->set_channel_surround(i, surround_dst); song->set_channel_mute(i, mute_dst); } } for (int i = 0; i < 64; i++) { unsigned char cv = file->get_byte(); if (!p_dont_set) song->set_channel_volume(i, cv); } CP_ERR_COND_V(file->eof_reached(), FILE_CORRUPTED); CP_ERR_COND_V(file->get_error(), FILE_CORRUPTED); return FILE_OK; }
CPLoader::Error CPLoader_IT::load_sample(CPSample *p_sample) { AuxSampleData aux_sample_data; 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]!='S') { //CP_PRINTERR("IT CPLoader CPSample: Failed Identifier"); return FILE_UNRECOGNIZED; } // Ignore deprecated 8.3 filename for (int i=0;i<12;i++) file->get_byte(); file->get_byte(); //ignore zerobyte p_sample->set_global_volume( file->get_byte() ); /* SAMPLE FLAGS */ uint8_t flags=file->get_byte(); aux_sample_data.loop_enabled=flags&IT_SAMPLE_LOOPED; aux_sample_data.pingpong_enabled=flags&IT_SAMPLE_LOOP_IS_PINGPONG; aux_sample_data.is16bit=flags&IT_SAMPLE_16BITS; aux_sample_data.exists=flags&IT_SAMPLE_EXISTS; aux_sample_data.stereo=flags&IT_SAMPLE_STEREO; aux_sample_data.compressed=flags&IT_SAMPLE_COMPRESSED; p_sample->set_default_volume(file->get_byte()); /* SAMPLE NAME */ char aux_name[26]; file->get_byte_array((uint8_t*)aux_name,26); p_sample->set_name(aux_name); // ?? uint8_t convert_flag=file->get_byte(); // PAN uint8_t pan=file->get_byte(); p_sample->set_pan( pan&0x7F ); p_sample->set_pan_enabled( pan & 0x80 ); aux_sample_data.length=file->get_dword(); aux_sample_data.loop_begin= file->get_dword(); aux_sample_data.loop_end= file->get_dword(); aux_sample_data.c5spd=file->get_dword(); /*p_sample->data.set_sustain_loop_begin=*/file->get_dword(); /*p_sample->data.sustain_loop_end=*/file->get_dword(); aux_sample_data.fileofs=file->get_dword(); p_sample->set_vibrato_speed( file->get_byte() ); p_sample->set_vibrato_depth( file->get_byte() ); p_sample->set_vibrato_rate( file->get_byte() ); switch( file->get_byte() ) { /* Vibrato Wave: 0=sine, 1=rampdown, 2=square, 3=random */ case 0: p_sample->set_vibrato_type( CPSample::VIBRATO_SINE ); break; case 1: p_sample->set_vibrato_type( CPSample::VIBRATO_SAW ); break; case 2: p_sample->set_vibrato_type( CPSample::VIBRATO_SQUARE ); break; case 3: p_sample->set_vibrato_type( CPSample::VIBRATO_RANDOM ); break; default: p_sample->set_vibrato_type( CPSample::VIBRATO_SINE ); break; } //printf("Name %s - Flags: fileofs :%i - c5spd %i - len %i 16b %i - data?: %i\n",p_sample->get_name(),aux_sample_data.fileofs,aux_sample_data.c5spd, aux_sample_data.length, aux_sample_data.is16bit,aux_sample_data.exists); CPSample_ID samp_id; if (aux_sample_data.exists) { samp_id=load_sample_data(aux_sample_data); CPSampleManager::get_singleton()->set_c5_freq(samp_id,aux_sample_data.c5spd); CPSampleManager::get_singleton()->set_loop_begin( samp_id,aux_sample_data.loop_begin ); CPSampleManager::get_singleton()->set_loop_end( samp_id,aux_sample_data.loop_end ); CPSample_Loop_Type loop_type=aux_sample_data.loop_enabled?( aux_sample_data.pingpong_enabled? CP_LOOP_BIDI: CP_LOOP_FORWARD):CP_LOOP_NONE; CPSampleManager::get_singleton()->set_loop_end( samp_id,aux_sample_data.loop_end ); CPSampleManager::get_singleton()->set_loop_type( samp_id, loop_type); } //printf("Loaded id is null?: %i\n",samp_id.is_null()); p_sample->set_sample_data(samp_id); if (!samp_id.is_null()) { // printf("Loaded ID: stereo: %i len %i 16bit %i\n",CPSampleManager::get_singleton()->is_stereo(samp_id), CPSampleManager::get_singleton()->get_size( samp_id), CPSampleManager::get_singleton()->is_16bits( samp_id) ); } CP_ERR_COND_V( file->eof_reached(),FILE_CORRUPTED ); CP_ERR_COND_V( file->get_error(),FILE_CORRUPTED ); return FILE_OK; }