User:Fastaro/Generalized Pythagorean tuning: Difference between revisions

Fastaro (talk | contribs)
Generating the ratios with Python code: - I changed the python code so it can be used in scale work shop
Fastaro (talk | contribs)
Generating the ratios with Python code: - changed to decimal format
Line 56: Line 56:
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
from math import log, floor
from math import log, floor
from fractions import Fraction


# Define 'p' and 'q'(q is the octave term, to keep everything within an octave keep q = 2)
# Define 'p' and 'q'(q is the octave term, to keep everything within an octave keep q = 2)
p = 3
p = 3
q = 2
q = 2
# Format fractions so 1 can be in denominator
def format_fraction(frac):
    if frac.denominator == 1:
        return f"{frac.numerator}/1"
    else:
        return str(frac)


# Define the function to calculate 'n' using the floor function
# Define the function to calculate 'n' using the floor function
def calculate_n(x, p, q):
def calculate_n(x, p, q):
     return floor(x * log(p) / log(q))
     return floor(x * log(p) / log(q))


# Define the range/edo for 'x'
# Define the range/edo for 'x'
Line 71: Line 82:
ratios1 = []
ratios1 = []
ratios2 = []
ratios2 = []


# Calculate and store the values of 'n' and the ratios for each 'x'
# Calculate and store the values of 'n' and the ratios for each 'x'
for x in range(limit):
for x in range(limit):
   
     n = calculate_n(x, p, q)
     n = calculate_n(x, p, q)
     ratio1 = (p**x) / (q**n)
 
     ratio1 = Fraction(p**x, q**n)
     ratios1.append(ratio1)
     ratios1.append(ratio1)
    # Must have this check so an extra note is not placed in for specific limit
     if (x != limit-1):
     if (x != limit-1):
         ratio2 = (q**(n+1)) / (p**x)
         ratio2 = Fraction(q**(n+1), p**x)
         ratios2.append(ratio2)
         ratios2.append(ratio2)


combined_ratios = ratios1 + ratios2
combined_ratios = ratios1 + ratios2


# Sort the combined list from lowest to highest
# Sort the combined list from lowest to highest
sorted_combined_ratios = sorted(combined_ratios)
sorted_combined_ratios = sorted(combined_ratios, key=lambda x: float(x))
formatted_ratios = '\n'.join([f'{ratio:.16f}'.replace('.', ',').rstrip('0').rstrip(',') for ratio in sorted_combined_ratios[1:]])
 
 
# Convert the sorted ratios to strings, remove the first item (1/1), and put it in scaleworkshop format
formatted_ratios_as_fractions = '\n'.join([format_fraction(ratio) for ratio in sorted_combined_ratios][1:])
 


print(formatted_ratios)
print(formatted_ratios_as_fractions)


</syntaxhighlight>1,0534979423868314
</syntaxhighlight>256/243


1,125
9/8


1,1851851851851851
32/27


1,265625
81/64


1,3333333333333333
4/3


1,423828125
729/512


1,5
3/2


1,5802469135802468
128/81


1,6875
27/16


1,7777777777777777
16/9


1,8984375
243/128


2
2/1


== Implications and applications ==
== Implications and applications ==