Module:MOS tuning spectrum: Difference between revisions
add in-progress function for splitting in-range comments and out-of-range comments |
mNo edit summary |
||
| (5 intermediate revisions by the same user not shown) | |||
| Line 5: | Line 5: | ||
local yesno = require("Module:yesno") | local yesno = require("Module:yesno") | ||
local getArgs = require("Module:Arguments").getArgs | local getArgs = require("Module:Arguments").getArgs | ||
local p = {} | local p = {} | ||
-- TODO: | -- TODO: | ||
-- - Add back old option from previous scale tree: toggle staggering of ratios. | |||
-- - (Low priority): Force-add comments that lie outside searched depth. If such | -- - (Low priority): Force-add comments that lie outside searched depth. If such | ||
-- ratios are added, they're added in either the last column or their own | -- ratios are added, they're added in either the last column or their own | ||
-- column appended after the last one. | -- column appended after the last one. (to be determined) | ||
-- Split comments into in-range and out-of-range comments. | -- Split comments into in-range and out-of-range comments. | ||
| Line 16: | Line 18: | ||
-- in the table of step ratios. If so, add the corresponding key-value pair into | -- in the table of step ratios. If so, add the corresponding key-value pair into | ||
-- the table of in-comments; if not, add to the table of out-comments. | -- the table of in-comments; if not, add to the table of out-comments. | ||
function p.preprocess_comments(comments, step_ratios) | function p.preprocess_comments(comments, step_ratios, depths) | ||
local in_comments = {} | local in_comments = {} | ||
local out_comments = {} | local out_comments = {} | ||
local out_ratios = {} | local out_ratios = {} | ||
for key, value in pairs(comments) do | for key, value in pairs(comments) do | ||
| Line 73: | Line 75: | ||
default_comments["4/1"] = string.format("'''Superhard %s'''", mos_as_string) | default_comments["4/1"] = string.format("'''Superhard %s'''", mos_as_string) | ||
default_comments["1/0"] = string.format("'''Collapsed %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 | -- Append boundary of proper scales to basic comment, if applicable | ||
| Line 97: | Line 97: | ||
-- - Step ratio and hardness | -- - Step ratio and hardness | ||
-- - Comments | -- - Comments | ||
local result = | local result = {} | ||
table.insert(result, '{| class="wikitable center-all"') | |||
table.insert(result, '|+ style="font-size: 105%; white-space: nowrap;" | Scale tree and tuning spectrum of ' .. mos_as_string) | |||
table.insert(result, '|-') | |||
table.insert(result, string.format('! rowspan="2" colspan="%d" | Generator<sup><abbr title="In steps of %s.">(%s)</abbr></sup>', deepest + 1, et_suffix, et_suffix)) | |||
table.insert(result, '! colspan="2" | Cents') | |||
table.insert(result, '! colspan="2" | Step ratio') | |||
table.insert(result, string.format('! rowspan="2" | %s', comments_header_text)) | |||
table.insert(result, '|-') | |||
table.insert(result, '! <abbr title="Chroma-positive generator">Bright</abbr>') | |||
table.insert(result, '! <abbr title="Chroma-negative generator">Dark</abbr>') | |||
table.insert(result, '! L:s') | |||
table.insert(result, '! Hardness') | |||
-- Rounding is done using string.format, to 3 decimal places (%.3f) | -- Rounding is done using string.format, to 3 decimal places (%.3f) | ||
| Line 130: | Line 131: | ||
-- New row | -- New row | ||
result | table.insert(result, "|-") | ||
-- Cells for bright generator, as steps in et | -- Cells for bright generator, as steps in et | ||
local current_depth = depths[i] | -- Bright gen cell is accompanied by cells to the left and right. | ||
for i = 1, | -- The variable current_depth is the number of left cells; the number of | ||
result | -- right cells is deepest minus current_depth. | ||
local current_depth = depths[i] | |||
local num_right_cells = deepest - current_depth | |||
for i = 1, current_depth do | |||
result | table.insert(result, "|") | ||
end | |||
table.insert(result, string.format("| [[%s|%s]]", et_as_string, bright_generator_string)) | |||
for i = 1, num_right_cells do | |||
table.insert(result, "|") | |||
end | end | ||
-- Cells for generators in cents | -- Cells for generators in cents | ||
result | table.insert(result, string.format("| %.3f", bright_generator_cents)) | ||
result | table.insert(result, string.format("| %.3f", dark_generator_cents )) | ||
-- Cell for step ratio | -- Cell for step ratio | ||
result | table.insert(result, string.format("| %d:%d", step_ratio[1], step_ratio[2])) | ||
-- Cell for hardness, with divide-by-zero check | -- Cell for hardness, with divide-by-zero check | ||
| Line 156: | Line 161: | ||
hardness = string.format("%.3f", step_ratio[1] / step_ratio[2]) | hardness = string.format("%.3f", step_ratio[1] / step_ratio[2]) | ||
end | end | ||
result | table.insert(result, string.format("| %s", hardness)) | ||
-- Cell for comment | -- Cell for comment | ||
| Line 169: | Line 174: | ||
comment = default_comment .. "<br />" .. custom_comment | comment = default_comment .. "<br />" .. custom_comment | ||
end | end | ||
result | table.insert(result, string.format("| style=\"text-align: left;\" | %s", comment)) | ||
end | end | ||
result | table.insert(result, "|}") | ||
return result | return table.concat(result, "\n") | ||
end | end | ||
| Line 276: | Line 281: | ||
in_comments, out_comments, out_ratios = p.preprocess_comments(comments, step_ratios) | in_comments, out_comments, out_ratios = p.preprocess_comments(comments, step_ratios) | ||
return | local args = {} | ||
--return out_comments | |||
return p._mos_tuning_spectrum(args) | |||
end | end | ||
return p | return p | ||