Module:ED intro: Difference between revisions
m Updated todo |
ArrowHead294 (talk | contribs) mNo edit summary |
||
| Line 1: | Line 1: | ||
local ord = require( | local ord = require("Module:Ordinal") | ||
local utils = require( | local utils = require("Module:Utils") | ||
local rat = require( | local rat = require("Module:Rational") | ||
local p = {} | local p = {} | ||
| Line 211: | Line 211: | ||
-- Parse the step count, the suffix, and the equave | -- Parse the step count, the suffix, and the equave | ||
local steps, equave = unparsed:match( | local steps, equave = unparsed:match("^(%d+)[Ee][Dd](.+)$") | ||
-- Determine if the ed is for a cent value | -- Determine if the ed is for a cent value | ||
local is_cents = string.match(equave, | local is_cents = string.match(equave, "%d*%.?%d+[Cc¢]$") ~= nil | ||
-- Parse equave | -- Parse equave | ||
| Line 231: | Line 231: | ||
parsed_equave = rat.new(3,2) | parsed_equave = rat.new(3,2) | ||
ed_type = ED_TYPE_EDF | ed_type = ED_TYPE_EDF | ||
elseif string.match(equave, | elseif string.match(equave, "^%d+$") ~= nil then | ||
-- Equave is arbitrary harmonic (not 2/1 or 3/1) | -- Equave is arbitrary harmonic (not 2/1 or 3/1) | ||
parsed_equave = tonumber(equave) | parsed_equave = tonumber(equave) | ||
ed_type = ED_TYPE_EDH | ed_type = ED_TYPE_EDH | ||
elseif string.match(equave, | elseif string.match(equave, "^%d+/%d+$") ~= nil then | ||
-- Equave is arbitrary ratio (not 3/2) | -- Equave is arbitrary ratio (not 3/2) | ||
local num, den = equave:match( | local num, den = equave:match("^(%d+)/(%d+)$") | ||
parsed_equave = rat.new(tonumber(num), tonumber(den)) | parsed_equave = rat.new(tonumber(num), tonumber(den)) | ||
ed_type = ED_TYPE_EDR | ed_type = ED_TYPE_EDR | ||
elseif is_cents then | elseif is_cents then | ||
-- Equave is arbitrary cent value | -- Equave is arbitrary cent value | ||
parsed_equave = tonumber(equave:match( | parsed_equave = tonumber(equave:match("^(%d*%.?%d+)[Cc¢]$")) | ||
ed_type = ED_TYPE_EDC | ed_type = ED_TYPE_EDC | ||
else | else | ||
| Line 333: | Line 333: | ||
-- Wrapper function; for use with a template | -- Wrapper function; for use with a template | ||
function p.ed_intro(frame) | function p.ed_intro(frame) | ||
local ed = frame.args[ | local ed = frame.args["ED"] | ||
local edo = frame.args[ | local edo = frame.args["EDO"] -- For backwards compatibility with edo intro | ||
return p._ed_intro(((edo == nil) and {ed} or {edo})[1]) | |||
end | end | ||
return p | return p | ||