Module:Infobox regtemp: Difference between revisions
Support for wart notation |
Support for higher-rank temps (up to rank 4) |
||
| Line 7: | Line 7: | ||
function p.infobox_RT(frame) | function p.infobox_RT(frame) | ||
local name = frame.args["tempname"] | local name = frame.args["tempname"] | ||
| Line 13: | Line 12: | ||
local basis = frame.args["commas"] | local basis = frame.args["commas"] | ||
local | local et1 = frame.args["edo_first"] | ||
local | local et2 = frame.args["edo_second"] | ||
local et3 = frame.args["edo_third"] | |||
local et4 = frame.args["edo_fourth"] | |||
local tuning = frame.args["tuning"] | local tuning = frame.args["tuning"] | ||
| Line 21: | Line 22: | ||
local mapping = frame.args["mapping"] | local mapping = frame.args["mapping"] | ||
local | local mos_override = frame.args["mosses"] | ||
local ploidacot_override = frame.args["ploidacot"] | local ploidacot_override = frame.args["ploidacot"] | ||
local colorname = frame.args["colorname"] | local colorname = frame.args["colorname"] | ||
| Line 37: | Line 38: | ||
-- process mapping | -- process mapping | ||
local | local rank = p.count_matches(mapping, ";") + 1 | ||
local period = string.match(mapping, "(-?%d+);") | |||
local genchain_mapping = {} | local genchain_mapping = {} | ||
for str in mapping:gmatch("(-?%d+)") do | for str in mapping:gmatch("(-?%d+)") do | ||
table.insert(genchain_mapping, str) | table.insert(genchain_mapping, str) | ||
end | end | ||
-- interpret subgroup | -- interpret subgroup | ||
| Line 53: | Line 51: | ||
end | end | ||
local equave = u.eval_num_arg(subgroup_basis[1]) | |||
local | |||
-- process et join | |||
function process_et_join(et) | |||
local et_eq, et_num = p.warts2ed(et) | |||
local et_eq_letter = p.equave2letter (et_eq) | |||
return "[[" .. et_num .. "ed" .. et_eq_letter .. "|" .. et .. "]]" | |||
end | end | ||
local et_table = {} | |||
for _, et in ipairs({et1, et2, et3, et4}) do | |||
if u.value_provided(et) then | |||
table.insert(et_table, process_et_join (et)) | |||
end | |||
end | end | ||
local et_join = table.concat(et_table, " & ") | |||
-- process generators | |||
function process_generators(genfrac_item, tuning_item) | |||
return "~" .. genfrac_item .. " = " .. tuning_item .. "{{c}}" | |||
end | end | ||
local genfrac_table = {} | |||
local | for str in genfrac:gmatch("(%d+/?%d*)") do | ||
table.insert(genfrac_table, str) | |||
end | end | ||
local tuning_table = {} | |||
- | for str in tuning:gmatch("(-?%d+%.?%d*)") do | ||
table.insert(tuning_table, str) | |||
end | end | ||
local generators_table = {} | |||
for i = 1, math.min(#genfrac_table, #tuning_table) do | |||
local | table.insert(generators_table, | ||
process_generators (genfrac_table[i], tuning_table[i])) | |||
end | end | ||
local generators = table.concat (generators_table, ", ") | |||
-- default value for mos | |||
local mos = "n/a" | |||
local cot_sig | -- autocalculating ploidacot | ||
if rank == 2 then | |||
local ploid = tonumber(period) | |||
local referent = u.eval_num_arg(subgroup_basis[2]) | |||
local cot = tonumber(genchain_mapping[2]) | |||
local suffix = "cleft" | |||
if equave == 2 then -- octave-based temp | |||
if referent == 3 then | |||
suffix = "cot" | |||
elseif referent == 5 then | |||
suffix = "seph" | |||
end | |||
elseif equave == 3 then -- twelfth-based temp | |||
if referent == 5 then | |||
referent_candidate = u.eval_num_arg(subgroup_basis[3]) | |||
if referent_candidate == 7 then | |||
referent = referent_candidate | |||
cot = tonumber(genchain_mapping[3]) | |||
suffix = "gem" | |||
end | |||
end | |||
end | |||
if suffix == "cleft" then | |||
suffix = referent .. suffix | |||
end | |||
local equave_size = 1200 * u.log2(equave) | |||
local referent_size = 1200 * u.log2(referent) | |||
local period_size = equave_size / ploid | |||
local generator_size = tonumber(tuning_table[1]) | |||
if cot < 0 then | |||
generator_size = equave_size - generator_size | |||
cot = -cot | |||
end | |||
-- find the shear | |||
local shear | |||
if cot ~= 0 then | |||
shear = (math.floor(generator_size * cot / period_size) | |||
- math.floor(referent_size % equave_size / period_size)) % cot | |||
else | |||
shear = 0 | |||
end | |||
-- omega extension | |||
if ploid == 1 and cot > 2 and shear == cot - ploid then | |||
shear = shear - cot | |||
end | |||
-- construct the ploidacot signature | |||
local MAX_GREEK_NUMERAL = 12 -- max number to convert to greek letters/numerals | |||
local ploid_sig | |||
if ploid == 1 then | |||
ploid_sig = "" -- omit the ploid part | |||
elseif ploid <= MAX_GREEK_NUMERAL then | |||
ploid_sig = p.num2greek(tostring(ploid), "ploid") .. "ploid " | |||
else | |||
ploid_sig = tostring (ploid) .. "-ploid " | |||
end | |||
local shear_sig | |||
if shear <= MAX_GREEK_NUMERAL then | |||
shear_sig = p.num2greeklet(tostring(shear)) | |||
else | |||
shear_sig = tostring(shear) .. "-sheared " | |||
end | |||
local cot_sig | |||
if cot <= MAX_GREEK_NUMERAL then | |||
cot_sig = p.num2greek(tostring(cot), "cot") .. suffix | |||
else | |||
cot_sig = tostring(cot) .. "-" .. suffix | |||
end | |||
ploidacot = ploid_sig .. shear_sig .. cot_sig | |||
else | else | ||
ploidacot = "n/a" | |||
end | end | ||
-- user override | -- user override | ||
if u.value_provided (mos_override) then | |||
mos = mos_override | |||
end | |||
if u.value_provided (ploidacot_override) then | if u.value_provided (ploidacot_override) then | ||
ploidacot = ploidacot_override | ploidacot = ploidacot_override | ||
end | end | ||
-- construct the table | -- construct the table | ||
| Line 161: | Line 198: | ||
table.insert(data, { | table.insert(data, { | ||
"ET join", | "ET join", | ||
et_join | |||
}) | }) | ||
table.insert(data, { | table.insert(data, { | ||
" | "Generators ([[" .. method .. "]])", | ||
generators | |||
}) | }) | ||
| Line 226: | Line 262: | ||
return frame:preprocess(debugg == true and "<pre>" .. result .. "</pre>" or result) | return frame:preprocess(debugg == true and "<pre>" .. result .. "</pre>" or result) | ||
end | |||
function p.count_matches(base, pattern) | |||
return select(2, string.gsub(base, pattern, "")) | |||
end | end | ||