Module:MOS genchain: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
Ganaram inukshuk (talk | contribs)
bugfix for multiperiod mosses
Ganaram inukshuk (talk | contribs)
adjusted genchain length
Line 24: Line 24:
function p.preprocess_genchain(input_mos)
function p.preprocess_genchain(input_mos)
local input_mos = input_mos or mos.new(5,2)
local input_mos = input_mos or mos.new(5,2)
local num_gens = 4 * (mos.period_step_count(input_mos) - 1)
local num_gens = (2 * (input_mos.nL + input_mos.nL + input_mos.ns))/mos.period_count(input_mos) - 2
local bright_gen = mos.bright_gen(input_mos)
local bright_gen = mos.bright_gen(input_mos)
local gens = mos.interval_mul(bright_gen, num_gens/2)
local gens = mos.interval_mul(bright_gen, math.floor(num_gens/2))
bright_gen = mos.interval_mul(bright_gen, -1)
bright_gen = mos.interval_mul(bright_gen, -1)
local genchain = { mos.period_reduce(gens, input_mos) }
local genchain = { mos.period_reduce(gens, input_mos) }
Line 38: Line 38:


function p._mos_genchain(input_mos)
function p._mos_genchain(input_mos)
local input_mos = input_mos or mos.new(10,5)
local input_mos = input_mos or mos.new(5,2)
local num_gens = mos.period_step_count(input_mos)
local num_gens = mos.period_step_count(input_mos)

Revision as of 23:33, 30 July 2024

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 (3)
Line Function Params
24 preprocess_genchain (input_mos)
39 _mos_genchain (main) (input_mos)
119 mos_genchain (invokable) (frame)
Lua modules required (3)
Variable Module Functions used
mos Module:MOS new
period_count
bright_gen
interval_mul
period_reduce
interval_add
period_step_count
period
interval_step_count
as_string
parse
tamnams Module:TAMNAMS degree_quality
interval_quality
yesno Module:Yesno dependency not used

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


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

-- TODO
-- - Cell coloring
-- - Mosprefix and mosabbrev entering
-- - Collapse option

-- 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 * (input_mos.nL + input_mos.nL + input_mos.ns))/mos.period_count(input_mos) - 2
	
	local bright_gen = mos.bright_gen(input_mos)
	local gens = mos.interval_mul(bright_gen, math.floor(num_gens/2))
	bright_gen = mos.interval_mul(bright_gen, -1)
	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(5,2)
	
	local num_gens = mos.period_step_count(input_mos)
	
	local genchain = p.preprocess_genchain(input_mos)
	local period_count = mos.period_count(input_mos)
	
	-- Begin table
	local result = "{| class=\"wikitable center-all\"\n"
		.. "|-\n"
	
	-- Generators header rows
	result = result .. "! Bright gens"
	for i = 1, period_count do
		result = result
		.. " !! Scale Degree"
		.. " !! Abbrev"
	end
	local result = result
		.. "\n"
		.. "|-\n"
		
	-- Add a row for each scale degree, plus their period-shifted counterparts
	for i = 1, #genchain do
		-- Number of generators
		local num_gens = math.ceil(#genchain/2) - i
		result = result .. string.format("| %s", num_gens)
		
		-- Scale degree (full name) and abbrev
		for j = 1, period_count do
			-- If the scale degree corresponds to the root, say it's both the
			-- root and the degree one period up.
			-- If the scale degree is reached by a negative number of gens, then
			-- say it's the degree one period up instead.
			local period_interval = mos.period(input_mos)
			local current_interval = mos.interval_add(genchain[i], mos.interval_mul(period_interval, j - 1))
			local period_raised_interval = mos.interval_add(current_interval, period_interval)
			if num_gens == 0 then
				result = result 
					.. string.format(" || %s<br>%s", tamnams.degree_quality(current_interval, input_mos, "sentence-case"), tamnams.degree_quality(period_raised_interval, input_mos, "sentence-case"))
					.. string.format(" || %s<br>%s", tamnams.degree_quality(current_interval, input_mos, "abbrev")       , tamnams.degree_quality(period_raised_interval, input_mos, "abbrev")       )
			elseif num_gens < 0 and mos.interval_step_count(current_interval) % mos.period_step_count(input_mos) == 0 then
				result = result 
					.. string.format(" || %s", tamnams.degree_quality(period_raised_interval, input_mos, "sentence-case"))
					.. string.format(" || %s", tamnams.degree_quality(period_raised_interval, input_mos, "abbrev"))
			else
				result = result 
					.. string.format(" || %s", tamnams.degree_quality(current_interval, input_mos, "sentence-case"))
					.. string.format(" || %s", tamnams.degree_quality(current_interval, input_mos, "abbrev"))
			end
		end
		
		-- End of row
		result = result 
			.. "\n"
			.. "|-\n"
	end
	result = result .. "|}"
	
	local bright_gen_as_text = tamnams.interval_quality(mos.bright_gen(input_mos), input_mos)
	local period_step_count = mos.period_step_count(input_mos)
	local scalesig = mos.as_string(input_mos)
	local child_step_count = input_mos.nL + input_mos.nL + input_mos.ns
	local child_scale_1 = mos.new(input_mos.nL+input_mos.ns, input_mos.nL, input_mos.equave)
	local child_scale_2 = mos.new(input_mos.nL, input_mos.nL+input_mos.ns, input_mos.equave)
	
	--result = string.format("Stacking the bright generator (a %s) from the root produces the following scale degrees. A chain of %s consecutive scale degrees produces one of the modes of %s, and expanding it to %s scale degrees produces the modes of either %s or %s.\n",
	--	bright_gen_as_text,
	--	period_step_count,
	--	scalesig,
	--	child_step_count,
	--	mos.as_string(child_scale_1),
	--	mos.as_string(child_scale_2)
	--	)
	--	.. result
	
	return result
end

function p.mos_genchain(frame)
	local scalesig = frame.args["Scale Signature"]
	local input_mos = mos.parse(scalesig) or mos.new(5,2)
	
	return p._mos_genchain(input_mos)
end

return p