Module:MOS in EDO allperiods

From Xenharmonic Wiki
Revision as of 09:06, 4 December 2023 by Ganaram inukshuk (talk | contribs) (Created page with "local mos = require('Module:MOS') local rat = require('Module:Rational') local utils = require('Module:Utils') local mosinedo = require('Module:MOS in EDO') local p = {} -- H...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Module documentation[view] [edit] [history] [purge]
Note: Do not invoke this module directly; use the corresponding template instead: Template:MOS in EDO allperiods.

This module calls Template:MOS in EDO allgens repeatedly to list every MOS scale in a particular equal temperament tuning over all possible periods.


local mos = require('Module:MOS')
local rat = require('Module:Rational')
local utils = require('Module:Utils')
local mosinedo = require('Module:MOS in EDO')
local p = {}

-- Helper function
-- Parses entries from a semicolon-delimited string and returns them in an array
-- TODO: Separate this and related functions (parse_pair and parse_kv_pairs) into its own module, as they're included
-- in various modules at this point, such as: scale tree, mos mdoes
function p.parse_entries(unparsed)
	local parsed = {}
	for entry in string.gmatch(unparsed, '([^;]+)') do
		local trimmed = entry:gsub("^%s*(.-)%s*$", "%1")
		table.insert(parsed, trimmed)		-- Add to array
	end
	return parsed
end

-- Main function
-- Creates an entire page section for every mos in an edo
-- Mosses with the same period are only shown; this function must be called
-- separately for each period count if it can support multi-period mosses
-- Generators start with half the period rounded down, plus 1
function p.moses_in_edo(edo, number_of_periods, temperaments)
	local edo = edo or 31
	local number_of_periods = number_of_periods or 1
	local temperaments = temperaments or { "slender", "valentine", "miracle", "nusecond", "hemithirds", "mothra", "orwell", "myna", "mohajira", "würschmidt", "squares", "semisept", "meantone", "casablanca", "tritonic" }
	
	-- Check whether the number of periods divides the edo
	-- If so, the entire page section will be for multiperiod mosses
	local period_in_edosteps = edo
	local verified_number_of_periods = 1
	if edo % number_of_periods == 0 then
		period_in_edosteps = edo / number_of_periods
		verified_number_of_periods = number_of_periods
	end
	
	local result = ""
	
	local starting_generator = math.floor(period_in_edosteps / verified_number_of_periods / 2) + 1
	
	for i = starting_generator, period_in_edosteps - 1 do
		local temperament_index = 1 + i - starting_generator
		result = result .. mosinedo.mos_in_edo(edo, i, verified_number_of_periods, temperaments[temperament_index])
	end
	
	return result
	
end

function p.moses_in_edo_frame(frame)
	
	local edo = tonumber(frame.args["EDO"])
	local gen_in_edosteps = tonumber(frame.args["Generator"])
	local temperaments = p.parse_entries(frame.args["Temperaments"])
	local number_of_periods = tonumber(frame.args["Number of Periods"])
	
	local result = p.moses_in_edo(edo, gen_in_edosteps, number_of_periods, temperaments)
	
end

return p