Module:Ups and downs notation: Difference between revisions
CompactStar (talk | contribs) No edit summary |
cleanup |
||
| Line 1: | Line 1: | ||
local ET = require("Module:ET") | local ET = require("Module:ET") | ||
local | local utils = require("Module:Utils") | ||
local p = {} | local p = {} | ||
| Line 23: | Line 23: | ||
function p.get_note_names_table(et, fifth) | function p.get_note_names_table(et, fifth) | ||
local note_names = {} | local note_names = {} | ||
for i = 0,et.size do | for i = 0, et.size do | ||
note_names[i] = {} | note_names[i] = {} | ||
end | end | ||
fifth = fifth or math.floor(math.log(3/2)/math.log(2) * et.size + 0.5) | fifth = fifth or math.floor(math.log(3 / 2) / math.log(2) * et.size + 0.5) | ||
local fourth = et.size - fifth -- 4/3 = [2 -1> | local fourth = et.size - fifth -- 4/3 = [2 -1> | ||
local chroma = (fifth * 7) % et.size -- 2187/2048 = [-11 7> | local chroma = (fifth * 7) % et.size -- 2187/2048 = [-11 7> | ||
local is_mavila = fifth/et.size < 4/7 | local is_mavila = fifth / et.size < 4 / 7 | ||
if is_mavila then | if is_mavila then | ||
chroma = et.size - chroma | chroma = et.size - chroma | ||
end | end | ||
local diatonic_note_idx = { | local diatonic_note_idx = { | ||
0, | 0, | ||
(fifth * 2) % et.size, | (fifth * 2) % et.size, | ||
(fifth * -3) % et.size, | (fifth * -3) % et.size, | ||
| Line 45: | Line 43: | ||
(fifth * 3) % et.size, | (fifth * 3) % et.size, | ||
(fifth * -2) % et.size, | (fifth * -2) % et.size, | ||
et.size | et.size, | ||
} | } | ||
| Line 59: | Line 57: | ||
local last_diatonic_note = 0 | local last_diatonic_note = 0 | ||
-- Add sharp/up notes | -- Add sharp/up notes | ||
for i = 0, et.size - 1 do | for i = 0, et.size - 1 do | ||
if | if utils.table_contains(diatonic_note_idx, i) then | ||
last_diatonic_note = i | last_diatonic_note = i | ||
else | else | ||
| Line 74: | Line 72: | ||
end | end | ||
local last_diatonic_names = note_names[last_diatonic_note] | local last_diatonic_names = note_names[last_diatonic_note] | ||
for j = 1, | for j = 1, #last_diatonic_names do | ||
if num_ups >= 3 then | if num_ups >= 3 then | ||
table.insert(note_names[i], "^<sup>" .. num_ups .. "</sup>" .. last_diatonic_names[j] .. string.rep("#", num_sharps) | table.insert( | ||
note_names[i], | |||
"^<sup>" | |||
.. num_ups | |||
.. "</sup>" | |||
.. last_diatonic_names[j] | |||
.. string.rep("#", num_sharps) | |||
.. string.rep("x", num_double_sharps) | |||
) | |||
else | else | ||
table.insert(note_names[i], string.rep("^", num_ups) .. last_diatonic_names[j] .. string.rep("#", num_sharps) .. string.rep("x", num_double_sharps)) | table.insert( | ||
note_names[i], | |||
string.rep("^", num_ups) | |||
.. last_diatonic_names[j] | |||
.. string.rep("#", num_sharps) | |||
.. string.rep("x", num_double_sharps) | |||
) | |||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
last_diatonic_note = et.size | last_diatonic_note = et.size | ||
-- Add flat/down notes | -- Add flat/down notes | ||
for i = et.size - 1, 0, -1 do | for i = et.size - 1, 0, -1 do | ||
if | if utils.table_contains(diatonic_note_idx, i) then | ||
last_diatonic_note = i | last_diatonic_note = i | ||
else | else | ||
| Line 97: | Line 109: | ||
num_downs = (last_diatonic_note - i) | num_downs = (last_diatonic_note - i) | ||
end | end | ||
last_diatonic_names = note_names[last_diatonic_note] | local last_diatonic_names = note_names[last_diatonic_note] | ||
for j = 1, | for j = 1, #last_diatonic_names do | ||
if num_downs >= 3 then | if num_downs >= 3 then | ||
table.insert(note_names[i], "v<sup>" .. num_downs .. "</sup>" .. last_diatonic_names[j] .. string.rep("b", num_flats)) | table.insert( | ||
note_names[i], | |||
"v<sup>" .. num_downs .. "</sup>" .. last_diatonic_names[j] .. string.rep("b", num_flats) | |||
) | |||
else | else | ||
table.insert(note_names[i], string.rep("v", num_downs) .. last_diatonic_names[j] .. string.rep("b", num_flats)) | table.insert( | ||
note_names[i], | |||
string.rep("v", num_downs) .. last_diatonic_names[j] .. string.rep("b", num_flats) | |||
) | |||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
return note_names | return note_names | ||
end | end | ||