Module:Infobox interval: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
Improved parsing |
||
| Line 8: | Line 8: | ||
local debug_mode = frame.args['debug'] ~= nil | local debug_mode = frame.args['debug'] ~= nil | ||
local rational = false | |||
local | local small = false | ||
local | local regular = false | ||
local | local ratio = nil | ||
local | local cents = nil | ||
local | local ket = nil | ||
local | local ratio_string = nil | ||
-- intervals with relatively small powers | |||
if frame.args['Ratio'] and #(frame.args['Ratio']) > 0 then | |||
ratio = rat.parse(frame.args['Ratio']) | |||
if ratio ~= nil then | |||
rational = true | |||
small = true | |||
regular = not ratio.nan and not ratio.inf and not ratio.zero | |||
cents = rat.cents(ratio) | |||
ket = rat.as_ket(ratio, frame) | |||
ratio_string = rat.as_ratio(ratio) | |||
end | |||
end | |||
-- intervals with large powers | |||
if ratio == nil and frame.args['Ket'] and #(frame.args['Ket']) > 0 then | |||
ratio = rat.from_ket(frame.args['Ket']) | |||
if ratio ~= nil then | |||
rational = true | |||
small = false | |||
regular = true | |||
cents = rat.cents(ratio) | |||
ket = rat.as_ket(ratio, frame) | |||
end | |||
end | |||
-- irrational intervals | |||
if ratio == nil and frame.args['Cents'] and #(frame.args['Cents']) > 0 then | |||
cents = tonumber(frame.args['Cents']) | |||
if cents ~= nil then | |||
rational = false | |||
small = true | |||
regular = true | |||
ratio_string = frame.args['Ratio'] or '' | |||
end | |||
end | |||
local infobox_data = {} | local infobox_data = {} | ||
local cats = '[[Category:Rational intervals]]' | local cats = '' | ||
if rational then | |||
cats = cats .. '[[Category:Rational intervals]]' | |||
else | |||
cats = cats .. '[[Category:Irrational intervals]]' | |||
end | |||
table.insert(infobox_data, { | if small then | ||
table.insert(infobox_data, { | |||
'Ratio', | |||
ratio_string | |||
table.insert(infobox_data, { | }) | ||
end | |||
if rational then | |||
table.insert(infobox_data, { | |||
if regular then | 'Factorization', | ||
rat.factorisation(ratio) | |||
}) | |||
end | |||
if regular and rational then | |||
table.insert(infobox_data, { | table.insert(infobox_data, { | ||
'[[Just intonation subgroup|Subgroup]]', | '[[Just intonation subgroup|Subgroup]]', | ||
| Line 36: | Line 80: | ||
}) | }) | ||
end | end | ||
if regular then | if regular and rational then | ||
table.insert(infobox_data, { | table.insert(infobox_data, { | ||
'[[Monzo]]', | '[[Monzo]]', | ||
ket | |||
}) | }) | ||
end | |||
if regular then | |||
table.insert(infobox_data, { | table.insert(infobox_data, { | ||
'Size in [[cent]]s', | 'Size in [[cent]]s', | ||
u._round(cents, 8) .. '¢' | |||
}) | }) | ||
end | end | ||
| Line 59: | Line 105: | ||
table.insert(infobox_data, { | table.insert(infobox_data, { | ||
'Name(s)', | 'Name(s)', | ||
'<abbr title="missing value for parameter \'Name\'">\'\'missing\'\'</abbr | '<abbr title="missing value for parameter \'Name\'">\'\'missing\'\'</abbr><sup>[[Template:Infobox Interval| ? ]]</sup>' | ||
}) | }) | ||
end | end | ||
| Line 73: | Line 119: | ||
local FJS_name = frame.args['FJS name'] | local FJS_name = frame.args['FJS name'] | ||
if not FJS_name or #FJS_name == 0 then | if (not FJS_name or #FJS_name == 0) and rational then | ||
FJS_name = rat.as_FJS(ratio) | FJS_name = rat.as_FJS(ratio) | ||
end | end | ||
| Line 83: | Line 129: | ||
end | end | ||
if regular then | if regular and small then | ||
table.insert(infobox_data, { | table.insert(infobox_data, { | ||
'Norms', | 'Norms', | ||
| Line 95: | Line 141: | ||
table.insert(infobox_data, { | table.insert(infobox_data, { | ||
'[[Harmonic entropy]]', | '[[Harmonic entropy]]', | ||
'~' .. u._round(i.harmonic_entropy( | '~' .. u._round(i.harmonic_entropy(cents), 6) | ||
}) | }) | ||
end | end | ||
| Line 106: | Line 152: | ||
}) | }) | ||
end | end | ||
if small then | |||
table.insert(infobox_data, { | |||
'<small>[https://www.yacavone.net/xen-calc/?q=' .. ratio_string .. ' open this interval in \'\'xen-calc\'\']</small>' | |||
}) | |||
end | |||
local s = infobox.build( | local s = infobox.build( | ||
Revision as of 14:21, 12 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
local rational = false
local small = false
local regular = false
local ratio = nil
local cents = nil
local ket = nil
local ratio_string = nil
-- intervals with relatively small powers
if frame.args['Ratio'] and #(frame.args['Ratio']) > 0 then
ratio = rat.parse(frame.args['Ratio'])
if ratio ~= nil then
rational = true
small = true
regular = not ratio.nan and not ratio.inf and not ratio.zero
cents = rat.cents(ratio)
ket = rat.as_ket(ratio, frame)
ratio_string = rat.as_ratio(ratio)
end
end
-- intervals with large powers
if ratio == nil and frame.args['Ket'] and #(frame.args['Ket']) > 0 then
ratio = rat.from_ket(frame.args['Ket'])
if ratio ~= nil then
rational = true
small = false
regular = true
cents = rat.cents(ratio)
ket = rat.as_ket(ratio, frame)
end
end
-- irrational intervals
if ratio == nil and frame.args['Cents'] and #(frame.args['Cents']) > 0 then
cents = tonumber(frame.args['Cents'])
if cents ~= nil then
rational = false
small = true
regular = true
ratio_string = frame.args['Ratio'] or ''
end
end
local infobox_data = {}
local cats = ''
if rational then
cats = cats .. '[[Category:Rational intervals]]'
else
cats = cats .. '[[Category:Irrational intervals]]'
end
if small then
table.insert(infobox_data, {
'Ratio',
ratio_string
})
end
if rational then
table.insert(infobox_data, {
'Factorization',
rat.factorisation(ratio)
})
end
if regular and rational then
table.insert(infobox_data, {
'[[Just intonation subgroup|Subgroup]]',
rat.subgroup(ratio)
})
end
if regular and rational then
table.insert(infobox_data, {
'[[Monzo]]',
ket
})
end
if regular then
table.insert(infobox_data, {
'Size in [[cent]]s',
u._round(cents, 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><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
local FJS_name = frame.args['FJS name']
if (not FJS_name or #FJS_name == 0) and rational then
FJS_name = rat.as_FJS(ratio)
end
if FJS_name and #FJS_name > 0 then
table.insert(infobox_data, {
'[[Functional Just System|FJS name]]',
frame:preprocess('<math>' .. FJS_name .. '</math>')
})
end
if regular and small 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(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
if small then
table.insert(infobox_data, {
'<small>[https://www.yacavone.net/xen-calc/?q=' .. ratio_string .. ' open this interval in \'\'xen-calc\'\']</small>'
})
end
local s = infobox.build(
'<u>Interval information</u>',
infobox_data
)
if not debug_mode then
s = s .. cats
end
return s
end
return p