Module:MOS intro: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
| Line 38: | Line 38: | ||
-- Create the intro string | -- Create the intro string | ||
local intro = scale_sig .. " is a" | local intro = "'''" .. scale_sig .. "''' is a" | ||
-- Add whether it's non-octave | -- Add whether it's non-octave | ||
Revision as of 00:46, 26 May 2023
- This module should not be invoked directly; use its corresponding template instead: Template:MOS intro.
This module automatically fills in an introduction for MOS scales. It clarifies the equave, numbers of long and short steps, and range of generators that produce it.
| Introspection summary for Module:MOS intro | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||||||||||||||
No function descriptions were provided. The Lua code may have further information.
local mos = require('Module:MOS')
local rat = require('Module:Rational')
local utils = require('Module:Utils')
local p = {}
-- Function that creates a mos intro sentence, given a mos
function p.mos_intro_sentence(input_mos)
local input_mos = input_mos or mos.new(3, 6)
-- Get the step counts and number of periods
local nL = input_mos.nL -- Number of large steps per equave
local ns = input_mos.ns -- Number of small steps per equave
local n = rat.gcd(nL, ns) -- Number of periods
local x = round(nL / n) -- Number of large steps per period
local y = round(ns / n) -- Number of small steps per period
-- Get the equave as a ratio and in cents
local equave = input_mos.equave
local equave_in_cents = rat.cents(equave)
-- Get the period in cents
local period_in_cents = equave_in_cents / n
-- Get the scalesig
local scale_sig = mos.as_string(input_mos)
-- Get the range of the generator, which is between the collapsed and equalized generator
-- The collapsed generator is the number of L's in the generator divided by the number of L's in the mos
-- The equalized generator is the same, but it's the sum of the number of L's and s's for the generator and mos
-- To express those in cent values, multiply by the equave in cents
-- The equalized generator is smaller than the collapsed generator
local generator = mos.bright_gen(input_mos)
local gen_collapsed_in_cents = equave_in_cents * generator["L"] / input_mos.nL
local gen_equalized_in_cents = equave_in_cents * (generator["L"] + generator["s"]) / (input_mos.nL + input_mos.ns)
-- Is the mos octave-equivalent or non-octave?
local is_octave_equivalent = equave_in_cents == 1200
-- Create the intro string
local intro = "'''" .. scale_sig .. "''' is a"
-- Add whether it's non-octave
if is_octave_equivalent then
intro = intro .. " [[moment of symmetry]] scale consisting of "
else
intro = intro .. " [[non-octave]] [[moment of symmetry]] scale consisting of "
end
-- Add the step counts per period
intro = intro .. nL .. " large steps and " .. ns .. " small steps,"
-- Add the number of repetitions
if n == 1 then
intro = intro .. " repating every "
elseif n == 2 then
intro = intro .. " with a period of " .. x .. " large steps and " .. y .. " small steps that repeats twice every "
else
intro = intro .. " with a period of " .. x .. " large steps and " .. y .. " small steps that repeats " .. n .. " times every "
end
-- Add the equivalence interval
if is_octave_equivalent then
intro = intro .. "octave"
else
intro = intro .. "interval of " .. equave_in_cents .. "¢"
end
-- Add the period (this is a pun)
if n == 1 then
intro = intro .. ". "
else
intro = intro .. ", or every " .. period_in_cents .. "¢. "
end
-- Add the generator range
intro = intro .. "This scale is made using a [[generator]] ranging from " .. gen_equalized_in_cents
intro = intro .. "¢ to " .. gen_collapsed_in_cents .. "¢."
return intro
end
-- Function for use with a template
function p.mos_intro(frame)
-- 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)
return p.mos_intro_sentence(input_mos)
end
return p