Module:Scale tree: Difference between revisions
Entries for the scale tree are now trimmed of extra spaces, so delimiters may have spaces before and after |
Added default comments as part of the module to make sure the scale signature is written correctly |
||
| Line 64: | Line 64: | ||
local depth = frame.args['depth'] or 5 | local depth = frame.args['depth'] or 5 | ||
local step_ratios = sb.sb_tree_ratios(depth) | local step_ratios = sb.sb_tree_ratios(depth) | ||
-- Default comments; these correspond to the TAMNAMS-named step ratios | |||
local default_comments | |||
default_comments['1/1'] = "Equalized " .. MOS.as_string(mos) | |||
default_comments['4/3'] = "Supersoft " .. MOS.as_string(mos) | |||
default_comments['3/2'] = "Soft " .. MOS.as_string(mos) | |||
default_comments['5/3'] = "Semisoft " .. MOS.as_string(mos) | |||
default_comments['2/1'] = "Basic " .. MOS.as_string(mos) | |||
default_comments['5/2'] = "Semihard " .. MOS.as_string(mos) | |||
default_comments['3/1'] = "Hard " .. MOS.as_string(mos) | |||
default_comments['4/1'] = "Superhard " .. MOS.as_string(mos) | |||
default_comments['1/0'] = "Collapsed " .. MOS.as_string(mos) | |||
-- Get comments | -- Get comments | ||
| Line 87: | Line 99: | ||
-- Entry of comments is done using an associative array, as entries may be sparse | -- Entry of comments is done using an associative array, as entries may be sparse | ||
-- If a default comment exists, it goes first and the custom comment is added on a newline in the cell itself | |||
-- Old code commented out | -- Old code commented out | ||
--local comments = frame.args[("comment_" .. step_ratio[1] .. "_" .. step_ratio[2])] or "" | --local comments = frame.args[("comment_" .. step_ratio[1] .. "_" .. step_ratio[2])] or "" | ||
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 contains_default_comment = default_comments[key] ~= nil | |||
local contains_custom_comment = comments[key] ~= nil | |||
if contains_default_comment and contains_custom_comment then | |||
comment = default_comments[key] .. "<br>" .. comments[key] | |||
elseif contains_default_comment and not contains_custom_comment then | |||
comment = comments[key] | comment = comments[key] | ||
elseif not contains_default_comment and contains_custom_comment then | |||
comment = default_comments[key] | |||
end | end | ||