Module:Infobox interval: Difference between revisions

Request explanation. Set straight the logic around superparticular marks
Squib (talk | contribs)
m maybe i should discuss this before editing a template lol.
Tags: Undo Mobile edit Mobile web edit Advanced mobile edit
 
(37 intermediate revisions by 7 users not shown)
Line 1: Line 1:
local p = {}
local p = {}
local he = require("Module:Harmonic entropy")
local infobox = require("Module:Infobox")
local rat = require("Module:Rational")
local rat = require("Module:Rational")
local utils = require("Module:Utils")
local utils = require("Module:Utils")
local he = require("Module:Harmonic entropy")
local yesno = require("Module:Yesno")
local infobox = require("Module:Infobox")


-- check whether the input is a non-empty string
-- check whether the input is a non-empty string
Line 11: Line 12:


function p.infobox_interval(frame)
function p.infobox_interval(frame)
local debug_mode = frame.args["debug"]
local debug_mode = yesno(frame.args["debug"])


local page_name = frame:preprocess("{{PAGENAME}}")
local page_name = frame:preprocess("{{PAGENAME}}")
Line 110: Line 111:
end
end
if rat.is_harmonic(ratio) then
if rat.is_harmonic(ratio) then
num, den = rat.as_pair (ratio)
table.insert(special_properties, "[[harmonic]]")
table.insert(special_properties, "[[harmonic]]")
cats = cats .. "[[Category:Harmonics]]"
cats = cats .. "[[Category:Harmonics|" .. string.rep("#", string.len(num)) .. "]]"
if rat.is_prime(ratio) then
table.insert(special_properties, "[[prime harmonic]]")
cats = cats .. "[[Category:Prime harmonics|" .. string.rep("#", string.len(num)) .. "]]"
end
if rat.is_highly_composite(ratio) then
table.insert(special_properties, "[[highly composite harmonic]]")
cats = cats .. "[[Category:Highly composite harmonics|" .. string.rep("#", string.len(num)) .. "]]"
end
elseif rat.is_harmonic(ratio, true, not small) then
elseif rat.is_harmonic(ratio, true, not small) then
table.insert(special_properties, "[[Harmonic|reduced harmonic]]")
table.insert(special_properties, "[[Harmonic|reduced harmonic]]")
cats = cats .. "[[Category:Octave-reduced harmonics]]"
cats = cats .. "[[Category:Octave-reduced harmonics]]"
end
if rat.is_subharmonic(ratio) then
table.insert(special_properties, "[[subharmonic]]")
cats = cats .. "[[Category:Subharmonics]]"
elseif rat.is_subharmonic(ratio, true, not small) then
elseif rat.is_subharmonic(ratio, true, not small) then
table.insert(special_properties, "[[Subharmonic|reduced subharmonic]]")
table.insert(special_properties, "[[Subharmonic|reduced subharmonic]]")
Line 138: Line 144:
table.insert(infobox_data, {
table.insert(infobox_data, {
"Expression",
"Expression",
frame:preprocess("<math>" .. ratio_string .. "</math>"),
"<math>" .. ratio_string .. "</math>",
})
})
end
end
Line 146: Line 152:
-- there was a subsequence of 4+ zeros
-- there was a subsequence of 4+ zeros
table.insert(infobox_data, {
table.insert(infobox_data, {
"[[Smonzos and svals|Subgroup monzo]]",
"[[Subgroup monzos and vals|Subgroup monzo]]",
rat.as_subgroup_ket(ratio, frame),
rat.as_subgroup_ket(ratio, frame),
})
})
Line 177: Line 183:
table.insert(infobox_data, {
table.insert(infobox_data, {
"Size in [[cent]]s",
"Size in [[cent]]s",
utils._round(cents, 8) .. "¢",
utils._round(cents, 7) .. "¢",
})
})
end
end
Line 188: Line 194:
-- removing manual line breaks
-- removing manual line breaks
local matches
local matches
name, matches = name:gsub("<br/?>", "")
name, matches = name:gsub("<br%s*/?>", "")
if matches > 0 then
if matches > 0 then
cats = cats .. "[[Category:Todo:remove manual line breaks]]"
cats = cats .. "[[Category:Todo:remove manual line breaks]]"
Line 195: Line 201:
name = name:gsub(",%s+", ",")
name = name:gsub(",%s+", ",")
-- placing line breaks after commas
-- placing line breaks after commas
name = name:gsub(",", ",<br/>")
name = name:gsub(",", ",<br>")
end
end
table.insert(infobox_data, {
table.insert(infobox_data, {
Line 212: Line 218:
if value_provided(colour_name) then
if value_provided(colour_name) then
table.insert(infobox_data, {
table.insert(infobox_data, {
"[[Color notation|Color name]]",
"[[Kite's color notation|Color name]]",
colour_name,
colour_name,
})
})
Line 225: Line 231:
local matches
local matches
FJS_name = FJS_name:gsub("%s", "")
FJS_name = FJS_name:gsub("%s", "")
FJS_name, matches = FJS_name:gsub("<br/?>", "")
FJS_name, matches = FJS_name:gsub("<br%s*/?>", "")
if matches > 0 then
if matches > 0 then
cats = cats .. "[[Category:Todo:remove manual line breaks]]"
cats = cats .. "[[Category:Todo:remove manual line breaks]]"
Line 244: Line 250:
table.insert(infobox_data, {
table.insert(infobox_data, {
"[[Functional Just System|FJS name]]",
"[[Functional Just System|FJS name]]",
frame:preprocess("<math>" .. FJS_name .. "</math>"),
"<math>" .. FJS_name .. "</math>",
})
})
end
end
Line 252: Line 258:
table.insert(infobox_data, {
table.insert(infobox_data, {
"Special properties",
"Special properties",
table.concat(special_properties, ",<br/>"),
table.concat(special_properties, ",<br>"),
})
})
end
end
Line 259: Line 265:
if rational and regular then
if rational and regular then
table.insert(infobox_data, {
table.insert(infobox_data, {
"[[Tenney height]] (log<sub>2</sub> ''nd'')",
"[[Tenney norm]] (log<sub>2</sub> ''nd'')",
utils._round(rat.tenney_height(ratio), 6),
utils._round(rat.tenney_height(ratio), 6),
})
})
table.insert(infobox_data, {
table.insert(infobox_data, {
"[[Weil height]] (log<sub>2</sub> max(''n'', ''d''))",
"[[Weil norm]] (log<sub>2</sub> max(''n'', ''d''))",
utils._round(rat.weil_height(ratio), 6),
utils._round(rat.weil_height(ratio), 6),
})
})
table.insert(infobox_data, {
table.insert(infobox_data, {
"[[Wilson height]] (sopfr (''nd''))",
"[[Wilson norm]] (sopfr(''nd''))",
utils._round(rat.wilson_height(ratio), 6),
utils._round(rat.wilson_height(ratio), 6),
})
})
end
end


if regular then
local harmonic_entropy = frame.args["Harmonic entropy"]
table.insert(infobox_data, {
if regular and value_provided(harmonic_entropy) then
frame:preprocess("[[Harmonic entropy]]<br/>(Shannon, <math>\\sqrt{nd}</math>)"),
harmonic_entropy_switch = harmonic_entropy:match("^[Yy][Ee][Ss]$")
"~" .. utils._round(he.harmonic_entropy(cents), 6) .. " bits",
if harmonic_entropy_switch then
})
table.insert(infobox_data, {
"[[Harmonic entropy]]<br>(Shannon, <math>\\sqrt{nd}</math>)",
"~" .. utils._round(he.harmonic_entropy(cents), 6) .. " bits",
})
end
end
end


Line 308: Line 318:
local S_expressions = rat.find_S_expression(ratio)
local S_expressions = rat.find_S_expression(ratio)
if #S_expressions > 0 then
if #S_expressions > 0 then
local caption = "[[Square superparticular|S-expression]]"
local caption = "[[S-expression]]"
if #S_expressions > 1 then
if #S_expressions > 1 then
caption = caption .. "s"
caption = caption .. "s"
Line 314: Line 324:
table.insert(infobox_data, {
table.insert(infobox_data, {
caption,
caption,
table.concat(S_expressions, ",<br/>"),
table.concat(S_expressions, ",<br>"),
})
})
end
end
Line 323: Line 333:
cats = cats .. "[[Category:Pages with internal sound examples]]"
cats = cats .. "[[Category:Pages with internal sound examples]]"
table.insert(infobox_data, {
table.insert(infobox_data, {
"[[File:" .. sound .. "|270px]]<br/><small>[[:File:" .. sound .. "|[sound info]]]</small>",
"[[File:" .. sound .. "|270px]]<br><span style=\"font-size: 75%;\">[[:File:" .. sound .. "|<nowiki>[sound info]</nowiki>]]</span>",
})
})
elseif debug_mode and debug_mode ~= "hide" and regular then
elseif debug_mode and debug_mode ~= "hide" and regular then
Line 331: Line 341:
local html_id = "interval_" .. tostring(math.floor(cents))
local html_id = "interval_" .. tostring(math.floor(cents))
table.insert(infobox_data, {
table.insert(infobox_data, {
'<div style="display: flex; justify-content: space-around;"><div style="width: 270px; text-align: center;">'
"<div style=\"display: flex; justify-content: space-around;\"><div style=\"width: 270px; text-align: center;\">"
.. frame:expandTemplate({
.. frame:expandTemplate({
title = "User:Plumtree/Interval Sound",
title = "User:Plumtree/Interval Sound",
Line 338: Line 348:
Center = "true",
Center = "true",
Label = "Audio demonstration",
Label = "Audio demonstration",
Attributes = 'id="' .. html_id .. '"',
Attributes = "id=\"" .. html_id .. "\"",
},
},
})
})
.. '<div class="sequence-audio-timbre-selector" data-target="'
.. "<div class=\"sequence-audio-timbre-selector\" data-target=\""
.. html_id
.. html_id
.. '" data-key="interval-audio" data-default="semisine"></div>'
.. "\" data-key=\"interval-audio\" data-default=\"semisine\"></div>"
.. "</div></div>",
.. "</div></div>",
})
})
Line 360: Line 370:
query = mw.uri.encode(query)
query = mw.uri.encode(query)
table.insert(infobox_data, {
table.insert(infobox_data, {
"<small>[https://www.yacavone.net/xen-calc/?q=" .. query .. " open this interval in ''xen-calc'']</small>",
"<span style=\"font-size: 75%;\">[https://www.yacavone.net/xen-calc/?q=" .. query .. " Open this interval in ''xen-calc'']</span>",
})
})
end
end


local s = infobox.build("<u>Interval information</u>", infobox_data)
local result = infobox.build("<u>Interval&nbsp;information</u>", infobox_data)
if not debug_mode then
if not debug_mode then
s = s .. cats
result = result .. cats
end
end
return s
return frame:preprocess(result)
end
end


return p
return p