Module:Collapsed huge table: Difference between revisions
Jump to navigation
Jump to search
Created page with "local p = {} local utils = require("Module:Utils") local rat = require("Module:Rational") local ud = require("Module:Ups and downs notation") local ET = require("Module:ET")..." Tags: Mobile edit Mobile web edit Advanced mobile edit |
m Oops |
||
| (4 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local | |||
local ET = require("Module:ET") | |||
local rat = require("Module:Rational") | local rat = require("Module:Rational") | ||
local ud = require("Module:Ups and downs notation") | local ud = require("Module:Ups and downs notation") | ||
local | local utils = require("Module:Utils") | ||
local yesno = require("Module:Yesno") | |||
-- Gets mapping of a monzo in a val | -- Gets mapping of a monzo in a val | ||
| Line 81: | Line 83: | ||
[47] = ET.approximate(et, 47), | [47] = ET.approximate(et, 47), | ||
} -- NOTE: indices are prime numbers | } -- NOTE: indices are prime numbers | ||
local debugg = yesno(frame.args["debug"]) | |||
local t_head = "{| class=\"wikitable center-1 right-2\"\n" | local t_head = "{| class=\"wikitable center-1 right-2\"\n" | ||
if et.size > | if et.size > 1 then | ||
t_head = "{| class=\"wikitable center-1 right-2 mw-collapsible mw-collapsed\"\n" | t_head = "{| class=\"wikitable center-1 right-2 mw-collapsible mw-collapsed\"\n" | ||
end | end | ||
| Line 93: | Line 96: | ||
-- List of all 23-limit ratios with numerator and denominator <= certain cents value and in the range 1/1 - 2/1 | -- List of all 23-limit ratios with numerator and denominator <= certain cents value and in the range 1/1 - 2/1 | ||
local ratios_list = get_ratios_list(54,2,23) | local ratios_list = get_ratios_list(54, 2, 23) | ||
result = t_head .. | |||
"|-\n" .. | |||
"! Steps\n" .. | "! Steps\n" .. | ||
"! Cents\n" .. | "! Cents\n" .. | ||
| Line 101: | Line 105: | ||
if rat.eq(et.equave, 2) then | if rat.eq(et.equave, 2) then | ||
if dual_fifth then | if dual_fifth then | ||
result = result | |||
.. "! [[Ups and downs notation|Ups and Downs Notation]]<br>(Dual Flat Fifth " | .. "! [[Ups and downs notation|Ups and Downs Notation]]<br>(Dual Flat Fifth " | ||
.. dual_flat_fifth | .. dual_flat_fifth | ||
| Line 107: | Line 111: | ||
.. et.size | .. et.size | ||
.. ")\n" | .. ")\n" | ||
result = result | |||
.. "! [[Ups and downs notation|Ups and Downs Notation]]<br>(Dual Sharp Fifth " | .. "! [[Ups and downs notation|Ups and Downs Notation]]<br>(Dual Sharp Fifth " | ||
.. dual_sharp_fifth | .. dual_sharp_fifth | ||
| Line 114: | Line 118: | ||
.. ")\n" | .. ")\n" | ||
else | else | ||
result = result .. "! [[Ups and downs notation|Ups and Downs Notation]]\n" | |||
end | end | ||
end | end | ||
| Line 120: | Line 124: | ||
if #additional_split > 0 then | if #additional_split > 0 then | ||
for i = 1, #additional_split[1] do | for i = 1, #additional_split[1] do | ||
result = result .. "! " .. additional_split[1][i] .. "\n" | |||
end | end | ||
end | end | ||
for i = 0, et.size do | for i = 0, et.size do | ||
result = result .. "|-\n" | |||
result = result .. "| " .. i .. "\n" | |||
result = result .. "| " .. utils._round_dec(ET.cents(et, i), 3) .. "\n" | |||
result = result .. "| " | |||
for j = 1, #ratios_list do | for j = 1, #ratios_list do | ||
-- Go through all ratios. | -- Go through all ratios. | ||
| Line 139: | Line 143: | ||
< (1200 / et.size) | < (1200 / et.size) | ||
then | then | ||
result = result .. "[[" .. ratios_list[j][1] .. "/" .. ratios_list[j][2] .. "]], " | |||
end | end | ||
end | end | ||
-- ??? | -- ??? | ||
if | if result:sub(-2, -1) == "| " then | ||
result = result .. "\n" | |||
else | else | ||
result = result:sub(0, -3) .. "\n" | |||
end | end | ||
if rat.eq(et.equave, 2) then | if rat.eq(et.equave, 2) then | ||
if dual_fifth then | if dual_fifth then | ||
result = result .. "| " .. ud_note(et, dual_flat_fifth, i) .. "\n" | |||
result = result .. "| " .. ud_note(et, dual_sharp_fifth, i) .. "\n" | |||
else | else | ||
result = result .. "| " .. ud_note(et, fifth, i) .. "\n" | |||
end | end | ||
end | end | ||
| Line 161: | Line 165: | ||
if (i + 2) <= #additional_split then | if (i + 2) <= #additional_split then | ||
for j = 1, #additional_split[i + 2] do | for j = 1, #additional_split[i + 2] do | ||
result = result .. "| " .. additional_split[i + 2][j] .. "\n" | |||
end | end | ||
end | end | ||
end | end | ||
result = result .. "|}" | |||
return | if debugg == true then | ||
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" | |||
end | |||
return frame:preprocess(result) | |||
end | end | ||
return p | return p | ||
Latest revision as of 05:59, 28 December 2025
- This module should not be invoked directly; use its corresponding template instead: Template:Collapsed huge table.
| Introspection summary for Module:Collapsed huge table | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| ||||||||||||||||||||||||
No function descriptions were provided. The Lua code may have further information.
| Todo: clarify
Explain how exactly this is different from Module: Interval table. |
local p = {}
local ET = require("Module:ET")
local rat = require("Module:Rational")
local ud = require("Module:Ups and downs notation")
local utils = require("Module:Utils")
local yesno = require("Module:Yesno")
-- Gets mapping of a monzo in a val
local function mapping(monzo, val)
local result = 0
for k, _ in pairs(val) do
result = result + val[k] * (monzo[k] or 0)
end
return result
end
-- Generates list of ratios up to a max numerator & denominator, max ratio size, and prime limit
local function get_ratios_list(max_nd, max_size, prime_limit)
local ratios = {}
local ratio_set = {}
for i = 1, max_nd do
for j = 1, max_nd do
local gcd = utils._gcd(i, j)
local reduced_i = i / gcd
local reduced_j = j / gcd
local ratio = reduced_i .. "/" .. reduced_j
if (i / j) >= 1 and (i / j) <= max_size and
rat.max_prime(rat.new(i, j)) <= prime_limit and
not ratio_set[ratio] then
ratio_set[ratio] = true
table.insert(ratios, { reduced_i, reduced_j })
end
end
end
return ratios
end
-- Utility function to get specific note name with ud.get_note_names_table
-- (this is essentially what "Template:Ups and downs note name" does)
local function ud_note(et, fifth, step)
return table.concat(ud.get_note_names_table(et, fifth)[step], ", "):sub(0, -1)
end
-- ???
local function mysplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
table.insert(t, str)
end
return t
end
function p.collapsed_huge_table(frame)
local additional = frame.args["additional"] or ""
local additional_split = mysplit(additional, "\n")
for i = 1, #additional_split do
additional_split[i] = mysplit(additional_split[i], ";")
end
local tuning = frame.args["tuning"]
local et = ET.parse(tuning) or ET.parse("12edo")
local patent_val = {
[2] = ET.approximate(et, 2),
[3] = ET.approximate(et, 3),
[5] = ET.approximate(et, 5),
[7] = ET.approximate(et, 7),
[11] = ET.approximate(et, 11),
[13] = ET.approximate(et, 13),
[17] = ET.approximate(et, 17),
[19] = ET.approximate(et, 19),
[23] = ET.approximate(et, 23),
[29] = ET.approximate(et, 29),
[31] = ET.approximate(et, 31),
[37] = ET.approximate(et, 37),
[41] = ET.approximate(et, 41),
[43] = ET.approximate(et, 43),
[47] = ET.approximate(et, 47),
} -- NOTE: indices are prime numbers
local debugg = yesno(frame.args["debug"])
local t_head = "{| class=\"wikitable center-1 right-2\"\n"
if et.size > 1 then
t_head = "{| class=\"wikitable center-1 right-2 mw-collapsible mw-collapsed\"\n"
end
local fifth = patent_val[3] - patent_val[2]
local fifth_error = ET.cents(et, fifth) - rat.cents(rat.new(3, 2))
local dual_fifth = math.abs(fifth_error) > (400 / et.size)
local dual_flat_fifth = ET.approximate(et, 3 / 2, -1)
local dual_sharp_fifth = ET.approximate(et, 3 / 2, 1)
-- List of all 23-limit ratios with numerator and denominator <= certain cents value and in the range 1/1 - 2/1
local ratios_list = get_ratios_list(54, 2, 23)
result = t_head ..
"|-\n" ..
"! Steps\n" ..
"! Cents\n" ..
"! Approximate Ratios\n"
if rat.eq(et.equave, 2) then
if dual_fifth then
result = result
.. "! [[Ups and downs notation|Ups and Downs Notation]]<br>(Dual Flat Fifth "
.. dual_flat_fifth
.. "\\"
.. et.size
.. ")\n"
result = result
.. "! [[Ups and downs notation|Ups and Downs Notation]]<br>(Dual Sharp Fifth "
.. dual_sharp_fifth
.. "\\"
.. et.size
.. ")\n"
else
result = result .. "! [[Ups and downs notation|Ups and Downs Notation]]\n"
end
end
if #additional_split > 0 then
for i = 1, #additional_split[1] do
result = result .. "! " .. additional_split[1][i] .. "\n"
end
end
for i = 0, et.size do
result = result .. "|-\n"
result = result .. "| " .. i .. "\n"
result = result .. "| " .. utils._round_dec(ET.cents(et, i), 3) .. "\n"
result = result .. "| "
for j = 1, #ratios_list do
-- Go through all ratios.
-- If they are mapped to the current step in the ET's patent val and < specified edostep error,
-- add to approximate ratios column.
local t = mapping(rat.new(ratios_list[j][1], ratios_list[j][2]), patent_val)
if
t == i
and math.abs(ET.cents(et, i) - utils._log(ratios_list[j][1] / ratios_list[j][2], 2) * 1200)
< (1200 / et.size)
then
result = result .. "[[" .. ratios_list[j][1] .. "/" .. ratios_list[j][2] .. "]], "
end
end
-- ???
if result:sub(-2, -1) == "| " then
result = result .. "\n"
else
result = result:sub(0, -3) .. "\n"
end
if rat.eq(et.equave, 2) then
if dual_fifth then
result = result .. "| " .. ud_note(et, dual_flat_fifth, i) .. "\n"
result = result .. "| " .. ud_note(et, dual_sharp_fifth, i) .. "\n"
else
result = result .. "| " .. ud_note(et, fifth, i) .. "\n"
end
end
if (i + 2) <= #additional_split then
for j = 1, #additional_split[i + 2] do
result = result .. "| " .. additional_split[i + 2][j] .. "\n"
end
end
end
result = result .. "|}"
if debugg == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
return p