Module:MOS: Difference between revisions
m Todo |
Bugfixes; added in cent functions anyway |
||
| Line 502: | Line 502: | ||
-- generator. | -- generator. | ||
function p.bright_gen_to_et_steps(mos, step_ratio) | function p.bright_gen_to_et_steps(mos, step_ratio) | ||
return interval_to_et_steps(p.bright_gen(mos), step_ratio) | return p.interval_to_et_steps(p.bright_gen(mos), step_ratio) | ||
end | end | ||
| Line 508: | Line 508: | ||
-- generator. | -- generator. | ||
function p.dark_gen_to_et_steps(mos, step_ratio) | function p.dark_gen_to_et_steps(mos, step_ratio) | ||
return interval_to_et_steps(p.dark_gen(mos), step_ratio) | return p.interval_to_et_steps(p.dark_gen(mos), step_ratio) | ||
end | end | ||
-- Given a mos and a step ratio, return the number of et-steps for its period. | -- Given a mos and a step ratio, return the number of et-steps for its period. | ||
function p.period_to_et_steps(mos, step_ratio) | function p.period_to_et_steps(mos, step_ratio) | ||
return interval_to_et_steps(p.period(mos), step_ratio) | return p.interval_to_et_steps(p.period(mos), step_ratio) | ||
end | end | ||
-- Given a mos and a step ratio, return the number of et-steps for its equave. | -- Given a mos and a step ratio, return the number of et-steps for its equave. | ||
function p.equave_to_et_steps(mos, step_ratio) | function p.equave_to_et_steps(mos, step_ratio) | ||
return interval_to_et_steps(p.equave(mos), step_ratio) | return p.interval_to_et_steps(p.equave(mos), step_ratio) | ||
end | end | ||
-- Given an interval vector and step ratio, compute the number of et-steps it | -- Given an interval vector and step ratio, compute the number of et-steps it | ||
-- corresponds to. | -- corresponds to. | ||
function p.interval_to_et_steps(interval, step_ratio) | function p.interval_to_et_steps(interval, step_ratio) | ||
return interval['L'] * step_ratio[1] + interval['s'] * step_ratio[2] | |||
end | |||
-------------------------------------------------------------------------------- | |||
------------------------------- CENT FUNCTIONS --------------------------------- | |||
-------------------------------------------------------------------------------- | |||
-- Given a mos and a step ratio, return the number of cents for its bright | |||
-- generator. | |||
function p.bright_gen_to_cents(mos, step_ratio) | |||
local interval_steps = p.interval_to_et_steps(p.bright_gen(mos), step_ratio) | |||
local equave_steps = p.equave_to_et_steps(mos, step_ratio) | |||
return interval_steps * rat.cents(mos.equave) / equave_steps | |||
end | |||
-- Given a mos and a step ratio, return the number of cents for its dark | |||
-- generator. | |||
function p.dark_gen_to_cents(mos, step_ratio) | |||
local interval_steps = p.interval_to_et_steps(p.dark_gen(mos), step_ratio) | |||
local equave_steps = p.equave_to_et_steps(mos, step_ratio) | |||
return interval_steps * rat.cents(mos.equave) / equave_steps | |||
end | |||
-- Given a mos and a step ratio, return the number of cents for its period. | |||
function p.period_to_cents(mos, step_ratio) | |||
local interval_steps = p.interval_to_et_steps(p.period(mos), step_ratio) | |||
local equave_steps = p.equave_to_et_steps(mos, step_ratio) | |||
return interval_steps * rat.cents(mos.equave) / equave_steps | |||
end | |||
-- Given a mos and a step ratio, return the number of cents for its equave. | |||
function p.equave_to_cents(mos, step_ratio) | |||
local interval_steps = p.interval_to_et_steps(p.equave(mos), step_ratio) | |||
local equave_steps = p.equave_to_et_steps(mos, step_ratio) | |||
return interval_steps * rat.cents(mos.equave) / equave_steps | |||
end | |||
-- Given an interval vector and step ratio, compute the number of cents it | |||
-- corresponds to. | |||
function p.interval_to_cents(interval, mos, step_ratio) | |||
local interval_steps = p.interval_to_et_steps(interval, step_ratio) | |||
local equave_steps = p.equave_to_et_steps(mos, step_ratio) | |||
return interval_steps * rat.cents(mos.equave) / equave_steps | |||
end | end | ||
| Line 565: | Line 606: | ||
--local interval = p.dark_gen(p.new(5,2)) | --local interval = p.dark_gen(p.new(5,2)) | ||
--return p.interval_chroma_count(interval, p.new(5,2), -1) | --return p.interval_chroma_count(interval, p.new(5,2), -1) | ||
return p. | return p.interval_to_cents({['L']=6,['s']=-2},p.new(5,2), {3,2}) | ||
end | end | ||
return p | return p | ||