Module:Infobox MOS: Difference between revisions

Inthar (talk | contribs)
No edit summary
ArrowHead294 (talk | contribs)
m No need to use NBSP on ones that aren't displayed
 
(312 intermediate revisions by 7 users not shown)
Line 1: Line 1:
local p = {}
local p = {}
local i = require('Module:Interval')
local u = require('Module:Utils')
local rat = require('Module:Rational')
local l = require('Module:Limits')
local MOS = require('Module:MOS')
local ET = require('Module:ET')
local infobox = require('Module:Infobox')


function display_range (arg1, arg2, arg3, arg4) --If arg1 < arg2, then display "arg3 to arg4"; otherwise display "arg4 to arg3".
local getArgs = require("Module:Arguments").getArgs
if arg1 < arg2 then
local ib = require("Module:Infobox")
return arg3 .. ' to ' .. arg4
local kbvis = require("Module:Keyboard vis")
else
local mos = require("Module:MOS")
return arg4 .. ' to ' .. arg3
local tamnams = require("Module:TAMNAMS")
local tip = require("Module:Template input parse")
local xp = require("Module:Xenpaper")
local yesno = require("Module:Yesno")
 
-- TODO: REWRITE. REFACTOR. AGAIN.
 
-- TODO: bugfix tamnams lookup breaking for mosses with 5 steps or less; interim
-- fix currently implemented shows smaller mosses as descending from itself.
 
