Module:Infobox regtemp: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
Lériendil (talk | contribs)
porting changes over from Infobox RT
Lériendil (talk | contribs)
deploying changes live
Line 63: Line 63:
local equave_letter
local equave_letter
local cot = tonumber(lowermap[1])
local cot = tonumber(lowermap[1])
if equave == "3" then
local referent = string.char(string.byte(subgroup, 3))
local suffix = "cleft"
if tonumber(equave) == 3 then
equave_letter = "t"
equave_letter = "t"
if tonumber(string.char(string.byte(subgroup, 3))) == 5 then
if tonumber(string.char(string.byte(subgroup, 3))) == 5 then
if tonumber(string.char(string.byte(subgroup, 5))) == 7 then
if tonumber(string.char(string.byte(subgroup, 5))) == 7 then
cot = tonumber(lowermap[2])
cot = tonumber(lowermap[2])
suffix = "gem"
end
end
elseif tonumber(string.char(string.byte(subgroup, 3))) == 2 then -- edf
elseif tonumber(string.char(string.byte(subgroup, 3))) == 2 then -- edf
equave_letter = "f"
equave_letter = "f"
equave = "3/2"
equave = "3/2"
referent = string.char(string.byte(subgroup, 5))
end
end
elseif equave == "2" then
if referent == "7" then
suffix = "gem"
end
elseif tonumber(equave) == 2 then
equave_letter = "o"
equave_letter = "o"
if tonumber(string.char(string.byte(subgroup, 3))) == 3 then
suffix = "cot"
elseif tonumber(string.char(string.byte(subgroup, 3))) == 5 then
suffix = "seph"
end
else
else
equave_letter = equave
equave_letter = equave
end
if suffix == "cleft" then
suffix = referent .. suffix
end
local ploidnum = math.log(tonumber(equave))*(1200/math.log(2))/tonumber(ploid)
local tuningnum = tonumber(tuning)
if cot < 0 then
tuningnum = math.log(tonumber(equave))*(1200/math.log(2)) - tuningnum
cot = math.abs(cot)
end
local shear = math.floor(tuningnum*cot/ploidnum)
shear = math.floor(cot*(shear/cot - math.floor(shear/cot)))
if cot > 2 then
if shear == cot-1 then
shear = -1
end
end
suffix = p.num2greek(ploid,"ploid") .. "ploid " .. p.num2greeklet(tostring(shear)) .. p.num2greek(tostring(cot), "cot") .. suffix
if ploidacot == "cleft" then
ploidacot = suffix
end
end
Line 116: Line 151:
return result
return result
end
function p.digit2greek(number, purpose)
local greek
if number == "1" then
if purpose == "ploid" then
greek = "ha"
elseif purpose == "cot" then
greek = "mono"
elseif purpose == "decade" then
greek = "deca"
else
greek = "hen"
end
elseif number == "2" then
if purpose == "decade" then
greek = "icosa"
elseif purpose == "unit" then
greek = "do"
else
greek = "di"
end
elseif number == "0" then
if purpose == "unit" then
greek = ""
else
greek = "a"
end
else
if number == "3" then
if purpose == "decade" then
greek = "tria"
else
greek = "tri"
end
elseif number == "4" then
greek = "tetra"
elseif number == "5" then
greek = "penta"
elseif number == "6" then
greek = "hexa"
elseif number == "7" then
greek = "hepta"
elseif number == "8" then
greek = "octa"
elseif number == "9" then
greek = "ennea"
end
if purpose == "decade" then
greek = greek .. "conta"
end
end
return greek
end
function p.num2greek(number, purpose)
local greek
if string.len(number) == 1 then
greek = p.digit2greek(number, purpose)
elseif string.len(number) == 2 then
local unit = string.char(string.byte(number, 2))
local decade = string.char(string.byte(number, 1))
greek = p.digit2greek(unit, "unit") .. p.digit2greek(decade, "decade")
end
return greek
end
function p.digit2greeklet(number, purpose)
local greek
if number == "1" then
if purpose == "decade" then
greek = "iota-"
elseif purpose == "unit" then
greek = "alpha-"
end
elseif number == "2" then
if purpose == "decade" then
greek = "kappa-"
elseif purpose == "unit" then
greek = "beta-"
end
elseif number == "3" then
if purpose == "decade" then
greek = "lambda-"
elseif purpose == "unit" then
greek = "gamma-"
end
elseif number == "4" then
if purpose == "decade" then
greek = "mu-"
elseif purpose == "unit" then
greek = "delta-"
end
elseif number == "5" then
if purpose == "decade" then
greek = "nu-"
elseif purpose == "unit" then
greek = "epsilon-"
end
elseif number == "6" then
if purpose == "decade" then
greek = "xi-"
elseif purpose == "unit" then
greek = "wau-"
end
elseif number == "7" then
if purpose == "decade" then
greek = "omicron-"
elseif purpose == "unit" then
greek = "zeta-"
end
elseif number == "8" then
if purpose == "decade" then
greek = "pi-"
elseif purpose == "unit" then
greek = "eta-"
end
elseif number == "9" then
if purpose == "decade" then
greek = "qoppa-"
elseif purpose == "unit" then
greek = "theta-"
end
elseif number == "0" then
greek = ""
elseif number == "-1" then
greek = "omega-"
end
return greek
end
function p.num2greeklet(number)
local greek
if string.len(number) == 1 then
greek = p.digit2greeklet(number, "unit")
elseif string.len(number) == 2 then
local unit = string.char(string.byte(number, 2))
local decade = string.char(string.byte(number, 1))
greek = p.digit2greeklet(decade, "decade") .. p.digit2greeklet(unit, "unit")
end
return greek
end
end


