Module:MOS interval HE: Difference between revisions

Ganaram inukshuk (talk | contribs)
mNo edit summary
ArrowHead294 (talk | contribs)
mNo edit summary
 
(5 intermediate revisions by the same user 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 = {}


-- Main function; to be called by wrapper
-- Main function; to be called by wrapper
Line 51: Line 52:
-- Create table headers
-- Create table headers
result = result
result = result
.. "! Interval"
.. "! Interval "
.. "!! Range in cents"
.. "!! Range in cents "
.. "!! Average of [[HE]]<br/>(from [http://www.mikebattagliamusic.com/HE-JS/HE.html HE Calc])"
.. "!! Average of [[HE]]<br />(from [http://www.mikebattagliamusic.com/HE-JS/HE.html HE Calc]) "
.. "!! Min of [[HE]]\n"
.. "!! Min of [[HE]]\n"
Line 69: 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 " , tamnams.interval_quality(current_bright_interval, input_mos, "sentence-case", mos_prefix))
tamnams.interval_quality(current_bright_interval, input_mos, "sentence-case", mos_prefix),
.. string.format("|| %.1f¢ ", cents)
cents,
.. string.format("|| ~%.4f nats ", interval_extension.harmonic_entropy_with_lookup_table(cents))
ie.harmonic_entropy_with_lookup_table(cents),
.. string.format("|| ~%.4f nats", interval_extension.harmonic_entropy_with_lookup_table(cents))
ie.harmonic_entropy_with_lookup_table(cents))
else
else
-- Calculate the best and average harmonic entropies
-- Calculate the best and average harmonic entropies
Line 82: 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 102: 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("|| %s " , tamnams.interval_quality(current_dark_interval, input_mos, "sentence-case", mos_prefix))
tamnams.interval_quality(current_dark_interval, input_mos, "sentence-case", mos_prefix),
.. string.format("|| %s " , dark_interval_range)
dark_interval_range,
.. string.format("|| ~%.4f nats " , he_dark_average)
he_dark_average,
.. string.format("|| ~%.4f nats\n" , he_dark_best)
he_dark_best,
.. "|-\n"
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))
bright_interval_range,
.. string.format("|| %s " , bright_interval_range)
he_bright_average,
.. string.format("|| ~%.4f nats " , he_bright_average)
he_bright_best)
.. string.format("|| ~%.4f nats" , he_bright_best)
end
end
result = result .. "\n"
result = result .. "\n"
Line 138: Line 138:
mos_abbrev = tamnams.verify_abbrev(input_mos, mos_abbrev)
mos_abbrev = tamnams.verify_abbrev(input_mos, mos_abbrev)


return p._mos_interval_he(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