Module:ET
This module provides helper functions for equal-step tunings.
Functions
new
- Returns an array consisting of the components of an equal-step tuning.
parse
- Designed to convert strings in the format
[number of steps]ed[equave]
into an ET structure, and returns it via thenew
function. For example,ET.parse("12edo")
returns an array containing{12, 2, "edo"}
as_string
- Returns the string representation for an ET structure.
backslash_ratio
- Converts steps to a proper ratio as a floating-point number.
backslash_display
- Displays an ET structure in backslash form (
[steps]\[number of divisions]
).
cents
- Converts the interval an ET structure represents to cents.
hekts
- Converts the interval an ET structure represents to hekts (relative cent of 13edt).
approximate
- Returns the floor, round, or ceiling of a particular ratio.
tempers_out
- Determines if an ET tempers out a provided rational number.
is_highly_composite
- Determines if an ET is highly composite.
is_zeta
- Determines if an ET holds any zeta records.
why_zeta
- Describes what specific properties an ET has if it is a zeta record ET.
local rat = require('Module:Rational')
local p = {}
local common_suffix = {
['3/2'] = 'f',
['2'] = 'o',
['2/1'] = 'o',
['3'] = 't',
['3/1'] = 't',
}
local common_ratio = {
['f'] = rat.new(3, 2),
['o'] = 2,
['t'] = 3
}
function p.new(size, equave, suffix)
size = size or 12
equave = equave or 2
if suffix == nil then
local equave_n, equave_m = rat.as_pair(equave)
local equave_ratio = rat.as_ratio(equave)
suffix = size .. 'ed'
if common_suffix[equave_ratio] then
suffix = suffix .. common_suffix[equave_ratio]
elseif equave_m == 1 then
suffix = suffix .. equave_n
else
suffix = suffix .. equave_ratio
end
end
return { size = size, equave = equave, suffix = suffix }
end
function p.parse(unparsed)
local size, suffix, equave = unparsed:match('^(%d+)(ed(.+))$')
if equave == nil then
return nil
end
size = tonumber(size)
equave = common_ratio[equave] or rat.parse(equave)
if size == nil or equave == nil then
return nil
end
return p.new(size, equave, suffix)
end
return p