Module:MOS intervals: Difference between revisions

R-4981 (talk | contribs)
Very sorry
R-4981 (talk | contribs)
No edit summary
Line 5: Line 5:
local et = require('Module:ET')
local et = require('Module:ET')
local tamnams = require('Module:TAMNAMS')
local tamnams = require('Module:TAMNAMS')
local interval_extension = require('Module:Interval_extension')
local p = {}
local p = {}


Line 31: Line 32:
local bright_gen_step_count = mos.bright_gen_step_count(input_mos)
local bright_gen_step_count = mos.bright_gen_step_count(input_mos)
local dark_gen_step_count = mos.dark_gen_step_count(input_mos)
local dark_gen_step_count = mos.dark_gen_step_count(input_mos)
-- Setup for harmonic entropy
local step_ratios = {
{ 4, 3 },
{ 3, 2 },
{ 5, 3 },
{ 2, 1 },
{ 5, 2 },
{ 3, 1 },
{ 4, 1 },
}
-- Create the table, starting with the headers
-- Create the table, starting with the headers
Line 38: Line 50:
result = result .. '! rowspan="2" | Steps subtended\n'
result = result .. '! rowspan="2" | Steps subtended\n'
result = result .. '! rowspan="2" | Range in cents\n'
result = result .. '! rowspan="2" | Range in cents\n'
result = result .. '! rowspan="2" | [[Harmonic entropy]]<br/>(Shannon, <math>\\sqrt{n\\cdot d}</math>)\n'
result = result .. '|-\n'
result = result .. '|-\n'
result = result .. '! Generic<sup>[[#mosstep-1|[1]]]</sup>\n'
result = result .. '! Generic<sup>[[#mosstep-1|[1]]]</sup>\n'
Line 63: Line 76:
result = result .. string.format("| %s\n" , mos.interval_as_string(current_bright_interval))
result = result .. string.format("| %s\n" , mos.interval_as_string(current_bright_interval))
result = result .. string.format("| %.1f¢\n", cents)
result = result .. string.format("| %.1f¢\n", cents)
result = result .. string.format("| %.6f nats\n", interval_extension.harmonic_entropy_with_lookup_table(cents))
else
else
-- Calculate the best and average harmonic entropies
local he_dark_average = 0
local he_bright_average = 0
local he_dark_best = 1000
local he_bright_best = 1000
for i = 1, #step_ratios do
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_bright = interval_extension.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_bright_average = he_bright_average + he_bright / #step_ratios
if he_dark_best > he_dark then
he_dark_best = he_dark
end
if he_bright_best > he_bright then
he_bright_best = he_bright
end
end
-- Calculate the cent values min and max for the current intervals
-- Calculate the cent values min and max for the current intervals
local sm_min_cents = mos.interval_to_cents(current_dark_interval, input_mos, {1,1})
local sm_min_cents = mos.interval_to_cents(current_dark_interval, input_mos, {1,1})
Line 81: Line 114:
result = result .. string.format("| %s\n" , mos.interval_as_string(current_dark_interval))
result = result .. string.format("| %s\n" , mos.interval_as_string(current_dark_interval))
result = result .. string.format("| %s\n" , dark_interval_range)
result = result .. string.format("| %s\n" , dark_interval_range)
result = result .. string.format("| %.6f¢ nats (average), %.6f¢ nats (min)\n" , he_dark_average, he_dark_best)
result = result .. "|-\n"
result = result .. "|-\n"
Line 87: Line 121:
result = result .. string.format("| %s\n" , mos.interval_as_string(current_bright_interval))
result = result .. string.format("| %s\n" , mos.interval_as_string(current_bright_interval))
result = result .. string.format("| %s\n" , bright_interval_range)
result = result .. string.format("| %s\n" , bright_interval_range)
result = result .. string.format("| %.6f¢ nats (average), %.6f¢ nats (min)\n" , he_bright_average, he_bright_best)
end
end