Module:Ups and downs notation

From Xenharmonic Wiki
Revision as of 23:00, 7 June 2023 by CompactStar (talk | contribs) (Created page with "local et = require('Module:ET') local rat = require('Module:Rational') local p = {} -- Returns a nested table of note names -- e.g. for 12edo, intended result would be someth...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Module documentation[view] [edit] [history] [purge]
This module should not be invoked directly; use its corresponding template instead: Template:Ups and downs note name.

This module gets the note name of an edo interval in ups and downs notation.

Introspection summary for Module:Ups and downs notation 
Functions provided (1)
Line Function Params
23 get_note_names (et)
Lua modules required (2)
Variable Module Functions used
et Module:ET dependency not used
rat Module:Rational new

No function descriptions were provided. The Lua code may have further information.


local et = require('Module:ET')
local rat = require('Module:Rational')
local p = {}

-- Returns a nested table of note names
-- e.g. for 12edo, intended result would be something like:
-- {
--	0 = {"C"},
--	1 = {"Db"},
--	2 = {"D"},
--	3 = {"Eb"},
--	4 = {"E"},
--	5 = {"F"},
--	6 = {"F#", "Gb"},
--	7 = {"G"},
--  8 = {"Ab"},
--  9 = {"A"},
--  10 = {"Bb"},
--  11 = {"B"},
--  12 = {"C"}
-- }

function p.get_note_names(et)
	local note_names = {}
	local i = 0
	local last_note = 0
	while i < et.size do
		note_names[i] = {}
	end
	
	local fifth = ET.approximate(et, rat.new(3, 2))
	local fourth = ET.approximate(et, rat.new(4, 3))
	local chroma = (fifth * 7) % et.size
	table.insert(interval_names[0], "C")
	table.insert(interval_names[(fourth * 5) % et.size], "Db")
	interval_names[(fifth * 2) % et.size] = {"D"}
	interval_names[(fourth * 3) % et.size] = {"m3"}
	interval_names[(fifth * 4) % et.size] = {"M3"}
	interval_names[fourth] = {"P4"}
	interval_names[fifth] = {"P5"}
	interval_names[(fourth * 4) % et.size] = {"m6"}
	interval_names[(fifth * 3) % et.size] = {"M6"}
	interval_names[(fourth * 2) % et.size] = {"m7"}
    interval_names[(fifth * 5) % et.size] = {"M7"}
	interval_names[et.size] = {"P8"}
	
	i = 0
	local last_note = 0
	while i < et.size do
		if note_names[i] == nil then
			local num_sharps = math.floor((i - last_note) / chroma)
			local num_ups = (i - last_note) % chroma
			local name = interval_names[last_note]
			local j = 0
			while j < num_sharps do
				name = name + "#"
			end
			j = 0
			while j < num_ups do
				name = "^" + name
			end
			note_names[i] = {note_names[last_note]}
			
		else
			last_note = i
		end
		i = i + 1
	end
end

return p