Module:Interval table: Difference between revisions

This get_"monzo" is no different from rat.new
ArrowHead294 (talk | contribs)
mNo edit summary
 
(67 intermediate revisions by 4 users not shown)
Line 1: Line 1:
local p = {}
local p = {}
local utils = require("Module:Utils")
 
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 ET = require("Module:ET")
local utils = require("Module:Utils")
 
local yesno = require("Module:Yesno")
local PRIME_LIST = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
  101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
  211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271}


-- Gets mapping of a monzo in a val
-- Gets mapping of a monzo in a val
local function mapping(monzo, val)
local function mapping(monzo, val)
local result = 0
local result = 0
Line 40: Line 38:
end
end


-- Utility fuunction to get specific note name with ud.get_note_names_table
-- Utility function to get specific note name with ud.get_note_names_table
-- (this is essentially what "Template:Ups and downs note name" does)
-- (this is essentially what "Template:Ups and downs note name" does)
local function ud_note(et, fifth, step)
local function ud_note(et, fifth, step)
Line 66: Line 64:
local tuning = frame.args["tuning"]
local tuning = frame.args["tuning"]
local et = ET.parse(tuning) or ET.parse("12edo")
local et = ET.parse(tuning) or ET.parse("12edo")
local debugg = yesno(frame.args["debug"])
local patent_val = {
local patent_val = {
[2] = ET.approximate(et, 2),
[2] = ET.approximate(et, 2),
Line 84: Line 83:
} -- NOTE: indices are prime numbers
} -- NOTE: indices are prime numbers


