Jump to content

Module:Svara/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Renamed user ExPsittacine (talk | contribs) at 07:58, 5 October 2018 (Sync). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local mSep = require('Module:Separated entries')
local getArgs = require('Module:Arguments').getArgs

local p = {}

-- This is still missing most lower and higher octave notes.
local svaraDesc = mw.loadData('Module:Svara/equivalents')
local svaraResolve = mw.loadData('Module:Svara/resolve')

function p.resolve(input, type)
	local svaras = svaraResolve[type]

	for key, value in pairs(input) do
		if svaras[value] then
    		input[key] = svaras[value];
    	end
    end

	return input
end

-- Called by the svaraC template
-- print(p.carnatic({'S', 'r1', 'g2', 'm1', 'P', 'd2', 'N3', "S'"}))
function p.carnatic(frame)
	-- Carnatic notation is case-insensitive. Enable the capitalise option.
	local input = p.sanitiseArgs(frame, true)
	input = p.resolve(input, "carnatic")

	return p._main(frame, input, 'carnatic')
end

-- Called by the svaraH template
-- print(p.hindustani({'S', 'r', 'G', 'm', 'P', 'd', 'N', "S'"}))
function p.hindustani(frame)
	local input = p.sanitiseArgs(frame)
	input = p.resolve(input, "hindustani")

	return p._main(frame, input, 'hindustani')
end

function p.getEquivalents(frame, args, type)
	local output = ''
	local western = {}
	local alternate = {}
	local altType = ""
	local altText = ""
	local entry
	
	-- print(p.getEquivalents({'S', 'R₂', 'G₃', 'M₁', 'P', 'D₂', 'N₃', 'Ṡ'}, 'carnatic'))
	
	if (type == "carnatic") then
		altType = "hindustani"
		altText = "Hindustani"
	else 
		altType = "carnatic"
		altText = "Carnatic"
	end
	for key, value in pairs(args) do
		output = output .. " " .. key .. "[" .. value .. "]"
		if svaraDesc[value] then
			entry = svaraDesc[value]
    		alternate[key] = entry[altType];
    		western[key] = entry["western"];
    	end
	end

	output = frame:expandTemplate{title = 'bulleted list', args = {altText .. ": " .. p._main(frame, alternate, nil),
		"Western: " .. p._main(frame, western, "western")}}
	
	output = "Alternate notations:" .. output
	
	return output
end
	
function p._main(frame, input, type)
	local foot = nil
	local abbr = true
	local svaras = {}
	
	if input['foot'] then
		foot = true
		input['foot'] = nil
	end

	if input['abbr'] then
		abbr = false
		input['abbr'] = nil
	end
	
	for key, value in pairs(input) do
		svaras[key] = value

		if (abbr) then
			if type ~= "western" then
				-- Use the abbr tag to add a description; avoid the default dotted
				-- underline style as it messes up the macrons.
				svaras[key] = frame:expandTemplate{title = 'abbr', args = {value, svaraDesc[value]['desc'], style="text-decoration:none;"}}
			end
		end
    end
    
	svaras['separator'] = " "
	local output = mSep.main(svaras)

	if (foot) then
		local equivalents = p.getEquivalents(frame, input, type)
		output = output .. frame:expandTemplate{title = 'efn', args = {equivalents, group=svara}}
	end
	
    return output
end

function p.sanitiseArgs(frame, capitalise)
	local args = getArgs(frame)

	-- Capitalise arguments.
	if (capitalise) then
		for key, value in pairs(args) do
    		args[key] = mw.ustring.upper(args[key]);
    	end
	end

	return args
end

function p.main(frame)
	local args = p.sanitiseArgs(frame)
	
	return p._main(frame, args)
end

return p