Module:Chord edo approximation: Difference between revisions
No edit summary |
No edit summary |
||
| Line 7: | Line 7: | ||
-- ===== CONFIGURATION VARIABLES ===== | -- ===== CONFIGURATION VARIABLES ===== | ||
local DEFAULT_ERROR_BASE = 5 | local DEFAULT_ERROR_BASE = 5 | ||
local DEFAULT_ERROR_PER_INTERVAL = 10 | local DEFAULT_ERROR_PER_INTERVAL = 10 | ||
local DEFAULT_MIN_EDO = 5 | local DEFAULT_MIN_EDO = 5 | ||
local DEFAULT_MAX_EDO = 60 | local DEFAULT_MAX_EDO = 60 | ||
| Line 86: | Line 86: | ||
local chord_str = args.chord or args[1] | local chord_str = args.chord or args[1] | ||
local chord_name = args.chord_name | local chord_name = args.chord_name | ||
local max_total_error = tonumber(args.max_total_error) | local max_total_error = tonumber(args.max_total_error) | ||
local min_edo = tonumber(args.min_edo) or DEFAULT_MIN_EDO | local min_edo = tonumber(args.min_edo) or DEFAULT_MIN_EDO | ||
local max_edo = tonumber(args.max_edo) or DEFAULT_MAX_EDO | local max_edo = tonumber(args.max_edo) or DEFAULT_MAX_EDO | ||
| Line 99: | Line 99: | ||
end | end | ||
if not max_total_error then | if not max_total_error then | ||
max_total_error = DEFAULT_ERROR_BASE + DEFAULT_ERROR_PER_INTERVAL * (#notes - 1) | max_total_error = DEFAULT_ERROR_BASE + DEFAULT_ERROR_PER_INTERVAL * (#notes - 1) | ||
| Line 128: | Line 126: | ||
return "No edos found within total relative error tolerance of " .. max_total_error .. "%" | return "No edos found within total relative error tolerance of " .. max_total_error .. "%" | ||
end | end | ||
-- Build JI play button: raw cents, no EDO involved | |||
local ji_cents_parts = {"0"} | |||
for _, c in ipairs(intervals_cents) do | |||
table.insert(ji_cents_parts, string.format("%.4f", c)) | |||
end | |||
local ji_cents_data = table.concat(ji_cents_parts, ",") | |||
local ji_play_btn = string.format( | |||
'<span class="edo-chord-play ji" data-cents="%s" title="Play %s in just intonation" role="button" tabindex="0">▶</span>', | |||
ji_cents_data, chord_str) | |||
local output = {} | local output = {} | ||
| Line 137: | Line 145: | ||
local caption_main | local caption_main | ||
if display_name ~= chord_str then | if display_name ~= chord_str then | ||
caption_main = string.format("Edo approximations for %s (%s)", display_name, chord_str) | caption_main = string.format("Edo approximations for %s (%s) %s", display_name, chord_str, ji_play_btn) | ||
else | else | ||
caption_main = string.format("Edo approximations for %s", display_name) | caption_main = string.format("Edo approximations for %s %s", display_name, ji_play_btn) | ||
end | end | ||