local t_head = '{| class="wikitable center-1 right-2"\n'
local t_head = "{| class=\"wikitable center-1 right-2"
if et.size > 72 then
if et.size > 20 then
t_head = '{| class="wikitable center-1 right-2 mw-collapsible mw-collapsed"\n'
t_head = t_head .. " mw-collapsible mw-collapsed"
end
end
t_head = t_head .. "\"\n"
local fifth = patent_val[3] - patent_val[2]
local fifth = patent_val[3] - patent_val[2]
local fifth_error = ET.cents(et, fifth) - rat.cents(rat.new(3, 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_fifth = (math.abs(fifth_error) > (400 / et.size))
local dual_flat_fifth = ET.approximate(et, 3 / 2, -1)
local dual_flat_fifth = ET.approximate(et, 3 / 2, -1)
local dual_sharp_fifth = ET.approximate(et, 3 / 2, 1)
local dual_sharp_fifth = ET.approximate(et, 3 / 2, 1)


-- List of all 13-limit ratios with numerator and denominator <= 81 and in the range 1/1 - 5/1
-- List of all 47-limit ratios with numerator and denominator <= certain cents value and in the range 1/1 - 12/1
local ratios_list = get_ratios_list(81, 5, 13)
local ratios_list = get_ratios_list((20 + (et.size / 4)), 12, 47)


wikitext = t_head ..  
result = t_head ..  
"! Steps\n"..  
"|-\n" ..
"! Cents\n"
"! Steps\n" ..
"! Cents\n"
if rat.eq(et.equave, 3) then
result = result .. "! [[Hekt]]s\n"
end
result = result ..
"! Approximate ratios\n"
if rat.eq(et.equave, 2) then
if rat.eq(et.equave, 2) then
if dual_fifth then
if dual_fifth then
wikitext = wikitext
result = result
.. "! [[Ups and downs notation|Ups and Downs Notation]]<br>(Dual Flat Fifth "
.. string.format("! [[Ups and downs notation]]<br />(Dual flat fifth %s\\%s)\n", dual_flat_fifth, et.size)
.. dual_flat_fifth
.. string.format("! [[Ups and downs notation]]<br />(Dual sharp fifth %s\\%s)\n", dual_sharp_fifth, et.size)
.. "\\"
.. et.size
.. ")\n"
wikitext = wikitext
.. "! [[Ups and downs notation|Ups and Downs Notation]]<br>(Dual Sharp Fifth "
.. dual_sharp_fifth
.. "\\"
.. et.size
.. ")\n"
else
else
wikitext = wikitext .. "! [[Ups and downs notation|Ups and Downs Notation]]\n"
result = result .. "! [[Ups and downs notation]]\n"
end
end
end
end
 
wikitext = wikitext .. "! Approximate Ratios\n"
 
if #additional_split > 0 then
if #additional_split > 0 then
for i = 1, #additional_split[1] do
for i = 1, #additional_split[1] do
wikitext = wikitext .. " ! " .. additional_split[1][i] .. "\n"
result = result .. string.format("! %s\n", additional_split[1][i])
end
end
end
end


    local decimalPlaces = 3 - math.floor(math.log(1200 / et.size, 10))
    if decimalPlaces > 3 then decimalPlaces = 3 end
    if decimalPlaces < 1 then decimalPlaces = 1 end
for i = 0, et.size do
for i = 0, et.size do
wikitext = wikitext .. "|-\n"
result = result .. "|-\n"
wikitext = wikitext .. "|" .. i .. "\n"
.. string.format("| %s\n", i)
wikitext = wikitext .. "|" .. utils._round(ET.cents(et, i), 6) .. "\n"
.. string.format("| %s\n", utils._round_dec(ET.cents(et, i), decimalPlaces))
if rat.eq(et.equave, 2) then
if dual_fifth then
if rat.eq(et.equave, 3) then
wikitext = wikitext .. "|" .. ud_note(et, dual_flat_fifth, i) .. "\n"
result = result .. string.format("| %s\n", utils._round_dec(ET.hekts(et, i), decimalPlaces))
wikitext = wikitext .. "|" .. ud_note(et, dual_sharp_fifth, i) .. "\n"
else
wikitext = wikitext .. "|" .. ud_note(et, fifth, i) .. "\n"
end
end
end
wikitext = wikitext .. "|"
result = result .. "| "
for j = 1, #ratios_list do
for j = 1, #ratios_list do
-- Go through all ratios.
-- Go through all ratios.
-- If they are mapped to the current step in the ET's patent val and <2/5 edo step error,
-- If they are mapped to the current step in the ET's patent val and < specified edostep error,
-- add to approximate ratios column.
-- add to approximate ratios column.
local t = mapping(rat.new(ratios_list[j][1], ratios_list[j][2]), patent_val)
local t = mapping(rat.new(ratios_list[j][1], ratios_list[j][2]), patent_val)
Line 148: Line 146:
t == i
t == i
and math.abs(ET.cents(et, i) - utils._log(ratios_list[j][1] / ratios_list[j][2], 2) * 1200)
and math.abs(ET.cents(et, i) - utils._log(ratios_list[j][1] / ratios_list[j][2], 2) * 1200)
< (1200 / (2.5 * et.size))
< (1200 / (math.log(et.size) * (et.size + 5)))
then
then
wikitext = wikitext .. "[[" .. ratios_list[j][1] .. "/" .. ratios_list[j][2] .. "]], "
result = result .. string.format("[[%s/%s]], ", ratios_list[j][1], ratios_list[j][2])
end
end
end
end
if wikitext:sub(-1, -1) == "|" then
wikitext = wikitext .. "\n"
-- ???
if result:sub(-2, -1) == "| " then
result = result .. "\n"
else
else
wikitext = wikitext:sub(0, -3) .. "\n"
result = result:sub(0, -3) .. "\n"
end
if rat.eq(et.equave, 2) then
if dual_fifth then
result = result .. string.format("| %s\n", ud_note(et, dual_flat_fifth, i))
result = result .. string.format("| %s\n", ud_note(et, dual_sharp_fifth, i))
else
result = result .. string.format("| %s\n", ud_note(et, fifth, i))
end
end
end
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
wikitext = wikitext .. "|" .. additional_split[i + 2][j] .. "\n"
result = result .. string.format("| %s\n", additional_split[i + 2][j])
end
end
end
end
end
end


wikitext = wikitext .. "|}"
result = result .. "|}"
 
return wikitext
if debugg == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
end


return p
return p