Module:Ups and downs notation: Difference between revisions

CompactStar (talk | contribs)
No edit summary
CompactStar (talk | contribs)
No edit summary
Line 35: Line 35:
function p.get_note_names_table(et)
function p.get_note_names_table(et)
local note_names = {}
local note_names = {}
local i = 0
for i = 0,et.size-1 do
while i <= et.size do
note_names[i] = {}
note_names[i] = {}
i = i + 1
i = i + 1
Line 67: Line 66:


-- Add sharp/up notes
-- Add sharp/up notes
i = 0
local last_major_note = nil
local last_major_note = 0
for i = 0,et.size-1 do
while i < et.size do
if table_contains(major_note_idx, i) then
if table_contains(major_note_idx, i) then
last_major_note = i
last_major_note = i
Line 80: Line 78:
end
end
local names = note_names[last_major_note]
local names = note_names[last_major_note]
local j = 1
for name in names do
while j <= #names do
name = string.rep("^", num_ups) .. name .. string.rep("#", num_sharps)
names[j] = string.rep("^", num_ups) .. names[j] .. string.rep("#", num_sharps)
j = j + 1
end
end
note_names[i] = name
note_names[i] = name
end
end
i = i + 1
end
end


-- Add flat/down notes
-- Add flat/down notes
i = et.size - 1
for i = et.size-1,0,-1 do
local last_major_note = et.size - 1
while i >= 0 do
if table_contains(major_note_idx, i) then
if table_contains(major_note_idx, i) then
last_major_note = i
last_major_note = i
else
local num_flats = math.floor((last_major_note - i) / chroma)
local num_flats = math.floor((last_major_note - i) / chroma)
local num_downs = (last_major_note - i) % chroma
local num_downs = (last_major_note - i) % chroma
if chroma == 0 then
if chroma == 0 then
num_flats = 0
num_flats = 0
num_downs = (last_major_note - i)
num_downs = (last_major_note - i)
end
end
for name in note_names[last_major_note] do
local name = note_names[last_major_note]
name = string.rep("v", num_downs) .. name .. string.rep("b", num_flats)
local j = 0
table.insert(note_names[i], name)
while j < num_flats do
name = name .. "b"
j = j + 1
end
end
j = 0
while j < num_downs do
name = "v" .. name
j = j + 1
end
note_names[i] = note_names[i] .. ", " .. name
end
end
i = i - 1
end
end
return note_names
return note_names