Module:MOS intervals: Difference between revisions

m -typo
Ganaram inukshuk (talk | contribs)
Added step size ranges, specified mosstep relations with respect to root
Line 3: Line 3:
local ord = require('Module:Ordinal')
local ord = require('Module:Ordinal')
local utils = require('Module:Utils')
local utils = require('Module:Utils')
local et = require('Module:ET')
local p = {}
local p = {}


Line 43: Line 44:
end
end
return return_string
return return_string
end
-- Helper function
-- Produces the cent range for a mosstep
function p.mos_interval_to_cent_range(step_pattern, mossteps, input_mos)
local nL = input_mos.nL
local ns = input_mos.ns
local equave_in_cents = rat.cents(input_mos.equave)
local L_count = 0
local s_count = 0
for i = 1, mossteps do
local step =  string.sub(step_pattern, i, i)
if step == "L" then
L_count = L_count + 1
elseif step == "s" then
s_count = s_count + 1
end
end
local result = ""
if utils._gcd(nL, ns) > 1 then
result = string.format("%.1f¢", (L_count + s_count) * equave_in_cents / (nL + ns))
else
local lim1 = (L_count + s_count) * equave_in_cents / (nL + ns)
local lim2 = (L_count) * equave_in_cents / (nL)
result = string.format("%.1f¢ to %.1f¢", math.min(lim1, lim2), math.max(lim1, lim2))
end
return result
end
end


Line 66: Line 97:
function p.mos_intervals(input_mos, mos_prefix)
function p.mos_intervals(input_mos, mos_prefix)
-- Default param for input mos is 5L 2s
-- Default param for input mos is 5L 2s
local input_mos = input_mos or mos.new(2, 5, 2)
local input_mos = input_mos or mos.new(5, 2, 2)
local mos_prefix = mos_prefix or "mos"
local mos_prefix = mos_prefix or "dia"
-- Get the scale sig
-- Get the scale sig
Line 88: Line 119:
local result = '{| class="wikitable"\n'
local result = '{| class="wikitable"\n'
result = result .. '|+Intervals of ' .. scale_sig .. '\n'
result = result .. '|+Intervals of ' .. scale_sig .. '\n'
result = result .. '! Interval classes\n'
result = result .. '! colspan="2" |Intervals-\n'
result = result .. '! Specific intervals\n'
result = result .. '! colspan="2" |Size-\n'
result = result .. '! Size in L\'s and s\'s\n'
result = result .. '! rowspan="2" |Abbrev.-\n'
result = result .. string.format("! Abbrev.\n")
result = result .. '|-\n'
result = result .. '!Generic (relation to root)-\n'
result = result .. '!Specific-\n'
result = result .. '!L\'s and s\'s-\n'
result = result .. '!Cents-\n'
-- First row is the unison
-- First row is the unison
result = result .. "|-\n"
result = result .. "|-\n"
result = result .. "|'''0-" .. mos_prefix .. "step (unison)'''\n"
result = result .. "|'''0-" .. mos_prefix .. "step (root)'''\n"
result = result .. "|Perfect 0-" .. mos_prefix .. "step\n"
result = result .. "|Perfect 0-" .. mos_prefix .. "step\n"
result = result .. "|0\n"
result = result .. "|0\n"
result = result .. string.format("| %.1f¢\n", 0)
result = result .. string.format("| P0ms\n")
result = result .. string.format("| P0ms\n")
Line 113: Line 149:
result = result .. "|Diminished " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|Diminished " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(darkest_mode, i) .. "\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(darkest_mode, i) .. "\n"
result = result .. string.format("| %s\n", p.mos_interval_to_cent_range(darkest_mode, i, input_mos))
result = result .. string.format("| d%ims\n", i)
result = result .. string.format("| d%ims\n", i)
result = result .. "|-\n"
result = result .. "|-\n"
result = result .. "|Perfect " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|Perfect " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(brightest_mode, i) .. "\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(brightest_mode, i) .. "\n"
result = result .. string.format("| %s\n", p.mos_interval_to_cent_range(brightest_mode, i, input_mos))
result = result .. string.format("| P%ims\n", i)
result = result .. string.format("| P%ims\n", i)
Line 126: Line 164:
result = result .. "|Perfect " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|Perfect " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(darkest_mode, i) .. "\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(darkest_mode, i) .. "\n"
result = result .. string.format("| %s\n", p.mos_interval_to_cent_range(darkest_mode, i, input_mos))
result = result .. string.format("| P%ims\n", i)
result = result .. string.format("| P%ims\n", i)
result = result .. "|-\n"
result = result .. "|-\n"
result = result .. "|Augmented " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|Augmented " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(brightest_mode, i) .. "\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(brightest_mode, i) .. "\n"
result = result .. string.format("| %s\n", p.mos_interval_to_cent_range(brightest_mode, i, input_mos))
result = result .. string.format("| A%ims\n", i)
result = result .. string.format("| A%ims\n", i)
Line 139: Line 179:
result = result .. "|Perfect " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|Perfect " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(darkest_mode, i) .. "\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(darkest_mode, i) .. "\n"
result = result .. string.format("| %s\n", p.mos_interval_to_cent_range(darkest_mode, i, input_mos))
result = result .. string.format("| P%ims\n", i)
result = result .. string.format("| P%ims\n", i)
Line 148: Line 189:
result = result .. "|Minor " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|Minor " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(darkest_mode, i) .. "\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(darkest_mode, i) .. "\n"
result = result .. string.format("| %s\n", p.mos_interval_to_cent_range(darkest_mode, i, input_mos))
result = result .. string.format("| m%ims\n", i)
result = result .. string.format("| m%ims\n", i)
result = result .. "|-\n"
result = result .. "|-\n"
result = result .. "|Major " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|Major " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(brightest_mode, i) .. "\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(brightest_mode, i) .. "\n"
result = result .. string.format("| %s\n", p.mos_interval_to_cent_range(brightest_mode, i, input_mos))
result = result .. string.format("| M%ims\n", i)
result = result .. string.format("| M%ims\n", i)
Line 164: Line 207:
result = result .. "|Perfect " .. steps_per_equave .. "-" .. mos_prefix .. "step'''\n"
result = result .. "|Perfect " .. steps_per_equave .. "-" .. mos_prefix .. "step'''\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(darkest_mode, steps_per_equave) .. "\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(darkest_mode, steps_per_equave) .. "\n"
result = result .. string.format("| %.1f¢\n", 1200)
result = result .. string.format("| P%ims\n", steps_per_equave)
result = result .. string.format("| P%ims\n", steps_per_equave)
else
else
Line 170: Line 214:
result = result .. "|Perfect " .. steps_per_equave .. "-" .. mos_prefix .. "step'''\n"
result = result .. "|Perfect " .. steps_per_equave .. "-" .. mos_prefix .. "step'''\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(darkest_mode, steps_per_equave) .. "\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(darkest_mode, steps_per_equave) .. "\n"
result = result .. string.format("| %.1f¢\n", rat.cents(input_mos.equave))
result = result .. string.format("| P%ims\n", steps_per_equave)
result = result .. string.format("| P%ims\n", steps_per_equave)
end
end