#! /usr/bin/env python # Create JI scales based on divisions import sys from math import gcd def fractions(n): """ Return all irreducible fractions between 1 and 2 with denominator n """ return[(x,n) for x in range(n+1,2*n) if gcd(x,n) == 1] def rational(x): """ Map a pitch to a rational number """ return float(x[0])/float(x[1]) try: limit = int(sys.argv[1]) + 1 except IndexError: print(f"Usage: {sys.argv[0]} ") sys.exit(1) except ValueError: print(f"Could not parse {sys.argv[1]} as integer") sys.exit(2) # fractions(n) excludes the octave, so we add it manually pitches = [(2,1)] for denominator in range(limit): pitches += fractions(denominator) # Print scala file print(f"{len(pitches)} tone ji scale") print(len(pitches)) for (x,y) in sorted(pitches, key=rational): print(str(x) + "/" + str(y))