Module:MOS intro: Difference between revisions

Inthar (talk | contribs)
No edit summary
Ganaram inukshuk (talk | contribs)
Changed to revamped function (now includes rothenberg propriety), while maintaining the same wording as before
Line 3: Line 3:
local utils = require('Module:Utils')
local utils = require('Module:Utils')
local et = require('Module:ET')
local et = require('Module:ET')
local tip = require('Module:Template input parse')
local p = {}
local p = {}


Line 45: Line 46:
-- Introduces the mos by its scale sig and names
-- Introduces the mos by its scale sig and names
-- Names must be entered as an array
-- Names must be entered as an array
function p.mos_intro_names(input_mos, tamnams_name, other_names)
function p.mos_intro_names(scale_sig, tamnams_name, other_names)
local input_mos = input_mos or mos.new(5, 2)
local scale_sig = scale_sig or "5L 2s"
local tamnams_name = tamnams_name or { "diatonic" }
local tamnams_name = tamnams_name or { "diatonic" }
local other_names = other_names or { "other-name" }
local other_names = other_names or { "other-name" }
-- Get the scalesig
local scale_sig = mos.as_string(input_mos)
-- Get all the mos's names, starting with tamnams names if applicable
-- Get all the mos's names, starting with tamnams names if applicable
Line 220: Line 218:
-- Construct the sentence
-- Construct the sentence
local scalesig_and_names = p.mos_intro_names(input_mos, tamnams_parsed, other_parsed)
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 steps_and_periods = p.mos_intro_steps_and_periods(input_mos)
local step_pattern = p.mos_intro_step_pattern(input_mos)
local step_pattern = p.mos_intro_step_pattern(input_mos)
Line 226: Line 224:
return string.format("%s %s %s %s", scalesig_and_names, steps_and_periods, step_pattern, gens)
return string.format("%s %s %s %s", scalesig_and_names, steps_and_periods, step_pattern, gens)
end
-- Main function (updated)
function p._mos_intro(input_mos, other_names)
local input_mos = input_mos or mos.new(10, 2)
local other_names = other_names or "hemifourths"
-- Scale sig
local scale_sig = mos.as_string(input_mos)
-- Tamnams names, if any
local tamnams_name = mos.tamnams_name[scale_sig] or ""
-- Parsed names
local tamnams_pasred = tip.parse_entries(tamnams_name)
local other_parsed = tip.parse_entries(other_names)
-- Step counts
local nL = input_mos.nL
local ns = input_mos.ns
local n = utils._gcd(nL, ns)
-- Equave as ratio and cents
local equave_as_ratio = rat.as_ratio(input_mos.equave)
local equave_in_cents = rat.cents(input_mos.equave)
-- How many decimal places to round to?
local round = 3
-- Build up intro text, starting with the scale sig and scale names
-- This is done through the aid of a helper function
local intro = p.mos_intro_names(scale_sig, tamnams_pasred, other_parsed)
-- 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]]")
-- Add step counts
intro = intro .. string.format(" containing %d large %s", nL, (nL == 1 and "step" or "steps"))
intro = intro .. string.format(" and %d small %s", ns, (ns == 1 and "step" or "steps"))
-- Add repetition
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)))
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(" 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 .. (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]] (%.d¢).", equave_as_ratio, utils._round(equave_in_cents, round)))
end
-- TODO: add descendant info
-- Add generator ranges
-- Get the eds (ets) corresponding to the collapsed and equalized mosses
local collapsed_et = et.new(nL, input_mos.equave)
local equalized_et = et.new(nL + ns, input_mos.equave)
-- Get the sizes of the bright generator for the collapsed and equalized et in steps
-- These are used to calculate cent values for the generators
-- The values for the dark generator are the period complements
local generator = mos.bright_gen(input_mos)
local gen_collapsed_in_steps = generator["L"]
local gen_equalized_in_steps = generator["L"] + generator["s"]
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
local bright_gen_min_r = tostring(utils._round_dec(bright_gen_min, round))
local bright_gen_max_r = tostring(utils._round_dec(bright_gen_max, round))
local dark_gen_min_r = tostring(utils._round_dec(dark_gen_min, 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 %s¢ to %s¢, or from %s¢ to %s¢.", bright_gen_min_r, bright_gen_max_r, dark_gen_min_r, dark_gen_max_r)
-- Rothenberg propriety (rothenprop) info
if ns == 1 then
intro = intro .. "Scales of this form always exhibit [[proper|Rothenberg propriety]] because there is only one small step."
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."
end
return intro
end
end


Line 234: Line 317:
local other_names = frame.args['Other Names'] or ""
local other_names = frame.args['Other Names'] or ""
return p.mos_intro(input_mos, other_names)
return p._mos_intro(input_mos, other_names)
end
end


return p
return p