Module:Ups and downs notation: Difference between revisions

TallKite (talk | contribs)
Undo revision 172565 by TallKite (talk)
Tag: Undo
TallKite (talk | contribs)
debugging...
Line 20: Line 20:
--  [12] = {"D"}
--  [12] = {"D"}
-- }
-- }
function round(x)
  return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5)
end


function p.get_note_names_table(et, fifth)
function p.get_note_names_table(et, fifth)
Line 103: Line 107:
last_diatonic_note = i
last_diatonic_note = i
else
else
local num_flats = math.floor((last_diatonic_note - i) / chroma)
local num_flats = round((last_diatonic_note - i) / chroma)
local num_downs = (last_diatonic_note - i) % chroma
local num_downs = (last_diatonic_note - i) % chroma
local num_ups = 0
if chroma == 0 then
if chroma == 0 then
num_flats = 0
num_flats = 0
num_downs = (last_diatonic_note - i)
num_downs = (last_diatonic_note - i)
end
if num_downs > chroma / 2 then
num_ups = chroma - num_downs
num_downs = 0
end
end
local last_diatonic_names = note_names[last_diatonic_note]
local last_diatonic_names = note_names[last_diatonic_note]
for j = 1, #last_diatonic_names do
for j = 1, #last_diatonic_names do
if num_ups >= 3 then
table.insert(
note_names[i],
"^<sup>" .. num_ups .. "</sup>" .. last_diatonic_names[j] .. string.rep("♭", num_flats)
)
end
if num_ups > 0 then
table.insert(
note_names[i],
string.rep("^", num_ups) .. last_diatonic_names[j] .. string.rep("♭", num_flats)
)
end
if num_downs >= 3 then
if num_downs >= 3 then
table.insert(
table.insert(