Module:Lumatone mapping intro: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
ArrowHead294 (talk | contribs)
mNo edit summary
ArrowHead294 (talk | contribs)
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local ET = require("Module:ET")
local ET = require("Module:ET")
local rat = require("Module:Rational")
local gcd = require("Module:Utils")._gcd
local gcd = require("Module:Utils")._gcd
local rat = require("Module:Rational")
local yesno = require("Module:Yesno")
local yesno = require("Module:Yesno")


Line 8: Line 8:
local tuning = frame.args["edo"]
local tuning = frame.args["edo"]
local et = ET.parse(tuning) or ET.parse(tuning .. "edo") or ET.parse("12edo")
local et = ET.parse(tuning) or ET.parse(tuning .. "edo") or ET.parse("12edo")
local debug_mode = yesno(frame.args["debug"])
local debugg = yesno(frame.args["debug"])
local octave = ET.approximate(et, 2)
local octave = ET.approximate(et, 2)
Line 40: Line 40:
end
end
return frame:preprocess(debug_mode == true and "<pre>" .. result .. "</pre>" or result)
-- Debugger option
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 12:21, 1 June 2025

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

This module automatically fills in the introduction for Lumatone keyboard mappings for EDOs.

Since the Standard Lumatone mapping for Pythagorean is based on the chain of fifths, the intro text will depend on how accurately an EDO approximates 3/2 and how many mutually-exclusive circles of fifths it has.
Introspection summary for Module:Lumatone mapping intro 
Functions provided (1)
Line Function Params
7 lum_intro (invokable) (frame)
Lua modules required (4)
Variable Module Functions used
ET Module:ET parse
approximate
cents
as_string
is_highly_composite
rat Module:Rational cents
new
gcd Module:Utils _gcd
yesno Module:Yesno yesno

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


local p = {}
local ET = require("Module:ET")
local rat = require("Module:Rational")
local gcd = require("Module:Utils")._gcd
local yesno = require("Module:Yesno")

function p.lum_intro(frame)
	local tuning = frame.args["edo"]
	local et = ET.parse(tuning) or ET.parse(tuning .. "edo") or ET.parse("12edo")
	local debugg = yesno(frame.args["debug"])
	
	local octave = ET.approximate(et, 2)
	local twelfth = ET.approximate(et, 3)

	local step_size = ET.cents(et, 1)
	local fifth = -octave + twelfth -- 3/2 = [-1 1>
	local fifth_error = ET.cents(et, fifth) - rat.cents(rat.new(3, 2))
	local is_far_fifth = (math.abs(fifth_error) / step_size >= 0.40)

	local result = (octave == 12
		and "The standard mapping of [[12edo]] onto the [[Lumatone]] agrees with the [[Standard Lumatone mapping for Pythagorean]]."
		or string.format("There are many conceivable ways to map [[%s]] onto the onto the [[Lumatone]] keyboard.", ET.as_string(et)))
	
	local rings = gcd(octave, twelfth)
	if rings > 1 then
		-- If the EDO has multiple rings of fifths
		result = result .. string.format(" However, it has %d mutually-exclusive rings of fifths, ", rings)
			.. "so the [[Standard Lumatone mapping for Pythagorean]] is not one of them."
		if ET.is_highly_composite(et) then
			-- If the EDO has multiple rings of fifths and is highly composite (multiples of 12 especially)
			result = result .. " Since it is [[highly composite]], many other mappings will also fail to cover the whole gamut."
		end
	elseif is_far_fifth == true then
		-- EDOs with inaccurate fifth (40% or higher relative error)
		result = result .. " However, as both of its fifths are about as far away from just as possible, "
			.. "neither the sharp or the flat versions of the [[Standard Lumatone mapping for Pythagorean]] work particularly well."
	elseif octave ~= 12 then
		-- If the EDO can be generated entirely by fifths
		result = result .. " Only one, however, agrees with the [[Standard Lumatone mapping for Pythagorean]]."
	end
	
	-- Debugger option
	if debugg == true then
		result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
	end
	
	return frame:preprocess(result)
end

return p