How to use the scamp._note_properties.NotePropertiesDictionary function in scamp

To help you get started, we’ve selected a few scamp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MarcTheSpark / scamp / scamp / _note_properties.py View on Github external
def __init__(self, **kwargs):
        NotePropertiesDictionary._standardize_plural_entry("articulations", kwargs)
        NotePropertiesDictionary._standardize_plural_entry("noteheads", kwargs)
        if len(kwargs["noteheads"]) == 0:
            kwargs["noteheads"] = ["normal"]
        NotePropertiesDictionary._standardize_plural_entry("notations", kwargs)
        NotePropertiesDictionary._standardize_plural_entry("texts", kwargs)
        NotePropertiesDictionary._standardize_plural_entry("playback_adjustments", kwargs)

        for i, adjustment in enumerate(kwargs["playback_adjustments"]):
            if isinstance(adjustment, str):
                kwargs["playback_adjustments"][i] = NotePlaybackAdjustment.from_string(adjustment)

        if "spelling_policy" not in kwargs:
            kwargs["spelling_policy"] = None
        if "temp" not in kwargs:
            # this is a throwaway directory that is not kept when we save to json
            kwargs["temp"] = {}
github MarcTheSpark / scamp / scamp / performance_note.py View on Github external
Represents a single note played by a ScampInstrument

        :param start_time: the start beat of the
        :type start_time: float
        :param length: the length of the note in beats (either a float or a list of floats representing tied segments)
        :param pitch: the pitch of the note (float or Envelope)
        :param volume: the volume of the note (float or Envelope)
        :param properties: dictionary of note properties, or string representing those properties
        """
        self.start_time = start_time
        # if length is a tuple, this indicates that the note is to be split into tied segments
        self.length = length
        # if pitch is a tuple, this indicates a chord
        self.pitch = pitch
        self.volume = volume
        self.properties = properties if isinstance(properties, NotePropertiesDictionary) \
            else NotePropertiesDictionary.from_unknown_format(properties)
github MarcTheSpark / scamp / scamp / score.py View on Github external
def __init__(self, pitch: Union[Envelope, float, Tuple, None], written_length: float,
                 properties: NotePropertiesDictionary):

        self.pitch = pitch
        self.written_length = Fraction(written_length).limit_denominator()
        self.properties = properties if isinstance(properties, NotePropertiesDictionary) \
            else NotePropertiesDictionary.from_unknown_format(properties)
github MarcTheSpark / scamp / scamp / _note_properties.py View on Github external
def mergeable_with(self, other_properties_dict):
        assert isinstance(other_properties_dict, NotePropertiesDictionary)
        return self.articulations == other_properties_dict.articulations and \
               self.notations == other_properties_dict.notations and \
               self.playback_adjustments == other_properties_dict.playback_adjustments and \
               self.text == other_properties_dict.text
github MarcTheSpark / scamp / scamp / performance.py View on Github external
def __init__(self, start_beat: float, length: Union[float, Tuple[float]], pitch: Union[float, Envelope, Sequence],
                 volume: Union[float, Envelope], properties: dict):
        self.start_beat = start_beat
        # if length is a tuple, this indicates that the note is to be split into tied segments
        self.length = length
        # if pitch is a tuple, this indicates a chord
        self.pitch = pitch
        self.volume = volume
        self.properties = properties if isinstance(properties, NotePropertiesDictionary) \
            else NotePropertiesDictionary.from_unknown_format(properties)
github MarcTheSpark / scamp / scamp / _note_properties.py View on Github external
def from_unknown_format(cls, properties):
        """
        Interprets a number of data formats as a NotePropertiesDictionary

        :param properties: can be of several formats:
            - a dictionary of note properties, using the standard format
            - a list of properties, each of which is a string or a NotePlaybackAdjustment. Each string may be
            colon-separated key / value pair (e.g. "articulation: staccato"), or simply the value (e.g. "staccato"),
            in which case an attempt is made to guess the key.
            - a string of comma-separated properties, which just gets split and treated like a list
            - a NotePlaybackAdjustment, which just put in a list and treated like a list input
        :return: a newly constructed NotePropertiesDictionary
        """
        if isinstance(properties, str):
            return NotePropertiesDictionary.from_string(properties)
        elif isinstance(properties, NotePlaybackAdjustment):
            return NotePropertiesDictionary.from_list([properties])
        elif isinstance(properties, list):
            return NotePropertiesDictionary.from_list(properties)
        elif properties is None:
            return cls()
        else:
            assert isinstance(properties, dict), "Properties argument wrongly formatted."
            return cls(**properties)
github MarcTheSpark / scamp / scamp / _note_properties.py View on Github external
def from_string(cls, properties_string):
        assert isinstance(properties_string, str)
        return NotePropertiesDictionary.from_list(_split_string_at_outer_commas(properties_string))
github MarcTheSpark / scamp / scamp / instruments.py View on Github external
def _standardize_properties(self, raw_properties) -> NotePropertiesDictionary:
        """
        Turns the properties given into the standard form of a NotePropertiesDictionary

        :param raw_properties: can be None, a string, a list, or a dict
        :return: a NotePropertiesDictionary
        """
        if isinstance(raw_properties, NotePropertiesDictionary):
            return raw_properties

        properties = NotePropertiesDictionary.from_unknown_format(raw_properties) \
            if not isinstance(raw_properties, NotePropertiesDictionary) else raw_properties

        # resolve the spelling policy based on defaults (local first, then more global)
        if properties["spelling_policy"] is None:
            # if the note doesn't say how to be spelled, check the instrument
            if self.default_spelling_policy is not None:
                properties.spelling_policy = self.default_spelling_policy
            # if the instrument doesn't have a default spelling policy check the host (probably a Session)
            elif self.ensemble is not None and self.ensemble.default_spelling_policy is not None:
                properties.spelling_policy = self.default_spelling_policy
            # if the host doesn't have a default, then don't do anything and it will fall back to playback_settings
        return properties
github MarcTheSpark / scamp / scamp / performance_note.py View on Github external
:param start_time: the start beat of the
        :type start_time: float
        :param length: the length of the note in beats (either a float or a list of floats representing tied segments)
        :param pitch: the pitch of the note (float or Envelope)
        :param volume: the volume of the note (float or Envelope)
        :param properties: dictionary of note properties, or string representing those properties
        """
        self.start_time = start_time
        # if length is a tuple, this indicates that the note is to be split into tied segments
        self.length = length
        # if pitch is a tuple, this indicates a chord
        self.pitch = pitch
        self.volume = volume
        self.properties = properties if isinstance(properties, NotePropertiesDictionary) \
            else NotePropertiesDictionary.from_unknown_format(properties)
github MarcTheSpark / scamp / scamp / _note_properties.py View on Github external
"""
        Interprets a number of data formats as a NotePropertiesDictionary

        :param properties: can be of several formats:
            - a dictionary of note properties, using the standard format
            - a list of properties, each of which is a string or a NotePlaybackAdjustment. Each string may be
            colon-separated key / value pair (e.g. "articulation: staccato"), or simply the value (e.g. "staccato"),
            in which case an attempt is made to guess the key.
            - a string of comma-separated properties, which just gets split and treated like a list
            - a NotePlaybackAdjustment, which just put in a list and treated like a list input
        :return: a newly constructed NotePropertiesDictionary
        """
        if isinstance(properties, str):
            return NotePropertiesDictionary.from_string(properties)
        elif isinstance(properties, NotePlaybackAdjustment):
            return NotePropertiesDictionary.from_list([properties])
        elif isinstance(properties, list):
            return NotePropertiesDictionary.from_list(properties)
        elif properties is None:
            return cls()
        else:
            assert isinstance(properties, dict), "Properties argument wrongly formatted."
            return cls(**properties)