Module:MOS intervals: Difference between revisions
No edit summary |
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: | ||
-- - | -- - 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 | -- 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) | ||
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 | local mos_name = tamnams.lookup_name(scalesig) | ||
local scalesig_and_name = mos_name == nil and scalesig or string.format("%s (%s)", mos_name, scalesig) | |||
local 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) | 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.", | 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 | -- Get params | ||
local | local scalesig = frame.args["Scale Signature"] | ||
local mos_prefix = frame.args["MOS Prefix"] | |||
local mos_abbrev = frame.args["MOS Abbrev"] | |||
local collapsed = yesno(frame.args["Collapsed"]) | |||
local | |||
local | |||
-- Parse scalesig | |||
local input_mos = mos.parse(scalesig) | |||
-- Verify name/prefix/abbrev | |||
mos_prefix = tamnams.verify_prefix(input_mos, mos_prefix) | |||
mos_abbrev = tamnams.verify_abbrev(input_mos, mos_abbrev) | |||
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 | ||