sforkowany z mirror/rnsutils
Add sfz parsing with note as midi height as well as default path attributes
rodzic
8872c0e55e
commit
17fc4d3614
|
@ -29,7 +29,7 @@ from rnsutils.instrument import RenoiseInstrument, second_to_renoise_time, db_to
|
|||
from rnsutils.utils import ENCODING_NONE, ENCODING_FLAC, ENCODING_OGG, encode_audio_file
|
||||
|
||||
__date__ = '2016-01-28'
|
||||
__updated__ = '2016-01-28'
|
||||
__updated__ = '2017-02-03'
|
||||
__author__ = 'olivier@pcedev.com'
|
||||
|
||||
|
||||
|
@ -57,10 +57,13 @@ SFZ_NOTE_LETTER_OFFSET = {'a': 9, 'b': 11, 'c': 0, 'd': 2, 'e': 4, 'f': 5, 'g':
|
|||
|
||||
|
||||
def sfz_note_to_midi_key(sfz_note):
|
||||
sharp = '#' in sfz_note
|
||||
letter = sfz_note[0].lower()
|
||||
octave = int(sfz_note[-1])
|
||||
return SFZ_NOTE_LETTER_OFFSET[letter] + ((octave + 1) * 12) + (1 if sharp else 0)
|
||||
try:
|
||||
return int(sfz_note)
|
||||
except ValueError:
|
||||
sharp = '#' in sfz_note
|
||||
letter = sfz_note[0].lower()
|
||||
octave = int(sfz_note[-1])
|
||||
return SFZ_NOTE_LETTER_OFFSET[letter] + ((octave + 1) * 12) + (1 if sharp else 0)
|
||||
|
||||
|
||||
class SfzToXrni(object):
|
||||
|
@ -68,6 +71,7 @@ class SfzToXrni(object):
|
|||
self.encoding = encoding
|
||||
self.sfz_path = sfz_path
|
||||
self.show_unused = show_unused
|
||||
self.sfz_default_path = ''
|
||||
|
||||
def load_default_sample_settings(self, renoise_global_sample, renoise_global_modulation_set):
|
||||
renoise_global_modulation_set.Devices.SampleMixerModulationDevice.Cutoff.Value = self.freq_to_cutoff(20000)
|
||||
|
@ -116,7 +120,7 @@ class SfzToXrni(object):
|
|||
|
||||
for section_name, section_content in sfz_content:
|
||||
|
||||
if section_name == 'group':
|
||||
if section_name in ('group', 'global'):
|
||||
self.convert_section(section_name, section_content, renoise_default_sample,
|
||||
renoise_default_modulation_set, renoise_default_sample,
|
||||
renoise_default_modulation_set, renoise_instrument)
|
||||
|
@ -129,21 +133,24 @@ class SfzToXrni(object):
|
|||
# link sample to its dedicated modulation set
|
||||
renoise_sample.ModulationSetIndex = section_idx
|
||||
|
||||
renoise_sample.FileName = None
|
||||
|
||||
self.convert_section(section_name, section_content, renoise_sample, renoise_modulation_set,
|
||||
renoise_default_sample, renoise_default_modulation_set, renoise_instrument)
|
||||
|
||||
renoise_instrument.root.SampleGenerator.Samples.append(renoise_sample)
|
||||
renoise_instrument.root.SampleGenerator.ModulationSets.append(renoise_modulation_set)
|
||||
if renoise_sample.FileName:
|
||||
renoise_instrument.root.SampleGenerator.Samples.append(renoise_sample)
|
||||
renoise_instrument.root.SampleGenerator.ModulationSets.append(renoise_modulation_set)
|
||||
|
||||
# copy wav content from sfz to renoise
|
||||
sample_filename = search_case_insensitive_path(
|
||||
os.path.join(self.sfz_path, str(renoise_sample.FileName)))
|
||||
# copy wav content from sfz to renoise
|
||||
sample_filename = search_case_insensitive_path(
|
||||
os.path.join(self.sfz_path, self.sfz_default_path, str(renoise_sample.FileName)))
|
||||
|
||||
if sample_filename is None:
|
||||
logging.info("missing sample file '%s'", renoise_sample.FileName)
|
||||
else:
|
||||
with open(sample_filename, 'rb') as sample_content:
|
||||
renoise_instrument.sample_data.append(encode_audio_file(sample_content.read(), self.encoding))
|
||||
if sample_filename is None:
|
||||
logging.info("missing sample file '%s'", renoise_sample.FileName)
|
||||
else:
|
||||
with open(sample_filename, 'rb') as sample_content:
|
||||
renoise_instrument.sample_data.append(encode_audio_file(sample_content.read(), self.encoding))
|
||||
|
||||
section_idx += 1
|
||||
|
||||
|
@ -252,6 +259,8 @@ class SfzToXrni(object):
|
|||
logging.info("Ignoring mute group info")
|
||||
elif key == 'off_by':
|
||||
logging.info("Ignoring mute group info")
|
||||
elif key == 'default_path':
|
||||
self.sfz_default_path = re.sub(r'\\+', r'/', value)
|
||||
else:
|
||||
unused_keys.append(key)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue