Module:MOS interval HE: Difference between revisions
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 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 | ||
function p. | 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(" | .. "|+ 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 | ||
.. "! | .. "! Interval " | ||
.. "!! Range in cents " | |||
.. "!! | .. "!! Average of [[HE]]<br />(from [http://www.mikebattagliamusic.com/HE-JS/HE.html HE Calc]) " | ||
.. "!! | .. "!! Min of [[HE]]\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 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 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 = | 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 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("%. | 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 136: | Line 120: | ||
result = result .. "|}" | result = result .. "|}" | ||
return result | return result | ||
end | end | ||
-- Wrapper function; to be called by template | -- Wrapper function; to be called by template | ||
function p. | 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) | ||
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 | ||