How to use the scamp.quantization.QuantizationScheme.from_time_signature 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 / performance.py View on Github external
def to_staff_group(self) -> StaffGroup:
        """
        Converts this PerformancePart to a StaffGroup object.
        (Quantizes in a default way, if necessary, but it should be quantized already.)

        :return: a new StaffGroup made from this PerformancePart
        """
        if not self.is_quantized():
            logging.warning("PerformancePart was not quantized before calling to_staff_group(); "
                            "quantizing according to default quantization time_signature")
            quantization_scheme = QuantizationScheme.from_time_signature(quantization_settings.default_time_signature)
            return self.quantized(quantization_scheme).to_staff_group()
        return StaffGroup.from_quantized_performance_part(self)
github MarcTheSpark / scamp / scamp / performance.py View on Github external
def quantized(self, quantization_scheme: QuantizationScheme = "default",
                  onset_weighting: float = "default",
                  termination_weighting: float = "default") -> 'PerformancePart':
        """
        Same as quantize, except that it returns a new copy, rather than changing this PerformancePart in place.

        :param quantization_scheme: the QuantizationScheme to use. If "default", uses the default time signature defined
            in the quantization_settings.
        :param onset_weighting: how much to weight note onsets in the quantization. If "default", uses the default
            value defined in the quantization_settings.
        :param termination_weighting: how much to weight note terminations in the quantization. If "default", uses the
            default value defined in the quantization_settings.
        :return: a quantized copy of this PerformancePart
        """
        if quantization_scheme == "default":
            quantization_scheme = QuantizationScheme.from_time_signature(quantization_settings.default_time_signature)

        copy = PerformancePart(instrument=self.instrument, name=self.name, voices=deepcopy(self.voices),
                               instrument_id=self._instrument_id)
        quantize_performance_part(copy, quantization_scheme, onset_weighting=onset_weighting,
                                  termination_weighting=termination_weighting)
        return copy
github MarcTheSpark / scamp / scamp / score.py View on Github external
error) to infinity, with a typical value somewhere around 1.
        :param title: Title of the piece to be printed on the score.
        :param composer: Composer of the piece to be printed on the score.
        :return: the resulting Score object, which can then be rendered either as XML or LilyPond
        """

        params = (time_signature, bar_line_locations, max_divisor, max_divisor_indigestibility, simplicity_preference)

        if quantization_scheme is None:
            if any(x is not None for x in params):
                quantization_scheme = QuantizationScheme.from_attributes(
                    time_signature=time_signature, bar_line_locations=bar_line_locations, max_divisor=max_divisor,
                    max_divisor_indigestibility=max_divisor_indigestibility, simplicity_preference=simplicity_preference
                )
            elif not performance.is_quantized():
                quantization_scheme = QuantizationScheme.from_time_signature(
                    quantization_settings.default_time_signature)

        elif any(x is not None for x in params):
            raise AttributeError("Either the quantization_scheme or one or more of the quantization-related arguments "
                                 "can be defined, but not both.")

        return Score.from_quantized_performance(
            performance if quantization_scheme is None else performance.quantized(quantization_scheme),
            title=title, composer=composer
        )
github MarcTheSpark / scamp / scamp / performance.py View on Github external
def quantize(self, quantization_scheme: QuantizationScheme = "default",
                 onset_weighting: float = "default",
                 termination_weighting: float = "default") -> 'PerformancePart':
        """
        Quantizes this PerformancePart according to the quantization_scheme

        :param quantization_scheme: the QuantizationScheme to use. If "default", uses the default time signature defined
            in the quantization_settings.
        :param onset_weighting: how much to weight note onsets in the quantization. If "default", uses the default
            value defined in the quantization_settings.
        :param termination_weighting: how much to weight note terminations in the quantization. If "default", uses the
            default value defined in the quantization_settings.
        :return: this PerformancePart, having been quantized
        """
        if quantization_scheme == "default":
            quantization_scheme = QuantizationScheme.from_time_signature(quantization_settings.default_time_signature)

        quantize_performance_part(self, quantization_scheme, onset_weighting=onset_weighting,
                                  termination_weighting=termination_weighting)
        return self
github MarcTheSpark / scamp / scamp / quantization.py View on Github external
max_divisor_indigestibility = max_divisor_indigestibility \
            if max_divisor_indigestibility is not None else "default"
        simplicity_preference = simplicity_preference if simplicity_preference is not None else "default"

        if isinstance(time_signature, Sequence) and not isinstance(time_signature, str):
            time_signature = list(time_signature)
            # make it easy to loop a series of time signatures by adding the string "loop" at the end
            loop = False
            if isinstance(time_signature[-1], str) and time_signature[-1].lower() == "loop":
                time_signature.pop()
                loop = True
            quantization_scheme = QuantizationScheme.from_time_signature_list(
                time_signature, max_divisor=max_divisor, max_divisor_indigestibility=max_divisor_indigestibility,
                simplicity_preference=simplicity_preference, loop=loop)
        else:
            quantization_scheme = QuantizationScheme.from_time_signature(
                time_signature, max_divisor=max_divisor, max_divisor_indigestibility=max_divisor_indigestibility,
                simplicity_preference=simplicity_preference)
        return quantization_scheme
github MarcTheSpark / scamp / scamp / performance.py View on Github external
def quantize(self, quantization_scheme: QuantizationScheme = "default", onset_weighting: float = "default",
                 termination_weighting: float = "default") -> 'Performance':
        """
        Quantizes all parts according to the quantization_scheme

        :param quantization_scheme: the QuantizationScheme to use. If "default", uses the default time signature defined
            in the quantization_settings.
        :param onset_weighting: how much to weight note onsets in the quantization. If "default", uses the default
            value defined in the quantization_settings.
        :param termination_weighting: how much to weight note terminations in the quantization. If "default", uses the
            default value defined in the quantization_settings.
        :return: this Performance, having been quantized
        """
        if quantization_scheme == "default":
            logging.warning("No quantization scheme given; quantizing according to default time signature.")
            quantization_scheme = QuantizationScheme.from_time_signature(quantization_settings.default_time_signature)

        for part in self.parts:
            part.quantize(quantization_scheme, onset_weighting=onset_weighting,
                          termination_weighting=termination_weighting)
        return self
github MarcTheSpark / scamp / scamp / performance.py View on Github external
def quantized(self, quantization_scheme: QuantizationScheme = "default", onset_weighting: float = "default",
                  termination_weighting: float = "default") -> 'Performance':
        """
        Same as quantize, except that it returns a new copy, rather than changing this Performance in place.

        :param quantization_scheme: the QuantizationScheme to use. If "default", uses the default time signature defined
            in the quantization_settings.
        :param onset_weighting: how much to weight note onsets in the quantization. If "default", uses the default
            value defined in the quantization_settings.
        :param termination_weighting: how much to weight note terminations in the quantization. If "default", uses the
            default value defined in the quantization_settings.
        :return: a quantized copy of this Performance
        """
        if quantization_scheme == "default":
            quantization_scheme = QuantizationScheme.from_time_signature(quantization_settings.default_time_signature)

        return Performance([part.quantized(quantization_scheme, onset_weighting=onset_weighting,
                                           termination_weighting=termination_weighting)
                            for part in self.parts], tempo_envelope=self.tempo_envelope)