Module:MOS scalesig: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
Ganaram inukshuk (talk | contribs)
Well-commented code should speak for itself!
ArrowHead294 (talk | contribs)
mNo edit summary
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
local p = {}
local getArgs = require("Module:Arguments").getArgs
local mos = require("Module:MOS")
local mos = require("Module:MOS")
local yesno = require("Module:Yesno")
local yesno = require("Module:Yesno")
local getArgs = require("Module:Arguments").getArgs
local p = {}


function p._mos_scalesig(input_mos, is_link, is_long)
-- Wrapper function; calls mos module's to-string and to-link functions
local is_link = yesno(is_link, false) -- Is the scalesig a link?
local is_long = yesno(is_long, false) -- Is the scalesig in the long form "xL ys (p/q-equivalent)"?
return (is_link == true
and (is_long and mos.as_long_link(input_mos) or mos.as_link(input_mos))
or (is_long and mos.as_long_string(input_mos) or mos.as_string(input_mos)))
end
 
-- Wrapper function
function p.mos_scalesig(frame)
function p.mos_scalesig(frame)
local args = getArgs(frame)
local args = getArgs(frame)
Line 20: Line 12:
local is_link = yesno(args["link"], false)
local is_link = yesno(args["link"], false)
local is_long = yesno(args["long"], false)
local is_long = yesno(args["long"], false)
local result
if is_link then
-- Text is a link to the mospage
-- Long link links to and displays "xL ys (p/q-equivalent)"
-- (Short) link instead displays "xL ys<p/q>"
-- Has no effect if it's octave-equivalent.
result = (is_long and mos.as_long_link(input_mos) or mos.as_link(input_mos))
else
-- Text is the scalesig, with nbsp and appropriate brackets added
-- Long string displays "xL ys (p/q-equivalent)"
-- (Short) string instead displays "xL ys<p/q>"
-- Has no effect if it's octave-equivalent.
result = (is_long and mos.as_long_string(input_mos) or mos.as_string(input_mos))
end
return p._mos_scalesig(input_mos, is_link, is_long)
return frame:preprocess(result)
end
 
function p.tester()
local input_mos = mos.new(5, 2)
return p._mos_scalesig(input_mos, true, true)
end
end


return p
return p

Latest revision as of 18:55, 13 December 2025

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

Module:MOS scalesig formats a string into a mos scale signature, with non-breaking spaces and, if non-octave, the appropriate brackets. Scale signatures can optionally be formatted as a link to the scale's wiki page.

Introspection summary for Module:MOS scalesig 
Functions provided (1)
Line Function Params
8 mos_scalesig (invokable) (frame)
Lua modules required (3)
Variable Module Functions used
getArgs Module:Arguments getArgs
mos Module:MOS parse
as_long_link
as_link
as_long_string
as_string
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 mos = require("Module:MOS")
local yesno = require("Module:Yesno")

-- Wrapper function; calls mos module's to-string and to-link functions
function p.mos_scalesig(frame)
	local args = getArgs(frame)
	
	local input_mos = mos.parse(args["scalesig"])
	local is_link = yesno(args["link"], false)
	local is_long = yesno(args["long"], false)
	local result
	
	if is_link then
		-- Text is a link to the mospage
		-- Long link links to and displays "xL ys (p/q-equivalent)"
		-- (Short) link instead displays "xL ys<p/q>"
		-- Has no effect if it's octave-equivalent.
		result = (is_long and mos.as_long_link(input_mos) or mos.as_link(input_mos))
	else
		-- Text is the scalesig, with nbsp and appropriate brackets added
		-- Long string displays "xL ys (p/q-equivalent)"
		-- (Short) string instead displays "xL ys<p/q>"
		-- Has no effect if it's octave-equivalent.
		result = (is_long and mos.as_long_string(input_mos) or mos.as_string(input_mos))
	end
	
	return frame:preprocess(result)
end

return p