Module:MOS intro: Difference between revisions

Ganaram inukshuk (talk | contribs)
Changed to revamped function (now includes rothenberg propriety), while maintaining the same wording as before
ArrowHead294 (talk | contribs)
mNo edit summary
 
(48 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local mos = require('Module:MOS')
local rat = require('Module:Rational')
local utils = require('Module:Utils')
local et = require('Module:ET')
local tip = require('Module:Template input parse')
local p = {}
local p = {}


-- Helper function that parses entries from a semicolon-delimited string and returns them in an array
local et = require("Module:ET")
function p.parse_entries(unparsed)
local mos = require("Module:MOS")
local parsed = {}
local rat = require("Module:Rational")
for entry in string.gmatch(unparsed, '([^;]+)') do
local tamnams = require("Module:TAMNAMS")
table.insert(parsed, entry) -- Add to array
local tip = require("Module:Template input parse")
end
local utils = require("Module:Utils")
return parsed
local yesno = require("Module:Yesno")
end
 
-- 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 74: Line 73:


-- Helper function
-- Helper function
-- Introduces the mos by its step counts and number of periods
-- Determines what mos the given mos descends from
-- This is meant to immediately follow the sentence provided by:
-- as well as what step ratio that produces this scale
-- - mos_intro_tamnams_names()
function p.find_mos_ancestor(input_mos)
function p.mos_intro_steps_and_periods(input_mos)
local input_mos = input_mos or mos.new(7, 7)
local input_mos = input_mos or mos.new(3, 6, 3)
-- Get the equave and the equave in cents
local z = input_mos.nL
local equave = input_mos.equave
local w = input_mos.ns
local equave_in_cents = rat.cents(equave)
local generations = 0
local equave_as_ratio = rat.as_ratio(equave)
-- Get the step counts and number of periods
-- For an ancestral mos zU wv and descendant xL ys, how many steps of size
local nL = input_mos.nL -- Number of large steps per equave
-- L and s can fit inside U and v? (basically the chunking operation)
local ns = input_mos.ns -- Number of small steps per equave
local lg_chunk = { nL = 1, ns = 0 }
local n = utils._gcd(nL, ns) -- Number of periods
local sm_chunk = { nL = 0, ns = 1 }
local x = round(nL / n) -- Number of large steps per period
local y = round(ns / n) -- Number of small steps per period
-- Construct the sentence
while (z ~= w) and (z + w > 10) do
sentence = " is "
local m1 = math.max(z, w)
local m2 = math.min(z, w)
-- Is the scale nonoctave?
if equave_in_cents == 1200 then
-- For use with updating ancestor mos chunks
sentence = sentence .. string.format("an [[octave equivalence|octave-equivalent]] [[moment of symmetry]] scale")
local z_prev = z
else
sentence = sentence .. string.format("a [[non-octave]] [[moment of symmetry]] scale", equave_as_ratio)
-- Count how many generations
end
generations = generations + 1
-- What are the step counts? Should the word "step" contain an s?
-- Update step ratios
local s_nl = ""
z = m2
local s_ns = ""
w = m1 - m2
if nL ~= 1 then
s_nl = "s"
-- Update large chunk
end
local prev_lg_chunk = { nL = lg_chunk.nL, ns = lg_chunk.ns }
if ns ~= 1 then
lg_chunk.nL = lg_chunk.nL + sm_chunk.nL
s_ns = "s"
lg_chunk.ns = lg_chunk.ns + sm_chunk.ns
end
sentence = sentence .. string.format(" containing %d large step%s and %d small step%s", nL, s_nl, ns, s_ns)
-- Update small chunk
if z ~= z_prev then
-- How large is the period in cents? Round to 3 decimal places
sm_chunk = prev_lg_chunk
local round = 3
end
local equave_rounded = tostring(utils._round_dec(equave_in_cents, round))
local period_rounded = tostring(utils._round_dec(equave_in_cents / n, round))
-- Should step be singular or plural?
local s_x = ""
local s_y = ""
local repetition = ""
if x ~= 1 then
s_x = "s"
end
if y ~= 1 then
s_y = "s"
end
if n == 2 then
repetition = "twice"
elseif n > 2 then
repetition = string.format("%d times", n)
end
if n == 1 and equave_in_cents == 1200 then
sentence = sentence .. string.format(", repeating every [[octave]].")
elseif n == 1 and equave_in_cents ~= 1200 then
sentence = sentence .. string.format(", repeating every interval of [[%s]] (%s¢).", equave_as_ratio, equave_rounded)
elseif n ~= 1 and equave_in_cents == 1200 then
sentence = sentence .. string.format(", with a [[period]] of %d large step%s and %d small step%s", x, s_x, y, s_y)
sentence = sentence .. string.format(" that repeats every %s¢, or %s every [[octave]].", period_rounded, repetition)
elseif n ~= 1 and equave_in_cents ~= 1200 then
sentence = sentence .. string.format(", with a [[period]] of %d large step%s and %d small step%s", x, s_x, y, s_y)
sentence = sentence .. string.format(" that repeats every %s¢, or %s every interval of %s (%s¢).", period_rounded, repetition, equave_as_ratio, equave_rounded)
end
end
return sentence
return mos.new(z, w, input_mos.equave), lg_chunk, sm_chunk, generations
end
end


-- Helper function
-- Helper function
-- Calculates the brightest mode of the true mos
-- What mos does the input mos descend from?
function p.mos_intro_step_pattern(input_mos)
function p.mos_descends_from(input_mos)
local input_mos = input_mos or mos.new(5, 2)
local input_mos = input_mos or mos.new(7, 7)
local brightest_mode = mos.brightest_mode(input_mos)
local ancestor_mos, lg_chunk, sm_chunk, generations = p.find_mos_ancestor(input_mos)
local sentence = string.format("[[mode|Modes]] of this scale are rotations of the step pattern '''%s'''.", brightest_mode)
--[[
 
-- Calculate the range of step ratios the ancestor should have
return sentence
-- Sort ratios by hardness
end
local num1 = lg_chunk.nL + lg_chunk.ns
 
local den1 = sm_chunk.nL + sm_chunk.ns
-- Helper function
local num2 = lg_chunk.nL
-- Calculates the generator ranges of the mos
local den2 = sm_chunk.nL
function p.mos_intro_generator_ranges(input_mos)
local first_ancestor_step_ratio = ""
local input_mos = input_mos or mos.new(5, 2)
local second_ancestor_step_ratio = ""
if num1/den1 < num2/den2 then
first_ancestor_step_ratio = string.format("%d:%d", num1, den1)
second_ancestor_step_ratio = string.format("%d:%d", num2, den2)
else
first_ancestor_step_ratio = string.format("%d:%d", num2, den2)
second_ancestor_step_ratio = string.format("%d:%d", num1, den1)
end
-- Get the step counts and number of periods
-- Step ratio range as text
local nL = input_mos.nL -- Number of large steps per equave
local step_ratio_range = string.format("%s to %s", first_ancestor_step_ratio, second_ancestor_step_ratio)
local ns = input_mos.ns -- Number of small steps per equave
local n = utils._gcd(nL, ns) -- Number of periods
-- Get the equave as a ratio and in cents
-- Step ratio range as a named range
local equave = input_mos.equave
local named_range = ""
local equave_in_cents = rat.cents(equave)
if step_ratio_range == "1:1 to 2:1" then
named_range = "soft-of-basic"
elseif step_ratio_range == "2:1 to 1:0" then
named_range = "hard-of-basic"
elseif step_ratio_range == "1:1 to 3:2" then
named_range = "soft"
elseif step_ratio_range == "3:2 to 2:1" then
named_range = "hyposoft"
elseif step_ratio_range == "2:1 to 3:1" then
named_range = "hypohard"
elseif step_ratio_range == "3:1 to 1:0" then
named_range = "hard"
elseif step_ratio_range == "1:1 to 4:3" then
named_range = "ultrasoft"
elseif step_ratio_range == "4:3 to 3:2" then
named_range = "parasoft"
elseif step_ratio_range == "3:2 to 5:3" then
named_range = "quasisoft"
elseif step_ratio_range == "5:3 to 2:1" then
named_range = "minisoft"
elseif step_ratio_range == "2:1 to 5:2" then
named_range = "minihard"
elseif step_ratio_range == "5:2 to 3:1" then
named_range = "quasihard"
elseif step_ratio_range == "3:1 to 4:1" then
named_range = "parahard"
elseif step_ratio_range == "4:1 to 1:0" then
named_range = "ultrahard"
end
]]--
-- Get the eds (ets) corresponding to the collapsed and equalized mosses
local descendant_text = ""
local collapsed_et = et.new(nL, input_mos.equave)
if generations == 1 then
local equalized_et = et.new(nL + ns, input_mos.equave)
descendant_text = string.format("%s is a child scale of [[%s]]", mos.as_string(input_mos), mos.as_string(ancestor_mos))
elseif generations == 2 then
-- Get the sizes of the bright generator for the collapsed and equalized et in steps
descendant_text = string.format("%s is a grandchild scale of [[%s]]", mos.as_string(input_mos), mos.as_string(ancestor_mos))
-- These are used to calculate cent values for the generators
elseif generations == 3 then
-- The values for the dark generator are the period complements
descendant_text = string.format("%s is a great-grandchild scale of [[%s]]", mos.as_string(input_mos), mos.as_string(ancestor_mos))
local generator = mos.bright_gen(input_mos)
else
local gen_collapsed_in_steps = generator["L"]
descendant_text = string.format("%s is related to [[%s]]", mos.as_string(input_mos), mos.as_string(ancestor_mos))
local gen_equalized_in_steps = generator["L"] + generator["s"]
end
local bright_gen_max = et.cents(collapsed_et, gen_collapsed_in_steps)
local bright_gen_min = et.cents(equalized_et, gen_equalized_in_steps)
local dark_gen_min = equave_in_cents / n - bright_gen_max
local dark_gen_max = equave_in_cents / n - bright_gen_min
-- Round values
--if named_range == "" then
local round = 3
-- descendant_text = descendant_text .. string.format(", produced by such scales with a [[step ratio]] within the range of %s.", step_ratio_range)
local bright_gen_min_r = tostring(utils._round_dec(bright_gen_min, round))
-- descendant_text = descendant_text .. "."
local bright_gen_max_r = tostring(utils._round_dec(bright_gen_max, round))
--else
local dark_gen_min_r = tostring(utils._round_dec(dark_gen_min, round))
-- descendant_text = descendant_text .. string.format(", produced by such scales with a [[step ratio]] within the %s range (%s).", named_range, step_ratio_range)
local dark_gen_max_r = tostring(utils._round_dec(dark_gen_max, round))
-- descendant_text = descendant_text .. "."
--end
local sentence = string.format("[[generator|Generators]] that produce this scale range from %s¢ to %s¢, or from %s¢ to %s¢.", bright_gen_min_r, bright_gen_max_r, dark_gen_min_r, dark_gen_max_r)
descendant_text = descendant_text .. string.format(", expanding it by %d tones.", input_mos.nL + input_mos.ns - ancestor_mos.nL - ancestor_mos.ns)
return sentence
return descendant_text
end
 
-- Function that creates a mos intro, given a mos and any other names
-- Intro (or lead section) consists of multiple sentences, and each is called individually
function p.mos_intro(input_mos, other_names)
local input_mos = input_mos or mos.new(5, 2)
local other_names = other_names or "name1; name2; name3"
-- Get the scale sig
local scale_sig = mos.as_string(input_mos)
-- Get tamnams names
local tamnams_name = mos.tamnams_name[scale_sig] or ""
-- Parse names
local tamnams_parsed = p.parse_entries(tamnams_name)
local other_parsed = p.parse_entries(other_names)
-- Construct the sentence
local scalesig_and_names = p.mos_intro_names(scale_sig, tamnams_parsed, other_parsed)
local steps_and_periods = p.mos_intro_steps_and_periods(input_mos)
local step_pattern = p.mos_intro_step_pattern(input_mos)
local gens = p.mos_intro_generator_ranges(input_mos)
return string.format("%s %s %s %s", scalesig_and_names, steps_and_periods, step_pattern, gens)
end
end


-- 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(10, 2)
local input_mos = input_mos or mos.new(5, 5, 3)
local other_names = other_names or "hemifourths"
local other_names = ""
-- Scale sig
-- Scale sig
Line 235: Line 208:
-- Tamnams names, if any
-- Tamnams names, if any
local tamnams_name = mos.tamnams_name[scale_sig] or ""
local tamnams_name = tamnams.lookup_name(input_mos) or ""
-- Parsed names
-- Parsed names
Line 241: 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 249: 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 = 3
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 258: Line 232:
-- Add equave equivalence
-- Add equave equivalence
intro = intro .. (equave_in_cents == 1200 and " is an [[octave equivalence|octave-equivalent]] [[moment of symmetry]] scale" or "is a [[nonoctave|non-octave]] [[moment of symmetry scale]]")
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 266: 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]] (%.3f).", equave_as_ratio, utils._round_dec(equave_in_cents, round)))
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 %.3f¢", equave_in_cents / n)
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(" every interval of [[%s]] (%.).", equave_as_ratio, utils._round(equave_in_cents, round)))
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 and nL + ns > 10 and nL ~= ns then
intro = intro .. " " .. p.mos_descends_from(input_mos)
end
-- Add generator ranges
-- Add generator ranges
Line 298: 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(" [[generator|Generators]] that produce this scale range from %to %, or from %to %.", bright_gen_min_r, bright_gen_max_r, dark_gen_min_r, dark_gen_max_r)
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 exhibit [[proper|Rothenberg propriety]] because there is only one small step."
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 in which every period is the same sequence of steps always exhibit [[proper|Rothenberg propriety]] because there is only one small step per period."
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 314: 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['Scale Signature']) or mos.new(5, 2, 2)
local input_mos = mos.parse(frame.args["Scale Signature"]) or mos.new(5, 2, 2)
local other_names = frame.args['Other Names'] or ""
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 p._mos_intro(input_mos, other_names)
return frame:preprocess(result)
end
end


return p
return p