Module:Infobox ET

From Xenharmonic Wiki
Revision as of 18:23, 1 October 2022 by Plumtree (talk | contribs) (Fifth ratio simplification)
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:Infobox ET.

This module automatically fills in information about a specified equal temperament tuning.

Introspection summary for Module:Infobox ET 
Functions provided (1)
Line Function Params
7 infobox_ET (invokable) (frame)
Lua modules required (4)
Variable Module Functions used
i Module:Interval parse_ET
_backslash_ratio
_to_cents
l Module:Limits consistency_limit
rat Module:Rational eq
as_float
new
as_table
as_ratio
u Module:Utils is_prime
_prime_factorization

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


local p = {}
local i = require('Module:Interval')
local u = require('Module:Utils')
local rat = require('Module:Rational')
local l = require('Module:Limits')

function p.infobox_ET(frame)
	local tuning = frame.args['tuning']
	local size, equave = i.parse_ET(tuning)
	local prime = ""
	if u.is_prime(size) then
		prime = " (prime)"
	end
	if rat.eq(equave, 2) then
		tuning = size
	end
	local step_size = i._backslash_ratio('1\\' .. tuning)
	local fifth = math.floor(math.log(1.5)/math.log(rat.as_float(equave))*size+0.5)
	local fifth_ratio = rat.new(fifth, size)
	if rat.as_table(fifth_ratio)[1] ~= fifth then
		fifth_ratio = ' (→' .. rat.as_ratio(fifth_ratio, '\\') .. ')'
	else
		fifth_ratio = ''
	end
	return '<div style="\n' ..
	'border: 1px solid #999;\n' ..
	'margin: 0;\n' ..
	'margin-left: 1em;\n' ..
	'margin-bottom: 0.5em;\n' ..
	'padding: 0.5em;\n' ..
	'background-color: #f0f0f0;\n' ..
	'min-width: 15em;\n' ..
	'float: right;\n' ..
	'">\n' ..
	'{| width="100%" style="border-collapse: collapse;"\n' ..
	'|+ style="font-weight: bold" | ' .. frame.args['tuning'] .. '\n' ..
	'|-\n' ..
	'| style="text-align:right; padding-right: 0.25em" | Prime factorization\n' ..
	'| style="background-color: white; padding-left: 0.25em; font-weight: bold" | ' .. u._prime_factorization(size) .. prime .. '\n' ..
	'|-\n' ..
	'| style="text-align:right; padding-right: 0.25em" | Step size\n' ..
	'| style="background-color: white; padding-left: 0.25em; font-weight: bold" | ' .. i._to_cents(step_size, 6) .. \n' ..
	'|-\n' ..
	'| style="text-align:right; padding-right: 0.25em" | Fifth\n' ..
	'| style="background-color: white; padding-left: 0.25em; font-weight: bold" | ' .. string.format("%d", fifth) .. '\\' .. tuning .. ' (' .. i._to_cents(i._backslash_ratio(fifth .. '\\' .. tuning), 6) .. '¢)' .. fifth_ratio .. '\n' ..
	'|-\n' ..
	'| style="text-align:right; padding-right: 0.25em" | Consistency limit\n' ..
	'| style="background-color: white; padding-left: 0.25em; font-weight: bold" | ' .. l.consistency_limit(size, equave) .. '\n' ..
	'|-\n' ..
	'| style="text-align:right; padding-right: 0.25em" | Distinct consistency limit\n' ..
	'| style="background-color: white; padding-left: 0.25em; font-weight: bold" | ' .. l.consistency_limit(size, equave, true) .. '\n' ..
	'|}</div>'
end

return p