Module:MOS genchain: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
Ganaram inukshuk (talk | contribs)
No edit summary
Ganaram inukshuk (talk | contribs)
No edit summary
Line 17: Line 17:
p.cell_color_sm_altered_size = "#F8CBAD"
p.cell_color_sm_altered_size = "#F8CBAD"


function p.genchain(input_mos, num_gens)
local input_mos = input_mos or mos.new(5,2)
local num_gens = num_gens or (mos.period_step_count(input_mos) - 1)
local bright_gen = mos.bright_gen(input_mos)
local stacked_gens = mos.unison()
local genchain = { mos.unison() }
local abs_num_gens = math.abs(num_gens)
local sign = num_gens > 0 and 1 or -1
for i = 1, abs_num_gens do
stacked_gens = mos.interval_add(stacked_gens, mos.interval_mul(bright_gen, sign))
table.insert(genchain, stacked_gens)
end
return genchain
end


-- wip; to replace genchain
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)
Line 56: Line 37:
local num_gens = mos.period_step_count(input_mos)
local num_gens = mos.period_step_count(input_mos)
local genchain = p.genchain(input_mos, num_gens)
local genchain = p.preprocess_genchain(input_mos)
local rev_genchain = p.genchain(input_mos, -num_gens)
-- Begin table
-- Begin table
Line 64: Line 44:
-- Generators header cell
-- Generators header cell
result = result .. "! Bright generator count\n"
result = result .. "! Number of bright gens\n"
-- Add a row for the generator counts
-- Add a row for the generator counts
-- Descending genchain
for i = 1, #genchain do
for i = num_gens - 1, 1, -1 do
result = result .. string.format("%s %s", (i == 1 and "|" or " ||"), i - num_gens)
if i == num_gens then
result = result .. string.format("| %s", -i)
else
result = result .. string.format(" || %s", -i)
end
end
-- Ascending genchain
for i = 1, num_gens do
result = result .. string.format(" || %s", i - 1)
end
end
result = result .. "\n"
result = result .. "\n"
Line 85: Line 56:
if period_count == 1 then
if period_count == 1 then
result = result .. "! Degree quality\n"
result = result .. "! Degree quality\n"
for i = num_gens, 1, -1 do
for i = 1, #genchain do
local current_interval = mos.interval_mul(genchain[i], -1)
result = result .. string.format("%s %s", (i == 1 and "|" or " ||"), tamnams.degree_quality(genchain[i], input_mos, "abbrev"))
current_interval = mos.equave_reduce(current_interval, input_mos)
if i == num_gens then
result = result .. string.format("| %s", tamnams.degree_quality(current_interval, input_mos, "abbrev"))
else
result = result .. string.format(" || %s", tamnams.degree_quality(current_interval, input_mos, "abbrev"))
end
end
end
for i = 2, num_gens do
local current_interval = mos.equave_reduce(genchain[i], input_mos)
result = result .. string.format(" || %s", tamnams.degree_quality(current_interval, input_mos, "abbrev"))
end
else
else
for i = 1, period_count do
for i = 1, period_count do

Revision as of 07:17, 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 (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
equave_reduce
interval_add
period_count
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.equave_reduce(gens, input_mos) }
	for i = 1, num_gens do
		gens = mos.interval_add(gens, bright_gen)
		table.insert(genchain, mos.equave_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)
	
	-- 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
	else
		for i = 1, period_count do
			--wip
		end
	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