local ET = require("Module:ET")
local u = require("Module:Utils")
local p = {}
local function table_contains(tbl, x)
found = false
for _, v in pairs(tbl) do
if v == x then
found = true
end
end
return found
end
-- Returns a table of note names
-- e.g. for 12edo, intended result would be something like:
-- {
-- 0 = "C",
-- 1 = "Db",
-- 2 = "D",
-- 3 = "Eb",
-- 4 = "E",
-- 5 = "F",
-- 6 = "Gb",
-- 7 = "G",
-- 8 = "Ab",
-- 9 = "A",
-- 10 = "Bb",
-- 11 = "B",
-- 12 = "C",
-- }
function p.get_note_names_table(et)
local note_names = {}
return note_names
-- local i = 0
-- while i < et.size do
-- note_names[i] = ""
-- end
-- local fifth = u.round(math.log(3/2)/math.log(2) * et.size)
-- local fourth = u.round(math.log(4/3)/math.log(2) * et.size)
-- local chroma = (fifth * 7) % et.size
-- local major_note_idx = {
-- 0,
-- (fifth * 2) % et.size,
-- (fifth * 4) % et.size,
-- fourth,
-- fifth,
-- (fifth * 3) % et.size,
-- (fifth * 5) % et.size,
-- tuning.size
-- }
-- -- Add major scale notes
-- note_names[major_note_idx[1]] = "C"
-- note_names[major_note_idx[2]] = "D"
-- note_names[major_note_idx[3]] = "E"
-- note_names[major_note_idx[4]] = "F"
-- note_names[major_note_idx[5]] = "G"
-- note_names[major_note_idx[6]] = "A"
-- note_names[major_note_idx[7]] = "B"
-- note_names[major_note_idx[8]] = "C"
-- -- Add sharp/up notes
-- i = 0
-- local last_major_note = 0
-- while i < et.size do
-- if table_contains(major_note_idx, i) then
-- last_major_note = i
-- else
-- local num_sharps = math.floor((i - last_major_note) / chroma)
-- local num_ups = (i - last_major_note) % chroma
-- local name = interval_names[last_major_note]
-- local j = 0
-- while j < num_sharps do
-- name = name + "#"
-- end
-- j = 0
-- while j < num_ups do
-- name = "^" + name
-- end
-- note_names[i] = name
-- end
-- i = i + 1
-- end
-- -- Add flat/down notes
-- i = et.size - 1
-- local last_major_note = tuning.size - 1
-- while i >= 0 do
-- if table_contains(major_note_idx, i) then
-- last_major_note = i
-- else
-- local num_flats = math.floor((last_major_note - i) / chroma)
-- local num_downs = (last_major_note - i) % chroma
-- local name = interval_names[last_major_note]
-- local j = 0
-- while j < num_flats do
-- name = name + "b"
-- end
-- j = 0
-- while j < num_downs do
-- name = "v" + name
-- end
-- note_names[i] = note_names[i] + ", " + name
-- end
-- i = i - 1
-- end
-- return note_names
end
function p.ups_and_downs_note_name(frame)
local et = ET.parse(frame.args['tuning']) or ET.parse('12edo')
local step = tonumber(frame.args['step'])
return p.get_note_names_table(et)[step]
end
return p