return p
return p

Revision as of 04:14, 21 October 2024

Module documentation[view] [edit] [history] [purge]
This module should not be invoked directly; use its corresponding template instead: Template:Infobox regtemp.
Module:Infobox regtemp is a draft module. It is incomplete and may not be in active development. If possible, editors are encouraged to help with its development. In the meantime, editors should avoid using this module across the Xenharmonic Wiki, except for testing.

This module generates an infobox providing information about a given regular temperament.

Introspection summary for Module:Infobox regtemp 
Functions provided (5)
Line Function Params
5 infobox_RT (invokable) (frame)
155 digit2greek (number, purpose)
211 num2greek (number, purpose)
226 digit2greeklet (number, purpose)
293 num2greeklet (number)
Lua modules required (2)
Variable Module Functions used
infobox Module:Infobox build
u Module:Utils dependency not used

No function descriptions were provided. The Lua code may have further information.


local p = {}
local u = require("Module:Utils")
local infobox = require("Module:Infobox")

function p.infobox_RT(frame)
	
	-- no real math functionality... yet
	local name = frame.args["tempname"]
	
	local subgroup = frame.args["subgroup"]
	local basis = frame.args["commas"]
	
	local edo_first = frame.args["edo_first"]
	local edo1 = tonumber(edo_first)
	local edo_second = frame.args["edo_second"]
	local edo2 = tonumber(edo_second)
	
	local tuning = frame.args["tuning"]
	local genfrac = frame.args["genfrac"]
	local method = frame.args["method"]
	
	local mos = frame.args["mosses"]
	local mapping = frame.args["mapping"]
	local ploidacot = frame.args["ploidacot"]
	local limit1 = frame.args["lim1"]
	local comp1 = frame.args["comp1"]
	local acc1 = frame.args["acc1"]
	local limit2 = frame.args["lim2"]
	local comp2 = frame.args["comp2"]
	local acc2 = frame.args["acc2"]
	
	local data = {}
	
	-- processed mapping
	local map = {}
	local lowermap = {}
	table.insert(data, {
		"Subgroups",
		subgroup
	})

	table.insert(data, {
		"Comma basis",
		basis
	})

	table.insert(data, {
		"Reduced mapping",
		"<" .. mapping .. "]"
	})

	-- autocalculating ploidacot (wip)
	for num in mapping:gmatch("(%d+); ") do
		table.insert(map, num)
	end
	local ploid = map[1]
	
	for num in mapping:gmatch("(%d+) ") do
		table.insert(lowermap, num)
	end
	
	local equave = string.char(string.byte(subgroup, 1))
	local equave_letter
	local cot = tonumber(lowermap[1])
	local referent = string.char(string.byte(subgroup, 3))
	local suffix = "cleft"
	if tonumber(equave) == 3 then
		equave_letter = "t"
		if tonumber(string.char(string.byte(subgroup, 3))) == 5 then
			if tonumber(string.char(string.byte(subgroup, 5))) == 7 then
				cot = tonumber(lowermap[2])
				suffix = "gem"
			end
		elseif tonumber(string.char(string.byte(subgroup, 3))) == 2 then -- edf
			equave_letter = "f"
			equave = "3/2"
			referent = string.char(string.byte(subgroup, 5))
		end
		if referent == "7" then
			suffix = "gem"
		end
	elseif tonumber(equave) == 2 then
		equave_letter = "o"
		if tonumber(string.char(string.byte(subgroup, 3))) == 3 then
			suffix = "cot"
		elseif tonumber(string.char(string.byte(subgroup, 3))) == 5 then
			suffix = "seph"
		end
	else
		equave_letter = equave
	end
	
	if suffix == "cleft" then
		suffix = referent .. suffix
	end
	
	local ploidnum = math.log(tonumber(equave))*(1200/math.log(2))/tonumber(ploid)
	local tuningnum = tonumber(tuning)
	if cot < 0 then
		tuningnum = math.log(tonumber(equave))*(1200/math.log(2)) - tuningnum
		cot = math.abs(cot)
	end
	local shear = math.floor(tuningnum*cot/ploidnum)
	shear = math.floor(cot*(shear/cot - math.floor(shear/cot)))
	if cot > 2 then
		if shear == cot-1 then
		shear = -1
		end
	end
	
	suffix = p.num2greek(ploid,"ploid") .. "ploid " .. p.num2greeklet(tostring(shear)) .. p.num2greek(tostring(cot), "cot") .. suffix
	if ploidacot == "cleft" then
		ploidacot = suffix
	end
	
	-- edo join
	table.insert(data, {
		"Edo join",
		"[[" .. edo_first .. "ed" .. equave_letter .. "|" .. edo_first .. "]] & [[" .. edo_second .. "ed" .. equave_letter .. "|" .. edo_second .. "]]"
	})

	table.insert(data, {
		"Generator ([[" .. method .. "]])",
		"~" .. genfrac .. " = " .. tuning .. "c"
	})

	table.insert(data, {
		"MOS scales",
		mos
	})

	table.insert(data, {
		"Ploidacot",
		ploidacot
	})

	table.insert(data, {
		"Minmax error",
		"(" .. limit1 .. "-[[odd limit]]) " .. acc1 .. "c; <br> (" .. limit2 .. "-[[odd limit]]) " .. acc2 .. "c"
	})

	table.insert(data, {
		"Target scale size",
		"(" .. limit1 .. "-[[odd limit]]) " .. comp1 .. " notes; <br> (" .. limit2 .. "-[[odd limit]]) " .. comp2 .. " notes"
	})

	local result = infobox.build(
		name,
		data
	)
	
	return result
