Module:Infobox interval: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
| Line 16: | Line 16: | ||
local ratio_approx = rat.as_float(ratio) | local ratio_approx = rat.as_float(ratio) | ||
local ratio_cents = rat.cents(ratio) | local ratio_cents = rat.cents(ratio) | ||
local regular = not ratio.nan and not ratio.zero and not ratio.inf | |||
local infobox_data = {} | local infobox_data = {} | ||
| Line 28: | Line 30: | ||
rat.factorisation(ratio) | rat.factorisation(ratio) | ||
}) | }) | ||
if regular then | |||
if | |||
table.insert(infobox_data, { | table.insert(infobox_data, { | ||
'[[Just intonation subgroup|Subgroup]]', | '[[Just intonation subgroup|Subgroup]]', | ||
subgroup | rat.subgroup(ratio) | ||
}) | |||
end | |||
if regular then | |||
table.insert(infobox_data, { | |||
'[[Monzo]]', | |||
ratio_ket | |||
}) | |||
table.insert(infobox_data, { | |||
'Size in [[cent]]s', | |||
i._to_cents(ratio_approx, 8) | |||
}) | }) | ||
end | end | ||
local name = frame.args['Name'] | local name = frame.args['Name'] | ||
| Line 78: | Line 81: | ||
end | end | ||
table.insert(infobox_data, { | if regular then | ||
table.insert(infobox_data, { | |||
'Norms', | |||
'[[Tenney height|log<sub>2</sub> n⋅d]]: ' .. u._round(rat.tenney_height(ratio), 6) .. '<br/>' | |||
.. '[[Weil height|max(n, d)]]: ' .. u._round(rat.weil_height(ratio), 6) .. '<br/>' | |||
.. '[[Benedetti height|n⋅d]]: ' .. u._round(rat.benedetti_height(ratio), 6) | |||
}) | |||
end | |||
if | if regular then | ||
table.insert(infobox_data, { | table.insert(infobox_data, { | ||
'[[Harmonic entropy]]', | '[[Harmonic entropy]]', | ||
Revision as of 18:06, 10 October 2022
- 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 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||||||||||||||
No function descriptions were provided. The Lua code may have further information.
local p = {}
local rat = require('Module:Rational')
local u = require('Module:Utils')
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 + irrational intervals
local ratio_arg = frame.args['Ratio'] or '2/1'
local ratio = rat.parse(ratio_arg) or rat.new(2)
local ratio_str = rat.as_ratio(ratio)
local ratio_ket = rat.as_ket(ratio, frame)
local ratio_approx = rat.as_float(ratio)
local ratio_cents = rat.cents(ratio)
local regular = not ratio.nan and not ratio.zero and not ratio.inf
local infobox_data = {}
local cats = '[[Category:Rational intervals]]'
table.insert(infobox_data, {
'Ratio',
ratio_str
})
table.insert(infobox_data, {
'Factorization',
rat.factorisation(ratio)
})
if regular then
table.insert(infobox_data, {
'[[Just intonation subgroup|Subgroup]]',
rat.subgroup(ratio)
})
end
if regular then
table.insert(infobox_data, {
'[[Monzo]]',
ratio_ket
})
table.insert(infobox_data, {
'Size in [[cent]]s',
i._to_cents(ratio_approx, 8)
})
end
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| ? ]]</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
if regular then
table.insert(infobox_data, {
'Norms',
'[[Tenney height|log<sub>2</sub> n⋅d]]: ' .. u._round(rat.tenney_height(ratio), 6) .. '<br/>'
.. '[[Weil height|max(n, d)]]: ' .. u._round(rat.weil_height(ratio), 6) .. '<br/>'
.. '[[Benedetti height|n⋅d]]: ' .. u._round(rat.benedetti_height(ratio), 6)
})
end
if regular then
table.insert(infobox_data, {
'[[Harmonic entropy]]',
'~' .. u._round(i.harmonic_entropy(ratio_cents), 6)
})
end
local sound = frame.args['Sound']
if sound and #sound > 0 then
cats = cats .. '[[Category:Pages with internal sound examples]]'
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=' .. ratio_str .. ' 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