Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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:
raise ValueError("Cannot have multiple values for a parameter property.")
properties_dict[key] = json.loads(value)
elif key == "voice":
if not len(values) == 1:
raise ValueError("Cannot have multiple values for a voice property.")
properties_dict["voice"] = value
properties_dict._convert_params_to_envelopes_if_needed()
return properties_dict
_engraving_settings_factory_defaults = {
"max_voices_per_part": 4,
"max_dots_allowed": 3,
"articulation_split_protocols": { # can be first, last, or both
"staccato": "last",
"staccatissimo": "last",
"marcato": "first",
"tenuto": "last",
"accent": "first"
},
"default_titles": ["On the Code Again", "The Long and Winding Code", "Code To Joy", "Take Me Home, Country Codes",
"Thunder Code", "Code to Nowhere", "Goodbye Yellow Brick Code", "Hit the Code, Jack"],
"default_composers": ["HTMLvis", "Rustin Beiber", "Javan Morrison", "Sia++", "The Rubytles", "CSStiny's Child",
"Perl Jam", "PHPrince", ],
"default_spelling_policy": SpellingPolicy.from_string("c major"),
"ignore_empty_parts": True,
"glissandi": GlissandiEngravingSettings(),
"pad_incomplete_parts": True,
"show_music_xml_command_line": "musescore",
}
class EngravingSettings(SavesToJSON):
def __init__(self, **settings):
self._max_voices_per_part = _engraving_settings_factory_defaults["max_voices_per_part"] \
if "max_voices_per_part" not in settings else settings["max_voices_per_part"]
assert isinstance(self._max_voices_per_part, int) and 0 <= self._max_voices_per_part < 5, \
"Max voices per part must be an integer from 1 to 4"
self.max_dots_allowed = _engraving_settings_factory_defaults["max_dots_allowed"] \
if "max_dots_allowed" not in settings else settings["max_dots_allowed"]
def default_spelling_policy(self, value):
if value is None or isinstance(value, SpellingPolicy):
self._default_spelling_policy = value
elif isinstance(value, str):
self._default_spelling_policy = SpellingPolicy.from_string(value)
else:
raise ValueError("Spelling policy not understood.")
def default_spelling_policy(self, value):
if value is None or isinstance(value, SpellingPolicy):
self._default_spelling_policy = value
elif isinstance(value, str):
self._default_spelling_policy = SpellingPolicy.from_string(value)
else:
raise ValueError("Spelling policy not understood.")
def _to_dict(self) -> dict:
# check to see this SpellingPolicy is identical to one made from one of the following string initializers
# if so, save it that way instead, for simplicity
for string_initializer in ("C", "G", "D", "A", "E", "B", "F#", "Db", "Ab", "Eb", "Bb", "F", "b", "#"):
if self.step_alteration_pairs == SpellingPolicy.from_string(string_initializer).step_alteration_pairs:
return {"key": string_initializer}
# otherwise, save the entire spelling
return {"step_alterations": self.step_alteration_pairs}
def spelling_policy(self, value):
if isinstance(value, SpellingPolicy):
self["spelling_policy"] = value
elif isinstance(value, str):
self["spelling_policy"] = SpellingPolicy.from_string(value)
elif hasattr(value, "__len__") and len(value) == 12 and \
all(hasattr(x, "__len__") and len(x) == 2 for x in value):
self["spelling_policy"] = tuple(tuple(x) for x in value)
else:
raise ValueError("Spelling policy not understood.")
"clef_pitch_centers": {
"bass": 48,
"tenor": 57,
"alto": 60,
"treble": 71,
"soprano": 67,
"mezzo-soprano": 64,
"baritone": 53,
},
"clef_selection_policy": "measure-wise",
"default_titles": ["On the Code Again", "The Long and Winding Code", "Code To Joy",
"Take Me Home, Country Codes", "Thunder Code", "Code to Nowhere",
"Goodbye Yellow Brick Code", "Hit the Code, Jack"],
"default_composers": ["HTMLvis", "Rustin Beiber", "Javan Morrison", "Sia++",
"The Rubytles", "CSStiny's Child", "Perl Jam", "PHPrince", ],
"default_spelling_policy": spelling.SpellingPolicy.from_string("C"),
"ignore_empty_parts": True,
"glissandi": GlissandiSettings(),
"tempo": TempoSettings(),
"pad_incomplete_parts": True,
"show_music_xml_command_line": "auto",
"show_microtonal_annotations": False,
}
_settings_name = "Engraving settings"
_json_path = "settings/engravingSettings.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.max_voices_per_part = self.max_dots_allowed = self.beat_hierarchy_spacing = self.num_divisions_penalty = \
self.rest_beat_hierarchy_spacing = self.rest_num_divisions_penalty = self.articulation_split_protocols = \