Module:Ups and downs notation: Difference between revisions
CompactStar (talk | contribs) No edit summary |
CompactStar (talk | contribs) No edit summary |
||
| Line 1: | Line 1: | ||
-- WIP | -- WIP | ||
local | local ET = require("Module:ET") | ||
local u = require( | local u = require("Module:Utils") | ||
local p = {} | local p = {} | ||
| Line 35: | Line 35: | ||
function p.get_note_names(tuning) | function p.get_note_names(tuning) | ||
local et = ET.parse("12edo") | |||
local note_names = {} | local note_names = {} | ||
local i = 0 | local i = 0 | ||
| Line 44: | Line 44: | ||
local fifth = u.round(math.log(3/2)/math.log(2) * tuning.size) | local fifth = u.round(math.log(3/2)/math.log(2) * tuning.size) | ||
local fourth = u.round(math.log(4/3)/math.log(2) * tuning.size) | local fourth = u.round(math.log(4/3)/math.log(2) * tuning.size) | ||
local chroma = (fifth * 7) % | local chroma = (fifth * 7) % ET.size | ||
local major_note_idx = { | local major_note_idx = { | ||
0, | 0, | ||
(fifth * 2) % | (fifth * 2) % et.size, | ||
(fifth * 4) % | (fifth * 4) % et.size, | ||
fourth, | fourth, | ||
fifth, | fifth, | ||
(fifth * 3) % | (fifth * 3) % et.size, | ||
(fifth * 5) % | (fifth * 5) % et.size, | ||
tuning.size | tuning.size | ||
} | } | ||
| Line 73: | Line 73: | ||
i = 0 | i = 0 | ||
local last_major_note = 0 | local last_major_note = 0 | ||
while i < | 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 94: | Line 94: | ||
-- Add flat/down notes | -- Add flat/down notes | ||
i = | i = et.size - 1 | ||
local last_major_note = tuning.size - 1 | local last_major_note = tuning.size - 1 | ||
while i >= 0 do | while i >= 0 do | ||
| Line 101: | Line 101: | ||
else | 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 | ||
local name = interval_names[last_major_note] | local name = interval_names[last_major_note] | ||
local j = 0 | local j = 0 | ||