-- Helper function
-- Concatenates the contents of two tables into one
-- This doesn't have a return value; rather, the first table passed has the
-- second table's contents added to it.
function p.concatenate_tables(t1, t2)
for i=1, #t2 do
t1[#t1 + 1] = t2[i]
end
end
end
end
-- Helper function
-- Annotates a section header with the equave as superscript text.
function p.annotate_section_header(input_mos, section_header)
local et_suffix = mos.et_suffix(input_mos)
return (et_suffix == "edo"
and string.format('<div style=\"margin-top: 0.6em;\"><b>%s</b></div>', section_header)
or  string.format('<div style=\"margin-top: 0.6em;\"><b>%s</b><sup><abbr title=\"In steps of %s\">(%s)</sup></div>', section_header, et_suffix, et_suffix)
)
end
-- Helper function
-- Create a keyboard visualization, based on the Halberstadt keyboard layout
function p.kb_vis(input_mos)
local input_mos = input_mos or mos.new(5, 2)
function round(num, numDecimalPlaces)
local brightest_mode = mos.brightest_mode(input_mos)
  local mult = 10^(numDecimalPlaces or 0)
  return math.floor(num * mult + 0.5) / mult
local vis = ""
if input_mos.nL + input_mos.ns < 40 then
vis = kbvis.vis_small(brightest_mode)
end
return {{["Header"] = vis}}
end
end
local common_suffix = {
['3/2'] = 'f',
['2'] = 'o',
['2/1'] = 'o',
['3'] = 't',
['3/1'] = 't',
}
local common_ratio = {
['f'] = rat.new(3, 2),
['o'] = 2,
['t'] = 3
}


function p.infobox_MOS(frame)
-- Helper function
-- debug mode
-- Adds categories
local debug_mode = frame.args['debug'] ~= nil
function p.categorize(input_mos)
local categories = ''
local input_mos = input_mos or mos.new(5, 2)
local tuning = frame.args['tuning']
-- Add to category of abstact mosses
local mos = MOS.parse(tuning) or MOS.parse('5L 2s')
local categories = " [[Category:Abstract MOS patterns]]"
assert(mos, "failed to parse variable mos")
-- category of the main article
categories = categories .. '[[Category:' .. tuning .. '| ]]'
local equave = mos.equave
-- Add notecount category if the notecount is greater than 3
local equave_link = ' (' .. equave .. '-equivalent)'
local notecount = input_mos.nL + input_mos.ns
local equave_disp = ' <' .. equave .. '>'
if notecount > 3 then
if rat.eq(equave, 2) then
categories = categories .. string.format(" [[Category:%d-tone scales]]", notecount)
equave_link = ''
equave_disp = ''
end
end
local prev_L, prev_s = '', ''
-- If the mos is octave-equivalent, add appropriate tamnams-named categories
if mos.nL > 1 then
-- Otherwise, add to nonoctave category
prev_L = '[[' .. (mos.nL - 1) .. 'L ' .. mos.ns .. 's' .. equave_link .. '|← ' .. (mos.nL - 1) .. 'L' .. mos.ns .. 's' .. equave_disp .. ']]'
if mos.is_octave_equivalent(input_mos) then
-- Caveats:
-- - Only octave-equivalent mos names are used as categories.
-- - Monowood and biwood are excluded (for now).
-- - Mosses whose notecounts > 10 and periods < 5 are categorized under
--  the closest tamnams-named ancestor.
local ancestor_mos = tamnams.find_ancestor(input_mos)
local tamnams_name = tamnams.lookup_name(ancestor_mos)
if tamnams_name ~= nil then
categories = categories .. string.format(" [[Category:%s]]", tamnams_name)
end
else
categories = categories .. " [[Category:Nonoctave]]"
end
end
local next_L = '[[' .. (mos.nL + 1) .. 'L ' .. mos.ns .. 's' .. equave_link .. '|' .. (mos.nL + 1) .. 'L' .. mos.ns .. 's' .. equave_disp .. '→]]'
if mos.ns > 1 then
return categories
prev_s = '[[' .. mos.nL .. 'L ' .. (mos.ns - 1) .. 's' .. equave_link .. '|↑' .. mos.nL .. 'L' .. (mos.ns - 1) .. 's' .. equave_disp .. ']]'
end
 
-- Helper function
-- Creates adjacent links for mos, found by +/-1 large or +/- small steps
function p.adjacent_links(input_mos)
local input_mos = input_mos or mos.new(1, 1)
local adjacent_mosses = {
mos.new(input_mos.nL - 1, input_mos.ns - 1, input_mos.equave), -- UL
mos.new(input_mos.nL    , input_mos.ns - 1, input_mos.equave), -- U
mos.new(input_mos.nL + 1, input_mos.ns - 1, input_mos.equave), -- UR
mos.new(input_mos.nL - 1, input_mos.ns    , input_mos.equave), -- L
mos.new(input_mos.nL + 1, input_mos.ns    , input_mos.equave), -- R
mos.new(input_mos.nL - 1, input_mos.ns + 1, input_mos.equave), -- DL
mos.new(input_mos.nL    , input_mos.ns + 1, input_mos.equave), -- D
mos.new(input_mos.nL + 1, input_mos.ns + 1, input_mos.equave), -- DR
}
local adjacent_links = {
mos.is_valid(adjacent_mosses[1]) and string.format("[[%s|&#x2196;&nbsp;%s]]", mos.as_long_string(adjacent_mosses[1], false), mos.as_string(adjacent_mosses[1]), true) or "",
mos.is_valid(adjacent_mosses[2]) and string.format("[[%s|&#x2191;&nbsp;%s]]", mos.as_long_string(adjacent_mosses[2], false), mos.as_string(adjacent_mosses[2]), true) or "",
mos.is_valid(adjacent_mosses[3]) and string.format("[[%s|%s&nbsp;&#x2197;]]", mos.as_long_string(adjacent_mosses[3], false), mos.as_string(adjacent_mosses[3]), true) or "",
mos.is_valid(adjacent_mosses[4]) and string.format("[[%s|&#x2190;&nbsp;%s]]", mos.as_long_string(adjacent_mosses[4], false), mos.as_string(adjacent_mosses[4]), true) or "",
mos.is_valid(adjacent_mosses[5]) and string.format("[[%s|%s&nbsp;&#x2192;]]", mos.as_long_string(adjacent_mosses[5], false), mos.as_string(adjacent_mosses[5]), true) or "",
mos.is_valid(adjacent_mosses[6]) and string.format("[[%s|&#x2199;&nbsp;%s]]", mos.as_long_string(adjacent_mosses[6], false), mos.as_string(adjacent_mosses[6]), true) or "",
mos.is_valid(adjacent_mosses[7]) and string.format("[[%s|&#x2193;&nbsp;%s]]", mos.as_long_string(adjacent_mosses[7], false), mos.as_string(adjacent_mosses[7]), true) or "",
mos.is_valid(adjacent_mosses[8]) and string.format("[[%s|%s&nbsp;&#x2198;]]", mos.as_long_string(adjacent_mosses[8], false), mos.as_string(adjacent_mosses[8]), true) or ""
}
return adjacent_links
end
 
-- TODO: Cleanup and adopt mos functions
-- Helper function
-- Produces section entries for scale sturcture
-- Section is returned as a jagged array and return value must be merged into
-- a larger array.
function p.scale_structure(input_mos)
local input_mos = input_mos or mos.new(5, 2)
local equave_as_string = mos.equave_as_string(input_mos)
local equave_in_cents  = mos.equave_to_cents(input_mos)
local number_of_periods = mos.period_count(input_mos)
local period_as_string = ""
if number_of_periods == 1 then
period_as_string = equave_as_string
else
period_as_string = mos.reduced_period_to_et_string(input_mos, "")
end
end
local next_s = '[[' .. mos.nL .. 'L ' .. (mos.ns + 1) .. 's' .. equave_link .. '|↓' .. mos.nL .. 'L' .. (mos.ns + 1) .. 's' .. equave_disp .. '\n]]'
local period_in_cents = equave_in_cents / number_of_periods
local step_pattern = string.format("...%d steps...", input_mos.nL + input_mos.ns)
if input_mos.nL + input_mos.ns <= 40 then
local brightest_mode = mos.brightest_mode(input_mos)
step_pattern = string.format("<abbr title=\"Brightest mode\">%s</abbr><br /><abbr title=\"Darkest mode\">%s</abbr>", brightest_mode, string.reverse(brightest_mode))
end
local section_header = "Scale structure"
local section_entries = {
{ ["Header"] = string.format("<div style=\"margin-top: 0.6em;\"><b>%s</b></div>", section_header)},
{ ["Header"] = "[[Step pattern]]", ["Data"] = step_pattern},
{ ["Header"] = "[[Equave]]"      , ["Data"] = string.format("%s (%.1f{{c}})", equave_as_string, equave_in_cents) },
{ ["Header"] = "[[Period]]"      , ["Data"] = string.format("%s (%.1f{{c}})", period_as_string, period_in_cents) }
}
 
return section_entries
end
 
-- Helper function
-- Produces generator ranges for scale
-- Section is returned as a jagged array and return value must be merged into
-- a larger array.
function p.generator_sizes(input_mos)
local input_mos = input_mos or mos.new(5, 2,3)
local paucitonic_et = 5
local bright_min_in_steps = mos.bright_gen_to_et_string(input_mos, {1, 1}, "")
local paucitonic_bright_steps = 3
local bright_max_in_steps = mos.bright_gen_to_et_string(input_mos, {1, 0}, "")
local paucitonic_dark_steps = paucitonic_et - paucitonic_bright_steps
local dark_min_in_steps  = mos.dark_gen_to_et_string  (input_mos, {1, 0}, "")
local equalized_et = 7
local dark_max_in_steps  = mos.dark_gen_to_et_string  (input_mos, {1, 1}, "")
local equalized_bright_steps = 4
local equalized_dark_steps = equalized_et - equalized_bright_steps
equave = 2
local structure_data = {}
local bright_min_in_cents = mos.bright_gen_to_cents(input_mos, {1, 1})
local bright_max_in_cents = mos.bright_gen_to_cents(input_mos, {1, 0})
local dark_min_in_cents = mos.dark_gen_to_cents(input_mos, {1, 0})
local dark_max_in_cents = mos.dark_gen_to_cents(input_mos, {1, 1})
local section_header = p.annotate_section_header(input_mos, "Generator size")
local section_entries = {
{ ["Header"] = section_header},
{ ["Header"] = "[[Bright]]", ["Data"] = string.format("%s to %s (%.1f{{c}} to %.1f{{c}})", bright_min_in_steps, bright_max_in_steps, bright_min_in_cents, bright_max_in_cents) },
{ ["Header"] = "[[Dark]]"  , ["Data"] = string.format("%s to %s (%.1f{{c}} to %.1f{{c}})", dark_min_in_steps, dark_max_in_steps, dark_min_in_cents, dark_max_in_cents) },
}
return section_entries
end
 
-- Helper function
-- Produces section entries for tamnams info
-- Conditions for tamnams info inclusion:
-- - Scale is octave-equivalent.
-- - Scales within the "named range" (6-10 notes, or is 1L 1s or 2L 2s) have
--  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.
-- Section is returned as a jagged array and return value must be merged into
-- a larger array.
function p.tamnams_information(input_mos)
local input_mos = input_mos or mos.new(6,6,3)
-- If a mos is octave-equivalent and has 10 or fewer steps, then it has a
-- tamnams name/prefix/abbrev.
-- If a mos is octave-equivalent, has more than 10 steps, and is not a root
-- mos nL ns, then:
-- - If it has 5 periods or less, then its closest ancestor has a tamnams
--  name.
-- - If it has more than 5 periods, then it relates to a root mos nL ns that
--  has more than 10 steps (ancestor therefore has no tamnams name).
-- If a mos is not octave-equivalent, then it may have a tamnams name (if
-- step count is 5 or less; currently unsupported) or not.
local is_octave_equivalent  = mos.is_octave_equivalent(input_mos)
local has_tamnams_name      = tamnams.lookup_name(input_mos) ~= nil
local is_within_named_range  = mos.step_count(input_mos) <= 10
local is_within_period_count = mos.period_count(input_mos) <= 5
local is_root_mos = input_mos.nL == input_mos.ns
local section_header = "TAMNAMS information"
local section_entries = nil
if is_octave_equivalent and has_tamnams_name then
section_entries = {
{ ["Header"] = string.format("<div style=\"margin-top: 0.6em;\"><b>%s</b></div>", section_header) },
{ ["Header"] = "[[TAMNAMS#Mos_pattern_names | Name]]"    , ["Data"] = tamnams.lookup_name  (input_mos) },
{ ["Header"] = "[[TAMNAMS#Mos_pattern_names | Prefix]]"  , ["Data"] = tamnams.lookup_prefix(input_mos) .. "-" },
{ ["Header"] = "[[TAMNAMS#Mos_pattern_names | Abbrev.]]" , ["Data"] = tamnams.lookup_abbrev(input_mos) }
}
elseif is_octave_equivalent and not has_tamnams_name and not is_root_mos and not is_within_named_range then
-- Lookup closest named ancestor mos
local ancestor_mos, ratio_1, ratio_2, generations = tamnams.find_ancestor_info(input_mos)
-- Link to ancestor mos
local ancestor_link = mos.as_link(ancestor_mos)
-- Lookup step ratio range
local step_ratio_range = string.format("%s:%s to %s:%s", ratio_1[1], ratio_1[2], ratio_2[1], ratio_2[2])
local range_name = tamnams.lookup_step_ratio_range(ratio_1, ratio_2)
local step_ratio_range_entry = range_name == nil and step_ratio_range or string.format("%s (%s)", step_ratio_range, range_name)
local ancestor_name = tamnams.lookup_name(ancestor_mos)
local ancestor_entry = ancestor_name == nil and ancestor_link or string.format("%s (%s)", ancestor_link, ancestor_name)
section_entries = {
{ ["Header"] = string.format("<div style=\"margin-top: 0.6em;\"><b>%s</b></div>", section_header) },
{ ["Header"] = "Related to"  , ["Data"] = ancestor_entry },
{ ["Header"] = "With tunings", ["Data"] = step_ratio_range_entry }
}
end
table.insert(structure_data, {
return section_entries
'Brightest mode',
end
'LLLsLLs'
})
table.insert(structure_data, {
'Period',
'2/1'
})
table.insert(structure_data, {
'Range for [[bright]] [[generator]]',
display_range(paucitonic_bright_steps/paucitonic_et, equalized_bright_steps/equalized_et,
paucitonic_bright_steps .. '\\' .. paucitonic_et .. '(' .. round(ET.cents(paucitonic_et, paucitonic_bright_steps), 1) .. ')',
equalized_bright_steps .. '\\' .. equalized_et .. '(' .. round(ET.cents(equalized_et, equalized_bright_steps), 1) .. ')'
)
})
table.insert(structure_data, {
'Range for [[dark]] [[generator]]',
display_range(paucitonic_dark_steps/paucitonic_et, equalized_dark_steps/equalized_et,
paucitonic_dark_steps .. '\\' .. paucitonic_et .. '(' .. round(ET.cents(paucitonic_et, paucitonic_dark_steps), 1) .. ')',
equalized_dark_steps .. '\\' .. equalized_et .. '(' .. round(ET.cents(equalized_et, equalized_dark_steps), 1) .. ')'
)
})
table.insert(structure_data, {
'Parent MOS',
'[[3L 2s]]'
})
table.insert(structure_data, {
'Daughter MOSes',
'[[5L 7s]], [[7L 5s]]'
})
table.insert(structure_data, {
'[[Operations on MOSes#Sistering|Sister MOS]]',
'[[2L 5s]]'
})
table.insert(structure_data, {
'[[Operations on MOSes#Neutralization|Neutralized MOS]]',
'[[3L 4s]]'
})
table.insert(structure_data, {
'[[TAMNAMS#Mos pattern names|TAMNAMS name]]',
'diatonic'
})


-- Compute et generators by taking mediants from paucitonic and equalized generators
-- Helper function
-- Adds a section for scale names
function p.other_names(other_names)
local other_names = other_names or {"p-chromatic", "hard diatonic"}
local supersoft_et = ET.new(1*paucitonic_et + 3*equalized_et, equave, nil)
local section_header = "Other names"
local supersoft_bright_steps = 1*paucitonic_bright_steps + 3*equalized_bright_steps
local supersoft_gen = ''.. supersoft_bright_steps .. '\\' .. ET.as_string(supersoft_et)
local supersoft_gen_cents = round(ET.cents(supersoft_et, supersoft_bright_steps), 1)
local soft_et = ET.new(1*paucitonic_et + 2*equalized_et, equave, nil)
if #other_names == 0 then
local soft_bright_steps = 1*paucitonic_bright_steps + 2*equalized_bright_steps
return nil
local soft_gen = ''.. soft_bright_steps .. '\\' .. ET.as_string(soft_et)
else
local soft_gen_cents = round(ET.cents(soft_et, soft_bright_steps), 1)
local scale_names = ""
for i=1, #other_names do
scale_names = scale_names .. other_names[i]
if i ~= #other_names then
scale_names = scale_names .. "<br />"
end
end
local section_entries = {
{ ["Header"] = string.format("<div style=\"margin-top: 0.6em;\"><b>%s</b></div>", section_header)},
{ ["Header"] = "Name(s)", ["Data"] = scale_names}
}
return section_entries
end
end
 
-- Helper function
-- Produces section for related scales
-- Section is returned as a jagged array and return value must be merged into
-- a larger array.
function p.related_scales(input_mos)
local input_mos = input_mos or mos.new(5, 2)
local semisoft_et = ET.new(2*paucitonic_et + 3*equalized_et, equave, nil)
-- Produce the mos's relatives
local semisoft_bright_steps = 2*paucitonic_bright_steps + 3*equalized_bright_steps
local parent_mos, sister_mos, soft_child_mos, hard_child_mos, neutral_mos, soft_flought_mos, hard_flought_mos
local semisoft_gen = ''.. semisoft_bright_steps .. '\\' .. ET.as_string(semisoft_et)
parent_mos = mos.parent(input_mos)
local semisoft_gen_cents = round(ET.cents(semisoft_et, semisoft_bright_steps), 1)
sister_mos = mos.sister(input_mos)
soft_child_mos, hard_child_mos = mos.children(input_mos)
neutral_mos = mos.neutralized(input_mos)
soft_flought_mos, hard_flought_mos = mos.interleaved(input_mos)
local basic_et = ET.new(1*paucitonic_et + 1*equalized_et, equave, nil)
-- Produce links to those relatives; parent and sister links have extra
local basic_bright_steps = 1*paucitonic_bright_steps + 1*equalized_bright_steps
-- checks to make sure they're valid mosses:
local basic_gen = ''.. basic_bright_steps .. '\\' .. ET.as_string(basic_et)
-- - If the input mos is a root mos (nL ns), then it has no parent
local basic_gen_cents = round(ET.cents(basic_et, basic_bright_steps), 1)
-- - If the input mos is a root mos, then it's its own sister
local is_nL_ns = input_mos.nL == input_mos.ns
local parent_scalesig      = is_nL_ns and "none" or mos.as_link(parent_mos)
local sister_scalesig      = is_nL_ns and (mos.as_string(input_mos) .. " (self)") or mos.as_link(sister_mos)
local soft_scalesig        = mos.as_link(soft_child_mos)
local hard_scalesig        = mos.as_link(hard_child_mos)
local neutral_scalesig      = mos.as_link(neutral_mos)
local soft_flought_scalesig = mos.as_link(soft_flought_mos)
local hard_flought_scalesig = mos.as_link(hard_flought_mos)
local semihard_et = ET.new(3*paucitonic_et + 2*equalized_et, equave, nil)
local section_header = "Related MOS scales"
local semihard_bright_steps = 3*paucitonic_bright_steps + 2*equalized_bright_steps
local section_entries = {
local semihard_gen = ''.. semihard_bright_steps .. '\\' .. ET.as_string(semihard_et)
{ ["Header"] = string.format("<div style=\"margin-top: 0.6em;\"><b>%s</b></div>", section_header)},
local semihard_gen_cents = round(ET.cents(semihard_et, semihard_bright_steps), 1)
{ ["Header"] = "[[Operations_on_MOSes#Parent_MOS | Parent]]"        , ["Data"] = parent_scalesig },
{ ["Header"] = "[[Operations_on_MOSes#Sister_MOS | Sister]]"        , ["Data"] = sister_scalesig },
{ ["Header"] = "[[Operations_on_MOSes#Daughter_MOS | Daughters]]"    , ["Data"] = soft_scalesig .. ", " .. hard_scalesig },
{ ["Header"] = "[[Operations_on_MOSes#Neutralization | Neutralized]]", ["Data"] = neutral_scalesig},
{ ["Header"] = "[[Flought_scale | 2-Flought]]"                      , ["Data"] = soft_flought_scalesig .. ", " .. hard_flought_scalesig }
}
local hard_et = ET.new(2*paucitonic_et + 1*equalized_et, equave, nil)
return section_entries
local hard_bright_steps = 2*paucitonic_bright_steps + 1*equalized_bright_steps
end
local hard_gen = ''.. hard_bright_steps .. '\\' .. ET.as_string(hard_et)
 
local hard_gen_cents = round(ET.cents(hard_et, hard_bright_steps), 1)
-- Helper function
-- Produces simple equal tunings
-- Includes xenpaper links
function p.equal_tunings(input_mos)
local input_mos = input_mos or mos.new(5, 2)
local bright_gen = mos.bright_gen(input_mos)
local step_ratios = {
{ 1, 1 },
{ 4, 3 },
{ 3, 2 },
{ 5, 3 },
{ 2, 1 },
{ 5, 2 },
{ 3, 1 },
{ 4, 1 },
{ 1, 0 }
}
local superhard_et = ET.new(3*paucitonic_et + 1*equalized_et, equave, nil)
local section_header = p.annotate_section_header(input_mos, "Equal tunings")
local superhard_bright_steps = 3*paucitonic_bright_steps + 1*equalized_bright_steps
local section_entries = {{ ["Header"] = section_header }}
local superhard_gen = ''.. superhard_bright_steps .. '\\' .. ET.as_string(superhard_et)
local superhard_gen_cents = round(ET.cents(superhard_et, superhard_bright_steps), 1)
local et_data = {}
for i = 1, #step_ratios do
table.insert(et_data, {
local step_ratio = step_ratios[i]
'[[TAMNAMS#Step ratio spectrum|Supersoft]] (L:s = 4:3)',
'[[' .. ET.as_string(supersoft_et) .. '|' .. supersoft_gen .. ']] (' .. supersoft_gen_cents .. '¢)'
local ed_as_string = mos.et_string(input_mos, step_ratio)
})
table.insert(et_data, {
local gen_in_steps = mos.bright_gen_to_et_string(input_mos, step_ratio, "")
'[[TAMNAMS#Step ratio spectrum|Soft]] (L:s = 3:2)',
local gen_in_cents = mos.bright_gen_to_cents(input_mos, step_ratio)
'[[' .. ET.as_string(soft_et) .. '|' .. soft_gen .. ']] (' .. soft_gen_cents .. '¢)'
})
local step_ratio_name = tamnams.lookup_step_ratio(step_ratio)
table.insert(et_data, {
step_ratio_name = step_ratio_name:gsub("^%l", string.upper)
'[[TAMNAMS#Step ratio spectrum|Semisoft]] (L:s = 5:3)',
'[[' .. ET.as_string(semisoft_et) .. '|' .. semisoft_gen .. ']] (' .. semisoft_gen_cents .. )'
local xenpaper_link = xp.mosstep_pattern_to_xenpaper_link(mos.brightest_mode(input_mos), step_ratios[i], input_mos.equave)
})
local caption = string.format("[[%s]] [%s (<span style=\"white-space: nowrap;\">L:s = %d:%d</span>)]", step_ratio_name, xenpaper_link, step_ratio[1], step_ratio[2])
table.insert(et_data, {
local text = string.format("[[%s|%s]] (%.1f{{c}})", ed_as_string, gen_in_steps, gen_in_cents)
'[[TAMNAMS#Step ratio spectrum|Basic]] (L:s = 2:1)',
'[[' .. ET.as_string(basic_et) .. '|' .. basic_gen .. ']] (' .. basic_gen_cents .. '¢)'
table.insert(section_entries, { ["Header"] = caption, ["Data"] = text })
})
table.insert(et_data, {
'[[TAMNAMS#Step ratio spectrum|Semihard]] (L:s = 5:2)',
'[[' .. ET.as_string(semihard_et) .. '|' .. semihard_gen .. ']] (' .. semihard_gen_cents .. '¢)'
})
table.insert(et_data, {
'[[TAMNAMS#Step ratio spectrum|Hard]] (L:s = 3:1)',
'[[' .. ET.as_string(hard_et) .. '|' .. hard_gen .. ']] (' .. hard_gen_cents .. '¢)'
})
table.insert(et_data, {
'[[TAMNAMS#Step ratio spectrum|Superhard]] (L:s = 4:1)',
'[[' .. ET.as_string(superhard_et) .. '|' .. superhard_gen .. ']] (' .. superhard_gen_cents .. '¢)'
})
result = p.build(
tuning,
structure_data,
et_data,
prev_L,
next_L,
prev_s,
next_s
)
if not debug_mode then
result = result .. categories
end
end
return result
 
