Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# if there's a colon, it represents a key / value pair, e.g. "articulation: staccato"
if ":" in note_property:
colon_index = note_property.index(":")
key, value = note_property[:colon_index].replace(" ", "").lower(), \
note_property[colon_index+1:].strip().lower()
else:
# otherwise, leave the key undecided for now
key = None
value = note_property.strip().lower()
# split values into a list based on the slash delimiter
values = [x.strip() for x in value.split("/")]
if key is None:
# if we weren't given a key/value pair, try to find it now
if values[0] in PlaybackAdjustmentsDictionary.all_articulations:
key = "articulations"
elif values[0] in PlaybackAdjustmentsDictionary.all_noteheads:
key = "noteheads"
elif values[0] in PlaybackAdjustmentsDictionary.all_notations:
key = "notations"
elif values[0] in ("#", "b", "sharps", "flats"):
key = "spelling_policy"
elif "volume" in values[0] or "pitch" in values[0] or "length" in values[0]:
key = "playback_adjustments"
else:
raise ValueError("Note property {} not understood".format(note_property))
if key in "articulations": # note that this allows the singular "articulation" too
for value in values:
if value in PlaybackAdjustmentsDictionary.all_articulations:
properties_dict["articulations"].append(value)
],
"default_soundfont": "general_midi",
"default_audio_driver": "auto",
"default_midi_output_device": None,
"default_max_soundfont_pitch_bend": 48,
"default_max_streaming_midi_pitch_bend": 2,
"soundfont_volume_to_velocity_curve": Envelope.from_points((0, 0), (0.1, 40), (1, 127)),
"streaming_midi_volume_to_velocity_curve": Envelope.from_points((0, 0), (1, 127)),
"osc_message_addresses": {
"start_note": "start_note",
"end_note": "end_note",
"change_pitch": "change_pitch",
"change_volume": "change_volume",
"change_parameter": "change_parameter"
},
"adjustments": PlaybackAdjustmentsDictionary(articulations={
"staccato": NotePlaybackAdjustment.scale_params(length=0.5),
"staccatissimo": NotePlaybackAdjustment.scale_params(length=0.3),
"tenuto": NotePlaybackAdjustment.scale_params(length=1.2),
"accent": NotePlaybackAdjustment.scale_params(volume=1.2),
"marcato": NotePlaybackAdjustment.scale_params(volume=1.5),
}),
"try_system_fluidsynth_first": False,
}
_settings_name = "Playback settings"
_json_path = "settings/playbackSettings.json"
_is_root_setting = True
def __init__(self, settings_dict: dict = None):
# This is here to help with auto-completion so that the IDE knows what attributes are available
self.named_soundfonts = self.default_soundfont = self.default_audio_driver = \
def __init__(self, articulations: dict = None, noteheads: dict = None, notations: dict = None):
# make sure there is an entry for every notehead, articulation, and notation
if articulations is None:
articulations = {x: None for x in PlaybackAdjustmentsDictionary.all_articulations}
else:
articulations = {x: articulations[x] if x in articulations else None
for x in PlaybackAdjustmentsDictionary.all_articulations}
if noteheads is None:
noteheads = {x: None for x in PlaybackAdjustmentsDictionary.all_noteheads}
else:
noteheads = {x: noteheads[x] if x in noteheads else None
for x in PlaybackAdjustmentsDictionary.all_noteheads}
if notations is None:
notations = {x: None for x in PlaybackAdjustmentsDictionary.all_notations}
else:
notations = {x: notations[x] if x in notations else None
for x in PlaybackAdjustmentsDictionary.all_notations}
super().__init__(articulations=articulations, noteheads=noteheads, notations=notations)
def _to_dict(self):
return {
key: value._to_dict() if hasattr(value, "_to_dict")
else PlaybackAdjustmentsDictionary._to_dict(value) if isinstance(value, dict)
else value for key, value in self.items() if value is not None
}
def get(self, notation_detail: str) -> NotePlaybackAdjustment:
"""
Get the :class:`NotePlaybackAdjustment` for the given notation detail.
Based on the name of the notation detail, it is automatically determined whether or not we are talking about
an articulation, a notehead, or another kind of notation.
:param notation_detail: name of the notation detail, e.g. "staccato" or "harmonic"
:return: the :class:`NotePlaybackAdjustment` for that detail
"""
if "notehead" in notation_detail:
notation_detail = notation_detail.replace("notehead", "").replace(" ", "").lower()
if notation_detail in PlaybackAdjustmentsDictionary.all_noteheads:
return self["noteheads"][notation_detail]
elif notation_detail in PlaybackAdjustmentsDictionary.all_articulations:
return self["articulations"][notation_detail]
elif notation_detail in PlaybackAdjustmentsDictionary.all_notations:
return self["notations"][notation_detail]
else:
raise ValueError("Playback property not found.")
def get(self, notation_detail: str) -> NotePlaybackAdjustment:
"""
Get the :class:`NotePlaybackAdjustment` for the given notation detail.
Based on the name of the notation detail, it is automatically determined whether or not we are talking about
an articulation, a notehead, or another kind of notation.
:param notation_detail: name of the notation detail, e.g. "staccato" or "harmonic"
:return: the :class:`NotePlaybackAdjustment` for that detail
"""
if "notehead" in notation_detail:
notation_detail = notation_detail.replace("notehead", "").replace(" ", "").lower()
if notation_detail in PlaybackAdjustmentsDictionary.all_noteheads:
return self["noteheads"][notation_detail]
elif notation_detail in PlaybackAdjustmentsDictionary.all_articulations:
return self["articulations"][notation_detail]
elif notation_detail in PlaybackAdjustmentsDictionary.all_notations:
return self["notations"][notation_detail]
else:
raise ValueError("Playback property not found.")
def __init__(self, articulations: dict = None, noteheads: dict = None, notations: dict = None):
# make sure there is an entry for every notehead, articulation, and notation
if articulations is None:
articulations = {x: None for x in PlaybackAdjustmentsDictionary.all_articulations}
else:
articulations = {x: articulations[x] if x in articulations else None
for x in PlaybackAdjustmentsDictionary.all_articulations}
if noteheads is None:
noteheads = {x: None for x in PlaybackAdjustmentsDictionary.all_noteheads}
else:
noteheads = {x: noteheads[x] if x in noteheads else None
for x in PlaybackAdjustmentsDictionary.all_noteheads}
if notations is None:
notations = {x: None for x in PlaybackAdjustmentsDictionary.all_notations}
else:
notations = {x: notations[x] if x in notations else None
for x in PlaybackAdjustmentsDictionary.all_notations}
super().__init__(articulations=articulations, noteheads=noteheads, notations=notations)
properties_dict["articulations"].append(value)
else:
logging.warning("Articulation {} not understood".format(value))
elif key in "noteheads": # note that this allows the singular "notehead" too
properties_dict["noteheads"] = []
for value in values:
if value in PlaybackAdjustmentsDictionary.all_noteheads:
properties_dict["noteheads"].append(value)
else:
logging.warning("Notehead {} not understood".format(value))
properties_dict["noteheads"].append("normal")
elif key in "notations": # note that this allows the singular "notation" too
for value in values:
if value in PlaybackAdjustmentsDictionary.all_notations:
properties_dict["notations"].append(value)
else:
logging.warning("Notation {} not understood".format(value))
elif key in "playback_adjustments": # note that this allows the singular "playback_adjustment" too
for value in values:
properties_dict["playback_adjustments"].append(NotePlaybackAdjustment.from_string(value))
elif key in ("key", "spelling", "spellingpolicy", "spelling_policy"):
try:
properties_dict["spelling_policy"] = SpellingPolicy.from_string(values[0])
except ValueError:
logging.warning("Spelling policy \"{}\" not understood".format(values[0]))
elif key.startswith("param_") or key.endswith("_param"):
if not len(values) == 1: