Enable keymap expansion and instrument picking

master
Olivier Jolly 2016-04-06 17:51:27 +02:00
rodzic f8304d2fab
commit 183eaaece8
2 zmienionych plików z 51 dodań i 1 usunięć

Wyświetl plik

@ -26,7 +26,7 @@ import os
from copy import deepcopy
from rnsutils.instrument import RenoiseInstrument
from rnsutils.utils import ENCODING_NONE, encode_audio_file, ENCODING_FLAC, ENCODING_OGG
from rnsutils.utils import ENCODING_NONE, encode_audio_file, ENCODING_FLAC, ENCODING_OGG, expand_keymap
from sf2utils.generator import Sf2Gen
from sf2utils.sf2parse import Sf2File
@ -250,6 +250,9 @@ def main(argv=None):
parser.add_argument("-u", "--unused", dest="show_unused", action="store_true", default=True,
help="show unused generators [default: %(default)s]")
parser.add_argument("--no-unused", dest="show_unused", action="store_false")
parser.add_argument("-i", "--instrument", dest="instruments_index", action="append", type=int,
help="instrument index to extract [default: all]")
parser.add_argument("--no-expand-keymap", dest="no_expand_keymap", action="store_true")
parser.add_argument("-o", "--ouput-dir", dest="output_dir",
help="output directory [default: current directory]")
parser.add_argument("-t", dest="template", help="template filename [default: %(default)s]",
@ -288,6 +291,9 @@ def main(argv=None):
if sf2_instrument.is_sentinel():
continue
if opts.instruments_index and instrument_idx not in opts.instruments_index:
continue
if not opts.quiet:
print("Converting '{}'...".format(sf2_instrument.name), end='')
@ -296,6 +302,9 @@ def main(argv=None):
renoise_instrument = RenoiseInstrument(template_filename=opts.template)
sf2_to_xrni.convert_instrument(sf2_instrument, renoise_instrument)
if not opts.no_expand_keymap:
expand_keymap(renoise_instrument)
output_filename = os.path.join(opts.output_dir or '',
'{}_{}.xrni'.format(instrument_idx, renoise_instrument.name))
# noinspection PyTypeChecker

Wyświetl plik

@ -70,3 +70,44 @@ def encode_audio_file(sample_content, encoding):
return _encode_ogg(sample_content)
return sample_content
def expand_keymap(instrument):
"""expand zones 'horizontally', ie keyranges, to cover as much as possible the whole key mapping"""
for velocity in range(0, 256):
minimum_note_start = None
maximum_note_end = None
# for each velocity, detect extremum zones
for sample_idx, sample in enumerate(instrument.root.SampleGenerator.Samples.Sample):
# only consider zones matching the current velocity
if not (sample.Mapping.VelocityStart <= velocity <= sample.Mapping.VelocityEnd):
continue
if minimum_note_start is None or sample.Mapping.NoteStart < minimum_note_start:
minimum_note_start = sample.Mapping.NoteStart
if maximum_note_end is None or sample.Mapping.NoteEnd > maximum_note_end:
maximum_note_end = sample.Mapping.NoteEnd
# if for the current velocity, we already span the whole range, no need to adapt any zone
if minimum_note_start == 0 and maximum_note_end >= 119:
continue
# else, extends every zone part being an extremum (there can be more than one for layered zones)
for sample in instrument.root.SampleGenerator.Samples.Sample:
if not (sample.Mapping.VelocityStart <= velocity <= sample.Mapping.VelocityEnd):
continue
if sample.Mapping.NoteStart == minimum_note_start:
logging.debug("Changing velocity range from %d-%d to %d-%d", sample.Mapping.NoteStart,
sample.Mapping.NoteEnd, 0, sample.Mapping.NoteEnd)
sample.Mapping.NoteStart = 0
if sample.Mapping.NoteEnd == maximum_note_end:
logging.debug("Changing velocity range from %d-%d to %d-%d", sample.Mapping.NoteStart,
sample.Mapping.NoteEnd, sample.Mapping.NoteStart, 119)
sample.Mapping.NoteEnd = 119