def write_header(self): # create xi file self.output_file.write(struct.pack( '21s22sb20sh', 'Extended Instrument: ', (self.filename[:-4] + ' ' * 22)[:22], 0x1a, pad_name(VERSION, 20), 0x0 )) self.output_file.write(struct.pack('96b', *(self.notes_samples)))
def write_regions_meta(self): self.output_file.write(struct.pack('h', len(self.regions))) # number of samples for region in self.regions: self.output_file.write(struct.pack( 'i', region['sample_bittype'] * region['sample_length'])) # sample length self.output_file.write(struct.pack('2i', 0, 0)) # sample loop start and end # volume volume = 255 if 'volume' in region: volume = math.floor( 255 * math.exp(float(region['volume']) / 10) / math.exp(0.6) ) # volume is in dB self.output_file.write(struct.pack('B', volume)) self.output_file.write(struct.pack('b', int(region['tune']))) # finetune (signed!) self.output_file.write(struct.pack('b', region['sample_type'])) # sample type #panning (unsigned!) pan = 128 if 'pan' in region: pan = (float(region['pan']) + 100) * 255 / 200 self.output_file.write(struct.pack('B', pan)) key = region['pitch_keycenter'] if 'pitch_keycenter' in region else region['lokey'] self.output_file.write(struct.pack( 'b', 1 - notes.index(key) + notes.index('e6') )) # relative note - transpose c4 ~ 00 sample_name = pad_name(os.path.split(region['sample_path'])[1], 22) self.output_file.write(struct.pack('b', len(sample_name.strip(' ')))) self.output_file.write(struct.pack('22s', sample_name))