Module:MOS intervals: Difference between revisions
Jump to navigation
Jump to search
Rewrite "main" function according to current personal standards |
Added abbreviations to table |
||
| Line 90: | Line 90: | ||
result = result .. '! Interval classes\n' | result = result .. '! Interval classes\n' | ||
result = result .. '! Specific intervals\n' | result = result .. '! Specific intervals\n' | ||
result = result .. '! Size (in ascending order)\n' | result = result .. '! Size\n(in ascending order)\n' | ||
result = result .. string.format("! Abbrev.\n") | |||
-- First row is the unison | -- First row is the unison | ||
| Line 111: | Line 112: | ||
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("| 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("| P%ims\n", i) | |||
elseif i % steps_per_period == steps_per_dark_gen and not is_nL_ns then | elseif i % steps_per_period == steps_per_dark_gen and not is_nL_ns then | ||
| Line 122: | Line 125: | ||
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("| 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("| A%ims\n", i) | |||
elseif i % steps_per_period == 0 and i ~= mossteps_per_equave then | elseif i % steps_per_period == 0 and i ~= mossteps_per_equave then | ||
| Line 133: | Line 138: | ||
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("| P%ims\n", i) | |||
else | else | ||
| Line 141: | Line 147: | ||
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("| 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("| M%ims\n", i) | |||
end | end | ||
| Line 155: | Line 163: | ||
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("| P%ims\n", steps_per_equave) | |||
else | else | ||
result = result .. "|-\n" | result = result .. "|-\n" | ||
| Line 160: | Line 169: | ||
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("| P%ims\n", steps_per_equave) | |||
end | end | ||
Revision as of 09:07, 3 December 2023
- This module should not be invoked directly; use its corresponding template instead: Template:MOS intervals.
This module generates a table showing interval varieties and qualities for a given MOS scale.
| Introspection summary for Module:MOS intervals | |||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| ||||||||||||||||||||||||||||||
No function descriptions were provided. The Lua code may have further information.
local mos = require('Module:MOS')
local rat = require('Module:Rational')
local ord = require('Module:Ordinal')
local utils = require('Module:Utils')
local p = {}
-- Helper function that turns a mosstep into a step count as a string
-- EG, the 3-mosstep of "LLsLsLs" becomes "2L + s"
function p.mos_interval_to_step_count_string(step_pattern, mossteps)
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
-- There are 9 combinations to write xL + ys, based on whether x and y are
-- 0, 1, or greater than 1
local return_string = ""
if L_count == 0 and s_count == 0 then
return_string = "0"
elseif L_count == 0 and s_count == 1 then
return_string = "s"
elseif L_count == 0 and s_count > 1 then
return_string = s_count .. "s"
elseif L_count == 1 and s_count == 0 then
return_string = "L"
elseif L_count == 1 and s_count == 1 then
return_string = "L + s"
elseif L_count == 1 and s_count > 1 then
return_string = "L + " .. s_count .. "s"
elseif L_count > 1 and s_count == 0 then
return_string = L_count .. "L"
elseif L_count > 1 and s_count == 1 then
return_string = L_count .. "L + s"
else
return_string = L_count .. "L + " .. s_count .. "s"
end
return return_string
end
-- Helper function
-- Extracts the prefix from the mos module, without the dash and without any text after that
-- May need to revisit to clean up code since this splits text at the "-"
function p.get_mos_prefix(scale_sig)
local unparsed = mos.tamnams_prefix[scale_sig]
local parsed = {}
if unparsed == nil then
return "mos"
else
for entry in string.gmatch(unparsed, '([^-]+)') do
local trimmed = entry:gsub("^%s*(.-)%s*$", "%1")
table.insert(parsed, trimmed) -- Add to array
end
return parsed[1]
end
end
function p.mos_intervals(input_mos, mos_prefix)
-- Default param for input mos is 5L 2s
local input_mos = input_mos or mos.new(2, 5, 2)
local mos_prefix = mos_prefix or "mos"
-- Get the scale sig
local scale_sig = mos.as_string(input_mos)
-- Get the brightest and darkest modes for the mos
local brightest_mode = mos.brightest_mode(input_mos)
local darkest_mode = string.reverse(brightest_mode)
-- Get the number of steps per period and equave
local steps_per_equave = (input_mos.nL + input_mos.ns)
local steps_per_period = steps_per_equave / utils._gcd(input_mos.nL, input_mos.ns)
-- Get the step counts for the bright and dark generators
local bright_gen = mos.bright_gen(input_mos)
local steps_per_bright_gen = bright_gen['L'] + bright_gen['s']
local steps_per_dark_gen = steps_per_period - steps_per_bright_gen
-- Create the table, starting with the headers
local result = '{| class="wikitable"\n'
result = result .. '|+Intevrals of ' .. scale_sig .. '\n'
result = result .. '! Interval classes\n'
result = result .. '! Specific intervals\n'
result = result .. '! Size\n(in ascending order)\n'
result = result .. string.format("! Abbrev.\n")
-- First row is the unison
result = result .. "|-\n"
result = result .. "|'''0-" .. mos_prefix .. "step (unison)'''\n"
result = result .. "|Perfect 0-" .. mos_prefix .. "step\n"
result = result .. "|0\n"
-- Successive rows are the mossteps, starting at the 1-mosstep
-- Name the interval according to whether it's major/minor or
-- perf/aug/dim; for nL ns mosses, it's only major/minor for any
-- non-period intervals.
local is_nL_ns = input_mos.nL == input_mos.ns
for i = 1, steps_per_equave - 1 do
if i % steps_per_period == steps_per_bright_gen and not is_nL_ns then
-- If i corresponds to the bright generator, then the large size is
-- perfect and the small size is diminished. Add two rows.
result = result .. "|-\n"
result = result .. '|rowspan="2"' .. "|'''" .. 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 .. string.format("| d%ims\n", i)
result = result .. "|-\n"
result = result .. "|Perfect " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(brightest_mode, i) .. "\n"
result = result .. string.format("| P%ims\n", i)
elseif i % steps_per_period == steps_per_dark_gen and not is_nL_ns then
-- If i corresponds to the dark generator, then the large size is
-- augmented and the small size is perfect. Add two rows.
result = result .. "|-\n"
result = result .. '|rowspan="2"' .. "|'''" .. 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 .. string.format("| P%ims\n", i)
result = result .. "|-\n"
result = result .. "|Augmented " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(brightest_mode, i) .. "\n"
result = result .. string.format("| A%ims\n", i)
elseif i % steps_per_period == 0 and i ~= mossteps_per_equave then
-- If i corresponds to the period, then the large and small sizes are
-- the same and they're perfect. This also applies to the equave. Add one row.
result = result .. "|-\n"
result = result .. "|'''" .. i .. "-" .. mos_prefix .. "step (period)'''\n"
result = result .. "|Perfect " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(darkest_mode, i) .. "\n"
result = result .. string.format("| P%ims\n", i)
else
-- For any other interval, and for generators for nL ns mosses, the
-- large size is major and the small size is minor. Add two rows.
result = result .. "|-\n"
result = result .. '|rowspan="2"' .. "|" .. 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 .. string.format("| m%ims\n", i)
result = result .. "|-\n"
result = result .. "|Major " .. i .. "-" .. mos_prefix .. "step\n"
result = result .. "|" .. p.mos_interval_to_step_count_string(brightest_mode, i) .. "\n"
result = result .. string.format("| M%ims\n", i)
end
end
-- Add the last row of the table, which is either the equave or octave
local equave_name = ""
if rat.eq(input_mos.equave, 2) then
result = result .. "|-\n"
result = result .. "|'''" .. steps_per_equave .. "-" .. mos_prefix .. "step (octave)'''\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 .. string.format("| P%ims\n", steps_per_equave)
else
result = result .. "|-\n"
result = result .. "|'''" .. steps_per_equave .. "-" .. mos_prefix .. "step (equave)'''\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 .. string.format("| P%ims\n", steps_per_equave)
end
result = result .. "|}"
return result
end
function p.mos_intervals_frame(frame)
-- Get input mos
local input_mos = mos.parse(frame.args['Scale Signature'])
-- Default param for mos prefix
-- If "NONE" is given, no prefix will be used
-- If left blank, try to find the appropriate mos prefix, or else defualt to "mos"
-- If not left blank, use the prefix passed in instead
local mos_prefix = "mos"
if mos_prefix == "NONE" then
mos_prefix = ""
elseif string.len(frame.args['MOS Prefix']) == 0 then
mos_prefix_lookup = p.get_mos_prefix(scale_sig)
if string.len(mos_prefix_lookup) ~= 0 then
mos_prefix = mos_prefix_lookup
end
else
mos_prefix = frame.args['MOS Prefix']
end
local result = p.mos_intervals(input_mos, mos_prefix)
return result
end
return p