Module:Interval table: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
CompactStar (talk | contribs)
No edit summary
CompactStar (talk | contribs)
No edit summary
Line 3: Line 3:
local iv = require('Module:Interval')
local iv = require('Module:Interval')
local rat = require('Module:Rational')
local rat = require('Module:Rational')
local ET = require('Module:ET')


function p.interval_table(frame)
function p.interval_table(frame)

Revision as of 08:04, 3 July 2023

Module documentation[view] [edit] [history] [purge]
This module should not be invoked directly; use its corresponding template instead: Template:Interval table.

This module automatically generates a table of intervals for an equal-step tuning, showing which just intervals are approximated relatively accurately.

Introspection summary for Module:Interval table 
Functions provided (1)
Line Function Params
7 interval_table (invokable) (frame)
Lua modules required (4)
Variable Module Functions used
ET Module:ET parse
approximate
cents
iv Module:Interval _to_cents
rat Module:Rational eq
u Module:Utils _round

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


local p = {}
local u = require('Module:Utils')
local iv = require('Module:Interval')
local rat = require('Module:Rational')
local ET = require('Module:ET')

function p.interval_table(frame)
	local tuning = frame.args['tuning']
	local et = ET.parse(tuning) or ET.parse('12edo')
	local wikitext = '{|class="wikitable"|\n'
	local octave = ET.approximate(et, 2)
	local fifth = ET.approximate(et, 3/2)
	local fifth_error = ET.cents(et, fifth) - iv._to_cents(3/2)
	local dual_fifth = math.abs(fifth_error) > (et.size / 3)

	wikitext = wikitext .. '!Steps\n'
	wikitext = wikitet .. '!Cents\n'
	if rat.eq(et.size, 2) then
		if dual_fifth then
			wikitext = wikitext .. '![[Ups and downs notation]] (dual flat fifth ' .. dual_flat_fifth  .. '\\' .. et.size .. ')\n'
			wikitext = wikitext .. '![[Ups and downs notation]] (dual sharp fifth ' .. dual_sharp_fifth .. '\\' .. et.size .. ')\n'
		else
			wikitext = wikitext .. '![[Ups and downs notation]]\n'
		end
	end
	
	for i in 1,et.size do
		wikitext = wikitext .. '|-\n'
		wikitext = wikitext .. '|' .. i .. '\n'
		wikitext = wikitext .. '|' .. u._round(1200 *(i / et.size), 3) .. '\n'
		if rat.eq(et.size, 2) then
			if dual_fifth then
				wikitext = wikitext .. '| {{UDnote|step=' .. i .. '|fifth=' .. dual_flat_fifth .. '}}\n'
				wikitext = wikitext .. '| {{UDnote|step=' .. i .. '|fifth=' .. dual_sharp_fifth .. '}}\n'
			else
				wikitext = wikitext .. '| {{UDnote|step=' .. i .. '}}\n'
			end
		end
	end
	
	wikitext = wikitext .. '|}'

	return wikitext
end

return p