Module:MOS: Difference between revisions

Ganaram inukshuk (talk | contribs)
Comments
Ganaram inukshuk (talk | contribs)
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(v1, v2)
function p.interval_add(interval_1, interval_2)
local interval_vector = {  
local interval_vector = {  
['L'] = v1['L'] + v2['L'],
['L'] = interval_1['L'] + interval_2['L'],
['s'] = v1['s'] + v2['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(v1, v2)
function p.interval_sub(interval_1, interval_2)
local interval_vector = {  
local interval_vector = {  
['L'] = v1['L'] - v2['L'],
['L'] = interval_1['L'] - interval_2['L'],
['s'] = v1['s'] - v2['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(v1, amt)
function p.interval_mul(interval, amt)
local interval_vector = {  
local interval_vector = {  
['L'] = v1['L'] * amt,
['L'] = interval['L'] * amt,
['s'] = v1['s'] * amt
['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(v1, mos)
function p.period_complement(interval, mos)
local period_vector = p.period(mos)
local period_vector = p.period(mos)
return p.interval_sub(period_vector, v1)
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(v1, mos)
function p.equave_complement(interval)
local equave_vector = p.equave(mos, v1)
local equave_vector = p.equave(mos, interval)
return p.interval_sub(equave_vector, v1)
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(v1, mos)
function p.period_reduce(interval, mos)
local step_count = p.interval_step_count(v1)
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(v1, periods)
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(v1, mos)
function p.equave_reduce(interval)
local step_count = p.interval_step_count(v1)
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(v1, equaves)
return p.interval_sub(interval, equaves)
end
end