How to use the scamp._metric_structure.MetricStructure.from_string 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 / score.py View on Github external
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
groups = []
        current_group_length = 1
        for beat_scheme in self.beat_schemes[1:]:
            if beat_scheme.length == last_beat_length:
                current_group_length += 1
            else:
                groups.append(current_group_length)
                current_group_length = 1
                last_beat_length = beat_scheme.length
        groups.append(current_group_length)

        # for each group make a metric layer out of the prime-factored length, breaking up large primes
        # (also, it's possible for a group to be one beat long, in which case it has empty prime factors. In this
        # case, we just need to use a MetricStructure(1)
        return MetricStructure(*(
            MetricStructure.from_string("*".join(str(x) for x in sorted(prime_factor(group))), True)
            if group != 1 else MetricStructure(1)
            for group in groups
        ))
github MarcTheSpark / scamp / scamp / quantization.py View on Github external
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)