Module:Infobox AFDO: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
m Fix
m Bugfix
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
local p = {}
local p = {}
local u = require('Module:Utils')
local getArgs = require("Module:Arguments").getArgs
local infobox = require('Module:Infobox')
local infobox = require("Module:Infobox")
local u = require("Module:Utils")
local yesno = require("Module:Yesno")


function p.infobox_AFDO(frame)
function p.infobox_AFDO(frame)
local args = getArgs(frame)
-- debug mode will disable the categories
-- debug mode will disable the categories
local debug_mode = frame.args['debug'] ~= nil
local debug_mode = yesno(frame.args["debug"] or args["debug"], false)
local categories = ''
local wtext = yesno(frame.args["wtext"] or args["wtext"])
local categories = ""
local steps = frame.args['steps']
local steps = frame.args["steps"]
local stepnum = tonumber(steps)
local stepnum = tonumber(steps)
local dualfifth = stepnum % 2 == 1
local dualfifth = stepnum % 2 == 1
Line 14: Line 19:
local special_properties = ""
local special_properties = ""
-- category of the main article
categories = categories .. "[[Category:AFDO|" .. string.rep("#", string.len (stepnum)) .. "]]"
--categories = categories .. '[[Category:' .. tuning .. '| ]]'
-- category of the equal division
--if rat.eq(et.equave, 2) then
categories = categories .. '[[Category:AFDO|' .. string.rep ('#', string.len (stepnum)) .. ']]'
--else
-- categories = categories .. '[[Category:' .. et.suffix .. '|' .. string.rep ('#', string.len (et.size)) .. ']]'
--end
-- prime test
-- prime test
local prime = ""
local prime = ""
if u.is_prime(et.size) then
if u.is_prime(stepnum) then
prime = " (prime)"
prime = " (prime)"
if rat.eq(et.equave, 2) then
-- if rat.eq(et.equave, 2) then
categories = categories .. '[[Category:Prime AFDO|' .. string.rep ('#', string.len (stepnum)) .. ']]'
categories = categories .. "[[Category:Prime AFDO|" .. string.rep("#", string.len (stepnum)) .. "]]"
end
-- end
end
end
local infobox_data = {}
local infobox_data = {}
table.insert(infobox_data, {
table.insert(infobox_data, {
'Prime factorization',
"Prime factorization",
u._prime_factorization(stepnum) .. prime
u._prime_factorization(stepnum) .. prime
})
})


table.insert(infobox_data, {
     if (dualfifth) then
'Fifth',
fifth .. '/' .. steps .. ' (' .. math.floor(math.log(fifth/steps)/math.log(2) * 1200 * 1000)/1000 .. 'c)'
})
 
     if(dualfifth) then
     table.insert(infobox_data, {
     table.insert(infobox_data, {
'Dual sharp fifth',
"Dual sharp fifth",
fifth .. '/' .. steps .. ' (' .. math.floor(math.log(fifth/steps)/math.log(2) * 1200 * 1000)/1000 .. 'c)'
fifth .. "/" .. steps .. " (" .. math.floor(math.log(fifth / steps) / math.log(2) * 1200 * 1000) / 1000 .. "c)"
})     
})     
table.insert(infobox_data, {
table.insert(infobox_data, {
'Dual flat fifth',
"Dual flat fifth",
(fifth-1) .. '/' .. steps .. ' (' .. math.floor(math.log((fifth-1)/steps)/math.log(2) * 1200 * 1000)/1000 .. 'c)'
(fifth-1) .. "/" .. steps .. " (" .. math.floor(math.log((fifth - 1) / steps) / math.log(2) * 1200 * 1000) / 1000 .. "c)"
})
})
    else
table.insert(infobox_data, {
"Fifth",
fifth .. "/" .. steps .. " (" .. math.floor(math.log(fifth / steps) / math.log(2) * 1200 * 1000) / 1000 .. "c)"
})
     end
     end


  if(special_properties ~= "") then
    if (special_properties ~= "") then
   table.insert(infobox_data, {'Special properties', special_properties})
   table.insert(infobox_data, {"Special properties", special_properties})
   end
   end


