Module:Scale tree: Difference between revisions
Attempted to stagger ratios |
ArrowHead294 (talk | contribs) mNo edit summary |
||
| (59 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
local MOS = require("Module:MOS") | |||
local ET = require("Module:ET") | |||
local rat = require("Module:Rational") | |||
local sb = require("Module:SB tree") | |||
local utils = require("Module:Utils") | |||
local yesno = require("Module:yesno") | |||
local p = {} | local p = {} | ||
-- Helper function that parses entries from a semicolon-delimited string and returns them in an array | -- Helper function that parses entries from a semicolon-delimited string and returns them in an array | ||
| Line 12: | Line 12: | ||
function p.parse_entries(unparsed) | function p.parse_entries(unparsed) | ||
local parsed = {} | local parsed = {} | ||
for entry in string.gmatch(unparsed, | -- for entry in string.gmatch(unparsed, "([^;]+)") do | ||
for entry in string.gmatch(unparsed, "([^%$]+)") do | |||
local trimmed = entry:gsub("^%s*(.-)%s*$", "%1") | local trimmed = entry:gsub("^%s*(.-)%s*$", "%1") | ||
table.insert(parsed, trimmed) -- Add to array | table.insert(parsed, trimmed) -- Add to array | ||
| Line 23: | Line 24: | ||
function p.parse_pair(unparsed) | function p.parse_pair(unparsed) | ||
local parsed = {} | local parsed = {} | ||
for entry in string.gmatch(unparsed, | for entry in string.gmatch(unparsed, "([^:]+)") do | ||
local trimmed = entry:gsub("^%s*(.-)%s*$", "%1") | local trimmed = entry:gsub("^%s*(.-)%s*$", "%1") | ||
table.insert(parsed, trimmed) -- Add to array | table.insert(parsed, trimmed) -- Add to array | ||
| Line 65: | Line 66: | ||
local step_ratios = sb.sb_tree_ratios(depth) | local step_ratios = sb.sb_tree_ratios(depth) | ||
local depths = sb.sb_tree_depths(depth) | local depths = sb.sb_tree_depths(depth) | ||
-- What is the equave suffix (edo, edt, edf, ed-p/q) | |||
local equave_suffix = "" | |||
if rat.eq(input_mos.equave, rat.new(2)) then | |||
equave_suffix = "o" | |||
elseif rat.eq(input_mos.equave, rat.new(3)) then | |||
equave_suffix = "t" | |||
elseif rat.eq(input_mos.equave, rat.new(3, 2)) then | |||
equave_suffix = "f" | |||
else | |||
equave_suffix = rat.as_ratio(input_mos.equave) | |||
end | |||
-- Default comments for TAMNAMS-named step ratios | -- Default comments for TAMNAMS-named step ratios | ||
local default_comments = {} | local default_comments = {} | ||
default_comments["1/1"] = "Equalized " | local mos_as_string = MOS.as_string(input_mos) | ||
default_comments["4/3"] = "Supersoft " | default_comments["1/1"] = string.format("'''Equalized %s'''", mos_as_string) | ||
default_comments["3/2"] = "Soft " | default_comments["4/3"] = string.format("'''Supersoft %s'''", mos_as_string) | ||
default_comments["5/3"] = "Semisoft " | default_comments["3/2"] = string.format("'''Soft %s'''", mos_as_string) | ||
default_comments["2/1"] = "Basic " | default_comments["5/3"] = string.format("'''Semisoft %s'''", mos_as_string) | ||
default_comments["5/2"] = "Semihard " | default_comments["2/1"] = string.format("'''Basic %s'''", mos_as_string) | ||
default_comments["3/1"] = "Hard " | default_comments["5/2"] = string.format("'''Semihard %s'''", mos_as_string) | ||
default_comments["4/1"] = "Superhard " | default_comments["3/1"] = string.format("'''Hard %s'''", mos_as_string) | ||
default_comments["1/0"] = "Collapsed " .. | default_comments["4/1"] = string.format("'''Superhard %s'''", mos_as_string) | ||
default_comments["1/0"] = string.format("'''Collapsed %s'''", mos_as_string) | |||
-- Append boundary of proper scales to basic comment, if applicable | |||
-- Monosmall mosses and knL ns mosses are always proper, but all other mosses | |||
-- are proper if the step ratio is within the soft-of-basic range | |||
if n < s then | |||
default_comments["2/1"] = default_comments["2/1"] .. "<br />Scales with tunings softer than this are proper" | |||
end | |||
-- | -- Produce table header for the comments | ||
local | local comments_header_text = "Comments" | ||
if s == 1 then | |||
comments_header_text = comments_header_text .. "<sup><abbr title=\"Every tuning produces a proper scale.\">(always proper)</abbr></sup>" | |||
elseif s == n and n > 1 then | |||
comments_header_text = comments_header_text .. "<sup><abbr title=\"Every true-MOS tuning produces a proper scale.\">(always proper)</abbr></sup>" | |||
end | |||
-- Table headers | -- Table headers | ||
| Line 87: | Line 113: | ||
-- - Step ratio and hardness | -- - Step ratio and hardness | ||
-- - Comments | -- - Comments | ||
result = | local result = "{| class=\"wikitable center-all\"\n" | ||
.. "|+ style=\"font-size: 105%; white-space: nowrap;\" | " .. string.format("Scale tree and tuning spectrum of %s\n", mos_as_string) | |||
.. "|-\n" | |||
.. string.format("! rowspan=\"2\" colspan=\"%d\" | Generator<sup><abbr title=\"In steps of ed%s.\">(ed%s)</abbr></sup>\n", depth + 1, equave_suffix, equave_suffix) | |||
.. "! colspan=\"2\" | Cents\n" | |||
.. "! colspan=\"2\" | Step ratio\n" | |||
.. "! rowspan=\"2\" | " .. comments_header_text .. "\n" | |||
.. "|-\n" | |||
.. "! Bright\n" | |||
.. "! Dark\n" | |||
.. "! L:s\n" | |||
.. "! Hardness\n" | |||
-- Rounding is done using string.format, to 3 decimal places (%.3f) | -- Rounding is done using string.format, to 3 decimal places (%.3f) | ||
| Line 109: | Line 136: | ||
-- Calculate the bright gen and cent value | -- Calculate the bright gen and cent value | ||
local bright_generator_steps = step_ratio[1] * abstract_bright_gen[ | local bright_generator_steps = step_ratio[1] * abstract_bright_gen["L"] + step_ratio[2] * abstract_bright_gen["s"] | ||
local bright_generator_cents = ET.cents(et, bright_generator_steps) | local bright_generator_cents = ET.cents(et, bright_generator_steps) | ||
| Line 121: | Line 148: | ||
-- Cells for bright generator, as steps in et | -- Cells for bright generator, as steps in et | ||
local current_depth = depths[i] | local current_depth = depths[i] | ||
for i = 1, depth+1 do | for i = 1, depth + 1 do | ||
result = result .. "| " | |||
if i == current_depth then | if i == current_depth then | ||
result = result .. string.format(" | result = result .. string.format("[[%s|%d\\%s]]", ET.as_string(et), bright_generator_steps, et.size) | ||
end | end | ||
result = result .. "\n" | |||
end | end | ||
| Line 139: | Line 166: | ||
local hardness = "" | local hardness = "" | ||
if step_ratio[2] == 0 then | if step_ratio[2] == 0 then | ||
hardness = " | hardness = "→ ∞" | ||
else | else | ||
hardness = string.format("%.3f", step_ratio[1] / step_ratio[2]) | hardness = string.format("%.3f", step_ratio[1] / step_ratio[2]) | ||
| Line 146: | Line 173: | ||
-- Cell for comment | -- Cell for comment | ||
-- Default comments are on their own line before custom comments | |||
local key = step_ratios[i][1] .. "/" .. step_ratios[i][2] -- The step ratio is (literally and figuratively) the key to add comments! | local key = step_ratios[i][1] .. "/" .. step_ratios[i][2] -- The step ratio is (literally and figuratively) the key to add comments! | ||
local comment = "" | local comment = "" | ||
local default_comment = default_comments[key] or "" | |||
local custom_comment = comments[key] or "" | |||
if default_comment == "" then | |||
comment = | comment = custom_comment | ||
else | |||
comment = | comment = default_comment .. "<br />" .. custom_comment | ||
end | end | ||
result = result .. string.format("| %s\n", comment) | result = result .. string.format("| style=\"text-align: left;\" | %s\n", comment) | ||
end | end | ||
| Line 165: | Line 189: | ||
result = result .. "|}" | result = result .. "|}" | ||
return result | return result | ||
end | end | ||
| Line 174: | Line 197: | ||
local comments = p.parse_kv_pairs(comments_unparsed) or {} | local comments = p.parse_kv_pairs(comments_unparsed) or {} | ||
local | local out_str = p._scale_tree(mos, depth, comments) | ||
return | local debugg = yesno(frame.args["debug"]) | ||
return frame:preprocess(debugg == true and "<pre>" .. out_str .. "</pre>" or out_str) | |||
end | end | ||
return p | return p | ||