Module:MOS: Difference between revisions
Comments |
Minor renaming to some params; added unison(), which returns a zero vector |
||
| Line 227: | Line 227: | ||
['L'] = mos.nL, | ['L'] = mos.nL, | ||
['s'] = mos.ns | ['s'] = mos.ns | ||
} | |||
return result | |||
end | |||
-- Compute the unison as a vector of L's and s's. | |||
-- The unison is denoted by moving up from the root by zero steps, and thus does | |||
-- not need a mos as input. It's basically a zero vector. | |||
-- The unison only has one size: perfect. | |||
function p.unison() | |||
local result = { | |||
['L'] = 0, | |||
['s'] = 0 | |||
} | } | ||
return result | return result | ||
| Line 345: | Line 357: | ||
-- Add two intervals together by adding their respective vectors. | -- Add two intervals together by adding their respective vectors. | ||
function p.interval_add( | function p.interval_add(interval_1, interval_2) | ||
local interval_vector = { | local interval_vector = { | ||
['L'] = | ['L'] = interval_1['L'] + interval_2['L'], | ||
['s'] = | ['s'] = interval_1['s'] + interval_2['s'] | ||
} | } | ||
return interval_vector | return interval_vector | ||
| Line 354: | Line 366: | ||
-- Subtract two intervals by subtracting their respective vectors. | -- Subtract two intervals by subtracting their respective vectors. | ||
function p.interval_sub( | function p.interval_sub(interval_1, interval_2) | ||
local interval_vector = { | local interval_vector = { | ||
['L'] = | ['L'] = interval_1['L'] - interval_2['L'], | ||
['s'] = | ['s'] = interval_1['s'] - interval_2['s'] | ||
} | } | ||
return interval_vector | return interval_vector | ||
| Line 363: | Line 375: | ||
-- Repeatedly add the same interval to itself. | -- Repeatedly add the same interval to itself. | ||
function p.interval_mul( | function p.interval_mul(interval, amt) | ||
local interval_vector = { | local interval_vector = { | ||
['L'] = | ['L'] = interval['L'] * amt, | ||
['s'] = | ['s'] = interval['s'] * amt | ||
} | } | ||
return interval_vector | return interval_vector | ||
| Line 376: | Line 388: | ||
-- Given an interval vector and a mos, find its period complement. | -- Given an interval vector and a mos, find its period complement. | ||
function p.period_complement( | function p.period_complement(interval, mos) | ||
local period_vector = p.period(mos) | local period_vector = p.period(mos) | ||
return p.interval_sub(period_vector, | return p.interval_sub(period_vector, interval) | ||
end | end | ||
-- 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( | function p.equave_complement(interval) | ||
local equave_vector = p.equave(mos, | local equave_vector = p.equave(mos, interval) | ||
return p.interval_sub(equave_vector, | 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. | ||
function p.period_reduce( | function p.period_reduce(interval, mos) | ||
local step_count = p.interval_step_count( | 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)) | ||
local periods = p.interval_mul(p.period(mos), reduce_amt) | local periods = p.interval_mul(p.period(mos), reduce_amt) | ||
return p.interval_sub( | return p.interval_sub(interval) | ||
end | end | ||
-- Given an interval vector and a mos, equave-reduce it. | -- Given an interval vector and a mos, equave-reduce it. | ||
function p.equave_reduce( | function p.equave_reduce(interval) | ||
local step_count = p.interval_step_count( | 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)) | ||
local equaves = p.interval_mul(p.equave(mos), reduce_amt) | local equaves = p.interval_mul(p.equave(mos), reduce_amt) | ||
return p.interval_sub( | return p.interval_sub(interval, equaves) | ||
end | end | ||