How to use the scamp.settings.quantization_settings 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 / quantization.py View on Github external
def _quantize_performance_voice(voice, quantization_scheme, onset_weighting="default", termination_weighting="default",
                                inner_split_weighting="default"):
    """
    Quantizes a voice (modifying notes in place) and returns a QuantizationRecord

    :param voice: a single voice (list of PerformanceNotes) from a PerformancePart
    :param quantization_scheme: a QuantizationScheme
    :param onset_weighting: How much do we care about accurate onsets
    :param termination_weighting: How much do we care about accurate terminations
    :return: QuantizationRecord, detailing all of the time signatures, beat divisions selected, etc.
    """
    assert isinstance(quantization_scheme, QuantizationScheme)
    if onset_weighting == "default":
        onset_weighting = quantization_settings.onset_weighting
    if termination_weighting == "default":
        termination_weighting = quantization_settings.termination_weighting
    if inner_split_weighting == "default":
        inner_split_weighting = quantization_settings.inner_split_weighting

    if engraving_settings.glissandi.control_point_policy == "split":
        for note in voice:
            note._divide_length_at_gliss_control_points()

    # make list of (note onset time, note) tuples
    raw_onsets = [(performance_note.start_beat, performance_note) for performance_note in voice]
    # make list of (note termination time, note) tuples
    raw_terminations = [(performance_note.start_beat + performance_note.length_sum(), performance_note)
                        for performance_note in voice]
    # make list of (inner split time, note) tuples
    raw_inner_splits = []
