From bb2a2a2117508ec0126a285d79f9d4245ec6b078 Mon Sep 17 00:00:00 2001 From: boyska Date: Mon, 10 Sep 2018 00:13:15 +0200 Subject: [PATCH] calf2ladspa: makes function with multiple presets --- calf2ladspa/calf2ladspa.py | 53 ++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 22 deletions(-) mode change 100644 => 100755 calf2ladspa/calf2ladspa.py diff --git a/calf2ladspa/calf2ladspa.py b/calf2ladspa/calf2ladspa.py old mode 100644 new mode 100755 index 24f34ca..e8a4372 --- a/calf2ladspa/calf2ladspa.py +++ b/calf2ladspa/calf2ladspa.py @@ -148,7 +148,7 @@ def ls_value_format(v): def ls_format(params, plugin_name): param_set = ', '.join(['{}={}'.format(k, ls_value_format(v)) for k, v in sorted(params.items())]) - return 'a = ladspa.%s(%s, in)' % \ + return ' a = ladspa.%s(%s, a)' % \ (fx_names[plugin_name] if plugin_name in fx_names else plugin_name, param_set) @@ -165,29 +165,38 @@ def usage(): 'liquidsoap ladspa code') +def get_parser(): + p = argparse.ArgumentParser() + p.add_argument('--function-name', type=str, default='calffilter', + help='Generate a liquidsoap function with this name') + p.add_argument('fname', nargs=1, + help='An XML file generated by calfjackhost') + p.add_argument('presets', nargs='*', + help='All the filters you want to use') + return p + + if __name__ == '__main__': - if len(sys.argv) <= 1: - usage() - sys.exit(2) - if sys.argv[1] in ('-h', '--help'): - usage() - sys.exit(0) - fname = sys.argv[1] - preset = sys.argv[2] if len(sys.argv) > 2 else None - dom = parse(fname) - if preset is None: + p = get_parser() + args = p.parse_args() + dom = parse(args.fname[0]) + if not args.presets: print('available presets:') for preset in dom.getElementsByTagName('preset'): print('-', preset.attributes['name'].value) sys.exit(0) - preset = [p for p in dom.getElementsByTagName('preset') - if p.attributes['name'].value == preset][0] - raw_params = parse_params(preset) - fx_type = preset.attributes['plugin'].value - if fx_type not in get_params: - print('plugin <%s> unsupported! output will probably be wrong' % - fx_type, file=sys.stderr) - params = raw_params - else: - params = get_params[fx_type](raw_params) - print(ls_format(params, fx_type)) + print('def %s(a) =' % args.function_name) + for preset in args.presets: + pr_info = [p for p in dom.getElementsByTagName('preset') + if p.attributes['name'].value == preset][0] + raw_params = parse_params(pr_info) + fx_type = pr_info.attributes['plugin'].value + if fx_type not in get_params: + print('plugin <%s> unsupported! output will probably be wrong' % + fx_type, file=sys.stderr) + params = raw_params + else: + params = get_params[fx_type](raw_params) + print(ls_format(params, fx_type)) + print(' a') + print('end')