Module:MOS genchain: Difference between revisions

Ganaram inukshuk (talk | contribs)
Base functionality complete (the for loops, basically)
Ganaram inukshuk (talk | contribs)
No edit summary
Line 20: Line 20:
function p.preprocess_genchain(input_mos)
function p.preprocess_genchain(input_mos)
local input_mos = input_mos or mos.new(5,2)
local input_mos = input_mos or mos.new(5,2)
local num_gens = 2 * mos.period_step_count(input_mos) - 2
local num_gens = 4 * (mos.period_step_count(input_mos) - 1)
local bright_gen = mos.bright_gen(input_mos)
local bright_gen = mos.bright_gen(input_mos)
local gens = mos.interval_mul(bright_gen, -num_gens/2)
local gens = mos.interval_mul(bright_gen, num_gens/2)
bright_gen = mos.interval_mul(bright_gen, -1)
local genchain = { mos.period_reduce(gens, input_mos) }
local genchain = { mos.period_reduce(gens, input_mos) }
for i = 1, num_gens do
for i = 1, num_gens do
Line 33: Line 34:


function p._mos_genchain(input_mos)
function p._mos_genchain(input_mos)
local input_mos = input_mos or mos.new(6,3)
local input_mos = input_mos or mos.new(6,2)
local num_gens = mos.period_step_count(input_mos)
local num_gens = mos.period_step_count(input_mos)
local genchain = p.preprocess_genchain(input_mos)
local genchain = p.preprocess_genchain(input_mos)
local period_count = mos.period_count(input_mos)
-- Begin table
-- Begin table
Line 43: Line 45:
.. "|-\n"
.. "|-\n"
-- Generators header cell
-- Generators header rows
result = result .. "! Number of bright gens\n"
result = result .. "! Bright gens"
for i = 1, period_count do
result = result
.. " !! Scale Degree"
.. " !! Abbrev"
end
local result = result
.. "\n"
.. "|-\n"
-- Add a row for the generator counts
-- Add a row for each scale degree, plus their period-shifted counterparts
for i = 1, #genchain do
for i = 1, #genchain do
result = result .. string.format("%s %s", (i == 1 and "|" or " ||"), i - num_gens)
-- Number of generators
end
result = result .. string.format("| %s", math.ceil(#genchain/2) - i)
result = result .. "\n"
local current_period_reduced_interval = genchain[i]
local period_interval = mos.period(input_mos)
-- Add a row for each period's genchain
for j = 1, period_count do
local period_count = mos.period_count(input_mos)
-- Scale degree (full name) and abbrev
if period_count == 1 then
current_period_reduced_interval = mos.interval_add(current_period_reduced_interval, mos.interval_mul(period_interval, j - 1))
result = result .. "! Degree quality\n"
result = result .. string.format(" || %s", tamnams.degree_quality(current_period_reduced_interval, input_mos, "sentence-case"))
for i = 1, #genchain do
result = result .. string.format(" || %s", tamnams.degree_quality(current_period_reduced_interval, input_mos, "abbrev"))
result = result .. string.format("%s %s", (i == 1 and "|" or " ||"), tamnams.degree_quality(genchain[i], input_mos, "abbrev"))
end
end
result = result .. "\n|}"
else
-- End of row
local mosprefix = "mos"
result = result
for i = 1, period_count do
.. "\n"
local period_step_count = mos.period_step_count(input_mos)
.. "|-\n"
result = result .. string.format("! Degree quality (%s-%sdegree to %s-%sdegree)\n", period_step_count * (i - 1), mosprefix, period_step_count * i - 1, mosprefix)
for j = 1, #genchain do
local current_interval = genchain[j]
current_interval = mos.interval_add(current_interval, mos.interval_mul(mos.period(input_mos), i - 1))
result = result .. string.format("%s %s", (j == 1 and "|" or " ||"), tamnams.degree_quality(current_interval, input_mos, "abbrev"))
end
result = result .. "\n"
end
result = result .. "|}"
end
end
result = result .. "|}"
local bright_gen_as_text = tamnams.interval_quality(mos.bright_gen(input_mos), input_mos)
local period_step_count = mos.period_step_count(input_mos)
local scalesig = mos.as_string(input_mos)
local child_step_count = input_mos.nL + input_mos.nL + input_mos.ns
local child_scale_1 = mos.new(input_mos.nL+input_mos.ns, input_mos.nL, input_mos.equave)
local child_scale_2 = mos.new(input_mos.nL, input_mos.nL+input_mos.ns, input_mos.equave)
result = "Stacking a generator of MOS-INTERVAL from the root produces the following scale degrees. A chain of NOTECOUNT consecutive scale degrees produces one of the modes of SCALESIG, and expanding it to DAUGHTER-NOTECOUNT produces the modes of DAUGHTER-SCALES.\n"
--result = string.format("Stacking the bright generator (a %s) from the root produces the following scale degrees. A chain of %s consecutive scale degrees produces one of the modes of %s, and expanding it to %s scale degrees produces the modes of either %s or %s.\n",
.. result
-- bright_gen_as_text,
-- period_step_count,
-- scalesig,
-- child_step_count,
-- mos.as_string(child_scale_1),
-- mos.as_string(child_scale_2)
-- )
-- .. result
return result
return result
end
function p.mos_genchain(frame)
local scalesig = frame["Scale Signature"]
local input_mos = mos.parse(scalesig)
return p._mos_genchain(input_mos)
end
end


return p
return p