Module:Infobox MOS: Difference between revisions

Ganaram inukshuk (talk | contribs)
m Added todo
Ganaram inukshuk (talk | contribs)
Fixed logic for tamnams info section
Line 220: Line 220:
-- Produces section entries for tamnams info
-- Produces section entries for tamnams info
-- Conditions for tamnams info inclusion:
-- Conditions for tamnams info inclusion:
-- - Scale must be octave-equivalent; equave-agnostic names aren't supported right now
-- - Scale is octave-equivalent.
-- - Scale must be within the "named range" (IE, it must appear in the mos module's tables for name, prefix, and abbrev)
-- - Scales within the "named range" (6-10 notes, or is 1L 1s or 2L 2s) have
-- - Octave-equivalent scales with note counts greater than 10 report the closest named mos instead
--  a tamnams name.
-- - Scales with a notecount greater than 10 and no more than 5 periods have
--  a tamnams-named ancestor.
-- - Scales with a notecount greater than 10 and more than 5 periods don't have
--  a tamnams-named ancestor, but will report what nL ns mos they descend from.
function p.tamnams_information(input_mos)
function p.tamnams_information(input_mos)
local input_mos = input_mos or mos.new(5, 2)
local input_mos = input_mos or mos.new(7, 7)
local scalesig = string.format("%dL %ds", input_mos.nL, input_mos.ns)
local scalesig = string.format("%dL %ds", input_mos.nL, input_mos.ns)
local tamnams_name = mos.tamnams_name[scalesig] or ""
local notecount = input_mos.nL + input_mos.ns
local tamnams_prefix = mos.tamnams_prefix[scalesig] or ""
local number_of_periods = utils._gcd(input_mos.nL, input_mos.ns)
local tamnams_abbrev = mos.tamnams_abbrev[scalesig] or ""
local tamnams_name = mos.tamnams_name[scalesig]
local tamnams_prefix = mos.tamnams_prefix[scalesig]
local tamnams_abbrev = mos.tamnams_abbrev[scalesig]
local is_octave_equivalent = rat.eq(input_mos.equave, 2)
local is_octave_equivalent = rat.eq(input_mos.equave, 2)
local is_within_named_range = tamnams_name ~= nil and notecount <= 10
local is_root_mos = input_mos.nL == input_mos.ns
local section_entries = nil
local section_entries = nil
if is_octave_equivalent then
if is_octave_equivalent then
-- Scale is within the "named range"
if is_within_named_range then
if input_mos.nL + input_mos.ns <= 10 and tamnams_name ~= "" then
-- Mos has a tamnams name
section_entries = {
section_entries = {
{"[[TAMNAMS#Mos_pattern_names | Name]]", tamnams_name},
{"[[TAMNAMS#Mos_pattern_names | Name]]", tamnams_name},
Line 242: Line 251:
{"[[TAMNAMS#Mos_pattern_names | Abbrev.]]", tamnams_abbrev}
{"[[TAMNAMS#Mos_pattern_names | Abbrev.]]", tamnams_abbrev}
}
}
-- Scale is outside the "named range"
elseif not is_within_named_range and notecount > 10 and not is_root_mos then
elseif input_mos.nL + input_mos.ns > 10 and not input_mos.nL == input_mos.ns then
-- Mos (probably) has a tamnams-named ancestor
local ancestor_mos, lg_chunk, sm_chunk, generations = p.find_mos_ancestor(input_mos)
local ancestor_mos, lg_chunk, sm_chunk, generations = p.find_mos_ancestor(input_mos)
local ancestor_scalesig = mos.as_string(ancestor_mos)
local ancestor_scalesig = mos.as_string(ancestor_mos)
local ancestor_name = mos.tamnams_name[ancestor_scalesig] or "none"
local ancestor_name = mos.tamnams_name[ancestor_scalesig]
local ancestor_entry = "none"
local ancestor_entry = ancestor_scalesig
if ancestor_name ~= "none" and ancestor_scalesig ~= scalesig then
if ancestor_name ~= nil then
ancestor_entry = string.format("[[%s]] (%s)", ancestor_scalesig, ancestor_name)
ancestor_entry = ancestor_entry .. string.format(" (%s)", ancestor_name)
end
end
Line 388: Line 397:
-- Tamnams info section, if applicable
-- Tamnams info section, if applicable
local tamnams_info = p.tamnams_information(tuning_parsed)
local tamnams_info = p.tamnams_information(tuning_parsed)
if tamnams_info_section ~= nil then
if tamnams_info ~= nil then
table.insert(sections, tamnams_info)
table.insert(sections, tamnams_info)
end
end