Module:MOS in EDO allperiods: Difference between revisions
Jump to navigation
Jump to search
Fixed error with starting generator calculation |
Added option to toggle displaying mosses of subset edos; for ease of entering temperaments, this requires entering temperaments as key-value pairs rather than an array, so entering temperaments is temporarily disabled |
||
Line 4: | Line 4: | ||
local mosinedo = require('Module:MOS in EDO') | local mosinedo = require('Module:MOS in EDO') | ||
local p = {} | local p = {} | ||
-- Main function | -- Main function | ||
Line 23: | Line 10: | ||
-- separately for each period count if it can support multi-period mosses | -- separately for each period count if it can support multi-period mosses | ||
-- Generators start with half the period rounded down, plus 1 | -- Generators start with half the period rounded down, plus 1 | ||
function p.moses_in_edo(edo, number_of_periods, temperaments) | -- If the edo has subset edos (such as 24edo containing 12edo and 8edo), mosses | ||
-- for those subset edos are skipped, unless show_subsets is set to 1 (true) | |||
function p.moses_in_edo(edo, number_of_periods, show_subsets, temperaments) | |||
local edo = edo or 12 | local edo = edo or 12 | ||
local number_of_periods = number_of_periods or 1 | local number_of_periods = number_of_periods or 1 | ||
local temperaments = temperaments | local show_subsets = show_subsets == 1 | ||
local temperaments = temperaments | |||
-- Check whether the number of periods divides the edo | -- Check whether the number of periods divides the edo | ||
Line 49: | Line 39: | ||
local show_temperament = temperaments ~= nil and #temperaments == math.floor(period_in_edosteps / verified_number_of_periods / 2) | local show_temperament = temperaments ~= nil and #temperaments == math.floor(period_in_edosteps / verified_number_of_periods / 2) | ||
-- Temporarily disable entry of temperament names | |||
-- Temperament names will be entered as a set of key-value pairs instead of an array | |||
show_temperament = false | |||
-- Add a table for each genpair | |||
local result = "" | local result = "" | ||
for i = starting_generator, period_in_edosteps - 1 do | for i = starting_generator, period_in_edosteps - 1 do | ||
local gen = i | local gen = i | ||
local comp = period_in_edosteps - gen | local comp = period_in_edosteps - gen | ||
result = result .. string.format("MOS scales with generators %i\\%i and %i\\%i.\n", gen, edo, comp, edo) | |||
local | -- Skip mosses that are supported by subset edos; this happens if the | ||
if | -- gen and comp have a gcd > 1; if show_subsets is set to true, then | ||
result = result .. | -- show them anyway | ||
local gcd = utils.gcd_(gen, comp) | |||
if gcd ~= 1 and not show_subsets then | |||
local subset_edo = edo / gcd; | |||
local subset_gen = gen / gcd; | |||
local subset_comp = comp / gcd; | |||
result = result .. string.format('Generators form a subset scale in [[%iedo]] with the generators %i\\%i and %i\\%i.\n', subset_edo, subset_gen, subset_edo, subset_comp, subset_edo) | |||
else | else | ||
result = result .. mosinedo.mos_in_edo(edo, i, verified_number_of_periods) | -- TODO: Rewrite code here for entry of temperaments as a set of | ||
-- key-value pairs | |||
local temperament_index = 1 + i - starting_generator | |||
if show_temperament then | |||
result = result .. mosinedo.mos_in_edo(edo, i, verified_number_of_periods, temperaments[temperament_index]) | |||
else | |||
result = result .. mosinedo.mos_in_edo(edo, i, verified_number_of_periods) | |||
end | |||
end | end | ||
end | end | ||
Line 73: | Line 80: | ||
local temperaments = p.parse_entries(frame.args["Temperaments"]) | local temperaments = p.parse_entries(frame.args["Temperaments"]) | ||
local number_of_periods = tonumber(frame.args["Number of Periods"]) | local number_of_periods = tonumber(frame.args["Number of Periods"]) | ||
local show_subsets = frame.args["Show Subsets"] == "1" | |||
local result = p.moses_in_edo(edo, number_of_periods, temperaments) | local result = p.moses_in_edo(edo, number_of_periods, show_subsets, temperaments) | ||
return result | return result |
Revision as of 05:49, 5 December 2023
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 = {}
-- 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
-- If the edo has subset edos (such as 24edo containing 12edo and 8edo), mosses
-- for those subset edos are skipped, unless show_subsets is set to 1 (true)
function p.moses_in_edo(edo, number_of_periods, show_subsets, temperaments)
local edo = edo or 12
local number_of_periods = number_of_periods or 1
local show_subsets = show_subsets == 1
local temperaments = temperaments
-- 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
-- Starting generator
-- If the generator and its complement are the same, skip that genpair by
-- incrementing the starting generator by 1
local starting_generator = math.ceil(period_in_edosteps / 2)
local complement = period_in_edosteps - starting_generator
if starting_generator == complement then
starting_generator = starting_generator + 1
end
-- Include temperament names?
local show_temperament = temperaments ~= nil and #temperaments == math.floor(period_in_edosteps / verified_number_of_periods / 2)
-- Temporarily disable entry of temperament names
-- Temperament names will be entered as a set of key-value pairs instead of an array
show_temperament = false
-- Add a table for each genpair
local result = ""
for i = starting_generator, period_in_edosteps - 1 do
local gen = i
local comp = period_in_edosteps - gen
result = result .. string.format("MOS scales with generators %i\\%i and %i\\%i.\n", gen, edo, comp, edo)
-- Skip mosses that are supported by subset edos; this happens if the
-- gen and comp have a gcd > 1; if show_subsets is set to true, then
-- show them anyway
local gcd = utils.gcd_(gen, comp)
if gcd ~= 1 and not show_subsets then
local subset_edo = edo / gcd;
local subset_gen = gen / gcd;
local subset_comp = comp / gcd;
result = result .. string.format('Generators form a subset scale in [[%iedo]] with the generators %i\\%i and %i\\%i.\n', subset_edo, subset_gen, subset_edo, subset_comp, subset_edo)
else
-- TODO: Rewrite code here for entry of temperaments as a set of
-- key-value pairs
local temperament_index = 1 + i - starting_generator
if show_temperament then
result = result .. mosinedo.mos_in_edo(edo, i, verified_number_of_periods, temperaments[temperament_index])
else
result = result .. mosinedo.mos_in_edo(edo, i, verified_number_of_periods)
end
end
end
return result
end
function p.moses_in_edo_frame(frame)
local edo = tonumber(frame.args["EDO"])
local temperaments = p.parse_entries(frame.args["Temperaments"])
local number_of_periods = tonumber(frame.args["Number of Periods"])
local show_subsets = frame.args["Show Subsets"] == "1"
local result = p.moses_in_edo(edo, number_of_periods, show_subsets, temperaments)
return result
end
return p