How to use the scamp.utilities.prime_factor 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 _get_beat_metric_layer(beat_length, subdivision_length):
        if not is_multiple(beat_length, subdivision_length):
            raise ValueError("Subdivision length does not neatly subdivide beat.")
        beat_divisor = int(round(beat_length / subdivision_length))

        # first, get the divisor prime factors
        divisor_factors = sorted(prime_factor(beat_divisor))

        # then get the natural divisors of the beat length from big to small
        natural_factors = sorted(prime_factor(Fraction(beat_length).limit_denominator().numerator), reverse=True)

        # now for each natural factor
        for natural_factor in natural_factors:
            # if it's a factor of the divisor
            if natural_factor in divisor_factors:
                # then pop it and move it to the front
                divisor_factors.pop(divisor_factors.index(natural_factor))
                divisor_factors.insert(0, natural_factor)
                # (Note that we sorted the natural factors from big to small so that the small ones get
                # pushed to the front last and end up at the very beginning of the queue)

        return MetricStructure.from_string("*".join(str(x) for x in divisor_factors), True)
github MarcTheSpark / scamp / scamp / score.py View on Github external
def _get_beat_division_hierarchy(beat_length, beat_divisor, small_to_big=True):
    # In general, it's best to divide a beat into the smaller prime factors first. For instance, a 6 tuple is probably
    # easiest as two groups of 3 rather than 3 groups of 2. (This is definitely debatable and context dependent.)
    # An special case occurs when the beat naturally wants to divide a certain way. For instance, a beat of length 1.5
    # divided into 6 will prefer to divide into 3s first and then 2s.

    # first, get the divisor prime factors from big to small (or small to big if set)
    divisor_factors = sorted(prime_factor(beat_divisor), reverse=not small_to_big)

    # then get the natural divisors of the beat length from big to small
    natural_factors = sorted(prime_factor(Fraction(beat_length).limit_denominator().numerator), reverse=True)

    # now for each natural factor
    for natural_factor in natural_factors:
        # if it's a factor of the divisor
        if natural_factor in divisor_factors:
            # then pop it and move it to the front
            divisor_factors.pop(divisor_factors.index(natural_factor))
            divisor_factors.insert(0, natural_factor)
            # (Note that we sorted the natural factors from big to small so that the small ones get
            # pushed to the front last and end up at the very beginning of the queue)

    return MetricStructure.from_string("*".join(str(x) for x in divisor_factors), True).get_beat_depths()
github MarcTheSpark / scamp / scamp / score.py View on Github external
def _get_beat_division_hierarchy(beat_length, beat_divisor, small_to_big=True):
    # In general, it's best to divide a beat into the smaller prime factors first. For instance, a 6 tuple is probably
    # easiest as two groups of 3 rather than 3 groups of 2. (This is definitely debatable and context dependent.)
    # An special case occurs when the beat naturally wants to divide a certain way. For instance, a beat of length 1.5
    # divided into 6 will prefer to divide into 3s first and then 2s.

    # first, get the divisor prime factors from big to small (or small to big if set)
    divisor_factors = sorted(prime_factor(beat_divisor), reverse=not small_to_big)

    # then get the natural divisors of the beat length from big to small
    natural_factors = sorted(prime_factor(Fraction(beat_length).limit_denominator().numerator), reverse=True)

    # now for each natural factor
    for natural_factor in natural_factors:
        # if it's a factor of the divisor
        if natural_factor in divisor_factors:
            # then pop it and move it to the front
            divisor_factors.pop(divisor_factors.index(natural_factor))
            divisor_factors.insert(0, natural_factor)
            # (Note that we sorted the natural factors from big to small so that the small ones get
            # pushed to the front last and end up at the very beginning of the queue)

    return MetricStructure.from_string("*".join(str(x) for x in divisor_factors), True).get_beat_depths()
github MarcTheSpark / scamp / scamp / quantization.py View on Github external
def _get_beat_metric_layer(beat_length, subdivision_length):
        if not is_multiple(beat_length, subdivision_length):
            raise ValueError("Subdivision length does not neatly subdivide beat.")
        beat_divisor = int(round(beat_length / subdivision_length))

        # first, get the divisor prime factors
        divisor_factors = sorted(prime_factor(beat_divisor))

        # then get the natural divisors of the beat length from big to small
        natural_factors = sorted(prime_factor(Fraction(beat_length).limit_denominator().numerator), reverse=True)

        # now for each natural factor
        for natural_factor in natural_factors:
            # if it's a factor of the divisor
            if natural_factor in divisor_factors:
                # then pop it and move it to the front
                divisor_factors.pop(divisor_factors.index(natural_factor))
                divisor_factors.insert(0, natural_factor)
                # (Note that we sorted the natural factors from big to small so that the small ones get
                # pushed to the front last and end up at the very beginning of the queue)

        return MetricStructure.from_string("*".join(str(x) for x in divisor_factors), True)