Module:MOS intervals: Difference between revisions
m bugfix lookup code |
todo |
||
| (5 intermediate revisions by the same user not shown) | |||
| Line 6: | Line 6: | ||
local tamnams = require("Module:TAMNAMS") | local tamnams = require("Module:TAMNAMS") | ||
local yesno = require("Module:Yesno") | local yesno = require("Module:Yesno") | ||
-- -- TODO: | |||
-- - (High priority): Refactor code so instead of string concatenation, lines | |||
-- are appended to a table, where table.concat() is called at the end. | |||
-- EXPERIMENTAL FEATURE: lookup table for intervals | -- EXPERIMENTAL FEATURE: lookup table for intervals | ||
| Line 55: | Line 59: | ||
local mos_abbrev = args["MOS Abbrev" ] or "m" | local mos_abbrev = args["MOS Abbrev" ] or "m" | ||
local is_collapsed = args["Is Collapsed"] == true | local is_collapsed = args["Is Collapsed"] == true | ||
local show_inregs = | local show_inregs = false | ||
-- Get the scale sig | -- Get the scale sig | ||
| Line 102: | Line 106: | ||
-- Otherwise, there are two rows to write, one for each size. | -- Otherwise, there are two rows to write, one for each size. | ||
if is_period then | if is_period then | ||
local cents = string.format("%.1f{{c}}", | local cents = mos.interval_to_cents(current_bright_interval, input_mos, {1, 1}) | ||
local cents_formatted = string.format("%.1f{{c}}", cents) | |||
result = result | result = result | ||
| Line 110: | Line 115: | ||
.. "| " .. tamnams.interval_quality(current_bright_interval, input_mos, "abbrev" , mos_abbrev) .. "\n" | .. "| " .. tamnams.interval_quality(current_bright_interval, input_mos, "abbrev" , mos_abbrev) .. "\n" | ||
.. "| <span style=\"white-space: nowrap;\">" .. mos.interval_as_string(current_bright_interval) .. "</span>\n" | .. "| <span style=\"white-space: nowrap;\">" .. mos.interval_as_string(current_bright_interval) .. "</span>\n" | ||
.. "| " .. | .. "| " .. cents_formatted .. "\n" | ||
.. (show_inregs and string.format("| %s\n", p.lookup_interval_range(cents)) or "") | .. (show_inregs and string.format("| %s\n", p.lookup_interval_range(cents)) or "") | ||
else | else | ||
| Line 121: | Line 126: | ||
-- 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("%.1f{{c}} to %.1f{{c}}", | local sm_min_sorted = math.min(sm_min_cents, sm_max_cents) | ||
local bright_interval_range = string.format("%.1f{{c}} to %.1f{{c}}", | local sm_max_sorted = math.max(sm_min_cents, sm_max_cents) | ||
local lg_min_sorted = math.min(lg_min_cents, lg_max_cents) | |||
local lg_max_sorted = math.max(lg_min_cents, lg_max_cents) | |||
-- Produce text ranges for intervals | |||
local dark_interval_range = string.format("%.1f{{c}} to %.1f{{c}}", sm_min_sorted, sm_max_sorted) | |||
local bright_interval_range = string.format("%.1f{{c}} to %.1f{{c}}", lg_min_sorted, lg_max_sorted) | |||
result = result | result = result | ||
| Line 131: | Line 142: | ||
.. "| <span style=\"white-space: nowrap;\">" .. mos.interval_as_string(current_dark_interval) .. "</span>\n" | .. "| <span style=\"white-space: nowrap;\">" .. mos.interval_as_string(current_dark_interval) .. "</span>\n" | ||
.. "| " .. dark_interval_range .. "\n" | .. "| " .. dark_interval_range .. "\n" | ||
.. (show_inregs and string.format("| %s to %s\n", p.lookup_interval_range(sm_min_sorted), p.lookup_interval_range(sm_max_sorted)) or "") | |||
.. "|-\n" | .. "|-\n" | ||
.. "| " .. tamnams.interval_quality(current_bright_interval, input_mos, "sentence-case", mos_prefix) .. "\n" | .. "| " .. tamnams.interval_quality(current_bright_interval, input_mos, "sentence-case", mos_prefix) .. "\n" | ||
| Line 136: | Line 148: | ||
.. "| <span style=\"white-space: nowrap;\">" .. mos.interval_as_string(current_bright_interval) .. "</span>\n" | .. "| <span style=\"white-space: nowrap;\">" .. mos.interval_as_string(current_bright_interval) .. "</span>\n" | ||
.. "| " .. bright_interval_range .. "\n" | .. "| " .. bright_interval_range .. "\n" | ||
.. (show_inregs and string.format("| %s to %s\n", p.lookup_interval_range( | .. (show_inregs and string.format("| %s to %s\n", p.lookup_interval_range(lg_min_sorted), p.lookup_interval_range(lg_max_sorted)) or "") | ||
end | end | ||