Module:Infobox interval: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
Plumtree (talk | contribs)
mNo edit summary
Plumtree (talk | contribs)
mNo edit summary
Line 61: Line 61:
end
end
-- TODO: Sound, xen-calc (colspan 2)
-- TODO: xen-calc (colspan 2)
local sound = frame.args['Sound']
if sound and #sound > 0 then
table.insert(infobox_data, {
'[[File:' .. sound .. '|270px]]<br/><small>[[:File:' .. sound .. '[sound info]]]</small>'
})
end
table.insert(infobox_data, {
'<small>[https://www.yacavone.net/xen-calc/?q=' .. rat.as_ratio(ratio) .. ' open this interval in \'\'xen-calc\'\']</small>'
})
local s = infobox.build(
local s = infobox.build(

Revision as of 12:35, 9 October 2022

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)
	local debug_mode = frame.args['debug'] ~= nil
	
	-- 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: xen-calc (colspan 2)
	local sound = frame.args['Sound']
	if sound and #sound > 0 then
		table.insert(infobox_data, {
			'[[File:' .. sound .. '|270px]]<br/><small>[[:File:' .. sound .. '[sound info]]]</small>'
		})
	end
	
	table.insert(infobox_data, {
		'<small>[https://www.yacavone.net/xen-calc/?q=' .. rat.as_ratio(ratio) .. ' open this interval in \'\'xen-calc\'\']</small>'
	})
	
	local s = infobox.build(
		'<u>Interval information</u>',
		infobox_data
	)
	if not debug_mode then
		s = s .. cats
	end
	return s
end

return p