Module:MOS interval HE: Difference between revisions

Ganaram inukshuk (talk | contribs)
Created page with "local mos = require("Module:MOS") local rat = require("Module:Rational") local et = require("Module:ET") local tamnams = require("Module:TAMNAMS") local interval_extension = r..."
 
ArrowHead294 (talk | contribs)
mNo edit summary
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local p = {}
local et = require("Module:ET")
local ie = require("Module:Interval extension")
local mos = require("Module:MOS")
local mos = require("Module:MOS")
local rat = require("Module:Rational")
local rat = require("Module:Rational")
local et = require("Module:ET")
local tamnams = require("Module:TAMNAMS")
local tamnams = require("Module:TAMNAMS")
local interval_extension = require("Module:Interval_extension")
local yesno = require("Module:Yesno")
local yesno = require("Module:Yesno")
local p = {}
-- TODO:
-- - Move harmonic entropy to separate module/template pair????


-- Main function; to be called by wrapper
-- Main function; to be called by wrapper
function p._mos_intervals(input_mos, mos_prefix, mos_abbrev, is_collapsed)
function p._mos_interval_he(input_mos, mos_prefix, mos_abbrev, is_collapsed)
-- Default param for input mos is 5L 2s
-- Default param for input mos is 5L 2s
local input_mos = input_mos or mos.new(5, 2, 2)
local input_mos = input_mos or mos.new(5, 2, 2)
Line 49: Line 47:
-- Create table title
-- Create table title
result = result
result = result
.. "|+ style=\"font-size: 105%; white-space: nowrap;\" | " .. string.format("Intervals of %s\n", scale_sig)
.. "|+ style=\"font-size: 105%; white-space: nowrap;\" | " .. string.format("Harmonic entropy info for %s\n", scale_sig)
.. "|-\n"
.. "|-\n"
-- Create table headers
-- Create table headers
result = result
result = result
.. "! colspan=\"3\" | Intervals"
.. "! Interval "
.. "!! rowspan=\"2\" | Steps subtended"
.. "!! Range in cents "
.. "!! rowspan=\"2\" | Range in cents"
.. "!! Average of [[HE]]<br />(from [http://www.mikebattagliamusic.com/HE-JS/HE.html HE Calc]) "
.. "!! rowspan=\"2\" | Average of [[HE]]<br/>(from [http://www.mikebattagliamusic.com/HE-JS/HE.html HE Calc])\n"
.. "!! Min of [[HE]]\n"
.. "!! rowspan=\"2\" | Min of [[HE]]\n"
.. "|-\n" -- Start of second row of header cells
.. "! Generic"
.. "!! Specific"
.. "!! Abbrev.\n"
-- Write each row
-- Write each row
Line 77: Line 70:
local cents = mos.interval_to_cents(current_bright_interval, input_mos, {1, 1})
local cents = mos.interval_to_cents(current_bright_interval, input_mos, {1, 1})
result = result .. "|-\n"
result = result .. string.format("|-\n | %s || %.1f{{c}} || ~%.4f&nbsp;nats || ~%.4f&nbsp;nats",
.. string.format("| '''%s-%sstep''' ", i - 1, mos_prefix)
tamnams.interval_quality(current_bright_interval, input_mos, "sentence-case", mos_prefix),
.. string.format("|| %s " , tamnams.interval_quality(current_bright_interval, input_mos, "sentence-case", mos_prefix))
cents,
.. string.format("|| %s " , tamnams.interval_quality(current_bright_interval, input_mos, "abbrev"      , mos_abbrev))
ie.harmonic_entropy_with_lookup_table(cents),
.. string.format("|| %s " , mos.interval_as_string(current_bright_interval))
ie.harmonic_entropy_with_lookup_table(cents))
.. string.format("|| %.1f¢ ", cents)
.. string.format("|| ~%.4f nats ", interval_extension.harmonic_entropy_with_lookup_table(cents))
.. string.format("|| ~%.4f nats", interval_extension.harmonic_entropy_with_lookup_table(cents))
else
else
-- Calculate the best and average harmonic entropies
-- Calculate the best and average harmonic entropies
Line 93: Line 83:
for i = 1, #step_ratios do
for i = 1, #step_ratios do
local step_ratio = step_ratios[i]
local step_ratio = step_ratios[i]
local he_dark = interval_extension.harmonic_entropy_with_lookup_table(mos.interval_to_cents(current_dark_interval, input_mos, step_ratio))
local he_dark = ie.harmonic_entropy_with_lookup_table(mos.interval_to_cents(current_dark_interval, input_mos, step_ratio))
local he_bright = interval_extension.harmonic_entropy_with_lookup_table(mos.interval_to_cents(current_bright_interval, input_mos, step_ratio))
local he_bright = ie.harmonic_entropy_with_lookup_table(mos.interval_to_cents(current_bright_interval, input_mos, step_ratio))
he_dark_average = he_dark_average + he_dark / #step_ratios
he_dark_average = he_dark_average + he_dark / #step_ratios
he_bright_average = he_bright_average + he_bright / #step_ratios
he_bright_average = he_bright_average + he_bright / #step_ratios
Line 113: Line 103:
-- Then sort, as the min and max may be swapped  
-- Then sort, as the min and max may be swapped  
-- This happens if the dark interval has more small steps than large steps
-- This happens if the dark interval has more small steps than large steps
local dark_interval_range  = string.format("%.1f¢ to %.1f¢", math.min(sm_min_cents, sm_max_cents), math.max(sm_min_cents, sm_max_cents))
local dark_interval_range  = string.format("%.1f{{c}} to %.1f{{c}}", math.min(sm_min_cents, sm_max_cents), math.max(sm_min_cents, sm_max_cents))
local bright_interval_range = string.format("%.1f¢ to %.1f¢", math.min(lg_min_cents, lg_max_cents), math.max(lg_min_cents, lg_max_cents))
local bright_interval_range = string.format("%.1f{{c}} to %.1f{{c}}", math.min(lg_min_cents, lg_max_cents), math.max(lg_min_cents, lg_max_cents))
result = result .. "|-\n"
result = result .. string.format("|-\n| %s || %s || ~%.4f&nbsp;nats || ~%.4f&nbsp;nats\n|-\n| %s || %s || ~%.4f&nbsp;nats || ~%.4f&nbsp;nats",
.. string.format("| rowspan=\"2\" | %s-%sstep ", i - 1, mos_prefix)
tamnams.interval_quality(current_dark_interval, input_mos, "sentence-case", mos_prefix),
.. string.format("|| %s " , tamnams.interval_quality(current_dark_interval, input_mos, "sentence-case", mos_prefix))
dark_interval_range,
.. string.format("|| %s " , tamnams.interval_quality(current_dark_interval, input_mos, "abbrev"      , mos_abbrev))
he_dark_average,
.. string.format("|| %s " , mos.interval_as_string(current_dark_interval))
he_dark_best,
.. string.format("|| %s " , dark_interval_range)
tamnams.interval_quality(current_bright_interval, input_mos, "sentence-case", mos_prefix),
.. string.format("|| ~%.4f nats " , he_dark_average)
bright_interval_range,
.. string.format("|| ~%.4f nats\n" , he_dark_best)
he_bright_average,
.. "|-\n"
he_bright_best)
.. string.format("| %s "  , tamnams.interval_quality(current_bright_interval, input_mos, "sentence-case", mos_prefix))
.. string.format("|| %s " , tamnams.interval_quality(current_bright_interval, input_mos, "abbrev"       , mos_abbrev))
.. string.format("|| %s " , mos.interval_as_string(current_bright_interval))
.. string.format("|| %s " , bright_interval_range)
.. string.format("|| ~%.4f nats " , he_bright_average)
.. string.format("|| ~%.4f nats" , he_bright_best)
end
end
result = result .. "\n"
result = result .. "\n"
Line 136: Line 120:
result = result .. "|}"
result = result .. "|}"


