Module:Infobox MOS: Difference between revisions

Ganaram inukshuk (talk | contribs)
Transfered kb-vis code to new module
Ganaram inukshuk (talk | contribs)
Updated comments; added back other names section
Line 7: Line 7:
local infobox = require('Module:Infobox')
local infobox = require('Module:Infobox')
local kbvis = require('Module:Keyboard vis')
local kbvis = require('Module:Keyboard vis')
local tip = require('Module:Template input parse')


-- TODO:
-- TODO:
-- Add back "other names" section
-- Add back xenpaper links?
-- Add back xenpaper links


-- Helper function
-- Helper function
Line 22: Line 22:
end
end


-- Helper function (TODO: make this its own module?)
-- Helper function
-- Creates a keyboard visualization, based on the defacto Halberstadt layout
-- Create a keyboard visualization, based on the Halberstadt keyboard layout
function p.kb_vis(input_mos)
function p.kb_vis(input_mos)
local input_mos = input_mos or mos.new(5, 2)
local input_mos = input_mos or mos.new(5, 2)
Line 101: Line 101:
-- Links that contain either "0L" or "0s" when the parent's L/s-count is 1
-- Links that contain either "0L" or "0s" when the parent's L/s-count is 1
-- refer to degenerate mosses (null-large and null-small, or 0L/0s) and
-- refer to degenerate mosses (either 0L or 0s), whose links should be made
-- links for those should be made blank instead.
-- blank instead.
for i = 1, #adjacent_links do
for i = 1, #adjacent_links do
local number_of_periods = utils._gcd(input_mos.nL, input_mos.ns)
local number_of_periods = utils._gcd(input_mos.nL, input_mos.ns)
Line 346: Line 346:
return section_entries
return section_entries
end
-- 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 section_header = "Other names"
if #other_names == 0 then
return nil
else
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 = {
{string.format("<b>%s</b>", section_header)},
{"Name(s)", scale_names}
}
return section_entries
end
end
end


Line 458: Line 484:


-- New "main" function
-- New "main" function
function p._infobox_mos(tuning)
function p._infobox_mos(tuning, other_names)
local tuning = tuning or "5L 2s"
local tuning = tuning or "5L 2s"
local other_names = other_names or ""
local tuning_parsed = mos.parse(tuning)
local tuning_parsed = mos.parse(tuning)
local other_names_parsed = tip.parse_entries(other_names) or tip.parse_entries(other_names, ',')
local sections = {}
local sections = {}
Line 484: Line 513:
if tamnams_info ~= nil then
if tamnams_info ~= nil then
p.concatenate_tables(sections, tamnams_info)
p.concatenate_tables(sections, tamnams_info)
end
-- Other names section, if applicable
local other_names = p.other_names(other_names_parsed)
if other_names ~= nil then
p.concatenate_tables(sections, other_names)
end
end
Line 508: Line 543:
local debug_mode = tonumber(frame.args['debug']) == 1
local debug_mode = tonumber(frame.args['debug']) == 1
local result = p._infobox_mos(tuning)
local result = p._infobox_mos(tuning, other_names)
if not debug_mode then
if not debug_mode then
result = result .. p.categorize(tuning)
result = result .. p.categorize(tuning)