Module:MOS tunings: Difference between revisions
No edit summary |
Added custom JI ratio entry; added option to omit ratios altogether; added search options (hopefully) |
||
| Line 130: | Line 130: | ||
-- Main function | -- Main function | ||
function p._mos_tunings(input_mos, mos_prefix, mos_abbrev, step_ratios, ji_ratios | function p._mos_tunings(input_mos, mos_prefix, mos_abbrev, step_ratios, ji_ratios) | ||
local input_mos = input_mos or mos.new(5,2) | local input_mos = input_mos or mos.new(5,2) | ||
local mos_prefix = mos_prefix or "mos" | local mos_prefix = mos_prefix or "mos" | ||
local mos_abbrev = mos_abbrev or "m" | local mos_abbrev = mos_abbrev or "m" | ||
local step_ratios = step_ratios or { {2,1}, {3,1}, {3,2} } | local step_ratios = step_ratios or {{2,1}, {3,1}, {3,2}} | ||
local | local ji_ratios = ji_ratios or {} | ||
-- Scalesig | |||
local scale_sig = mos.as_string(input_mos) | local scale_sig = mos.as_string(input_mos) | ||
| Line 145: | Line 145: | ||
-- Preprocess JI ratios | -- Preprocess JI ratios | ||
local | local modal_union = mos.modal_union(input_mos) | ||
local sorted_ji_ratios, search_info = p.preprocess_ji_ratios(input_mos, modal_union, step_ratios, ji_ratios) | local sorted_ji_ratios, search_info = p.preprocess_ji_ratios(input_mos, modal_union, step_ratios, ji_ratios) | ||
| Line 175: | Line 174: | ||
-- Headers for JI ratios; this spans two rows | -- Headers for JI ratios; this spans two rows | ||
result = result .. "! rowspan=\"2\" class=\"unsortable\" | Approx.<br>Ratios\n" | if #ji_ratios ~= 0 then | ||
result = result .. "! rowspan=\"2\" class=\"unsortable\" | Approx.<br>Ratios\n" | |||
result = result .. "|-\n" | |||
end | |||
-- Second row of headers | -- Second row of headers | ||
| Line 208: | Line 209: | ||
-- Add cells for JI ratios | -- Add cells for JI ratios | ||
local ratios_as_text = jira.ratios_as_text(sorted_ji_ratios[i]) | if #ji_ratios ~= 0 then | ||
local ratios_as_text = jira.ratios_as_text(sorted_ji_ratios[i]) | |||
result = result .. string.format("|| %s", ratios_as_text) | |||
end | |||
result = result .. "\n" | result = result .. "\n" | ||
| Line 235: | Line 238: | ||
-- Default is the simple step ratios | -- Default is the simple step ratios | ||
parsed = tip.parse_numeric_pairs(unparsed) or {{2,1}, {3,1}, {3,2}} | parsed = tip.parse_numeric_pairs(unparsed) or {{2,1}, {3,1}, {3,2}} | ||
end | |||
return parsed | |||
end | |||
-- Parse JI ratios passed into template | |||
-- If the unparsed string corresponds to a list of JI ratios ("a/b; c/d; e/f"), | |||
-- then parse it as a list of ratios. If it's not that, parse it as search | |||
-- params. If the text is "NONE", then there should be no ratios passed in. | |||
-- If the unparsed string is an empty string, return nil. (This is so the | |||
-- wrapper function can go by default search params.) | |||
function p.parse_ji_ratios(unparsed, equave_in_cents) | |||
local parsed = nil | |||
local parsed_as_search_params = jira.parse_search_params(unparsed) | |||
local parsed_as_ratios = tip.parse_numeric_pairs(unparsed, "/") | |||
if unparsed == "NONE" then | |||
parsed = {} | |||
elseif #parsed_as_ratios ~= 0 then | |||
parsed = parsed_as_ratios | |||
elseif unparsed == "" then | |||
parsed = nil | |||
else | |||
parsed = jira.search_by_params(parsed_as_search_params, equave_in_cents) | |||
end | end | ||
return parsed | return parsed | ||
| Line 243: | Line 268: | ||
-- Get params | -- Get params | ||
local scalesig = frame.args["Scale Signature"] | local scalesig = frame.args["Scale Signature"] | ||
local input_mos = mos.parse(scalesig) | |||
local equave_in_cents = mos.equave_to_cents(input_mos) | |||
local mos_prefix = frame.args["MOS Prefix"] | local mos_prefix = frame.args["MOS Prefix"] | ||
local mos_abbrev = frame.args["MOS Abbrev"] | local mos_abbrev = frame.args["MOS Abbrev"] | ||
local collapsed = yesno(frame.args["Collapsed"], false) -- Currently does nothing | local collapsed = yesno(frame.args["Collapsed"], false) -- Currently does nothing | ||
local step_ratios = p.parse_step_ratios(frame.args["Step Ratios"] | local step_ratios = p.parse_step_ratios(frame.args["Step Ratios"]) or {{1,1}, {3,2}, {2,1}} | ||
local ji_ratios = p.parse_ji_ratios(frame.args["JI Ratios"], equave_in_cents) or jira.search_by_int_limit(30, equave_in_cents) | |||
local | |||
-- Verify name/prefix/abbrev | -- Verify name/prefix/abbrev | ||
mos_prefix = tamnams.verify_prefix(input_mos, mos_prefix) | mos_prefix = tamnams.verify_prefix(input_mos, mos_prefix) | ||