Module:MOS genchain

From Xenharmonic Wiki
Revision as of 07:49, 30 July 2024 by Ganaram inukshuk (talk | contribs) (Base functionality complete (the for loops, basically))
Jump to navigation Jump to search
Module documentation[view] [edit] [history] [purge]
This module should not be invoked directly; use its corresponding template instead: Template:MOS genchain.

This module produces a table illustrating the generator chain for a MOS scale.

Introspection summary for Module:MOS genchain 
Functions provided (2)
Line Function Params
20 preprocess_genchain (input_mos)
34 _mos_genchain (main) (input_mos)
Lua modules required (4)
Variable Module Functions used
mos Module:MOS new
period_step_count
bright_gen
interval_mul
period_reduce
interval_add
period_count
period
tamnams Module:TAMNAMS degree_quality
tip Module:Template input parse dependency not used
yesno Module:Yesno dependency not used

No function descriptions were provided. The Lua code may have further information.


local mos = require("Module:MOS")
local tip = require("Module:Template input parse")
local tamnams = require("Module:TAMNAMS")
local yesno = require("Module:Yesno")
local p = {}

-- Global variables for cell colors
-- Colors are as follows:
-- - Orange and blue for small and large sizes, respectively
-- - Darker colors for altered scale degrees
-- - No color for period intervals
p.cell_color_none = "NONE"				-- For cells that don't have a color (default cell color applies)
p.cell_color_perfect_size = "NONE"		-- Only applies for periods, including the root and equave
p.cell_color_lg_altered_size = "#BDD7EE"
p.cell_color_large_size      = "#DDEBF7"
p.cell_color_small_size      = "#FCE4D6"
p.cell_color_sm_altered_size = "#F8CBAD"


function p.preprocess_genchain(input_mos)
	local input_mos = input_mos or mos.new(5,2)
	local num_gens = 2 * mos.period_step_count(input_mos) - 2
	
	local bright_gen = mos.bright_gen(input_mos)
	local gens = mos.interval_mul(bright_gen, -num_gens/2)
	local genchain = { mos.period_reduce(gens, input_mos) }
	for i = 1, num_gens do
		gens = mos.interval_add(gens, bright_gen)
		table.insert(genchain, mos.period_reduce(gens, input_mos))
	end
	return genchain
end

function p._mos_genchain(input_mos)
	local input_mos = input_mos or mos.new(6,3)
	
	local num_gens = mos.period_step_count(input_mos)
	
	local genchain = p.preprocess_genchain(input_mos)
	
	-- Begin table
	local result = "{| class=\"wikitable center-all\"\n"
		.. "|-\n"
	
	-- Generators header cell
	result = result .. "! Number of bright gens\n"
		
	-- Add a row for the generator counts
	for i = 1, #genchain do
		result = result .. string.format("%s %s", (i == 1 and "|" or " ||"), i - num_gens)
	end
	result = result .. "\n"
		
	-- Add a row for each period's genchain
	local period_count = mos.period_count(input_mos)
	if period_count == 1 then
		result = result .. "! Degree quality\n"
		for i = 1, #genchain do
			result = result .. string.format("%s %s", (i == 1 and "|" or " ||"), tamnams.degree_quality(genchain[i], input_mos, "abbrev"))
		end
		result = result .. "\n|}"
	else
		local mosprefix = "mos"
		for i = 1, period_count do
			local period_step_count = mos.period_step_count(input_mos)
			result = result .. string.format("! Degree quality (%s-%sdegree to %s-%sdegree)\n", period_step_count * (i - 1), mosprefix, period_step_count * i - 1, mosprefix)
			for j = 1, #genchain do
				local current_interval = genchain[j]
				current_interval = mos.interval_add(current_interval, mos.interval_mul(mos.period(input_mos), i - 1))
				result = result .. string.format("%s %s", (j == 1 and "|" or " ||"), tamnams.degree_quality(current_interval, input_mos, "abbrev"))
			end
			result = result .. "\n"
		end
		result = result .. "|}"
	end
	
	result = "Stacking a generator of MOS-INTERVAL from the root produces the following scale degrees. A chain of NOTECOUNT consecutive scale degrees produces one of the modes of SCALESIG, and expanding it to DAUGHTER-NOTECOUNT produces the modes of DAUGHTER-SCALES.\n"
		.. result
	
	return result
end

return p