def print_pch2(fn: str): if not fn.lower().endswith('.pch2'): print("error: patch file should have extension '.pch2'") exit(-1) data = ProjectData() path = os.path.abspath(fn) patch = parse_pch2(data, path) mod_table = [['Name', 'ID', 'Type', 'Parameters', 'Area']] for m in patch.modules: p = patch.find_mod_params(m.location, m.id) mod_table.append( [m.type_name, m.id, m.type, str(p.values), m.location.short_str()]) cab_table = [['From', '', 'To', 'Color', 'Type', 'Area']] for c in patch.cables: mf_name = patch.find_module(c.module_from, c.loc).type_name mt_name = patch.find_module(c.module_to, c.loc).type_name pin1, pin2 = c.type.short_str().split('-') cab_table.append([ '{}(id={}, {}={})'.format(mf_name, c.module_from, pin1, c.jack_from), '->', '{}(id={}, {}={})'.format(mt_name, c.module_to, pin2, c.jack_to), c.color.short_str(), c.type.short_str(), c.loc.short_str() ]) print('Patch file: {}\n'.format(os.path.basename(path))) print('Modules') print(tabulate(mod_table, headers='firstrow', tablefmt='simple')) print('\nCables') print(tabulate(cab_table, headers='firstrow', tablefmt='simple'))
def print_module(fn_pch2: str, mod_id: int, loc: Location): if not fn_pch2.lower().endswith('.pch2'): print("error: patch file should have extension '.pch2'") exit(-1) data = ProjectData() path = os.path.abspath(os.path.expanduser(fn_pch2)) p = parse_pch2(data, path) m = p.find_module(mod_id, loc) if m is None: print('error: cannot find module with id {} in the {} location'.format( mod_id, loc.short_str())) exit(-1) udo = Udo(p, m) params_midi = p.find_mod_params(loc, mod_id) params_mapped = udo.get_params() assert params_midi.num_params == len(params_mapped) tbl = [['Type', 'Raw', 'Mapped']] for raw, mapped in zip(params_midi.values, params_mapped): tbl.append(['Parameter', str(raw), str(mapped)]) for mode in m.modes: tbl.append(['Mode', str(mode), '']) print('Patch: {}'.format(fn_pch2)) print('Details of the module:\n{}'.format(m)) print() print(tabulate(tbl, headers='firstrow', tablefmt='simple'))
def get_all_module_pch2(): # -> List[Patch] global all_module_pch2 if all_module_pch2 is None: data = ProjectData() p = [ parse_pch2(data, f) for f in [ get_test_resource('test_all_modules_1.pch2'), get_test_resource('test_all_modules_2.pch2') ] ] all_module_pch2 = p return all_module_pch2
def setUp(self): self.data = ProjectData() self.poly_mix2 = parse_pch2(self.data, get_test_resource('test_poly_mix2.pch2')) self.udo_mix2_k = """opcode Mix21A_v0, 0, iiiiiiiii ; TODO: lin/log scale, chain input iLev1, iSw1, iLev2, iSw2, iScale, izIn1, izIn2, izInChain, izOut xin k1 zkr izIn1 k2 zkr izIn2 k3 zkr izInChain kout = k1 + k2*iLev1*iSW1 + k3*iLev2*iSW2 zkw kout, izOut endop """ self.udo_mix2_a = """opcode Mix21A_v1, 0, iiiiiiiii
def setUp(self): self.data = ProjectData() self.poly_mix2 = parse_pch2(self.data, get_test_resource('test_poly_mix2.pch2')) self.udo_mix2_k = """;@ args iiiii, kkk, k opcode Mix21A_v0, 0, iiiiiiiii ; MULTIMODE support a/k? ; TODO: lin/log scale, chain input iLev1, iSw1, iLev2, iSw2, iScale, izIn1, izIn2, izInChain, izOut xin k1 zkr izIn1 k2 zkr izIn2 k3 zkr izInChain aout = a1 + a2*kLev1*iSW1 + a3*kLev2*iSW2 zkw aout, izOut endop """ self.udo_mix2_a = """;@ args iiiii, aaa, a
def gen_udo_status_doc(): tpl_url = 'https://github.com/gleb812/pch2csd/blob/master/pch2csd/resources/templates/modules/{}.txt' data = ProjectData() with open('Module-implementation-status.md', 'w') as md: md.write('This file is automatically generated.\n\n') md.write('| Template | Module name | Status |\n') md.write('|----------|-------------|--------|\n') for p in [ parse_pch2(data, get_test_resource(pch2file)) for pch2file in ['test_all_modules_1.pch2', 'test_all_modules_2.pch2'] ]: for m in p.modules: status = StringIO() validate_udo(m.type, status, print_action=False) md.write('| [{}]({}) | {} | {} |\n'.format( '{}.txt'.format(m.type), tpl_url.format(m.type), m.type_name, '<br>'.join(status.getvalue().splitlines())))
def convert_pch2(fn: str): if not fn.lower().endswith('.pch2'): print("error: the patch file should have extension '.pch2'") exit(-1) data = ProjectData() path = os.path.abspath(os.path.expanduser(fn)) p = parse_pch2(data, path) zak = ZakSpace() try: udos = zak.connect_patch(p) except ValueError as e: print('error: {}'.format(e)) exit(-1) csd = Csd(p, zak, udos) dirname = os.path.dirname(path) csd_save_path = os.path.join(dirname, os.path.basename(path) + '.csd') with open(csd_save_path, 'w') as f: f.write(csd.get_code())
def validate_udo(type_id: int, io=sys.stdout, print_action=True): if print_action: print("checking module type '{id}' ({id}.txt)".format(id=type_id), file=io) pch2_files = [ get_test_resource(s) for s in ['test_all_modules_1.pch2', 'test_all_modules_2.pch2'] ] data, mod, patch = ProjectData(), None, None for p in map(lambda x: parse_pch2(data, x), pch2_files): for m in p.modules: if m.type == type_id: mod, patch = m, p break if mod is not None: if print_action: print('module name: {}'.format(mod.type_name), file=io) udo = UdoTemplate(mod) v = UdoTemplateValidation(data, udo) v.print_errors(io) return v.is_valid(with_todos=True) else: print("error: unknown module type '{}'".format(type_id), file=io) return False
def setUp(self): self.data = ProjectData()
def setUp(self): self.data = ProjectData() self.poly_mix2_fn = get_test_resource('test_poly_mix2.pch2') self.modes_LfoC = get_test_resource('test_modes_LfoC.pch2') self.LevAmp = get_test_resource('test_LevAmp.pch2')
def setUp(self): self.data = ProjectData() self.r2b_b2r_fn = get_test_resource('test_convert_r2b_b2r.pch2')
def setUp(self): self.data = ProjectData() self.poly_mix2 = parse_pch2(self.data, get_test_resource('test_poly_mix2.pch2'))
def setUp(self): self.data = ProjectData() self.poly_mix2_fn = get_test_resource('test_poly_mix2.pch2')