local result = infobox.build(
local result = infobox.build(
'<-<small>&nbsp;[[' .. (steps - 1).. 'afdo]]&nbsp;</small>' .. '[[' .. steps .. 'afdo]]' .. '<small>&nbsp;[[' .. (steps + 1).. 'afdo]]&nbsp;-></small>',
string.format("[[%safdo]]", steps),
infobox_data
infobox_data,
string.format("[[%safdo|&larr;&nbsp;%safdo]]", steps - 1, steps - 1),
string.format("[[%safdo|%safdo&nbsp;&rarr;]]", steps + 1, steps + 1)
)
)
Line 66: Line 67:
result = result .. categories
result = result .. categories
end
end
return result
if wtext then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
end


return p
return p

Latest revision as of 14:56, 15 December 2025

Module documentation[view] [edit] [history] [purge]
This module should not be invoked directly; use its corresponding template instead: Template:Infobox AFDO.

Generates an infobox providing information about a given arithmetic frequency division of the octave.

Introspection summary for Module:Infobox AFDO 
Functions provided (1)
Line Function Params
7 infobox_AFDO (invokable) (frame)
Lua modules required (4)
Variable Module Functions used
getArgs Module:Arguments getArgs
infobox Module:Infobox build
u Module:Utils is_prime
_prime_factorization
yesno Module:Yesno yesno

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


local p = {}
local getArgs = require("Module:Arguments").getArgs
local infobox = require("Module:Infobox")
local u = require("Module:Utils")
local yesno = require("Module:Yesno")

function p.infobox_AFDO(frame)
	local args = getArgs(frame)
	
	-- debug mode will disable the categories
	local debug_mode = yesno(frame.args["debug"] or args["debug"], false)
	local wtext = yesno(frame.args["wtext"] or args["wtext"])
	local categories = ""
	
	local steps = frame.args["steps"]
	local stepnum = tonumber(steps)
	local dualfifth = stepnum % 2 == 1
	local fifth = steps+math.ceil(steps/2)
	local special_properties = ""
	
	categories = categories .. "[[Category:AFDO|" .. string.rep("#", string.len (stepnum)) .. "]]"
	
	-- prime test
	local prime = ""
	if u.is_prime(stepnum) then
		prime = " (prime)"
		-- if rat.eq(et.equave, 2) then
			categories = categories .. "[[Category:Prime AFDO|" .. string.rep("#", string.len (stepnum)) .. "]]"
		-- end
	end
	
	local infobox_data = {}
	table.insert(infobox_data, {
		"Prime factorization",
		u._prime_factorization(stepnum) .. prime
	})

    if (dualfifth) then
    	table.insert(infobox_data, {
		"Dual sharp fifth",
		fifth .. "/" .. steps .. " (" .. math.floor(math.log(fifth / steps) / math.log(2) * 1200 * 1000) / 1000 .. "c)"
		})    
		table.insert(infobox_data, {
		"Dual flat fifth",
		(fifth-1) .. "/" .. steps .. " (" .. math.floor(math.log((fifth - 1) / steps) / math.log(2) * 1200 * 1000) / 1000 .. "c)"
		})
    else
		table.insert(infobox_data, {
		"Fifth",
		fifth .. "/" .. steps .. " (" .. math.floor(math.log(fifth / steps) / math.log(2) * 1200 * 1000) / 1000 .. "c)"
		})
		
    end

    if (special_properties ~= "") then
   		table.insert(infobox_data, {"Special properties", special_properties})
   	end

	local result = infobox.build(
		string.format("[[%safdo]]", steps),
		infobox_data,
		string.format("[[%safdo|&larr;&nbsp;%safdo]]", steps - 1, steps - 1),
		string.format("[[%safdo|%safdo&nbsp;&rarr;]]", steps + 1, steps + 1)
	)
	
	if not debug_mode then
		result = result .. categories
	end
	
	if wtext then
		result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
	end
	
	return frame:preprocess(result)
end

return p