calf2ladspa: makes function with multiple presets
This commit is contained in:
parent
bde9138200
commit
bb2a2a2117
1 changed files with 31 additions and 22 deletions
53
calf2ladspa/calf2ladspa.py
Normal file → Executable file
53
calf2ladspa/calf2ladspa.py
Normal file → Executable file
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue