Module:Chord edo approximation: Difference between revisions
No edit summary |
No edit summary |
||
| Line 7: | Line 7: | ||
-- ===== CONFIGURATION VARIABLES ===== | -- ===== CONFIGURATION VARIABLES ===== | ||
local | local DEFAULT_ERROR_BASE = 5 -- Base tolerance % | ||
local DEFAULT_ERROR_PER_INTERVAL = 10 -- Added per interval above root | |||
local DEFAULT_MIN_EDO = 5 | local DEFAULT_MIN_EDO = 5 | ||
local DEFAULT_MAX_EDO = 60 | local DEFAULT_MAX_EDO = 60 | ||
| Line 85: | 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) -- may be nil; computed below if not provided | ||
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 96: | Line 97: | ||
if not notes then | if not notes then | ||
return "Error: Invalid chord format (use 'a:b:c' with positive integers, e.g. '4:5:6')" | return "Error: Invalid chord format (use 'a:b:c' with positive integers, e.g. '4:5:6')" | ||
end | |||
-- Dynamic default tolerance: scales with chord size — 5 + 10·(notes - 1) | |||
-- So dyad=15%, triad=25%, tetrad=35%, pentad=45%, etc. | |||
if not max_total_error then | |||
max_total_error = DEFAULT_ERROR_BASE + DEFAULT_ERROR_PER_INTERVAL * (#notes - 1) | |||
end | end | ||