def get_prog_block_index(self, prog): duration = int(self.ui.duration.value()) prog_block_index, prog_index, offset = [], 0, 0 if len(prog) != 0: if self.ui.blocks.count() == 0: search_space = ["Block"] else: search_space = self.main.get_blocks().split(",") if self.last_prog_block == (prog, search_space): return self.last_prog_block_index self.last_prog_block = (prog, search_space) for x in search_space: parts = x.split() params = Options.parse_block_params(parts[1:]) dur = params['duration'] if 'duration' in params else duration for i in range(dur): prog_block_index.append((offset, parts[0], prog_index)) prog_offset = 0 for itk, tk in enumerate(prog[prog_index]): if itk != 0: offset += (tk[0] - prog_offset) * len(prog[prog_index][itk - 1][1]) prog_offset = tk[0] prog_index += 1 if prog_index >= len(prog): prog_index =0 self.last_prog_block_index = (0, offset, prog_block_index) return (1, offset, prog_block_index)
def load_block(self, block_str): p = block_str.split(" ") self.ui.blockcombo.setCurrentIndex(combo_index_by_text(self.ui.blockcombo, p[0])) if len(p) == 1: return params = Options.parse_block_params(p[1:]) if 'duration' in params: self.ui.duration.setValue(params['duration']) if 'bpm' in params: self.ui.bpm.setValue(params["bpm"]) if 'wild' in params: self.ui.wildness.setValue(params["wild"]) if 'swing' in params: if params["swing"]: self.ui.swing.setCurrentIndex(2) else: self.ui.swing.setCurrentIndex(1) if 'key' in params: self.ui.key.setCurrentIndex(combo_index_by_text(self.ui.key, params["key"])) if 'resolution' in params: self.ui.resolution.setCurrentIndex(combo_index_by_text(self.ui.resolution, str(params["resolution"])))