scamp_extensions.composers.barlicity.rationalize_scale

scamp_extensions.composers.barlicity.rationalize_scale(cents_values: Sequence[float], nominal_tolerance: float, min_harmonicity: float, num_candidates: int, num_to_return: Optional[int] = None, write_pretty: bool = False) Union[Tuple[Sequence, float], Sequence[Tuple[Sequence, float]]][source]

Uses Clarence Barlow’s algorithms for scale rationalization to determine optimal rational tunings given an input scale in cents values. Candidate scales are generated by finding rational frequency ratios from the start note that satisfy the minimum harmonicity requirement, and that resolve to near the specified number of cents. The nominal tolerance specifies the maximum acceptable deviation from the desired cents value. Having generated interval candidates for each scale degree, all possible scales using these candidates are compared, resulting in a ranking from highest to lowest “specific harmonicity” (which is just a measure of how simple the intrascalar ratios are)..

Parameters:
  • cents_values – An array of cent values for the pitches of the scale, all in reference to a distance from the first degree of the scale

  • nominal_tolerance – Number of cents that ratio candidates are allowed to deviate from the specified cents value. (Intervals that fall further away also rank lower when choosing the top candidates.)

  • min_harmonicity – Minimum harmonicity of intervals used to generate interval candidates.

  • num_candidates – Number of alternative candidates considered for each interval.

  • num_to_return – if None, we just return the best tuning (or a list of equally best tunings) and the specific harmonicity. If a number n, we return a list of the top n tunings as ordered pairs (tuning, harmonicity)

  • write_pretty – if True, it returns a list fraction strings (easier to read); if false, a list of tuples

Returns:

a list of (tuning, specific_harmonicity) tuples, if n > 1, otherwise just the (tuning, harmonicity) pair for the scale with greatest specific harmonicity.