Module:Infobox MOS: Difference between revisions

Ganaram inukshuk (talk | contribs)
m todo
Ganaram inukshuk (talk | contribs)
create helper function for adding the equave as superscript text to a section header; drop rat module
Line 1: Line 1:
local p = {}
local p = {}
local rat = require("Module:Rational")
local mos = require("Module:MOS")
local mos = require("Module:MOS")
local xp = require("Module:Xenpaper")
local xp = require("Module:Xenpaper")
Line 18: Line 17:
t1[#t1 + 1] = t2[i]
t1[#t1 + 1] = t2[i]
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
end


Line 51: Line 60:
-- If the mos is octave-equivalent, add appropriate tamnams-named categories
-- If the mos is octave-equivalent, add appropriate tamnams-named categories
-- Otherwise, add to nonoctave category
-- Otherwise, add to nonoctave category
if rat.eq(input_mos.equave, rat.new(2)) then
if mos.is_octave_equivalent(input_mos) then
-- Caveats:
-- Caveats:
-- - Only octave-equivalent mos names are used as categories.
-- - Only octave-equivalent mos names are used as categories.
Line 108: Line 117:
local input_mos = input_mos or mos.new(5, 2)
local input_mos = input_mos or mos.new(5, 2)
local equave_as_string = rat.as_ratio(input_mos.equave)
local equave_as_string = mos.equave_as_string(input_mos)
local equave_in_cents = rat.cents(input_mos.equave)
local equave_in_cents = mos.equave_to_cents(input_mos)
local number_of_periods = mos.period_count(input_mos)
local number_of_periods = mos.period_count(input_mos)
Line 154: Line 163:
local dark_max_in_cents = mos.dark_gen_to_cents(input_mos, {1, 1})
local dark_max_in_cents = mos.dark_gen_to_cents(input_mos, {1, 1})
local section_header = "Generator size"
local section_header = p.annotate_section_header(input_mos, "Generator size")
local et_suffix = mos.et_suffix(input_mos)
local section_header = (et_suffix == "edo"
and string.format('<div style=\"margin-top: 0.6em;\"><b>Generator size</b></div>')
or  string.format('<div style=\"margin-top: 0.6em;\"><b>Generator size</b><sup><abbr title=\"In steps of %s\">(%s)</sup></div>', et_suffix, et_suffix))
local section_entries = {
local section_entries = {
{section_header},
{section_header},
{"[[Bright]]", 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)},
{"[[Bright]]", 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)},
{"[[Dark]]", 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)},
{"[[Dark]]" , 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)},
}
}
Line 192: Line 196:
local tamnams_abbrev = tamnams.lookup_abbrev(input_mos)
local tamnams_abbrev = tamnams.lookup_abbrev(input_mos)
local is_octave_equivalent = rat.eq(input_mos.equave, 2)
local is_octave_equivalent = mos.is_octave_equivalent(input_mos)
local is_within_named_range = tamnams_name ~= nil and notecount <= 10
local is_within_named_range = tamnams_name ~= nil and notecount <= 10
local is_root_mos = input_mos.nL == input_mos.ns
local is_root_mos = input_mos.nL == input_mos.ns
Line 307: Line 311:
-- Includes xenpaper links
-- Includes xenpaper links
function p.equal_tunings(input_mos)
function p.equal_tunings(input_mos)
local input_mos = input_mos or mos.new(5, 2, rat.new(5,3))
local input_mos = input_mos or mos.new(5, 2)
local bright_gen = mos.bright_gen(input_mos)
local bright_gen = mos.bright_gen(input_mos)
Line 323: Line 327:
}
}
local section_header = "Equal tunings"
local section_header = p.annotate_section_header(input_mos, "Equal tunings")
local equave_annotation = ""
local section_entries = {{section_header}}
if rat.eq(input_mos.equave, 3) then
equave_annotation = "<sup><abbr title=\"In steps of edt\">(edt)</sup>"
elseif rat.eq(input_mos.equave, rat.new(3,2)) then
equave_annotation = "<sup><abbr title=\"In steps of edf\">(edf)</sup>"
elseif not rat.eq(input_mos.equave, 2) then
local equave_as_ratio = rat.as_ratio(input_mos.equave)
equave_annotation = string.format("<sup><abbr title=\"In steps of ed%s\">(ed%s)</sup>", equave_as_ratio, equave_as_ratio)
end
local section_entries = {
{string.format("<div style=\"margin-top: 0.6em;\"><b>%s</b>%s</div>", section_header, equave_annotation)},
}
for i = 1, #step_ratios do
for i = 1, #step_ratios do
local step_ratio = step_ratios[i]
local step_ratio = step_ratios[i]