Module:Infobox interval: Difference between revisions
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( | ||