end

function p.digit2greek(number, purpose)

	local greek
	
	if number == "1" then
		if purpose == "ploid" then
			greek = "ha"
		elseif purpose == "cot" then
			greek = "mono"
		elseif purpose == "decade" then
			greek = "deca"
		else
			greek = "hen"
		end
	elseif number == "2" then
		if purpose == "decade" then
			greek = "icosa"
		elseif purpose == "unit" then
			greek = "do"
		else
			greek = "di"
		end
	elseif number == "0" then
		if purpose == "unit" then
			greek = ""
		else
			greek = "a"
		end
	else
		if number == "3" then
			if purpose == "decade" then
				greek = "tria"
			else
				greek = "tri"
			end
		elseif number == "4" then
			greek = "tetra"
		elseif number == "5" then
			greek = "penta"
		elseif number == "6" then
			greek = "hexa"
		elseif number == "7" then
			greek = "hepta"
		elseif number == "8" then
			greek = "octa"
		elseif number == "9" then
			greek = "ennea"
		end
		if purpose == "decade" then
			greek = greek .. "conta"
		end
	end

	return greek
end

function p.num2greek(number, purpose)

	local greek
	
	if string.len(number) == 1 then
		greek = p.digit2greek(number, purpose)
	elseif string.len(number) == 2 then
		local unit = string.char(string.byte(number, 2))
		local decade = string.char(string.byte(number, 1))
		
		greek = p.digit2greek(unit, "unit") .. p.digit2greek(decade, "decade")
	end
	return greek
end

function p.digit2greeklet(number, purpose)

	local greek
	
	if number == "1" then
		if purpose == "decade" then
			greek = "iota-"
		elseif purpose == "unit" then
			greek = "alpha-"
		end
	elseif number == "2" then
		if purpose == "decade" then
			greek = "kappa-"
		elseif purpose == "unit" then
			greek = "beta-"
		end
	elseif number == "3" then
		if purpose == "decade" then
			greek = "lambda-"
		elseif purpose == "unit" then
			greek = "gamma-"
		end
	elseif number == "4" then
		if purpose == "decade" then
			greek = "mu-"
		elseif purpose == "unit" then
			greek = "delta-"
		end
	elseif number == "5" then
		if purpose == "decade" then
			greek = "nu-"
		elseif purpose == "unit" then
			greek = "epsilon-"
		end
	elseif number == "6" then
		if purpose == "decade" then
			greek = "xi-"
		elseif purpose == "unit" then
			greek = "wau-"
		end
	elseif number == "7" then
		if purpose == "decade" then
			greek = "omicron-"
		elseif purpose == "unit" then
			greek = "zeta-"
		end
	elseif number == "8" then
		if purpose == "decade" then
			greek = "pi-"
		elseif purpose == "unit" then
			greek = "eta-"
		end
	elseif number == "9" then
		if purpose == "decade" then
			greek = "qoppa-"
		elseif purpose == "unit" then
			greek = "theta-"
		end	
	elseif number == "0" then
		greek = ""
	elseif number == "-1" then
		greek = "omega-"
	end

	return greek
end

function p.num2greeklet(number)

	local greek
	
	if string.len(number) == 1 then
		greek = p.digit2greeklet(number, "unit")
	elseif string.len(number) == 2 then
		local unit = string.char(string.byte(number, 2))
		local decade = string.char(string.byte(number, 1))
		
		greek = p.digit2greeklet(decade, "decade") .. p.digit2greeklet(unit, "unit")
	end
	return greek
end

return p