Module:Infobox interval

From Xenharmonic Wiki
Revision as of 12:19, 9 October 2022 by Plumtree (talk | contribs) (Module created)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Module documentation[view] [edit] [history] [purge]
This module should not be invoked directly; use its corresponding template instead: Template:Infobox interval.

This module generates an infobox providing information about a given interval.

Introspection summary for Module:Infobox interval 
Functions provided (1)
Line Function Params
6 infobox_interval (invokable) (frame)
Lua modules required (3)
Variable Module Functions used
infobox Module:Infobox build
i Module:Interval _to_cents
rat Module:Rational parse
new
as_ratio
as_ket
as_float

No function descriptions were provided. The Lua code may have further information.


local p = {}
local rat = require('Module:Rational')
local i = require('Module:Interval')
local infobox = require('Module:Infobox')

function p.infobox_interval(frame)
	-- TODO: better input parsing
	local ratio_arg = frame.args('Ratio') or '2/1'
	local ratio = rat.parse(ratio_arg) or rat.new(2)
	
	local infobox_data = {}
	local cats = '[[Category:Rational intervals]]'
	
	table.insert(infobox_data, {
		'Ratio',
		rat.as_ratio(ratio)
	})
	table.insert(infobox_data, {
		'[[Monzo]]',
		rat.as_ket(ratio, frame)
	})
	table.insert(infobox_data, {
		'Size in [[cent]]s',
		i._to_cents(rat.as_float(ratio), 6)
	})

	local name = frame.args['Name']
	if name and #name > 0 then
		local caption = 'Name'
		if name:match(',') then caption = 'Names' end
		table.insert(infobox_data, {
			caption,
			name
		})
	else
		cats = cats .. '[[Category:Todo:add interval name]]'
		table.insert(infobox_data, {
			'Name(s)',
			'<abbr title="missing value for parameter \'Name\'">\'\'missing\'\'</abbr></span><sup>[[Template:Infobox Interval| ?&nbsp;]]</sup>'
		})
	end
	
	-- TODO: compute?
	local colour_name = frame.args['Color name']
	if colour_name and #colour_name > 0 then
		table.insert(infobox_data, {
			'[[Color notation|Color name]]',
			colour_name
		})
	end
	
	-- TODO: compute
	local FJS_name = frame.args['FJS name']
	if FJS_name and #FJS_name > 0 then
		table.insert(infobox_data, {
			'[[Functional Just System|FJS name]]',
			FJS_name
		})
	end
	
	-- TODO: Sound, xen-calc (colspan 2)
	
	return infobox.build(
		'<u>Interval information</u>',
		infobox_data
	) .. cats
end

return p