Module:MOS tuning spectrum: Difference between revisions
New template because I hated my old code so much |
No edit summary |
||
| Line 2: | Line 2: | ||
local ET = require("Module:ET") | local ET = require("Module:ET") | ||
local rat = require("Module:Rational") | local rat = require("Module:Rational") | ||
local | local mediants = require("Module:Mediants") | ||
local utils = require("Module:Utils") | local utils = require("Module:Utils") | ||
local yesno = require("Module:yesno") | local yesno = require("Module:yesno") | ||
local p = {} | local p = {} | ||
-- | -- Re-re-rewrite of tuning spectrum | ||
- | function p._mos_tuning_spectrum(args) | ||
local default_ratios, default_depths | |||
function p. | local default_depth = 5 | ||
local | default_ratios, default_depths = mediants.find_mediants({{1,1}, {1,0}}, default_depth); | ||
local input_mos = args["Input MOS"] or MOS.new(5, 2) | |||
local depth = args["Depth"] or 5 | |||
local comments = args["Comments"] or {} | |||
local step_ratios = args["Ratios"] or default_ratios | |||
local depths = args["Depths"] or default_depths | |||
local input_mos = | |||
local depth = | |||
local comments = | |||
local equave = input_mos.equave | local equave = input_mos.equave | ||
| Line 63: | Line 24: | ||
local n = utils._gcd(L, s) -- Number of periods | local n = utils._gcd(L, s) -- Number of periods | ||
local abstract_bright_gen = MOS.bright_gen(input_mos) | local abstract_bright_gen = MOS.bright_gen(input_mos) | ||
-- What is the equave suffix (edo, edt, edf, ed-p/q) | -- What is the equave suffix (edo, edt, edf, ed-p/q) | ||
| Line 191: | Line 149: | ||
end | end | ||
-- Wrapper function; to be called by template | |||
function p.scale_tree(frame) | function p.scale_tree(frame) | ||
local | local args = getArgs(frame) | ||
local depth = frame.args[" | |||
local | -- Parse scalesig | ||
local comments = | local input_mos = MOS.parse(args["Scale Signature"]) | ||
args["Input MOS"] = input_mos | |||
args["Scale Signature"] = nil | |||
-- Parse depth | |||
local depth = tonumber(args["Depth"]) | |||
frame.args["Depth"] = tonumber(args["Depth"]) | |||
-- Generate mediants and depths | |||
local ratios, depths | |||
ratios, depths = mediants.find_mediants({{1,1}, {1,0}}, depth) | |||
frame.args["Ratios"] = ratios | |||
frame.args["Depths"] = depths | |||
-- Transfer comments from args to comments | |||
local comments = {} | |||
for i = 1, #ratios do | |||
local key = string.format("%d/%d", ratios[i][1], ratios[i][2]) | |||
if args[key] ~= nil then | |||
comments[key] = args[key] | |||
args[key] = nil | |||
end | |||
end | |||
-- Parse debug option | |||
local debugg = yesno(args["debug"]) | |||
local out_str = p._scale_tree( | -- Output | ||
local out_str = p._scale_tree(args) | |||
return frame:preprocess(debugg == true and "<pre>" .. out_str .. "</pre>" or out_str) | return frame:preprocess(debugg == true and "<pre>" .. out_str .. "</pre>" or out_str) | ||
end | end | ||
return p | return p | ||