github MarcTheSpark / scamp / scamp / quantization.py View on Github external
:param max_divisor: the max divisor for all beats in the is measure (see :class:`BeatQuantizationScheme`)
        :param max_divisor_indigestibility: the max indigestibility for all beats in the is measure
            (see :class:`BeatQuantizationScheme`)
        :param simplicity_preference: the simplicity preference for all beats in the is measure
            (see :class:`BeatQuantizationScheme`)
        """
        if bar_line_locations is not None:
            if time_signature is not None:
                raise AttributeError("Either time_signature or bar_line_locations may be defined, but not both.")
            else:
                # since time_signature can be a list of bar lengths, we just convert bar_line_locations to lengths
                time_signature = [bar_line_locations[0]] + [bar_line_locations[i+1] - bar_line_locations[i]
                                                            for i in range(len(bar_line_locations) - 1)]
        elif time_signature is None:
            # if both bar_line_locations and time_signature are none, the time signature should be the settings default
            time_signature = quantization_settings.default_time_signature

        max_divisor = max_divisor if max_divisor is not None else "default"
        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)
github MarcTheSpark / scamp / scamp / quantization.py View on Github external
"""
    Quantizes a voice (modifying notes in place) and returns a QuantizationRecord

    :param voice: a single voice (list of PerformanceNotes) from a PerformancePart
    :param quantization_scheme: a QuantizationScheme
    :param onset_weighting: How much do we care about accurate onsets
    :param termination_weighting: How much do we care about accurate terminations
    :return: QuantizationRecord, detailing all of the time signatures, beat divisions selected, etc.
    """
    assert isinstance(quantization_scheme, QuantizationScheme)
    if onset_weighting == "default":
        onset_weighting = quantization_settings.onset_weighting
    if termination_weighting == "default":
        termination_weighting = quantization_settings.termination_weighting
    if inner_split_weighting == "default":
        inner_split_weighting = quantization_settings.inner_split_weighting

    if engraving_settings.glissandi.control_point_policy == "split":
        for note in voice:
            note._divide_length_at_gliss_control_points()

    # make list of (note onset time, note) tuples
    raw_onsets = [(performance_note.start_beat, performance_note) for performance_note in voice]
    # make list of (note termination time, note) tuples
    raw_terminations = [(performance_note.start_beat + performance_note.length_sum(), performance_note)
                        for performance_note in voice]
    # make list of (inner split time, note) tuples
    raw_inner_splits = []
    for performance_note in voice:
        if hasattr(performance_note.length, "__len__"):
            t = performance_note.start_beat
            for length_segment in performance_note.length[:-1]:
github MarcTheSpark / scamp / scamp / quantization.py View on Github external
All beats will follow the same quantization scheme, as dictated by the parameters.

        :param time_signature: Either a TimeSignature object or something that can be interpreted as such (e.g. a
            string to parse as a time signature, a measure length)
        :param max_divisor: the max divisor for all beats in the is measure (see :class:`BeatQuantizationScheme`)
        :param max_divisor_indigestibility: the max indigestibility for all beats in the is measure
            (see :class:`BeatQuantizationScheme`)
        :param simplicity_preference: the simplicity preference for all beats in the is measure
            (see :class:`BeatQuantizationScheme`)
        """
        # load default settings if not specified (the default simplicity_preference gets loaded
        # later in the constructor of BeatQuantizationScheme if nothing is specified here)
        if max_divisor == "default":
            max_divisor = quantization_settings.max_divisor
        if max_divisor_indigestibility == "default":
            max_divisor_indigestibility = quantization_settings.max_divisor_indigestibility

        # allow for different formulations of the time signature argument
        if isinstance(time_signature, str):
            time_signature = TimeSignature.from_string(time_signature)
        elif isinstance(time_signature, tuple):
            time_signature = TimeSignature(*time_signature)
        elif isinstance(time_signature, Number):
            time_signature = TimeSignature.from_measure_length(time_signature)

        assert isinstance(time_signature, TimeSignature)

        # now we convert the beat lengths to BeatQuantizationSchemes and construct our object
        if max_divisor_indigestibility is None:
            # no max_divisor_indigestibility, so just use the max divisor
            beat_schemes = [
                BeatQuantizationScheme.from_max_divisor(beat_length, max_divisor, simplicity_preference)
github MarcTheSpark / scamp / scamp / quantization.py View on Github external
def _quantize_performance_voice(voice, quantization_scheme, onset_weighting="default", termination_weighting="default",
                                inner_split_weighting="default"):
    """
    Quantizes a voice (modifying notes in place) and returns a QuantizationRecord

    :param voice: a single voice (list of PerformanceNotes) from a PerformancePart
    :param quantization_scheme: a QuantizationScheme
    :param onset_weighting: How much do we care about accurate onsets
    :param termination_weighting: How much do we care about accurate terminations
    :return: QuantizationRecord, detailing all of the time signatures, beat divisions selected, etc.
    """
    assert isinstance(quantization_scheme, QuantizationScheme)
    if onset_weighting == "default":
        onset_weighting = quantization_settings.onset_weighting
    if termination_weighting == "default":
        termination_weighting = quantization_settings.termination_weighting
    if inner_split_weighting == "default":
        inner_split_weighting = quantization_settings.inner_split_weighting

    if engraving_settings.glissandi.control_point_policy == "split":
        for note in voice:
            note._divide_length_at_gliss_control_points()

    # make list of (note onset time, note) tuples
    raw_onsets = [(performance_note.start_beat, performance_note) for performance_note in voice]
    # make list of (note termination time, note) tuples
    raw_terminations = [(performance_note.start_beat + performance_note.length_sum(), performance_note)
                        for performance_note in voice]
    # make list of (inner split time, note) tuples
    raw_inner_splits = []
    for performance_note in voice:
        if hasattr(performance_note.length, "__len__"):
github MarcTheSpark / scamp / scamp / quantization.py View on Github external
def __init__(self, length: float, divisors: Sequence, simplicity_preference: float = "default"):

        # load default if not specified
        if simplicity_preference == "default":
            simplicity_preference = quantization_settings.simplicity_preference

        # actual length of the beat
        self.length = float(length)
        self.length_as_fraction = Fraction(length).limit_denominator()
        assert is_x_pow_of_y(self.length_as_fraction.denominator, 2), \
            "Beat length must be some multiple of a power of 2 division of the bar."

        # now we populate a self.quantization_divisions with tuples consisting of the allowed divisions and
        # their undesirabilities. Undesirability is a factor by which the error in a given quantization option
        # is multiplied; the lowest possible undesirability is 1
        assert hasattr(divisors, "__len__") and len(divisors) > 0
        if isinstance(divisors[0], tuple):
            # already (divisor, undesirability) tuples
            self.quantization_divisions = divisors
        else:
            # we've just been given the divisors, and have to figure out the undesirabilities
github MarcTheSpark / scamp / scamp / quantization.py View on Github external
"""
        Constructs a MeasureQuantizationScheme from a time signature.
        All beats will follow the same quantization scheme, as dictated by the parameters.

        :param time_signature: Either a TimeSignature object or something that can be interpreted as such (e.g. a
            string to parse as a time signature, a measure length)
        :param max_divisor: the max divisor for all beats in the is measure (see :class:`BeatQuantizationScheme`)
        :param max_divisor_indigestibility: the max indigestibility for all beats in the is measure
            (see :class:`BeatQuantizationScheme`)
        :param simplicity_preference: the simplicity preference for all beats in the is measure
            (see :class:`BeatQuantizationScheme`)
        """
        # load default settings if not specified (the default simplicity_preference gets loaded
        # later in the constructor of BeatQuantizationScheme if nothing is specified here)
        if max_divisor == "default":
            max_divisor = quantization_settings.max_divisor
        if max_divisor_indigestibility == "default":
            max_divisor_indigestibility = quantization_settings.max_divisor_indigestibility

        # allow for different formulations of the time signature argument
        if isinstance(time_signature, str):
            time_signature = TimeSignature.from_string(time_signature)
        elif isinstance(time_signature, tuple):
            time_signature = TimeSignature(*time_signature)
        elif isinstance(time_signature, Number):
            time_signature = TimeSignature.from_measure_length(time_signature)

        assert isinstance(time_signature, TimeSignature)

        # now we convert the beat lengths to BeatQuantizationSchemes and construct our object
        if max_divisor_indigestibility is None:
            # no max_divisor_indigestibility, so just use the max divisor