Module:MOS intervals: Difference between revisions

Ganaram inukshuk (talk | contribs)
No edit summary
Ganaram inukshuk (talk | contribs)
Adopt verify functions, rewrite for code readability, add option for collapsing intervals table
Line 6: Line 6:
local tamnams = require("Module:TAMNAMS")
local tamnams = require("Module:TAMNAMS")
local interval_extension = require("Module:Interval_extension")
local interval_extension = require("Module:Interval_extension")
local yesno = require("Module:Yesno")
local p = {}
local p = {}


-- TODO:
-- TODO:
-- - Convert tooltips to footnotes... somehow
-- - Address footnotes
-- - Move harmonic entropy to separate module/template pair????


-- Main function; to be called by wrapper
-- Main function; to be called by wrapper
function p._mos_intervals(input_mos, mos_prefix, mos_abbrev)
function p._mos_intervals(input_mos, mos_prefix, mos_abbrev, is_collapsed)
-- Default param for input mos is 5L 2s
-- Default param for input mos is 5L 2s
local input_mos = input_mos or mos.new(5, 2, 2)
local input_mos = input_mos or mos.new(5, 2, 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 is_collapsed = is_collapsed == true
-- Get the scale sig
-- Get the scale sig
Line 44: Line 47:
}
}
-- Create the table, starting with the headers
-- Create the table
local result = "{| class=\"wikitable\"\n"
local result = "{| class=\"wikitable sortable mw-collapsible" .. (is_collapsed and " mw-collapsed\"\n" or "\"\n")
-- Create table caption
result = result
.. "|+ style=\"font-size: 105%;\" | Intervals of " .. scale_sig .. "\n"
.. "|+ style=\"font-size: 105%;\" | Intervals of " .. scale_sig .. "\n"
.. "! colspan=\"3\" | Intervals !! rowspan=\"2\" | Steps subtended !! rowspan=\"2\" | Range in cents !! rowspan=\"2\" | Average of [[HE]]<br/>(from [http://www.mikebattagliamusic.com/HE-JS/HE.html HE Calc])\n !! rowspan=\"2\" | Min of [[HE]]\n"
.. "|-\n"
-- Create table headers
.. "! Generic<sup>[[#mosstep-1|[1]]]</sup> !! Specific<sup>[[#mosstep-2|[2]]]</sup> !! Abbrev.<sup>[[#mosstep-3|[3]]]</sup>\n"
result = result
.. "! colspan=\"3\" | Intervals"
.. "!! rowspan=\"2\" | Steps subtended"
.. "!! rowspan=\"2\" | Range in cents"
.. "!! rowspan=\"2\" | Average of [[HE]]<br/>(from [http://www.mikebattagliamusic.com/HE-JS/HE.html HE Calc])\n"
.. "!! rowspan=\"2\" | Min of [[HE]]\n"
.. "|-\n" -- Start of second row of header cells
.. "! Generic<sup>[[#mosstep-1|[1]]]</sup>"
.. "!! Specific<sup>[[#mosstep-2|[2]]]</sup>"
.. "!! Abbrev.<sup>[[#mosstep-3|[3]]]</sup>\n"
-- Write each row
-- Write each row
Line 131: Line 146:
end
end


function p.mos_intervals_description(input_mos)
function p.mos_intervals_description(input_mos, mos_name, mos_prefix)
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 "dia"
local scalesig = mos.as_string(input_mos)
-- How many periods?
-- What are the period intervals?
local period_count = mos.period_count(input_mos)
local period_count = mos.period_count(input_mos)
local period_interval = mos.period(input_mos)
local period_interval = mos.period(input_mos)
-- What are the period intervals?
local period_intervals = {}
local period_intervals = {}
for i = 1, period_count + 1 do
for i = 1, period_count + 1 do
Line 157: Line 174:
end
end
local tamnams_name = tamnams.lookup_name(input_mos)
local mos_name = tamnams.lookup_name(scalesig)
local scalesig = mos.as_string(input_mos)
local scalesig_and_name = mos_name == nil and scalesig or string.format("%s (%s)", mos_name, scalesig)
local scalesig_and_name = tamnams_name == nil and scalesig or string.format("%s (%s)", tamnams_name, scalesig)
local result = string.format("The intervals of %s are named after the number of mossteps (L and s) they subtend.", scalesig_and_name)
local result = string.format("The intervals of %s are named after the number of mossteps (L and s) they subtend.", scalesig_and_name)
Line 171: Line 187:
.. string.format(" Each interval, apart from %s (%s), has two varieties or sizes each.", period_interval_desc, period_intervals_as_text)
.. string.format(" Each interval, apart from %s (%s), has two varieties or sizes each.", period_interval_desc, period_intervals_as_text)
local gen_qualities_desc = input_mos.nL == input_mos.ns and "." or string.format(", and augmented, perfect, and diminished for the generators of %s.", tamnams_name or scalesig)
local gen_qualities_desc = input_mos.nL == input_mos.ns and "." or string.format(", and augmented, perfect, and diminished for the generators of %s.", mos_name or scalesig)
result = result
result = result
.. string.format(" Interval varieties are named major and minor for the large and small sizes, respectively%s", gen_qualities_desc)
.. string.format(" Interval varieties are named major and minor for the large and small sizes, respectively%s", gen_qualities_desc)
Line 180: Line 196:
-- Wrapper function; to be called by template
-- Wrapper function; to be called by template
function p.mos_intervals(frame)
function p.mos_intervals(frame)
-- Get input mos
-- Get params
local input_mos = mos.parse(frame.args["Scale Signature"])
local scalesig  = frame.args["Scale Signature"]
local mos_prefix = frame.args["MOS Prefix"]
-- Default param for mos prefix
local mos_abbrev = frame.args["MOS Abbrev"]
-- If "NONE" is given, no prefix will be used
local collapsed  = yesno(frame.args["Collapsed"])
-- If left blank, try to find the appropriate mos prefix, or else defualt to "mos"
-- If not left blank, use the prefix passed in instead
local scale_sig = mos.as_string(input_mos)
local mos_prefix = tamnams.lookup_prefix(input_mos)
local mos_abbrev = tamnams.lookup_abbrev(input_mos)
if frame.args["MOS Prefix"] == "NONE" then
-- Parse scalesig
mos_prefix = ""
local input_mos = mos.parse(scalesig)
mos_abbrev = ""
elseif string.len(frame.args["MOS Prefix"]) > 0 then
mos_prefix = frame.args["MOS Prefix"]
mos_abbrev = frame.args["MOS Prefix"]
end
if frame.args["MOS Abbrev"] == "NONE" then
-- Verify name/prefix/abbrev
mos_abbrev = ""
mos_prefix = tamnams.verify_prefix(input_mos, mos_prefix)
elseif string.len(frame.args["MOS Abbrev"]) > 0 then
mos_abbrev = tamnams.verify_abbrev(input_mos, mos_abbrev)
mos_abbrev = frame.args["MOS Abbrev"]
end


return p.mos_intervals_description(input_mos) .. "\n" .. p._mos_intervals(input_mos, mos_prefix, mos_abbrev)
return p.mos_intervals_description(input_mos) .. "\n" .. p._mos_intervals(input_mos, mos_prefix, mos_abbrev, is_collapsed)
end
end


return p
return p