Module:MOS tuning spectrum: Difference between revisions
todo: refactor |
refactor code |
||
| Line 8: | Line 8: | ||
-- TODO: | -- TODO: | ||
-- - (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 18: | Line 16: | ||
-- 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 75: | Line 73: | ||
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 99: | Line 95: | ||
-- - 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, '! Bright') | |||
table.insert(result, '! Dark') | |||
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 132: | Line 129: | ||
-- New row | -- New row | ||
result | table.insert(result, "|-") | ||
-- Cells for bright generator, as steps in et | -- Cells for bright generator, as steps in et | ||
-- Bright gen cell is accompanied by cells to the left and right. | |||
-- The variable current_depth is the number of left cells; the number of | |||
-- right cells is deepest minus current_depth. | |||
local current_depth = depths[i] | local current_depth = depths[i] | ||
local | local num_right_cells = deepest - current_depth | ||
for i = 1, current_depth do | |||
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 | |||
-- 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 155: | Line 159: | ||
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 168: | Line 172: | ||
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 280: | ||
local args = {} | local args = {} | ||
--return out_comments | |||
return p._mos_tuning_spectrum(args) | return p._mos_tuning_spectrum(args) | ||
end | end | ||
return p | return p | ||