Module:MOS tunings: Difference between revisions
Jump to navigation
Jump to search
m correct function name |
m a module |
||
| Line 2: | Line 2: | ||
local tamnams = require("Module:TAMNAMS") | local tamnams = require("Module:TAMNAMS") | ||
local et = require("Module:ET") | local et = require("Module:ET") | ||
local yesno = require("Module:Yesno") | |||
local p = {} | local p = {} | ||
Revision as of 08:00, 22 August 2024
- This module should not be invoked directly; use its corresponding template instead: Template:MOS tunings.
This module displays the cent values of a MOS scale's degrees under various tunings, or step ratios, as well as the nearest JI ratios represented by those scale degrees.
| Introspection summary for Module:MOS tunings | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| ||||||||||||||||||||||||
No function descriptions were provided. The Lua code may have further information.
local mos = require("Module:MOS")
local tamnams = require("Module:TAMNAMS")
local et = require("Module:ET")
local yesno = require("Module:Yesno")
local p = {}
-- Rewritten/simplified module replacement for Module:MOS degrees
-- A new template is chosen because it's a better name than the old one
-- TODO:
-- - Header capitalization
-- - Text align
-- - Step ratio input (only the simple ratios are being displayed)
-- - JI ratio input??
-- - Diatonic interval category lookup?!!
-- Main function
function p._mos_tunings(input_mos, mos_prefix, mos_abbrev, step_ratios)
local input_mos = input_mos or mos.new(5,2)
local mos_prefix = mos_prefix or "mos"
local mos_abbrev = mos_abbrev or "m"
local step_ratios = step_ratios or { {2,1}, {3,1}, {3,2} }
local modal_union = mos.modal_union(input_mos)
local scale_sig = mos.as_string(input_mos)
-- Create table
local result = "{| class=\"wikitable sortable\"\n"
-- Table caption
result = result .. string.format("|+ style=\"font-size: 105%%; white-space: nowrap;\" | Tunings of %s\n", scale_sig)
-- First row of headers
-- First two headers span two rows
result = result .. "! rowspan=\"2\" class=\"unsortable\" | Scale degree\n"
result = result .. "! rowspan=\"2\" class=\"unsortable\" | Abbrev.\n"
-- Headers for tunings; these span two cols
for i = 1, #step_ratios do
local step_ratio_as_text = tamnams.lookup_step_ratio(step_ratios[i]) or string.format("%s:%s", step_ratios[i][1], step_ratios[i][2])
local et_as_string = et.as_string(mos.mos_to_et(input_mos, step_ratios[i]))
local header_text = string.format("%s<br>%s", step_ratio_as_text, et_as_string)
result = result .. string.format("! colspan=\"2\" | %s\n", header_text)
end
result = result .. "|-\n"
-- Second row of headers
for i = 1, #step_ratios do
result = result .. "! Steps\n"
result = result .. "! Cents\n"
end
-- Add a for each scale degree
for i = 1, #modal_union do
local interval = modal_union[i]
-- Add cells for the degree names
local degree_name = tamnams.degree_quality(interval, input_mos, "sentence-case", mos_prefix)
local degree_abbrev = tamnams.degree_quality(interval, input_mos, "abbrev" , mos_abbrev)
result = result
.. "|-\n"
.. string.format("| %s || %s", degree_name, degree_abbrev)
-- Add cells for each interval's tunings
for j = 1, #step_ratios do
local step_ratio = step_ratios[j]
local step_count = mos.interval_to_et_steps(interval, step_ratio)
local cents = mos.interval_to_cents(interval, input_mos, step_ratio)
result = result
.. " "
.. string.format("|| %s\\%s || %.1f", step_count, input_mos.nL * step_ratio[1] + input_mos.ns * step_ratio[2], cents)
end
result = result .. "\n"
end
-- End of table
result = result .. "|}"
return result
end
-- Wrapper function; to be called by template
function p.mos_tunings(frame)
-- Get params
local scalesig = frame.args["Scale Signature"]
local mos_prefix = frame.args["MOS Prefix"]
local mos_abbrev = frame.args["MOS Abbrev"]
local collapsed = yesno(frame.args["Collapsed"], false) -- Currently does nothing
-- Parse scalesig
local input_mos = mos.parse(scalesig)
-- Verify name/prefix/abbrev
mos_prefix = tamnams.verify_prefix(input_mos, mos_prefix)
mos_abbrev = tamnams.verify_abbrev(input_mos, mos_abbrev)
return p._mos_tunings(input_mos, mos_prefix, mos_abbrev)
end
return p