Module:MOS mode degrees: Difference between revisions
m Adding back in step count requirement for now, as supporting arbitrary modmosses requires additional support |
Added tiebreaker for modmos modes with more than one "closest mode": use the darkest of the closest modes |
||
| Line 428: | Line 428: | ||
-- This finds the closest mode for only the modmos's step pattern, not all rotations | -- This finds the closest mode for only the modmos's step pattern, not all rotations | ||
-- Alterations are denoted as a UDP followed by which scale degrees are altered from the original mode | -- Alterations are denoted as a UDP followed by which scale degrees are altered from the original mode | ||
function p.compare_modmos_with_true_mos_modes(input_mos, | -- If multiple true-mos modes are tied with being closest, use the darkest mode instead | ||
function p.compare_modmos_with_true_mos_modes(input_mos, true_mos_modes, modmos_step_pattern) | |||
local input_mos = input_mos or mos.new(5, 2) | local input_mos = input_mos or mos.new(5, 2) | ||
local | local true_mos_modes = true_mos_modes or p.calculate_step_pattern_rotations(mos.new(5, 2), "LLLsLLs", true) | ||
local modmos_step_pattern = modmos_step_pattern or "sLsLLsA" | local modmos_step_pattern = modmos_step_pattern or "sLsLLsA" | ||
| Line 446: | Line 447: | ||
local index_of_closest_mode = 1 | local index_of_closest_mode = 1 | ||
local lowest_number_of_alterations = mossteps_per_equave | local lowest_number_of_alterations = mossteps_per_equave | ||
for i = 1, # | for i = 1, #true_mos_modes do | ||
local number_of_alterations = 0 | local number_of_alterations = 0 | ||
-- Get the current mode's degree vector | -- Get the current mode's degree vector | ||
local mode_vector = p.calculate_mode_degrees(input_mos, | local mode_vector = p.calculate_mode_degrees(input_mos, true_mos_modes[i]) | ||
-- Compare the vectors | -- Compare the vectors | ||
for j = 1, # | for j = 1, #true_mos_modes[i] do | ||
if mode_vector[j] ~= modmos_vector[j] then | if mode_vector[j] ~= modmos_vector[j] then | ||
number_of_alterations = number_of_alterations + 1 | number_of_alterations = number_of_alterations + 1 | ||
| Line 463: | Line 464: | ||
index_of_closest_mode = i | index_of_closest_mode = i | ||
lowest_number_of_alterations = number_of_alterations | lowest_number_of_alterations = number_of_alterations | ||
end | |||
-- If the current mode had the same number of alterations but is of a darker mode, update | |||
if number_of_alterations == lowest_number_of_alterations then | |||
index_of_closest_mode = i | |||
end | end | ||
end | end | ||
| Line 472: | Line 478: | ||
-- Calculate alterations by comparing the modmos and the closest mode's degrees | -- Calculate alterations by comparing the modmos and the closest mode's degrees | ||
local mode_vector = p.calculate_mode_degrees(input_mos, | local mode_vector = p.calculate_mode_degrees(input_mos, true_mos_modes[index_of_closest_mode]) | ||
local alterations = "" | local alterations = "" | ||
for i = 1, #mode_vector do | for i = 1, #mode_vector do | ||
| Line 492: | Line 498: | ||
-- Calculate the modes for the truemos and modmos | -- Calculate the modes for the truemos and modmos | ||
local | local true_mos_modes = p.calculate_step_pattern_rotations(input_mos, mos.brightest_mode(input_mos), true) | ||
local modmos_modes = p.calculate_step_pattern_rotations(input_mos, modmos_step_pattern, false) | local modmos_modes = p.calculate_step_pattern_rotations(input_mos, modmos_step_pattern, false) | ||
| Line 498: | Line 504: | ||
local alterations = {} | local alterations = {} | ||
for i = 1, #modmos_modes do | for i = 1, #modmos_modes do | ||
local alteration = p.compare_modmos_with_true_mos_modes(input_mos, | local alteration = p.compare_modmos_with_true_mos_modes(input_mos, true_mos_modes, modmos_modes[i]) | ||
table.insert(alterations, alteration) | table.insert(alterations, alteration) | ||
end | end | ||