|
|
| Line 21: |
Line 21: |
| return u._round(result, prec) | | return u._round(result, prec) |
| end | | end |
| end
| |
|
| |
| -- edf = ed3/2, edo = ed2, edt = ed3
| |
| local equaves =
| |
| {
| |
| ['f'] = rat.new(3, 2),
| |
| ['o'] = 2,
| |
| ['t'] = 3
| |
| }
| |
|
| |
| -- returns size of an ET given its name
| |
| function p.parse_ET_size(frame)
| |
| local args = getArgs(frame)
| |
| local size, equave = p.parse_ET(args[1])
| |
| return size
| |
| end
| |
|
| |
| -- returns equave of an ET given its name
| |
| function p.parse_ET_equave(frame)
| |
| local args = getArgs(frame)
| |
| local size, equave = p.parse_ET(args[1])
| |
| return rat.as_float(equave)
| |
| end
| |
|
| |
| -- returns size and equave of an ET given its name; cannot be used with {{#invoke:}}
| |
| function p.parse_ET(input)
| |
| input = string.lower(input)
| |
| local size, equave
| |
| -- size defaults to 12
| |
| size = u.eval_num_arg(input:match("^([0-9]+)"), 12)
| |
| if input:match("^[0-9]*[%-]?ed[fot]$") then
| |
| equave = equaves[tostring(input:match("[fot]"))]
| |
| else
| |
| -- equave defaults to 2
| |
| equave = rat.parse(input:match("^.-ed(.+)%s*$")) or 2
| |
| end
| |
| return size, equave
| |
| end
| |
|
| |
| -- return ratio corresponding to an interval written in backslash notation
| |
| -- ("steps" of "size" equal divisions of the "equave")
| |
|
| |
| function p.backslash_ratio(frame)
| |
| local args = getArgs(frame)
| |
| return p._backslash_ratio(args[1])
| |
| end
| |
|
| |
| function p._backslash_ratio(input)
| |
| -- result defaults to 0
| |
| local result = 0
| |
| -- steps defaults to 1
| |
| local steps = input:match("%s*(%-?[0-9]+)\\.-") or 1
| |
| local size, equave = p.parse_ET(input:match("\\(.*)"))
| |
| if tonumber(size) == 0 then
| |
| return 1
| |
| end
| |
| result = rat.as_float(equave)^(tonumber(steps)/tonumber(size))
| |
| return result
| |
| end | | end |
|
| |
|
| return p | | return p |