Module:MOS intro: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
Ganaram inukshuk (talk | contribs)
No edit summary
Ganaram inukshuk (talk | contribs)
Cent values are now rounded to 3 decimal places; the word "step" will now be made plural if needed
Line 1: Line 1:
local mos = require('Module:MOS')
local mos = require('Module:MOS')
local rat = require('Module:Rational')
local rat = require('Module:Rational')
local utils = require('Module:Utils')
local et = require('Module:ET')
local utils = require('Module:Utils')
local utils = require('Module:Utils')
local p = {}
local p = {}
Line 6: Line 8:
-- Function that creates a mos intro sentence, given a mos
-- Function that creates a mos intro sentence, given a mos
function p.mos_intro_sentence(input_mos)
function p.mos_intro_sentence(input_mos)
local input_mos = input_mos or mos.new(3, 6)
local input_mos = input_mos or mos.new(4, 5, 3)
-- Get the step counts and number of periods
-- Get the step counts and number of periods
Line 25: Line 27:
local scale_sig = mos.as_string(input_mos)
local scale_sig = mos.as_string(input_mos)
-- Get the range of the generator, which is between the collapsed and equalized generator
-- Get the eds (ets) corresponding to the collapsed and equalized mosses
-- The collapsed generator is the number of L's in the generator divided by the number of L's in the mos
local collapsed_et = et.new(nL, input_mos.equave)
-- 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
local equalized_et = et.new(nL + ns, input_mos.equave)
-- To express those in cent values, multiply by the equave in cents
-- The equalized generator is smaller than the collapsed generator
-- Get the sizes of the generator for the collapsed and equalized et in steps
-- These are used to calculate cent values for the generators
local generator = mos.bright_gen(input_mos)
local generator = mos.bright_gen(input_mos)
local gen_collapsed_in_cents = equave_in_cents * generator["L"] / input_mos.nL
local gen_collapsed_in_steps = generator["L"]
local gen_equalized_in_cents = equave_in_cents * (generator["L"] + generator["s"]) / (input_mos.nL + input_mos.ns)
local gen_equalized_in_steps = generator["L"] + generator["s"]
-- Is the mos octave-equivalent or non-octave?
-- Is the mos octave-equivalent or non-octave?
local is_octave_equivalent = equave_in_cents == 1200
local is_octave_equivalent = equave_in_cents == 1200
-- How many places should cent values be rounded to?
local round = 3
-- Create the intro string
-- Create the intro string
Line 48: Line 54:
-- Add the step counts per period
-- Add the step counts per period
intro = intro .. nL .. " large steps and " .. ns .. " small steps,"
-- Determine where "steps" should be plural or singular, as well
if nL == 1 then
intro = intro .. "1 large step and "
else
intro = intro .. nL .. " large steps and "
end
if ns == 1 then
intro = intro .. "1 small step,"
else
intro = intro .. ns .. " small steps,"
end
-- Add the number of repetitions
-- Add the number of repetitions
-- If multi-period, determine whether "steps" should be plural or singular, as well
if n == 1 then
if n == 1 then
intro = intro .. " repating every "
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
else
intro = intro .. " with a period of " .. x .. " large steps and " .. y .. " small steps that repeats " .. n .. " times every "
if x == 1 then
intro = intro .. " with a period of 1 large step and "
else
intro = intro .. " with a period of " .. n .. " large steps and "
end
if y == 1 then
intro = intro .. "1 small step "
else
intro = intro .. n .. " small steps "
end
if n == 2 then
intro = intro .. "that repeats twice every "
else
intro = intro .. "that repeats " .. n .. " times every "
end
end
end
Line 63: Line 92:
intro = intro .. "octave"
intro = intro .. "octave"
else
else
intro = intro .. "interval of " .. equave_in_cents .. "¢"
intro = intro .. "interval of " .. utils._round_dec(equave_in_cents, round) .. "¢"
end
end
Line 70: Line 99:
intro = intro .. ". "
intro = intro .. ". "
else
else
intro = intro .. ", or every " .. period_in_cents .. "¢. "
intro = intro .. ", or every " .. utils._round_dec(period_in_cents, round) .. "¢. "
end
end
-- Add the generator range
-- Add the generator range
intro = intro .. "This scale is made using a [[generator]] ranging from " .. gen_equalized_in_cents
local collapsed_gen_in_cents = utils._round_dec(et.cents(equalized_et, gen_equalized_in_steps), round)
intro = intro .. "¢ to " .. gen_collapsed_in_cents .. "¢."
local equalized_gen_in_cents = utils._round_dec(et.cents(collapsed_et, gen_collapsed_in_steps), round)
intro = intro .. "This scale is made using a [[generator]] ranging from " .. equalized_gen_in_cents
intro = intro .. "¢ to " .. collapsed_gen_in_cents .. "¢."
return intro
return intro

Revision as of 01:00, 27 May 2023

Module documentation[view] [edit] [history] [purge]
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 
Functions provided (2)
Line Function Params
9 mos_intro_sentence (input_mos)
114 mos_intro (invokable) (frame)
Lua modules required (4)
Variable Module Functions used
et Module:ET new
cents
mos Module:MOS new
as_string
bright_gen
parse
rat Module:Rational gcd
cents
utils Module:Utils _round_dec

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 et = require('Module:ET')
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(4, 5, 3)
	
	-- 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 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 generator for the collapsed and equalized et in steps
	-- These are used to calculate cent values for the generators
	local generator = mos.bright_gen(input_mos)
	local gen_collapsed_in_steps = generator["L"]
	local gen_equalized_in_steps = generator["L"] + generator["s"]
	
	-- Is the mos octave-equivalent or non-octave?
	local is_octave_equivalent = equave_in_cents == 1200
	
	-- How many places should cent values be rounded to?
	local round = 3
	
	-- 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
	-- Determine where "steps" should be plural or singular, as well
	if nL == 1 then
		intro = intro .. "1 large step and "
	else
		intro = intro .. nL .. " large steps and "
	end
	if ns == 1 then
		intro = intro .. "1 small step,"
	else
		intro = intro .. ns .. " small steps,"
	end
	
	-- Add the number of repetitions
	-- If multi-period, determine whether "steps" should be plural or singular, as well
	if n == 1 then
		intro = intro .. " repating every "
	else
		if x == 1 then
			intro = intro .. " with a period of 1 large step and "
		else
			intro = intro .. " with a period of " .. n .. " large steps and "
		end
		if y == 1 then
			intro = intro .. "1 small step "
		else
			intro = intro .. n .. " small steps "
		end
		if n == 2 then
			intro = intro .. "that repeats twice every "
		else
			intro = intro .. "that repeats " .. n .. " times every "
		end
	end
	
	-- Add the equivalence interval
	if is_octave_equivalent then
		intro = intro .. "octave"
	else
		intro = intro .. "interval of " .. utils._round_dec(equave_in_cents, round) .. "¢"
	end
	
	-- Add the period (this is a pun)
	if n == 1 then
		intro = intro .. ". "
	else
		intro = intro .. ", or every " .. utils._round_dec(period_in_cents, round) .. "¢. "
	end
	
	-- Add the generator range
	local collapsed_gen_in_cents = utils._round_dec(et.cents(equalized_et, gen_equalized_in_steps), round)
	local equalized_gen_in_cents = utils._round_dec(et.cents(collapsed_et, gen_collapsed_in_steps), round)
	intro = intro .. "This scale is made using a [[generator]] ranging from " .. equalized_gen_in_cents
	intro = intro .. "¢ to " .. collapsed_gen_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