return section_entries
end
end


function p.build(title, structure_entries, et_entries, prev_x, next_x, prev_y, next_y)
-- New "main" function
local s = '<div style="\n' ..
function p._infobox_mos(input_mos)
'border: 1px solid #999;\n' ..
local input_mos = input_mos or mos.new(4, 5, 3)
'margin: 0;\n' ..
local other_names_unparsed = ""
'margin-left: 1em;\n' ..
'margin-bottom: 0.5em;\n' ..
'padding: 0.5em;\n' ..
'background-color: #f0f0f0;\n' ..
'min-width: 15em;\n' ..
'float: right;\n' ..
'max-width: 100%;\n' ..
'overflow: auto;\n' ..
'">\n' ..
'{| width="100%" style="border-collapse: collapse;"\n' ..
'|+ style="font-weight: bold; text-align: center;" | '
local has_adjacent_x = (prev_x and #prev_x > 0) or (next_x and #next_x > 0)
local has_adjacent_y = (prev_y and #prev_y > 0) or (next_y and #next_y > 0)
if prev_y then -- prev y
local other_names_parsed = tip.parse_entries(other_names_unparsed) or tip.parse_entries(other_names_unparsed, ",")
s = s .. '<table style="width: 100%; margin: 0"><tr>'
.. '<td></td><td style="\n'
local sections = {}
.. 'width: 50%; padding-left: 1em; padding-right: 1em; text-align: center; font-size: smaller">'
.. prev_y
-- Keyboard visualization
.. '\n</td><td></td>'
local kb_vis = p.kb_vis(input_mos)
.. '\n<tr>'
p.concatenate_tables(sections, kb_vis)
.. '<td style="width: 15%; text-align: left; white-space: nowrap; font-size: smaller">'
.. (prev_x or '')
-- Scale structure section
.. '</td>'
local scale_structure = p.scale_structure(input_mos)
.. '<td style="width: 70%; padding-left: 1em; padding-right: 1em; text-align: center">'
p.concatenate_tables(sections, scale_structure)
.. title
.. '</td>'
-- Interval range section
.. '<td style="width: 15%; text-align: right; white-space: nowrap; font-size: smaller">'
--local step_sizes = p.step_sizes(tuning_parsed)
.. (next_x or '')
--p.concatenate_tables(sections, step_sizes)
.. '</td>'
.. '</tr>'
-- Generator sizes section
if next_y then
local gen_sizes = p.generator_sizes(input_mos)
s = s .. '<tr>'
p.concatenate_tables(sections, gen_sizes)
.. '<td></td><td style="\n'
.. 'width: 50%; padding-left: 1em; padding-right: 1em; text-align: center; font-size: smaller">'
-- Tamnams info section, if applicable
.. next_y
local tamnams_info = p.tamnams_information(input_mos)
.. '\n</td><td></td>'
if tamnams_info ~= nil then
.. '</tr>'
p.concatenate_tables(sections, tamnams_info)
end
end
s = s ..  '</table>'
elseif has_adjacent_x then -- no prev y, has adjacent x
-- Other names section, if applicable
s = s .. '<table style="width: 100%; margin: 0"><tr>'
local other_names_section = p.other_names(other_names_parsed)
.. '<td style="width: 15%; text-align: left; white-space: nowrap; font-size: smaller">'
if other_names_section ~= nil then
.. (prev_x or '')
p.concatenate_tables(sections, other_names_section)
.. '</td>'
.. '<td style="width: 70%; padding-left: 1em; padding-right: 1em; text-align: center">'
.. title
.. '</td>'
.. '<td style="width: 15%; text-align: right; white-space: nowrap; font-size: smaller">'
.. (next_x or '')
.. '</td>'
.. '</tr>'
if next_y then
s = s .. '<tr><td></td>'
.. '<td style="\n'
.. 'width: 50%; padding-left: 1em; padding-right: 1em; text-align: center; font-size: smaller">'
.. next_y
.. '\n</td><td></td>'
.. '</tr>'
end
s = s ..  '</table>'
elseif next_y then -- no prev y, no adjacent x, so first row should be title in center
s = s .. '<table style="width: 100%; margin: 0"><tr>'
.. '<td>'
.. '</td>'
.. '<td>'
.. title
.. '</td>'
.. '<td>'
.. '</td>'
.. '</tr>'
.. '<tr><td></td>'
.. '<td style="\n'
.. 'width: 50%; text-align: left; white-space: nowrap; font-size: smaller">'
.. next_y
.. '\n</td><td></td>'
.. '</tr>'
.. '</table>'
else
s = s .. title
end
end
s = s .. '\n'
for i, entry in ipairs(structure_entries) do
-- Related scales section
if #entry > 1 then
local related_scales = p.related_scales(input_mos)
local caption = entry[1]
p.concatenate_tables(sections, related_scales)
local text = entry[2]
s = s .. '|-\n' ..
-- Equal tunings section
'| style="text-align:right; padding-right: 0.25em" | ' .. caption .. '\n' ..
local equal_tunings = p.equal_tunings(input_mos)
'| style="background-color: white; padding-left: 0.25em; font-weight: bold" | ' .. text .. '\n'
p.concatenate_tables(sections, equal_tunings)
elseif #entry == 1 then
 
local text = entry[1]
-- Adjacent links
s = s .. '|-\n'
local adjacent_links = p.adjacent_links(input_mos)
.. '| colspan="2" style="text-align: center;" | ' .. text .. '\n'
end
local args = {
["Adjacent Links"] = adjacent_links,
["Title"] = mos.as_long_string(input_mos),
["Rows"] = sections,
["name"] = "Infobox MOS"
}
return ib._infobox(args)
--return sections
end
 
-- Wrapper function
function p.infobox_MOS(frame)
local args = getArgs(frame)
-- "Scale Signature" is preferred; "Tuning" is supported for legacy purposes
local unparsed = args["Tuning"] or args["Scale Signature"]
local input_mos = mos.parse(unparsed)
local other_names = args["othernames"] or nil
local debug_mode = yesno(args["debug"], false)
local wtext = yesno(frame.args["wtext"] or args["wtext"])
local result = p._infobox_mos(input_mos)
if not debug_mode then
result = result .. p.categorize(input_mos)
end
end
s = s .. '|-\n'
    .. '|colspan="2" style="text-align:center;"| <b>Equal tunings</b>\n'
if wtext then
for i, entry in ipairs(et_entries) do
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
if #entry > 1 then
local caption = entry[1]
local text = entry[2]
s = s .. '|-\n' ..
'| style="text-align:right; padding-right: 0.25em" | ' .. caption .. '\n' ..
'| style="background-color: white; padding-left: 0.25em; font-weight: bold" | ' .. text .. '\n'
elseif #entry == 1 then
local text = entry[1]
s = s .. '|-\n'
.. '| colspan="2" style="text-align: center;" | ' .. text .. '\n'
end
end
end
s = s .. '|}</div>'
return s
return frame:preprocess(result)
end
end


return p
return p