User:Fastaro/Generalized Pythagorean tuning: Difference between revisions
→Generating the ratios with Python code: - I changed the python code so it can be used in scale work shop |
→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 | |||
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) | 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)) | ||
# 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( | print(formatted_ratios_as_fractions) | ||
</syntaxhighlight> | </syntaxhighlight>256/243 | ||
9/8 | |||
32/27 | |||
81/64 | |||
4/3 | |||
729/512 | |||
3/2 | |||
128/81 | |||
27/16 | |||
16/9 | |||
243/128 | |||
2 | 2/1 | ||
== Implications and applications == | == Implications and applications == | ||