Module:MOS interval HE: Difference between revisions
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 tamnams = require("Module:TAMNAMS") | local tamnams = require("Module:TAMNAMS") | ||
local yesno = require("Module:Yesno") | local yesno = require("Module:Yesno") | ||
-- 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 nats || ~%.4f nats", | ||
tamnams.interval_quality(current_bright_interval, input_mos, "sentence-case", mos_prefix), | |||
cents, | |||
ie.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 = | local he_dark = ie.harmonic_entropy_with_lookup_table(mos.interval_to_cents(current_dark_interval, input_mos, step_ratio)) | ||
local he_bright = | 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("%. | 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("%. | 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 | result = result .. string.format("|-\n| %s || %s || ~%.4f nats || ~%.4f nats\n|-\n| %s || %s || ~%.4f nats || ~%.4f nats", | ||
tamnams.interval_quality(current_dark_interval, input_mos, "sentence-case", mos_prefix), | |||
dark_interval_range, | |||
he_dark_average, | |||
he_dark_best, | |||
tamnams.interval_quality(current_bright_interval, input_mos, "sentence-case", mos_prefix), | |||
bright_interval_range, | |||
he_bright_average, | |||
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) | ||
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 | ||