return result
end
function p.mos_intervals_description(input_mos, mos_prefix)
local input_mos = input_mos or mos.new(5,2)
local mos_prefix = mos_prefix or "dia"
local scalesig = mos.as_string(input_mos)
-- How many periods?
-- What are the period intervals?
local period_count = mos.period_count(input_mos)
local period_interval = mos.period(input_mos)
local period_intervals = {}
for i = 1, period_count + 1 do
local interval = mos.interval_mul(period_interval, i-1)
table.insert(period_intervals, interval)
end
-- As a sentence piece
local period_intervals_as_text = ""
if #period_intervals == 2 then
period_intervals_as_text = string.format("%s and %s", tamnams.interval_quality(period_intervals[1], input_mos, "none", mos_prefix), tamnams.interval_quality(period_intervals[2], input_mos, "none", mos_prefix))
else
for i = 1, period_count do
period_intervals_as_text = period_intervals_as_text
.. string.format("%s, ", tamnams.interval_quality(period_intervals[i], input_mos, "none", mos_prefix))
end
period_intervals_as_text = period_intervals_as_text
.. string.format("and %s", tamnams.interval_quality(period_intervals[period_count + 1], input_mos, "none", mos_prefix))
end
local result = string.format("The intervals of %s are named after the number of mossteps (L and s) they subtend.", scalesig)
local period_interval_desc = ""
if period_count == 1 then
period_interval_desc = "the root and " .. (rat.eq(input_mos.equave, 2) and "octave" or "equave")
else
period_interval_desc = "the period intervals"
end
result = result
.. string.format(" Each interval, apart from %s (%s), has two varieties, or sizes, each.", period_interval_desc, period_intervals_as_text)
result = result
.. " Interval varieties are named major and minor for the large and small sizes, respectively"
.. (input_mos.nL == input_mos.ns and "." or ", and augmented, perfect, and diminished for the scale's generators.")
return result
return result
end
end


-- Wrapper function; to be called by template
-- Wrapper function; to be called by template
function p.mos_intervals(frame)
function p.mos_interval_he(frame)
-- Get params
-- Get params
local scalesig  = frame.args["Scale Signature"]
local scalesig  = frame.args["Scale Signature"]
Line 200: Line 138:
mos_abbrev = tamnams.verify_abbrev(input_mos, mos_abbrev)
mos_abbrev = tamnams.verify_abbrev(input_mos, mos_abbrev)


return p.mos_intervals_description(input_mos, mos_prefix) .. "\n" .. p._mos_intervals(input_mos, mos_prefix, mos_abbrev, is_collapsed)
local result = p._mos_interval_he(input_mos, mos_prefix, mos_abbrev, is_collapsed)
local debugg = yesno(frame.args["debug"])
-- Debugger option
if debugg == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
end


return p
return p