Module:MOS intro: Difference between revisions
m Rounding for period size in cents |
ArrowHead294 (talk | contribs) mNo edit summary |
||
| (34 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local et = require("Module:ET") | |||
local mos = require("Module:MOS") | |||
local rat = require("Module:Rational") | |||
local tamnams = require("Module:TAMNAMS") | |||
local tip = require("Module:Template input parse") | |||
local utils = require("Module:Utils") | |||
local yesno = require("Module:Yesno") | |||
-- TODO: | |||
-- - Possible cleanup/rewording | |||
-- - Possible official deprecation of other names; focus should be on what a mos | |||
-- is, not what it's called. | |||
-- Helper function | -- Helper function | ||
| Line 110: | Line 118: | ||
-- What mos does the input mos descend from? | -- What mos does the input mos descend from? | ||
function p.mos_descends_from(input_mos) | function p.mos_descends_from(input_mos) | ||
local input_mos = input_mos or mos.new( | local input_mos = input_mos or mos.new(7, 7) | ||
local ancestor_mos, lg_chunk, sm_chunk, generations = p.find_mos_ancestor(input_mos) | local ancestor_mos, lg_chunk, sm_chunk, generations = p.find_mos_ancestor(input_mos) | ||
--[[ | |||
-- Calculate the range of step ratios the ancestor should have | -- Calculate the range of step ratios the ancestor should have | ||
-- Sort ratios by hardness | -- Sort ratios by hardness | ||
| Line 164: | Line 173: | ||
named_range = "ultrahard" | named_range = "ultrahard" | ||
end | end | ||
]]-- | |||
local descendant_text = "" | local descendant_text = "" | ||
| Line 173: | Line 183: | ||
descendant_text = string.format("%s is a great-grandchild scale of [[%s]]", mos.as_string(input_mos), mos.as_string(ancestor_mos)) | descendant_text = string.format("%s is a great-grandchild scale of [[%s]]", mos.as_string(input_mos), mos.as_string(ancestor_mos)) | ||
else | else | ||
descendant_text = string.format("%s is | descendant_text = string.format("%s is related to [[%s]]", mos.as_string(input_mos), mos.as_string(ancestor_mos)) | ||
end | end | ||
if named_range == "" then | --if named_range == "" then | ||
-- descendant_text = descendant_text .. string.format(", produced by such scales with a [[step ratio]] within the range of %s.", step_ratio_range) | |||
else | -- descendant_text = descendant_text .. "." | ||
--else | |||
end | -- descendant_text = descendant_text .. string.format(", produced by such scales with a [[step ratio]] within the %s range (%s).", named_range, step_ratio_range) | ||
-- descendant_text = descendant_text .. "." | |||
--end | |||
descendant_text = descendant_text .. string.format(", expanding it by %d tones.", input_mos.nL + input_mos.ns - ancestor_mos.nL - ancestor_mos.ns) | |||
return descendant_text | return descendant_text | ||
end | end | ||
| Line 188: | Line 201: | ||
-- Main function (updated) | -- Main function (updated) | ||
function p._mos_intro(input_mos, other_names) | function p._mos_intro(input_mos, other_names) | ||
local input_mos = input_mos or mos.new( | local input_mos = input_mos or mos.new(5, 5, 3) | ||
local other_names = | local other_names = "" | ||
-- Scale sig | -- Scale sig | ||
| Line 195: | Line 208: | ||
-- Tamnams names, if any | -- Tamnams names, if any | ||
local tamnams_name = | local tamnams_name = tamnams.lookup_name(input_mos) or "" | ||
-- Parsed names | -- Parsed names | ||
| Line 201: | Line 214: | ||
local other_parsed = tip.parse_entries(other_names) | local other_parsed = tip.parse_entries(other_names) | ||
-- Step counts | -- Step counts for large steps, small steps, and number of periods | ||
local nL = input_mos.nL | local nL = input_mos.nL | ||
local ns = input_mos.ns | local ns = input_mos.ns | ||
| Line 209: | Line 222: | ||
local equave_as_ratio = rat.as_ratio(input_mos.equave) | local equave_as_ratio = rat.as_ratio(input_mos.equave) | ||
local equave_in_cents = rat.cents(input_mos.equave) | local equave_in_cents = rat.cents(input_mos.equave) | ||
local period_in_cents = equave_in_cents / n | |||
-- How many decimal places to round to? | -- How many decimal places to round to? | ||
local round = | local round = 1 | ||
-- Build up intro text, starting with the scale sig and scale names | -- Build up intro text, starting with the scale sig and scale names | ||
| Line 218: | Line 232: | ||
-- Add equave equivalence | -- Add equave equivalence | ||
intro = intro .. | if rat.eq(input_mos.equave, rat.new(2)) then | ||
intro = intro .. " is a 2/1-equivalent ([[octave equivalence|octave-equivalent]]) [[moment of symmetry]] scale" | |||
elseif rat.eq(input_mos.equave, rat.new(3)) then | |||
intro = intro .. " is a 3/1-equivalent ([[tritave]]-equivalent) [[moment of symmetry]] scale" | |||
elseif rat.eq(input_mos.equave, rat.new(3,2)) then | |||
intro = intro .. " is a 3/2-equivalent (fifth-equivalent) [[moment of symmetry]] scale" | |||
else | |||
intro = intro .. string.format(" is a %s-equivalent ([[nonoctave|non-octave]]) [[moment of symmetry]] scale", equave_as_ratio) | |||
end | |||
-- Add step counts | -- Add step counts | ||
| Line 226: | Line 248: | ||
-- Add repetition | -- Add repetition | ||
if n == 1 then | if n == 1 then | ||
intro = intro .. ", repeating every " .. (equave_in_cents == 1200 and "[[octave]]." or string.format(" interval of [[%s]] (%. | intro = intro .. ", repeating every " .. (equave_in_cents == 1200 and "[[octave]]." or string.format(" interval of [[%s]] (%.1f{{cent}}).", equave_as_ratio, equave_in_cents, round)) | ||
else | else | ||
intro = intro .. string.format(", with a [[period]] of %d large %s", nL/n, (nL/n == 1 and "step" or "steps")) | intro = intro .. string.format(", with a [[period]] of %d large %s", nL/n, (nL/n == 1 and "step" or "steps")) | ||
intro = intro .. string.format(" and %d small %s", ns/n, (ns/n == 1 and "step" or "steps")) | intro = intro .. string.format(" and %d small %s", ns/n, (ns/n == 1 and "step" or "steps")) | ||
intro = intro .. string.format(" that repeats every % | intro = intro .. string.format(" that repeats every %.1f{{cent}}", period_in_cents) | ||
intro = intro .. (n == 2 and " or twice every" or string.format(" or %d times every", n)) .. (equave_in_cents == 1200 and " octave." or string.format(" | intro = intro .. (n == 2 and ", or twice every" or string.format(", or %d times every", n)) .. (equave_in_cents == 1200 and " octave." or string.format(" interval of [[%s]] (%.1f{{cent}}).", equave_as_ratio, equave_in_cents, round)) | ||
end | end | ||
-- TODO: add descendant info | -- TODO: add descendant info | ||
if equave_in_cents == 1200 | if equave_in_cents == 1200 and nL + ns > 10 and nL ~= ns then | ||
intro = intro .. " " .. p.mos_descends_from(input_mos) | intro = intro .. " " .. p.mos_descends_from(input_mos) | ||
end | end | ||
| Line 261: | Line 283: | ||
local dark_gen_max_r = tostring(utils._round_dec(dark_gen_max, round)) | local dark_gen_max_r = tostring(utils._round_dec(dark_gen_max, round)) | ||
intro = intro .. string.format(" [[ | intro = intro .. string.format(" [[Generator]]s that produce this scale range from %s{{cent}} to %s{{cent}}, or from %s{{cent}} to %s{{cent}}.", bright_gen_min_r, bright_gen_max_r, dark_gen_min_r, dark_gen_max_r) | ||
-- Rothenberg propriety (rothenprop) info | -- Rothenberg propriety (rothenprop) info | ||
if ns == 1 then | if ns == 1 then | ||
intro = intro .. " Scales of this form always | intro = intro .. " Scales of this form are always [[proper]] because there is only one small step." | ||
elseif ns / n == 1 then | elseif ns / n == 1 then | ||
intro = intro .. " Scales | intro = intro .. " Scales of the true MOS form, where every period is the same, are [[proper]] because there is only one small step per period." | ||
end | end | ||
return intro | return intro | ||
end | end | ||
| Line 277: | Line 298: | ||
function p.mos_intro_frame(frame) | function p.mos_intro_frame(frame) | ||
-- Get and parse the the mos's scale signature, in the form xL ys or xL ys <p/q> | -- Get and parse the the mos's scale signature, in the form xL ys or xL ys <p/q> | ||
local input_mos = mos.parse(frame.args[ | local input_mos = mos.parse(frame.args["Scale Signature"]) or mos.new(5, 2, 2) | ||
local other_names = frame.args[ | local other_names = frame.args["Other Names"] or "" | ||
local depparams = (other_names ~= "" and " [[Category:Pages with deprecated parameters]]" or "") | |||
local result = p._mos_intro(input_mos, other_names) .. depparams | |||
local debugg = yesno(frame.args["debug"]) | |||
-- Debugger option | |||
if debugg == true then | |||
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" | |||
end | |||
return | return frame:preprocess(result) | ||
end | end | ||
return p | return p | ||