Module:MOS: Difference between revisions

Ganaram inukshuk (talk | contribs)
Bugfixes; added in cent functions anyway
Ganaram inukshuk (talk | contribs)
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.
-- TODO:
-- - Reduction functions (period-reduce and equave-reduce) should work based on
--  how modular arithmetic works. EG, 0 mod 7 is 0, as is 7 mod 7 and -7 mod 7,
--  and -3 mod 7 is 4. This means they should also be able to accept negative
--  intervals in the sense that stacking downwards and +1 octave produces an
--  inverted interval (EG stacking a perf 5th down and going up one octave is
--  the same as going up a perf 4th). Whether this should be part of the reduce
--  functions or be its own thing (invert?) is tbd.


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
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.interval_to_cents({['L']=6,['s']=-2},p.new(5,2), {3,2})
return p.equave_complement({['L']=-3,['s']=-1},p.new(5,2))


end
end


return p
return p