Module:MOS: Difference between revisions
is_valid_mos -> is_valid |
et_steps_as_string -> et_string; mos_to_et -> as_et; will momentarily break modules |
||
| Line 115: | Line 115: | ||
-- link text as an ed, rather than a mos. | -- link text as an ed, rather than a mos. | ||
function p.as_link(mos) | function p.as_link(mos) | ||
local link = p.is_valid(mos) and p.as_long_string(mos) or p. | local link = p.is_valid(mos) and p.as_long_string(mos) or p.degenerate_mos_to_et_string(mos) | ||
local text = p.is_valid(mos) and p.as_string(mos) or p. | local text = p.is_valid(mos) and p.as_string(mos) or p.degenerate_mos_to_et_string(mos) | ||
if link == text then | if link == text then | ||
return string.format("[[%s]]", link) | return string.format("[[%s]]", link) | ||
| Line 127: | Line 127: | ||
-- instead. Degenerate mosses link to the corresponding equal-division page. | -- instead. Degenerate mosses link to the corresponding equal-division page. | ||
function p.as_long_link(mos) | function p.as_long_link(mos) | ||
local link = p.is_valid(mos) and p.as_long_string(mos) or p. | local link = p.is_valid(mos) and p.as_long_string(mos) or p.degenerate_mos_to_et_string(mos) | ||
return string.format("[[%s]]", link) | return string.format("[[%s]]", link) | ||
end | end | ||
| Line 221: | Line 221: | ||
-- equal division (equal tuning), this function inputs such a mos and outputs it | -- equal division (equal tuning), this function inputs such a mos and outputs it | ||
-- as an et-string. Returns nil if it's not degenerate. | -- as an et-string. Returns nil if it's not degenerate. | ||
function p. | function p.degenerate_mos_to_et_string(mos, suffix) | ||
if (mos.nL > 0 and mos.ns == 0) or (mos.nL == 0 and mos.ns > 0) then | if (mos.nL > 0 and mos.ns == 0) or (mos.nL == 0 and mos.ns > 0) then | ||
local mos_as_et = et.new(mos.nL, mos.equave, suffix) | local mos_as_et = et.new(mos.nL, mos.equave, suffix) | ||
| Line 720: | Line 720: | ||
-- ratios to be entered. (The rational module isn't suitable since it simplifies | -- ratios to be entered. (The rational module isn't suitable since it simplifies | ||
-- ratios.) | -- ratios.) | ||
function p. | function p.as_et(mos, step_ratio, suffix) | ||
local suffix = suffix or nil | local suffix = suffix or nil | ||
local et_size = mos.nL * step_ratio[1] + mos.ns * step_ratio[2] | local et_size = mos.nL * step_ratio[1] + mos.ns * step_ratio[2] | ||
| Line 757: | Line 757: | ||
-- Given a mos, return its equal temperament suffix as a string (edo, edt, edf, or ed-p/q). | -- Given a mos, return its equal temperament suffix as a string (edo, edt, edf, or ed-p/q). | ||
function p. | function p.et_suffix(mos) | ||
if rat.eq(mos.equave, rat.new(2)) then | if rat.eq(mos.equave, rat.new(2)) then | ||
return "edo" | return "edo" | ||
| Line 770: | Line 770: | ||
-- Given a mos and step ratio, return its equal temperament as a string "{steps}\{division}{suffix}". | -- Given a mos and step ratio, return its equal temperament as a string "{steps}\{division}{suffix}". | ||
function p. | function p.as_et_string(mos, step_ratio, suffix) | ||
local suffix = suffix or nil | local suffix = suffix or nil | ||
local et_mos = p. | local et_mos = p.as_et(mos, step_ratio, suffix) | ||
return et.as_string(et_mos) | return et.as_string(et_mos) | ||
end | end | ||
| Line 778: | Line 778: | ||
-- Given a mos and step ratio, compute the number of et-steps for its bright gen | -- Given a mos and step ratio, compute the number of et-steps for its bright gen | ||
-- as a string "{steps}\{division}{suffix}". | -- as a string "{steps}\{division}{suffix}". | ||
function p. | function p.bright_gen_to_et_string(mos, step_ratio, suffix) | ||
return p. | return p.interval_to_et_string(p.bright_gen(mos), mos, step_ratio, suffix) | ||
end | end | ||
-- Given a mos and step ratio, compute the number of et-steps for its dark gen, | -- Given a mos and step ratio, compute the number of et-steps for its dark gen, | ||
-- as a string "{steps}\{division}{suffix}". | -- as a string "{steps}\{division}{suffix}". | ||
function p. | function p.dark_gen_to_et_string(mos, step_ratio, suffix) | ||
return p. | return p.interval_to_et_string(p.dark_gen(mos), mos, step_ratio, suffix) | ||
end | end | ||
-- Given a mos and step ratio, compute the number of et-steps for its period, | -- Given a mos and step ratio, compute the number of et-steps for its period, | ||
-- as a string "{steps}\{division}{suffix}". | -- as a string "{steps}\{division}{suffix}". | ||
function p. | function p.period_to_et_string(mos, step_ratio, suffix) | ||
return p. | return p.interval_to_et_string(p.period(mos), mos, step_ratio, suffix) | ||
end | end | ||
| Line 798: | Line 798: | ||
-- NOTE: no such function for returning only the number of steps is needed since | -- NOTE: no such function for returning only the number of steps is needed since | ||
-- that's the same as period_count(). | -- that's the same as period_count(). | ||
function p. | function p.reduced_period_to_et_string(mos, suffix) | ||
return p. | return p.interval_to_et_string({["L"] = 1, ["s"] = 1}, p.root_mos(mos), {1,0}, suffix) | ||
end | end | ||
-- Given a mos and step ratio, compute the number of et-steps for its equave, | -- Given a mos and step ratio, compute the number of et-steps for its equave, | ||
-- as a string "{steps}\{division}{suffix}". | -- as a string "{steps}\{division}{suffix}". | ||
function p. | function p.equave_to_et_string(mos, step_ratio, suffix) | ||
return p. | return p.interval_to_et_string(p.equave(mos), mos, step_ratio, suffix) | ||
end | end | ||
| Line 811: | Line 811: | ||
-- corresponds to, as a string "{steps}\{division}{suffix}". Requires info | -- corresponds to, as a string "{steps}\{division}{suffix}". Requires info | ||
-- about the mos itself. | -- about the mos itself. | ||
function p. | function p.interval_to_et_string(interval, mos, step_ratio, suffix) | ||
local suffix = suffix or nil | local suffix = suffix or nil | ||
local mos_et = p. | local mos_et = p.as_et(mos, step_ratio, suffix) | ||
return et.backslash_display(mos_et, p.interval_to_et_steps(interval, step_ratio)) | return et.backslash_display(mos_et, p.interval_to_et_steps(interval, step_ratio)) | ||
end | end | ||
| Line 868: | Line 868: | ||
--return p.as_string(input_mos, false) | --return p.as_string(input_mos, false) | ||
--return p. | --return p.as_et(p.new(5,2), {2,1}) | ||
return p.as_string(p.new(5,2)) .. "\n" .. p.as_link(p.new(5,2,3)) .. "\n" .. p.as_long_link(p.new(5,2)) .. "\n" .. p.as_long_link(p.new(5,2,3)) .. "\n" .. p.as_link(p.new(5,0)) .. "\n" .. p.as_link(p.new(5,0,3)) .. "\n" .. p.as_long_link(p.new(5,0)) .. "\n" .. p.as_long_link(p.new(5,0,3)) | return p.as_string(p.new(5,2)) .. "\n" .. p.as_link(p.new(5,2,3)) .. "\n" .. p.as_long_link(p.new(5,2)) .. "\n" .. p.as_long_link(p.new(5,2,3)) .. "\n" .. p.as_link(p.new(5,0)) .. "\n" .. p.as_link(p.new(5,0,3)) .. "\n" .. p.as_long_link(p.new(5,0)) .. "\n" .. p.as_long_link(p.new(5,0,3)) | ||