Module:Powharmonic series: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
ArrowHead294 (talk | contribs)
m +Debugging option
ArrowHead294 (talk | contribs)
mNo edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local yesno = require("Module:Yesno")


function p.powharmonic(frame)
function p.powharmonic(frame)
     local n = tonumber(frame.args["n"])
     local n = tonumber(frame.args["n"])
     local expo = tonumber(frame.args["expo"])
     local expo = tonumber(frame.args["expo"])
     local out_str = "{| class=\"wikitable center-all\"\n"
     local result = "{| class=\"wikitable center-all\"\n"
    .. "|+ style=\"font-size: 105%;\" | " .. string.format("Intervals of the %s-Powharmonic series\n", expo)
    .. "|+ style=\"font-size: 105%; white-space: nowrap;\" | " .. string.format("Intervals of the %s-Powharmonic series\n", expo)
    .. "|-\n"
    .. "|-\n"
    .. "! rowspan=\"2\" | Pitch !! colspan=\"2\" | Frequency multiplier !! colspan=\"3\" | Pitch\n"
    .. "! rowspan=\"2\" | Pitch !! colspan=\"2\" | Frequency multiplier !! colspan=\"3\" | Pitch\n"
Line 17: Line 19:
     for i = 1, n do
     for i = 1, n do
         p_current = 1200 * math.log(i) / math.log(2) * expo
         p_current = 1200 * math.log(i) / math.log(2) * expo
         out_str = out_str
         result = result
             .. "|-\n"
             .. "|-\n"
             .. "| ".. string.format("%s", i)
             .. "| ".. string.format("%s", i)
Line 29: Line 31:
     end
     end


     out_str = out_str .. "|}"
     result = result .. "|}"
      
      
     local debugg = frame.args["debug"]
    -- Debugger option
     return frame:preprocess(debugg == "true" and "<pre>" .. out_str .. "</pre>" or out_str)
     local debugg = yesno(frame.args["debug"])
     if debugg == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
end


return p
return p

Latest revision as of 13:09, 1 June 2025

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

This module generates a table showing the intervals of a powharmonic series for a given exponent, which is used to model timbres involving stretched or compressed harmonics.

Introspection summary for Module:Powharmonic series 
Functions provided (1)
Line Function Params
5 powharmonic (invokable) (frame)
Lua modules required (1)
Variable Module Functions used
yesno Module:Yesno yesno

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


local p = {}

local yesno = require("Module:Yesno")

function p.powharmonic(frame)
    local n = tonumber(frame.args["n"])
    local expo = tonumber(frame.args["expo"])
    local result = "{| class=\"wikitable center-all\"\n"
	    .. "|+ style=\"font-size: 105%; white-space: nowrap;\" | " .. string.format("Intervals of the %s-Powharmonic series\n", expo)
	    .. "|-\n"
	    .. "! rowspan=\"2\" | Pitch !! colspan=\"2\" | Frequency multiplier !! colspan=\"3\" | Pitch\n"
	    .. "|-\n"
	    .. "! Definition !! Decimal !! [[Cent]]s !! Change (cents) !! Octave-reduced (cents)"
	    .. "\n"
    local fmt_cent = string.format("%%.%df", tonumber(frame.args["prec"]))
    local p_prev = 0
    local p_current = 0

    for i = 1, n do
        p_current = 1200 * math.log(i) / math.log(2) * expo
        result = result
            .. "|-\n"
            .. "| ".. string.format("%s", i)
            .. " || " .. string.format("%s<sup>%s</sup>", i, expo)
            .. " || " .. string.format(fmt_cent, i^expo)
            .. " || " .. string.format(fmt_cent, p_current)
            .. " || " .. string.format(fmt_cent, p_current - p_prev)
            .. " || " .. string.format(fmt_cent, math.fmod(p_current, 1200))
            .. "\n"
        p_prev = p_current
    end

    result = result .. "|}"
    
    -- Debugger option
    local debugg = yesno(frame.args["debug"])
    if debugg == true then
		result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
	end
	
	return frame:preprocess(result)
end

return p