Module:Interval table: Difference between revisions

ArrowHead294 (talk | contribs)
mNo edit summary
ArrowHead294 (talk | contribs)
mNo edit summary
 
(16 intermediate revisions by 3 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")


-- Gets mapping of a monzo in a val
-- Gets mapping of a monzo in a val
Line 62: 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 87: Line 90:
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)
Line 94: Line 97:
local ratios_list = get_ratios_list((20 + (et.size / 4)), 12, 47)
local ratios_list = get_ratios_list((20 + (et.size / 4)), 12, 47)


wtext = t_head ..  
result = t_head ..  
"|-\n" ..
"|-\n" ..
"! Steps\n" ..  
"! Steps\n" ..
"! Cents\n" ..
"! Cents\n"
"! Approximate Ratios\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
wtext = wtext
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"
.. "! [[Ups and downs notation|Ups and Downs Notation]]<br />(Dual Sharp Fifth "
.. dual_sharp_fifth
.. "\\"
.. et.size
.. ")\n"
else
else
wtext = wtext .. "! [[Ups and downs notation|Ups and Downs Notation]]\n"
result = result .. "! [[Ups and downs notation]]\n"
end
end
end
end
Line 119: Line 120:
if #additional_split > 0 then
if #additional_split > 0 then
for i = 1, #additional_split[1] do
for i = 1, #additional_split[1] do
wtext = wtext .. "! " .. 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
wtext = wtext .. "|-\n"
result = result .. "|-\n"
.. "| " .. i .. "\n"
.. string.format("| %s\n", i)
.. "| " .. utils._round_dec(ET.cents(et, i), 3) .. "\n"
.. string.format("| %s\n", utils._round_dec(ET.cents(et, i), decimalPlaces))
.. "| "
if rat.eq(et.equave, 3) then
result = result .. string.format("| %s\n", utils._round_dec(ET.hekts(et, i), decimalPlaces))
end
result = result .. "| "
for j = 1, #ratios_list do
for j = 1, #ratios_list do
-- Go through all ratios.
-- Go through all ratios.
Line 138: Line 148:
< (1200 / (math.log(et.size) * (et.size + 5)))
< (1200 / (math.log(et.size) * (et.size + 5)))
then
then
wtext = wtext .. "[[" .. 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 wtext:sub(-2, -1) == "| " then
if result:sub(-2, -1) == "| " then
wtext = wtext .. "\n"
result = result .. "\n"
else
else
wtext = wtext:sub(0, -3) .. "\n"
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
wtext = wtext .. "| " .. ud_note(et, dual_flat_fifth, i) .. "\n"
result = result .. string.format("| %s\n", ud_note(et, dual_flat_fifth, i))
wtext = wtext .. "| " .. ud_note(et, dual_sharp_fifth, i) .. "\n"
result = result .. string.format("| %s\n", ud_note(et, dual_sharp_fifth, i))
else
else
wtext = wtext .. "| " .. ud_note(et, fifth, i) .. "\n"
result = result .. string.format("| %s\n", ud_note(et, fifth, i))
end
end
end
end
Line 160: Line 170:
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
wtext = wtext .. "| " .. additional_split[i + 2][j] .. "\n"
result = result .. string.format("| %s\n", additional_split[i + 2][j])
end
end
end
end
end
end


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


return p
return p