Module:MOS: Difference between revisions
Bugfixes; added in cent functions anyway |
a bugfix; reduce functions now accept negative intervals |
||
| Line 27: | Line 27: | ||
-- after the mos. | -- after the mos. | ||
-- - Functions that have to do with equal tunings will have "et" in its name. | -- - Functions that have to do with equal tunings will have "et" in its name. | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 398: | Line 389: | ||
-- Given a vector representing an interval, compute the number of mossteps it | -- Given a vector representing an interval, compute the number of mossteps it | ||
-- corresponds to. Knowledge of the corresponding mos is not needed. | -- corresponds to. Knowledge of the corresponding mos is not needed. Intervals | ||
-- can be negative, resulting in a negative output. | |||
function p.interval_step_count(interval) | function p.interval_step_count(interval) | ||
return interval['L'] + interval['s'] | return interval['L'] + interval['s'] | ||
| Line 463: | Line 455: | ||
-- Given an interval vector and a mos, find its equave complement. | -- Given an interval vector and a mos, find its equave complement. | ||
function p.equave_complement(interval) | function p.equave_complement(interval, mos) | ||
local equave_vector = p.equave(mos, interval) | local equave_vector = p.equave(mos, interval) | ||
return p.interval_sub(equave_vector, interval) | return p.interval_sub(equave_vector, interval) | ||
end | end | ||
-- Given an interval vector and a mos, period-reduce it. | -- Given an interval vector and a mos, period-reduce it. This works like | ||
-- modular arithmetic, so passing a negative interval returns a positive one. | |||
function p.period_reduce(interval, mos) | function p.period_reduce(interval, mos) | ||
local interval = p.normalize_interval(interval) | |||
local step_count = p.interval_step_count(interval) | local step_count = p.interval_step_count(interval) | ||
local reduce_amt = math.floor(step_count / p.period_step_count(mos)) | local reduce_amt = math.floor(step_count / p.period_step_count(mos)) | ||
| Line 477: | Line 471: | ||
end | end | ||
-- Given an interval vector and a mos, equave-reduce it. | -- Given an interval vector and a mos, equave-reduce it. This works like | ||
-- modular arithmetic, so passing a negative interval returns a positive one. | |||
function p.equave_reduce(interval) | function p.equave_reduce(interval) | ||
local interval = p.normalize_interval(interval) | |||
local step_count = p.interval_step_count(interval) | local step_count = p.interval_step_count(interval) | ||
local reduce_amt = math.floor(step_count / p.equave_step_count(mos)) | local reduce_amt = math.floor(step_count / p.equave_step_count(mos)) | ||
| Line 606: | Line 602: | ||
--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.equave_complement({['L']=-3,['s']=-1},p.new(5,2)) | ||
end | end | ||
return p | return p | ||