def _process_static_data(self): simple_deciders = { 'PLAYER': self._assert_correct_player, 'TITLE': self.SM_converter.make_setter('title'), 'SUBTITLE': self._parse_implicit_subtitle, 'ARTIST': self.SM_converter.make_setter('artist'), 'BPM': self._set_initial_bpm, 'DIFFICULTY': self.SM_converter.set_difficulty, 'LNTYPE': self._set_ln_type, 'LNOBJ': self._add_ln_object, 'STAGEFILE': self.SM_converter.make_file_setter('bg'), 'BANNER': self.SM_converter.make_file_setter('banner'), 'END IF': self._puke_from_gimmicks, 'ELSE': self._puke_from_gimmicks, 'ENDRANDOM': self._puke_from_gimmicks, 'SKIP': self._puke_from_gimmicks, 'DEF': self._puke_from_gimmicks, 'ENDSW': self._puke_from_gimmicks, 'RANDOM': self._puke_from_gimmicks, 'IF': self._puke_from_gimmicks, 'RONDAM': self._puke_from_gimmicks, 'SETRANDOM': self._puke_from_gimmicks, 'ELSEIF': self._puke_from_gimmicks, 'SWITCH': self._puke_from_gimmicks, 'CASE': self._puke_from_gimmicks, } advanced_deciders = { r'STP (\d{3})\.(\d{3})': self._add_ms_stop, r'BPM([0-9a-fA-F]{2})': self._define_extended_bpm, r'EXBPM([0-9a-fA-F]{2})': self._define_extended_bpm, r'STOP([0-9a-zA-Z]{2})': self._define_stop, r'WAV([0-9a-zA-Z]{2})': self._define_wav } with standard_tqdm( iterable=self._static_data, desc='Processing static data') as progress_static_data: for header, value in progress_static_data: header = header.upper() if header in simple_deciders: simple_deciders[header](value) for candidate in advanced_deciders: if match(candidate, header): additional_data = findall(candidate, header)[0] if is_non_str_sequence(additional_data): advanced_deciders[candidate](value, *additional_data) else: advanced_deciders[candidate](value, additional_data)
def do_scan(simple_deciders, message): amount = 0 filtered = [] for measure, channel, datum in self._dynamic_data: if channel in simple_deciders: filtered.append((measure, channel, datum)) amount += 1 if amount == 0: return with standard_tqdm(iterable=filtered, desc=message, total=amount) as progress_dynamic_data: for measure, channel, datum in progress_dynamic_data: if channel in simple_deciders: simple_deciders[channel](datum)
def _perform_static_reading(self): try: with open(self.BM_file_path, 'rb') as in_file: encoding = char_detect(in_file.read())['encoding'] with open(self.BM_file_path, 'r', encoding=encoding) as in_file: data = in_file.readlines() except IOError: print('Error occurred when opening BM chart') raise with standard_tqdm(iterable=data, desc='Performing static reading') as progress_data: for datum in progress_data: self._feed_message(datum)
def copy_files(self): output_dir = path.dirname(self.SM_file_path) if len(self._affected_files) == 0: return with standard_tqdm(iterable=self._affected_files, desc="Copying files into new directory" ) as progress_affected_files: for file_path in progress_affected_files: file_name = path.split(file_path)[1] output_file = path.join(output_dir, file_name) if path.exists(output_file): return copy2(file_path, output_file)
def _offset_dynamic_data(self): ordered_datums = sorted((T[2] for T in self._dynamic_data), key=operator.attrgetter('initial_measure')) ordered_time_sgn = self.timing_manager.time_sgn_list if len(ordered_time_sgn) == 0: return current_shift = 0 new_shift = 0 current_time_sgn = ordered_time_sgn.pop(0) changing_displacement = True with standard_tqdm(iterable=ordered_datums, desc='Displacing rows') as progress_ordered_datum: for datum in progress_ordered_datum: displacement_measure, displacement_amount = current_time_sgn while datum.initial_measure > displacement_measure: if len(ordered_time_sgn) == 0: displacement_measure, displacement_amount = 9e4000, 9e4000 else: current_time_sgn = ordered_time_sgn.pop(0) displacement_measure, displacement_amount = current_time_sgn current_shift += new_shift new_shift = displacement_amount - 1 changing_displacement = False if datum.initial_measure < displacement_measure: changing_displacement = False datum.global_position += current_shift if datum.initial_measure == displacement_measure: local_position = datum.initial_position - datum.initial_measure new_local_position = local_position * displacement_amount displacement = new_local_position - local_position datum.global_position += displacement datum.global_position += current_shift if not changing_displacement: new_shift = displacement_amount - 1 changing_displacement = True
def compose_chart(self): if len(self.objects) == 0: raise EmptyChart self.objects.sort(key=operator.attrgetter('position')) measure_splits = {} with standard_tqdm(iterable=self.objects, desc='Composing SM chart manifold') as progress_objects: for obj in progress_objects: measure = obj.measure if measure not in measure_splits: measure_splits[measure] = 4 cur_split = measure_splits[measure] measure_splits[measure] = lcm(cur_split, obj.position.denominator) amount_of_measures = max(measure_splits) + 1 measures = [] with standard_tqdm(range(amount_of_measures), desc='Filling SM chart with 0') as progress_measures: for measure_num in progress_measures: length = measure_splits.get(NonNegativeInt(measure_num), 4) measures.append( [ [ Representations.NOTHING for _ in range(len(self.keys)) ] for _ in range(length) ] ) with standard_tqdm(iterable=self.objects, desc='Injecting objects into SM chart') as progress_objects: for obj in progress_objects: measure_split = measure_splits[obj.measure] local_position = obj.position.numerator % obj.position.denominator scaled_position = local_position * (measure_split // obj.position.denominator) if obj.key not in self.keys: continue relative_position = self.keys.index(obj.key) this_measure = measures[obj.measure] this_measure[scaled_position][relative_position] = obj.symbol row_template = "{}" * len(self.keys) notes = "\n,\n".join( "\n".join( row_template.format(*row) for row in measure ) for measure in measures ) audio_out_file = self._parent.OGG_file_name result = self._SM_format.format(**{ **self._meta_data, 'BPM_changes': self._parent.timing_manager.bpm_string, 'stops': self._parent.timing_manager.ms_stops_string, 'measures': notes, 'audio_name': audio_out_file }) result = result.encode('utf-8', errors='ignore') tqdm.write('Writing SM file') try: with open(self._parent.SM_file_path, 'wb') as f: f.write(result) except IOError: tqdm.write('Error while opening SM file') raise