Module:TAMNAMS: Difference between revisions

Ganaram inukshuk (talk | contribs)
m Corrected pipe character
Ganaram inukshuk (talk | contribs)
Added functions that list every mos's mode's udp and cpo
Line 629: Line 629:
------------------------- MODE NOTATION FUNCTIONS ------------------------------
------------------------- MODE NOTATION FUNCTIONS ------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Given an input mos, list the udps for each of its modes.
function p.mos_mode_udps(input_mos)
local steps_per_period = mos.period_step_count(input_mos)
local period_count = mos.period_count(input_mos)
local udps = {}
for i = 1, steps_per_period do
local gens_up = steps_per_period - i
local gens_down = steps_per_period - gens_up - 1
local udp = string.format("%s|%s", gens_up, gens_down)
if period_count > 1 then
udp = udp .. string.format("(%s)", period_count)
end
table.insert(udps, udp)
end
return udps
end
-- Given an input mos, list the cpos for each of its modes. The circular
-- permutation orderings are listed starting from the brightest mode.
-- Example with 5L 2s modes
--  MODE NAME  | UDP | CPO
-- ------------+-----+-----
--  Lydian    | 6|0 | 1
--  Ionian    | 5|1 | 5
--  Mixolydian | 4|2 | 2
--  Dorian    | 3|3 | 6
--  Aeolian    | 2|4 | 3
--  Phrygian  | 1|5 | 7
--  Lociran    | 0|6 | 4
function p.mos_mode_cpos(input_mos)
local steps_per_period = mos.period_step_count(input_mos)
local period_count = mos.period_count(input_mos)
local steps_per_bright_gen = mos.bright_gen_step_count(input_mos)
local cpos = {}
for i = 1, steps_per_period do
local cpo = ((i - 1) * steps_per_bright_gen) % steps_per_period + 1
table.insert(cpos, cpo)
end
return cpos
end


-- Given a string that represents a mode, return its udp.
-- Given a string that represents a mode, return its udp.
-- If a mode is for a modmos, it will return the closest brightest mode followed
-- If a mode is for a modmos, it will return the closest brightest mode followed
-- by its altered scale degrees.
-- by its altered scale degrees.
-- TODO: add altered scale degrees
function p.mode_udp(input_mode, input_mos)
function p.mode_udp(input_mode, input_mos)
true_modes = mos.modes_to_step_matrices(input_mos)
local true_modes = mos.modes_to_step_matrices(input_mos)
input_mode_as_step_matrix = mos.mode_to_step_matrix(input_mode)
local input_mode_as_step_matrix = mos.mode_to_step_matrix(input_mode)
-- For each mode, count the number of differences between each true mode
-- For each mode, count the number of differences between each true mode
Line 642: Line 685:
-- If the number of diffs is ever zero, then the entered mode was a true-mos
-- If the number of diffs is ever zero, then the entered mode was a true-mos
-- mode and has zero alterations.
-- mode and has zero alterations.
lowest_differences = mos.equave_step_count(input_mos)
local lowest_differences = mos.equave_step_count(input_mos)
bright_gens_down_per_period = 0
local bright_gens_down_per_period = 0
closest_mode_as_step_matrix = {}
local closest_mode_as_step_matrix = {}
for i = 1, #true_modes do
for i = 1, #true_modes do
differences = 0
local differences = 0
current_true_mode = true_modes[i]
local current_true_mode = true_modes[i]
for j = 1, #input_mode_as_step_matrix do
for j = 1, #input_mode_as_step_matrix do
mode_interval = input_mode_as_step_matrix[j]
local mode_interval = input_mode_as_step_matrix[j]
true_interval = current_true_mode[j]  
local true_interval = current_true_mode[j]  
if not mos.interval_eq(mode_interval, true_interval) then
if not mos.interval_eq(mode_interval, true_interval) then
Line 667: Line 710:
-- Produce the UDP (as text) for the mode, formatted as up|dp(p) for multi-
-- Produce the UDP (as text) for the mode, formatted as up|dp(p) for multi-
-- period mosses, or u|d for single-period mosses.
-- period mosses, or u|d for single-period mosses.
period_count = mos.period_count(input_mos)
local period_count = mos.period_count(input_mos)
dark_gens_down_per_period = mos.period_step_count(input_mos) - 1 - bright_gens_down_per_period
local dark_gens_down_per_period = mos.period_step_count(input_mos) - 1 - bright_gens_down_per_period
udp = ""
udp = ""
if period_count == 1 then
if period_count == 1 then
Line 677: Line 720:
-- Produce the list of alterations, if the mode is for a modmos.
-- Produce the list of alterations, if the mode is for a modmos.
alterations = ""
local alterations = ""
closest_true_mos_mode = true_modes[bright_gens_down_per_period + 1]
local closest_true_mos_mode = true_modes[bright_gens_down_per_period + 1]
if differences > 0 then
if lowest_differences > 0 then
for i = 1, #input_mode_as_step_matrix do
for i = 1, #input_mode_as_step_matrix do
mode_interval = input_mode_as_step_matrix[i]
mode_interval = input_mode_as_step_matrix[i]
Line 699: Line 742:


function p.tester()
function p.tester()
mos_modes = mos.modes_by_brightness(mos.new(5,2))
local mos_modes = mos.modes_by_brightness(mos.new(5,2))
output_ = ""
local output_ = ""
for i = 1, #mos_modes do
for i = 1, #mos_modes do
output_ = output_ .. mos_modes[i] .. " " .. p.mode_udp(mos_modes[i], mos.new(5,2)) .. "\n"
output_ = output_ .. mos_modes[i] .. " " .. p.mode_udp(mos_modes[i], mos.new(5,2)) .. "\n"
Line 707: Line 750:
output_ = output_ .. "LLsLsAs" .. " " .. p.mode_udp("LLsLsAs", mos.new(5,2))
output_ = output_ .. "LLsLsAs" .. " " .. p.mode_udp("LLsLsAs", mos.new(5,2))
return output_
return p.mos_mode_cpos(mos.new(5,2))