Module:Interval table: Difference between revisions
CompactStar (talk | contribs) No edit summary |
CompactStar (talk | contribs) No edit summary |
||
| Line 5: | Line 5: | ||
local ud = require('Module:Ups and downs notation') | local ud = require('Module:Ups and downs notation') | ||
local ET = require('Module:ET') | local ET = require('Module:ET') | ||
-- Gets mapping of a monzo in a val | |||
local function mapping(monzo, val) | |||
local result = 0 | |||
for k,v in pairs(val) do | |||
result = val[k] * (monzo[k] or 0) | |||
end | |||
return result | |||
end | |||
local function gcd(a, b) | local function gcd(a, b) | ||
return b==0 and a or gcd(b,a%b) | return b==0 and a or gcd(b,a%b) | ||
end | end | ||
| Line 27: | Line 26: | ||
for j=1,max_nd do | for j=1,max_nd do | ||
t = i/gcd(i,j) .. "/" .. j/gcd(i,j) | t = i/gcd(i,j) .. "/" .. j/gcd(i,j) | ||
if (i/j) >= 1 and (i/j) <= max_size and not table_contains(ratio_strings, t) then | if (i/j) >= 1 and (i/j) <= max_size and not u.table_contains(ratio_strings, t) then | ||
ratios[#ratios + 1] = {i/gcd(i,j),j/gcd(i,j)} | ratios[#ratios + 1] = {i/gcd(i,j),j/gcd(i,j)} | ||
ratio_strings[#ratio_strings + 1] = t | ratio_strings[#ratio_strings + 1] = t | ||
| Line 47: | Line 46: | ||
local tuning = frame.args['tuning'] | local tuning = frame.args['tuning'] | ||
local et = ET.parse(tuning) or ET.parse('12edo') | local et = ET.parse(tuning) or ET.parse('12edo') | ||
local patent_val = { | |||
ET.approximate(et, 2), | |||
ET.approximate(et, 3), | |||
ET.approximate(et, 5), | |||
ET.approximate(et, 7), | |||
ET.approximate(et, 11), | |||
ET.approximate(et, 13), | |||
ET.approximate(et, 17), | |||
ET.approximate(et, 19), | |||
ET.approximate(et, 23), | |||
ET.approximate(et, 29), | |||
ET.approximate(et, 31), | |||
ET.approximate(et, 37), | |||
ET.approximate(et, 41), | |||
ET.approximate(et, 47), | |||
ET.approximate(et, 53), | |||
ET.approximate(et, 59), | |||
ET.approximate(et, 61), | |||
} | |||
local wikitext = '{|class="wikitable"\n' | local wikitext = '{|class="wikitable"\n' | ||
local octave = | local octave = patent_val[1] | ||
local fifth = | local fifth = patent_val[2] - patent_val[1] | ||
local fifth_error = ET.cents(et, fifth) - iv._to_cents(3/2) | local fifth_error = ET.cents(et, fifth) - iv._to_cents(3/2) | ||
local dual_fifth = math.abs(fifth_error) > (400 / et.size) | local dual_fifth = math.abs(fifth_error) > (400 / et.size) | ||
local dual_flat_fifth = ET.approximate(et, 3/2, -1) | local dual_flat_fifth = ET.approximate(et, 3/2, -1) | ||
local dual_sharp_fifth = ET.approximate(et, 3/2, 1) | local dual_sharp_fifth = ET.approximate(et, 3/2, 1) | ||
local ratios_list = get_ratios_list( | |||
-- List of all ratios with numerator and denominator <= 60 and in the range 1/1 - 5/1 | |||
local ratios_list = get_ratios_list(60, 5) | |||
wikitext = wikitext .. '!Steps\n' | wikitext = wikitext .. '!Steps\n' | ||
| Line 83: | Line 104: | ||
wikitext = wikitext .. '|' | wikitext = wikitext .. '|' | ||
for j=1,#ratios_list do | for j=1,#ratios_list do | ||
-- Go through all ratios, if they are mapped to the current step in the ET's patent val, add to approximate ratios column | |||
t = mapping(u.get_monzo(ratios_list[j]), patent_val) | |||
-- | if t == i then | ||
wikitext = wikitext .. ratios_list[j][1] .. '/' .. ratios_list[j][2] .. ', ' | |||
wikitext = wikitext .. | |||
end | end | ||
end | end | ||
wikitext = wikitext .. '\n' | wikitext = wikitext:sub(0, -2) .. '\n' | ||
end | end | ||