Module:Ups and downs notation: Difference between revisions

CompactStar (talk | contribs)
No edit summary
CompactStar (talk | contribs)
No edit summary
Line 22: Line 22:
--  12 = {"C"}
--  12 = {"C"}
-- }
-- }
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


function p.get_note_names(tuning)
function p.get_note_names(tuning)
Line 34: Line 45:
local chroma = (fifth * 7) % et.size
local chroma = (fifth * 7) % et.size
local major_note_idx = {
0,
(fifth * 2) % tuning.size,
(fifth * 4) % tuning.size,
fourth,
fifth,
(fifth * 3) % tuning.size,
(fifth * 5) % tuning.size,
tuning.size
}
-- Add major scale notes
-- Add major scale notes
table.insert(note_names[0], "C")
table.insert(note_names[major_note_idx[1]], "C")
table.insert(note_names[(fifth * 2) % tuning.size], "D")
table.insert(note_names[major_note_idx[2]], "D")
table.insert(note_names[(fifth * 4) % tuning.size], "E")
table.insert(note_names[major_note_idx[3]], "E")
table.insert(note_names[fourth], "F")
table.insert(note_names[major_note_idx[4]], "F")
table.insert(note_names[fifth], "G")
table.insert(note_names[major_note_idx[5]], "G")
table.insert(note_names[(fifth * 3) % tuning.size], "A")
table.insert(note_names[major_note_idx[6]], "A")
     table.insert(note_names[(fifth * 5) % tuning.size], "B")
     table.insert(note_names[major_note_idx[7]], "B")
     table.insert(note_names[et.size], "C")
     table.insert(note_names[major_note_idx[8]], "C")
i = 0
i = 0
local last_major_note = 0
local last_major_note = 0
while i < tuning.size do
while i < tuning.size do
if #(note_names[i]) == 0 then
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_sharps = math.floor((i - last_major_note) / chroma)
local num_ups = (i - last_major_note) % chroma
local num_ups = (i - last_major_note) % chroma
Line 59: Line 82:
name = "^" + name
name = "^" + name
end
end
table.insert(note_names[i], note_names[last_note])
table.insert(note_names[i], name)
else
last_major_note = i
end
end
i = i + 1
i = i + 1
end
end
return note_names