How to use the scamp.instruments.ScampInstrument 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 / ensemble.py View on Github external
def new_silent_part(self, name=None):
        """
        Creates and returns a new ScampInstrument for this Ensemble with no PlaybackImplementations.

        :param name: name of the new part
        :return: the newly created ScampInstrument
        """
        return self.add_instrument(ScampInstrument(name, self))
github MarcTheSpark / scamp / scamp / instruments.py View on Github external
def new_silent_part(self, name: str = None, default_spelling_policy: SpellingPolicy = None,
                        clef_preference="from_name") -> 'ScampInstrument':
        """
        Creates and returns a new ScampInstrument for this Ensemble with no PlaybackImplementations.

        :param name: name of the new part
        :param default_spelling_policy: the :attr:`~ScampInstrument.default_spelling_policy` for the new part
        :param clef_preference: the :attr:`~ScampInstrument.clef_preference` for the new part
        :return: the newly created ScampInstrument
        """
        return self.add_instrument(ScampInstrument(name, self, default_spelling_policy=default_spelling_policy,
                                                   clef_preference=clef_preference))
github MarcTheSpark / scamp / scamp / instruments.py View on Github external
clock = Clock()

        # standardize properties if necessary, turn pitch and volume into lists if necessary
        properties = self._standardize_properties(properties)
        pitch = Envelope.from_list(pitch) if hasattr(pitch, "__len__") else pitch
        volume = Envelope.from_list(volume) if hasattr(volume, "__len__") else volume

        # get the starting values for all the parameters to pass to the playback implementations
        start_pitch = pitch.start_level() if isinstance(pitch, Envelope) else pitch
        start_volume = volume.start_level() if isinstance(volume, Envelope) else volume
        other_param_start_values = {param: value.start_level() if isinstance(value, Envelope) else value
                                    for param, value in properties.iterate_extra_parameters_and_values()}

        with self._note_info_lock:
            # generate a new id for this note, and set up all of its info
            note_id = next(ScampInstrument._note_id_generator)
            self._note_info_by_id[note_id] = {
                "clock": clock,
                "start_time_stamp": TimeStamp(clock),
                "end_time_stamp": None,
                "split_points": [],
                "parameter_start_values": dict(other_param_start_values, pitch=start_pitch, volume=start_volume),
                "parameter_values": dict(other_param_start_values, pitch=start_pitch, volume=start_volume),
                "parameter_change_segments": {},
                "segments_list_lock": Lock(),
                "properties": properties,
                "max_volume": max_volume,
                "flags": [] if flags is None else flags
            }

            if clock.is_fast_forwarding() and "silent" not in self._note_info_by_id[note_id]["flags"]:
                self._note_info_by_id[note_id]["flags"].append("silent")
github MarcTheSpark / scamp / scamp / instruments.py View on Github external
assert param_name in note_info["parameter_values"], \
                "Cannot change parameter {}, as it was undefined at note start.".format(param_name)

            if param_name in note_info["parameter_change_segments"]:
                segments_list = note_info["parameter_change_segments"][param_name]
            else:
                segments_list = note_info["parameter_change_segments"][param_name] = []

            # if there was a previous segment changing this same parameter, and it's not done yet, we should abort it
            if len(segments_list) > 0:
                segments_list[-1].abort_if_running()

            # this helps to keep track of which call to change_note_parameter happened first, since when
            # do_animation_sequence gets forked, order can become indeterminate (see comment there)
            call_priority = next(ScampInstrument._change_param_call_counter)

            if hasattr(target_value_or_values, "__len__"):
                # assume linear segments unless otherwise specified
                transition_curve_shape_or_shapes = [0] * len(target_value_or_values) if \
                    transition_curve_shape_or_shapes == 0 else transition_curve_shape_or_shapes
                assert hasattr(transition_length_or_lengths, "__len__") and \
                       hasattr(transition_curve_shape_or_shapes, "__len__")
                assert len(target_value_or_values) == len(transition_length_or_lengths) == \
                       len(transition_curve_shape_or_shapes), \
                    "List of target values must be accompanied by a equal length list of transition lengths and shapes."

                def do_animation_sequence():
                    for target, length, shape in zip(target_value_or_values, transition_length_or_lengths,
                                                     transition_curve_shape_or_shapes):
                        with note_info["segments_list_lock"]:
                            if len(segments_list) > 0 and segments_list[-1].running: