Module:Infobox ET: Difference between revisions
Semitones implemented for non-EDOs |
m Refactoring |
||
Line 21: | Line 21: | ||
-- towards is one of: -1 (floor), 0 (nearest), 1 (ceil) | -- towards is one of: -1 (floor), 0 (nearest), 1 (ceil) | ||
local function approximation( | local function approximation(suffix, size, equave, interval, towards, precomputed_approx) | ||
local approx = approximate(size, equave, interval, towards or 0) | local approx = approximate(size, equave, interval, towards or 0) | ||
if precomputed_approx then | if precomputed_approx then | ||
approx = precomputed_approx | approx = precomputed_approx | ||
end | |||
local tuning = size | |||
if not rat.eq(equave, 2) then | |||
tuning = tuning .. suffix | |||
end | end | ||
local ratio = rat.new(approx, size) | local ratio = rat.new(approx, size) | ||
if rat.as_table(ratio)[1] ~= approx then | if rat.as_table(ratio)[1] ~= approx then | ||
ratio = ' (→' .. rat.as_ratio(ratio, '\\') .. ')' | ratio = ' (→' .. rat.as_ratio(ratio, '\\') | ||
if not rat.eq(equave, 2) then | |||
ratio = ratio .. suffix | |||
end | |||
ratio = ratio .. ')' | |||
else | else | ||
ratio = '' | ratio = '' | ||
end | end | ||
local cents = i._to_cents(i._backslash_ratio(approx .. '\\' .. tuning), 6) | |||
return approx .. '\\' .. tuning .. ' (' .. cents .. '¢)' .. ratio | |||
end | end | ||
Line 44: | Line 51: | ||
prime = " (prime)" | prime = " (prime)" | ||
end | end | ||
local suffix = tuning:match('%d+(ed.+)') | |||
local step_size = i._backslash_ratio('1\\' .. tuning) | local step_size = i._backslash_ratio('1\\' .. tuning) | ||
local fifth = approximate(size, equave, 3/2) | local fifth = approximate(size, equave, 3/2) | ||
Line 70: | Line 75: | ||
table.insert(infobox_data, { | table.insert(infobox_data, { | ||
'Fifth', | 'Fifth', | ||
approximation( | approximation(suffix, size, equave, 3/2) | ||
}) | }) | ||
end | end | ||
Line 80: | Line 85: | ||
table.insert(infobox_data, { | table.insert(infobox_data, { | ||
'Sharp fifth', | 'Sharp fifth', | ||
approximation( | approximation(suffix, size, equave, 3/2, 1) | ||
}) | }) | ||
table.insert(infobox_data, { | table.insert(infobox_data, { | ||
'Flat fifth', | 'Flat fifth', | ||
approximation( | approximation(suffix, size, equave, 3/2, -1) | ||
}) | }) | ||
local sharp = approximate(size, equave, 3/2, 1) | local sharp = approximate(size, equave, 3/2, 1) | ||
Line 90: | Line 95: | ||
table.insert(infobox_data, { | table.insert(infobox_data, { | ||
'Major 2nd', | 'Major 2nd', | ||
approximation( | approximation(suffix, size, equave, 9/8, 0, sharp + flat - octave) | ||
}) | }) | ||
end | end |