Module:Interval edo approximation: Difference between revisions

Pailiaq (talk | contribs)
m bug fixing
Pailiaq (talk | contribs)
m bug fixing
Line 1: Line 1:
-- EDO Approximations Module
-- EDO Approximations Module
-- Calculates EDO approximations for just intervals
-- Calculates EDO approximations for just intervals
-- Usage: {{#invoke:EDO_Approximations|main|interval=3/2|tolerance=9|min_edo=10|max_edo=60}}
-- Usage: {{#invoke:EDO_Approximations|main|interval=3/2|tolerance=9|min_edo=5|max_edo=60}}


local p = {}
local p = {}
-- ===== CONFIGURATION VARIABLES =====
local DEFAULT_TOLERANCE = 9.0  -- Relative error tolerance in percent
local DEFAULT_MIN_EDO = 5      -- Minimum EDO to check
local DEFAULT_MAX_EDO = 60    -- Maximum EDO to check
-- ====================================


-- Convert a frequency ratio to cents
-- Convert a frequency ratio to cents
Line 112: Line 118:
     local interval_str = args.interval or args[1]
     local interval_str = args.interval or args[1]


     -- Convert string parameters to numbers with proper defaults
     -- Convert string parameters to numbers using config defaults
    -- Python defaults: RELATIVE_ERROR_TOLERANCE = 9.0, EDO_RANGE_MIN = 10, EDO_RANGE_MAX = 60
     local tolerance = tonumber(args.tolerance) or DEFAULT_TOLERANCE
     local tolerance = tonumber(args.tolerance) or 9.0
     local min_edo = tonumber(args.min_edo) or DEFAULT_MIN_EDO
     local min_edo = tonumber(args.min_edo) or 10
     local max_edo = tonumber(args.max_edo) or DEFAULT_MAX_EDO
     local max_edo = tonumber(args.max_edo) or 60


     -- Validate interval parameter
     -- Validate interval parameter (required, no default)
     if not interval_str then
     if not interval_str then
         return "Error: No interval specified"
         return "Error: No interval specified"