Module:MOS intervals

From Xenharmonic Wiki
Revision as of 23:37, 6 June 2024 by Ganaram inukshuk (talk | contribs) (Added todo)
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 intervals.

This module generates a table showing interval varieties and qualities for a given MOS scale.

Introspection summary for Module:MOS intervals 
Functions provided (2)
Line Function Params
13 _mos_intervals (main) (input_mos, mos_prefix)
87 mos_intervals (invokable) (frame)
Lua modules required (6)
Variable Module Functions used
et Module:ET dependency not used
mos Module:MOS new
as_string
mode_to_step_matrix
brightest_mode
darkest_mode
equave_step_count
period_step_count
bright_gen_step_count
dark_gen_step_count
interval_eq
interval_as_string
interval_to_cents
parse
ord Module:Ordinal dependency not used
rat Module:Rational dependency not used
tamnams Module:TAMNAMS interval_quality
lookup_prefix
utils Module:Utils dependency not used

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


local mos = require('Module:MOS')
local rat = require('Module:Rational')
local ord = require('Module:Ordinal')
local utils = require('Module:Utils')
local et = require('Module:ET')
local tamnams = require('Module:TAMNAMS')
local p = {}

-- TODO:
-- - Fix rounding, capitalization

-- Main function; to be called by wrapper
function p._mos_intervals(input_mos, mos_prefix)
	-- Default param for input mos is 5L 2s
	local input_mos = input_mos or mos.new(5, 2, 2)
	local mos_prefix = mos_prefix or "dia"
	
	-- Get the scale sig
	local scale_sig = mos.as_string(input_mos)
	
	-- Get the brightest and darkest modes as step matrices
	local bright_step_matrix = mos.mode_to_step_matrix(mos.brightest_mode(input_mos))
	local dark_step_matrix = mos.mode_to_step_matrix(mos.darkest_mode(input_mos))
	
	-- Get the number of steps per period and equave
	local equave_step_count = mos.equave_step_count(input_mos)
	local period_step_count = mos.period_step_count(input_mos)
	
	-- Get the step counts for the bright and dark generators
	local bright_gen_step_count = mos.bright_gen_step_count(input_mos)
	local dark_gen_step_count = mos.dark_gen_step_count(input_mos)
	
	-- Create the table, starting with the headers
	local result = '{| class="wikitable"\n'
	result = result .. '|+ Intervals of ' .. scale_sig .. '\n'
	result = result .. '! colspan="2" | Intervals\n'
	result = result .. '! colspan="2" | Size\n'
	result = result .. '! rowspan="2" | Abbrev.\n'
	result = result .. '|-\n'
	result = result .. '! Generic\n'
	result = result .. '! Specific\n'
	result = result .. '! Steps\n'
	result = result .. '! Range in cents\n'
	
	-- Write each row
	for i = 1, #bright_step_matrix do

		-- Compare the bright and dark intervals. If they're the same, then the
		-- current interval class is a period interval.
		local current_bright_interval = bright_step_matrix[i]
		local current_dark_interval = dark_step_matrix[i]
		local is_period = mos.interval_eq(current_bright_interval, current_dark_interval)
		
		-- If it's a period interval, then there is only one row to write.
		-- Otherwise, there are two rows to write.
		if is_period then
			result = result .. "|-\n"
			result = result .. string.format("| '''%s-%sstep'''\n", i-1, mos_prefix)
			result = result .. string.format("| %s\n" , tamnams.interval_quality(current_bright_interval, input_mos))
			result = result .. string.format("| %s\n" , mos.interval_as_string(current_bright_interval))
			result = result .. string.format("| %d¢\n", mos.interval_to_cents(current_bright_interval, input_mos, {1,1}))
			result = result .. string.format("| %s\n" , tamnams.interval_quality(current_bright_interval, input_mos, "abbrev", "m"))
		else
			result = result .. "|-\n"
			result = result .. string.format("| rowspan=\"2\" | %s-%sstep\n", i-1, mos_prefix)
			result = result .. string.format("| %s\n" , tamnams.interval_quality(current_dark_interval, input_mos))
			result = result .. string.format("| %s\n" , mos.interval_as_string(current_dark_interval))
			result = result .. string.format("| %.3f¢ to %.3f¢\n", mos.interval_to_cents(current_dark_interval, input_mos, {1,1}), mos.interval_to_cents(current_dark_interval, input_mos, {1,0}))
			result = result .. string.format("| %s\n" , tamnams.interval_quality(current_dark_interval, input_mos, "abbrev", "m"))
			
			result = result .. "|-\n"
			result = result .. string.format("| %s\n" , tamnams.interval_quality(current_bright_interval, input_mos))
			result = result .. string.format("| %s\n" , mos.interval_as_string(current_bright_interval))
			result = result .. string.format("| %.3f¢ to %.3f¢\n", mos.interval_to_cents(current_bright_interval, input_mos, {1,1}), mos.interval_to_cents(current_dark_interval, input_mos, {1,0}))
			result = result .. string.format("| %s\n" , tamnams.interval_quality(current_bright_interval, input_mos, "abbrev", "m"))
		end

	end
	
	result = result .. "|}"	
	
	return result
	
end

-- Wrapper function; to be called by template
function p.mos_intervals(frame)
	-- Get input mos
	local input_mos = mos.parse(frame.args['Scale Signature'])
	
	-- Default param for mos prefix
	-- If "NONE" is given, no prefix will be used
	-- If left blank, try to find the appropriate mos prefix, or else defualt to "mos"
	-- If not left blank, use the prefix passed in instead
	local scale_sig = mos.as_string(input_mos)
	local mos_prefix = tamnams.lookup_prefix(input_mos)
	if frame.args['MOS Prefix'] == "NONE" then
		mos_prefix = ""
	elseif string.len(frame.args['MOS Prefix']) > 0 then
		mos_prefix = frame.args['MOS Prefix']
	end

	local result = p._mos_intervals(input_mos, mos_prefix)

	return result
end

return p