Module:MOS tuning spectrum: Difference between revisions
code cleanup; adopt sorting function for when custom initial ratios are entered |
add in-progress function for splitting in-range comments and out-of-range comments |
||
| Line 11: | Line 11: | ||
-- 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. | ||
-- Split comments into in-range and out-of-range comments. | |||
-- Iterate through the comments and determine whether the key for a comment is | |||
-- 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. | |||
function p.preprocess_comments(comments, step_ratios) | |||
local in_comments = {} | |||
local out_comments = {} | |||
local out_ratios = {} | |||
for key, value in pairs(comments) do | |||
local key_found_in_step_ratios = utils.table_contains(step_ratios, key, function(key, ratio) | |||
return key == string.format("%s/%s", ratio[1], ratio[2]) end | |||
) | |||
if key_found_in_step_ratios then | |||
in_comments[key] = value | |||
else | |||
out_comments[key] = value | |||
table.insert(out_ratios, tip.parse_numeric_pair(key, "/", true)) | |||
end | |||
end | |||
mediants.sort_ratios(out_ratios) | |||
return in_comments, out_comments, out_ratios | |||
end | |||
-- Re-re-rewrite of tuning spectrum | -- Re-re-rewrite of tuning spectrum | ||
| Line 47: | 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 230: | Line 258: | ||
function p.tester() | function p.tester() | ||
local args = {} | --local args = {} | ||
return p._mos_tuning_spectrum(args) | --return p._mos_tuning_spectrum(args) | ||
local comments = { | |||
["5/4"] = "aaa", | |||
["2/1"] = "bbb" | |||
} | |||
local step_ratios = { | |||
{1,1}, | |||
{5,4}, | |||
{4,3} | |||
} | |||
local in_comments = {} | |||
local out_comments = {} | |||
in_comments, out_comments, out_ratios = p.preprocess_comments(comments, step_ratios) | |||
return out_ratios | |||
end | end | ||
return p | return p | ||