Commit 47631740 authored by ale's avatar ale

Move some auxiliary binaries to the 'aux' subdir

parent acdc543c
......@@ -13,10 +13,10 @@ libengine_la_LIBADD = $(SNDFILE_LIBS) $(SAMPLERATE_LIBS)
noinst_PROGRAMS = load-drumkit verify-voice
load_drumkit_SOURCES = engine/load-drumkit.c
load_drumkit_SOURCES = aux/load-drumkit.c
load_drumkit_LDADD =
verify_voice_SOURCES = engine/verify-voice.c
verify_voice_SOURCES = aux/verify-voice.c
verify_voice_LDADD =
if LV2
#!/usr/bin/env python
# Convert (some) SFZ metadata files to Hydrogen drumkit files.
import re
import os
import sys
_keys = ['a', 'a#', 'b', 'c', 'c#', 'd', 'd#', 'e', 'f', 'f#', 'g', 'g#']
_keys_to_note = dict((v, k) for k, v in enumerate(_keys))
_key_rx = re.compile(r'^([abcdefg]#?)(\d+)$')
def key_to_note(key):
m = _key_rx.match(key)
base_note = _keys_to_note[]
octave = int(
return 21 + octave * 12 + base_note
def get_key(region):
if 'pitch_keycenter' in region:
return region['pitch_keycenter']
return region['lokey']
def common_root(names):
root = names[0]
for n in names[1:]:
for i in xrange(min(len(root), len(n))):
if root[i] != n[i]:
root = root[:i]
return root.rstrip('-_+=(). ')
def read_sfz(filename):
regions = []
with open(filename) as fd:
in_region = False
region = {}
for line in fd:
line = line.strip()
if not line:
if line.startswith('<region>'):
if region:
region = {'lovel': 0, 'hivel': 127}
in_region = True
elif line.startswith('<'):
in_region = False
elif in_region:
key, value = line.split('=', 1)
value = int(value)
except ValueError:
region[key] = value
return regions
def to_xml(instruments):
print '''<?xml version="1.0" encoding="UTF-8"?>
<drumkit_info xmlns:xsi="" xmlns="">
for id, ins in enumerate(instruments):
print ''' <instrument>
<gain>1</gain>''' % {'id': id, 'name': ins['name'], 'note': ins['note'], 'mute_group': ins['mute_group']}
for l in ins['layers']:
print ''' <layer>
</layer>''' % (l['sample'], l.get('lovel', 0) / 127.0, l.get('hivel', 127) / 127.0)
print ''' </instrumentComponent>
print ''' </instrumentList>
def convert(filename):
dir = os.path.dirname(filename)
regions = read_sfz(filename)
# Regroup by pitch_keycenter
by_pitch = {}
for r in regions:
by_pitch.setdefault(get_key(r), []).append(r)
instruments = []
for key, rlist in by_pitch.iteritems():
note = key_to_note(key)
rlist.sort(key=lambda x: x['lovel'])
instrument_name = common_root([
os.path.splitext(x['sample'])[0] for x in rlist])
if not instrument_name:
instrument_name = 'instrument_%s' + key
'note': note,
'name': instrument_name,
'layers': rlist,
'mute_group': rlist[0].get('group', -1),
print >>sys.stderr, 'note %d: %s' % (note, instrument_name)
for r in rlist:
print >>sys.stderr, ' + [%d, %d] %s' % (
int(r['lovel']), int(r['hivel']),
os.path.join(dir, r['sample']))
if __name__ == '__main__':
if len(sys.argv) < 2:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment