Module:ED intro: Difference between revisions

Ganaram inukshuk (talk | contribs)
m Updated todo
ArrowHead294 (talk | contribs)
mNo edit summary
Line 1: Line 1:
local ord = require('Module:Ordinal')
local ord = require("Module:Ordinal")
local utils = require('Module:Utils')
local utils = require("Module:Utils")
local rat = require('Module:Rational')
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('^(%d+)[Ee][Dd](.+)$')
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, '%d*%.?%d+[Cc¢]$') ~= nil
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, '^%d+$') ~= nil then
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, '^%d+/%d+$') ~= nil then
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('^(%d+)/(%d+)$')
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('^(%d*%.?%d+)[Cc¢]$'))
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['ED']
local ed = frame.args["ED"]
local edo = frame.args['EDO'] -- For backwards compatibility with edo intro
local edo = frame.args["EDO"] -- For backwards compatibility with edo intro


if edo ~= nil then
return p._ed_intro(((edo == nil) and {ed} or {edo})[1])
return p._ed_intro(edo)
else
return p._ed_intro(ed)
end
end
end


return p
return p