Module:MOS tuning spectrum: Difference between revisions
todo |
Remove depth arg entirely from function, as deepest depth can be found via helper function from mediants module |
||
| Line 6: | Line 6: | ||
-- TODO: | -- TODO: | ||
-- - (Low priority): Force-add comments that lie outside searched depth. If such | -- - (Low priority): Force-add comments that lie outside searched depth. If such | ||
-- ratios are added, they're added in either the last column or their own | -- ratios are added, they're added in either the last column or their own | ||
| Line 16: | Line 12: | ||
-- Re-re-rewrite of tuning spectrum | -- Re-re-rewrite of tuning spectrum | ||
function p._mos_tuning_spectrum(args) | function p._mos_tuning_spectrum(args) | ||
-- Find default ratios, if nothing was entered | |||
local default_ratios, default_depths | local default_ratios, default_depths | ||
local default_depth = 5 | local default_depth = 5 | ||
default_ratios, default_depths = mediants.find_mediants({{1,1}, {1,0}}, default_depth) | 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 input_mos = args["Input MOS" ] or mos.new(5, 2) | ||
local comments = args["Comments" ] or {} | |||
local comments = args["Comments"] or {} | |||
local step_ratios = args["Step Ratios"] or default_ratios | local step_ratios = args["Step Ratios"] or default_ratios | ||
local depths = args["Depths"] or default_depths | local depths = args["Depths" ] or default_depths | ||
local deepest = mediants.deepest_depth(depths) | |||
local equave = input_mos.equave | local equave = input_mos.equave | ||
local large_steps = input_mos.nL -- Large steps in mos | local large_steps = input_mos.nL -- Large steps in mos | ||
local small_steps = input_mos.ns -- Small steps in mos | local small_steps = input_mos.ns -- Small steps in mos | ||
| Line 71: | Line 68: | ||
.. "|+ style=\"font-size: 105%; white-space: nowrap;\" | " .. string.format("Scale tree and tuning spectrum of %s\n", mos_as_string) | .. "|+ style=\"font-size: 105%; white-space: nowrap;\" | " .. string.format("Scale tree and tuning spectrum of %s\n", mos_as_string) | ||
.. "|-\n" | .. "|-\n" | ||
.. string.format("! rowspan=\"2\" colspan=\"%d\" | Generator<sup><abbr title=\"In steps of %s.\">(%s)</abbr></sup>\n", | .. string.format("! rowspan=\"2\" colspan=\"%d\" | Generator<sup><abbr title=\"In steps of %s.\">(%s)</abbr></sup>\n", deepest + 1, et_suffix, et_suffix) | ||
.. "! colspan=\"2\" | Cents\n" | .. "! colspan=\"2\" | Cents\n" | ||
.. "! colspan=\"2\" | Step ratio\n" | .. "! colspan=\"2\" | Step ratio\n" | ||
| Line 155: | Line 152: | ||
-- Processed args: | -- Processed args: | ||
-- - Input MOS (processed from textual scalesig) | -- - Input MOS (processed from textual scalesig) | ||
-- - Step Ratios (table of step ratios found) | -- - Step Ratios (table of step ratios found) | ||
-- - Depths (table of how deep each step ratio was found at) | -- - Depths (table of how deep each step ratio was found at) | ||
| Line 163: | Line 158: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
-- Parse scalesig | -- Parse scalesig as input mos, then remove scalesig | ||
local input_mos = mos.parse(args["Scale Signature"]) | local input_mos = mos.parse(args["Scale Signature"]) | ||
args["Input MOS"] = input_mos | args["Input MOS"] = input_mos | ||
args["Scale Signature"] = nil | args["Scale Signature"] = nil | ||
-- Parse initial ratios | -- Parse initial ratios | ||
local first_ratio = args["First Step Ratio"] or {1,1} | local first_ratio = args["First Step Ratio"] or {1,1} | ||
local last_ratio = args["Last Step Ratio" ] or {1,0} | local last_ratio = args["Last Step Ratio" ] or {1,0} | ||
-- Then generate mediants and depths | -- Then generate mediants and depths | ||
-- If using depth-based search, parse the depth, then remove it from args | |||
-- If using int-limit search, parse the int limit, then remove it from args, | |||
-- and remove depth for good measure | |||
local step_ratios, depths | local step_ratios, depths | ||
local use_int_limit = args["Int Limit"] ~= nil | |||
if use_int_limit then | if use_int_limit then | ||
-- Int-limit search; parse int-limit | |||
local int_limit = tonumber(args["Int Limit"]) | |||
args["Int Limit"] = nil | |||
-- Find ratios and depths found | |||
step_ratios, depths = mediants.find_mediants_by_int_limit({first_ratio, last_ratio}, int_limit) | step_ratios, depths = mediants.find_mediants_by_int_limit({first_ratio, last_ratio}, int_limit) | ||
else | |||
-- Depth-based search; parse depth | |||
local depth = tonumber(args["Depth"]) or 5 | |||
-- Find ratios and depths found | |||
step_ratios, depths = mediants.find_mediants({first_ratio, last_ratio}, depth) | step_ratios, depths = mediants.find_mediants({first_ratio, last_ratio}, depth) | ||
end | end | ||
args["Depth"] = nil | |||
args["Step Ratios"] = step_ratios | args["Step Ratios"] = step_ratios | ||
args["Depths"] = depths | args["Depths"] = depths | ||