calf2ladspa: support calf eq8

This commit is contained in:
boyska 2018-09-09 22:51:43 +02:00
parent 2a401bebd8
commit bde9138200

View file

@ -2,6 +2,9 @@
import sys
from xml.dom.minidom import parse
import re
from collections import defaultdict
import argparse
def key_change(key):
@ -16,6 +19,10 @@ def starting(key, args):
return any(key.startswith(x) for x in args)
def search(key, *regexps):
return any(bool(re.search(r, key)) for r in regexps)
def parse_params(preset):
return {par.attributes['name'].value: par.attributes['value'].value
for par in preset.getElementsByTagName('param')}
@ -23,29 +30,39 @@ def parse_params(preset):
def multibandcompressor_get_params(params):
newparams = {}
for key in params:
skipped = 0
for key, val in params.items():
if starting(key, ('level_', 'meter_', 'clip_', 'detection',
'compression', 'mode', 'output', 'notebook')):
'compression', 'mode', 'output', 'notebook',
)):
skipped += 1
continue
if key == 'bypass' or key.startswith('solo'):
newparams[key_change(key)] = bool(int(params[key]))
newparams[key_change(key)] = bool(int(val))
elif search(key, r'p\d_q$'):
par['q_%c' % key[1]] = float(val)
elif key.startswith('bypass') or re.match(r'output\d', key):
continue
elif search(key, 's_level$'):
newparams['level_%c' % key[0]] = bool(int(val))
elif starting(key, ('attack', 'ratio', 'release', 'makeup', 'knee',
'threshold')):
newparams[key_change(key)] = float(params[key])
elif starting(key, ('mode', 'notebook', 'output')):
newparams[key_change(key)] = int(params[key])
newparams[key_change(key)] = float(val)
elif search(key, '^mode', '^output', '_mode$'):
newparams[key_change(key)] = int(val)
elif key.startswith('freq'):
num = int(key[-1])
newparams['split_%d_%d' % (num+1, num+2)] = float(params[key])
newparams['split_%d_%d' % (num+1, num+2)] = float(val)
else:
print('!!', key, params[key], file=sys.stderr)
print('!!', key, val, file=sys.stderr)
if skipped:
print('%d skipped' % skipped, file=sys.stderr)
return newparams
def filter_get_params(params):
newparams = {}
skipped = 0
for key in params:
if key == 'freq':
newparams['frequency'] = float(params[key])
@ -57,13 +74,63 @@ def filter_get_params(params):
newparams[key] = int(params[key])
else:
print('!!', key, params[key], file=sys.stderr)
skipped += 1
if skipped:
print('%d skipped' % skipped, file=sys.stderr)
return newparams
def eq_get_params(params):
par = {}
skipped = 0
for key, val in params.items():
if starting(key, ('level_', 'meter_', 'clip_', 'detection',
'compression', 'mode', 'output', 'notebook',
'analyzer', 'zoom', 'individuals', 'bypass',
)) or\
search(key, '^.s_freq$'):
skipped += 1
continue
if search(key, '^bypass$', '^solo'):
par[key_change(key)] = bool(int(val))
elif search(key, r'p\d_q$'):
par['q_%c' % key[1]] = float(val)
elif search(key, r'^p\d_active$'):
par['f%c_active' % key[1]] = bool(int(val))
elif key.endswith('_active'):
par[key] = bool(int(val))
elif search(key, r'\d_freq$'):
par['freq_%c' % key[1]] = float(val)
elif search(key, r'^.p_freq$'):
par['freq_%c' % key[0]] = float(val)
elif search(key, 's_level$'):
par['level_%c' % key[0]] = float(val)
elif search(key, r'^p\d_level$'):
par['level_%c' % key[1]] = float(val)
elif re.match(r'output\d', key):
continue
elif starting(key, ('attack', 'ratio', 'release', 'makeup', 'knee',
'threshold')) \
or re.search('_freq$', key):
par[key_change(key)] = float(val)
elif search(key, '_mode$'):
par[key_change(key)] = int(val)
elif key.startswith('freq'):
num = int(key[-1])
par['split_%d_%d' % (num+1, num+2)] = float(val)
else:
print('!! <%s> = `%s`' % (key, val), file=sys.stderr)
par[key] = val
print('%d skipped' % skipped, file=sys.stderr)
return par
get_params = {
'multibandcompressor': multibandcompressor_get_params,
'filter': filter_get_params,
'eq8': eq_get_params,
}
fx_names = {'eq8': 'equalizer8band'}
def ls_value_format(v):
@ -80,8 +147,10 @@ def ls_value_format(v):
def ls_format(params, plugin_name):
param_set = ', '.join(['{}={}'.format(k, ls_value_format(v))
for k, v in params.items()])
return 'a = ladspa.%s(%s, in)' % (plugin_name, param_set)
for k, v in sorted(params.items())])
return 'a = ladspa.%s(%s, in)' % \
(fx_names[plugin_name] if plugin_name in fx_names
else plugin_name, param_set)
def usage():