Jump to content

Module:Svara/sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Sync
Sync
Line 4: Line 4:
local p = {}
local p = {}


-- Some of the characters used do not render properly on all browsers.
-- This is still missing most lower and higher octave notes.
local svaraDesc = mw.loadData('Module:Svara/equivalents')
local svaraDesc = mw.loadData('Module:Svara/equivalents')
local svaraResolve = mw.loadData('Module:Svara/resolve')
local svaraResolve = mw.loadData('Module:Svara/resolve')


-- Convert shorthand notation into standard notation.
function p.resolve(input, type)
function p.resolve(input, type)
local svaras = svaraResolve[type]
local svaras = svaraResolve[type]
Line 13: Line 14:
for key, value in pairs(input) do
for key, value in pairs(input) do
if svaras[value] then
if svaras[value] then
input[key] = svaras[value];
input[key] = svaras[value];
end
end
end
end


return input
return input
Line 39: Line 40:
end
end


-- Get the equivalent note in other notation standards.
-- print(p.getEquivalents({'S', 'R₂', 'G₃', 'M₁', 'P', 'D₂', 'N₃', 'Ṡ'}, 'carnatic'))
function p.getEquivalents(frame, args, type)
function p.getEquivalents(frame, args, type)
local output = ''
local output = ''
Line 46: Line 49:
local altText = ""
local altText = ""
local entry
local entry

-- print(p.getEquivalents({'S', 'R₂', 'G₃', 'M₁', 'P', 'D₂', 'N₃', 'Ṡ'}, 'carnatic'))
if (type == "carnatic") then
if (type == "carnatic") then
altType = "hindustani"
altType = "hindustani"
Line 56: Line 57:
altText = "Carnatic"
altText = "Carnatic"
end
end

for key, value in pairs(args) do
for key, value in pairs(args) do
output = output .. " " .. key .. "[" .. value .. "]"
if svaraDesc[value] then
if svaraDesc[value] then
entry = svaraDesc[value]
entry = svaraDesc[value]
alternate[key] = entry[altType];
alternate[key] = entry[altType];
western[key] = entry["western"];
western[key] = entry["western"];
end
end
end
end


Line 72: Line 73:
return output
return output
end
end

-- Generates the output.
function p._main(frame, input, type)
function p._main(frame, input, type)
local foot = nil
local foot = nil
Line 98: Line 100:
end
end
end
end
end
end

svaras['separator'] = " "
svaras['separator'] = " "
local output = mSep.main(svaras)
local output = mSep.main(svaras)
Line 105: Line 107:
if (foot) then
if (foot) then
local equivalents = p.getEquivalents(frame, input, type)
local equivalents = p.getEquivalents(frame, input, type)
output = output .. frame:expandTemplate{title = 'efn', args = {equivalents, group=svara}}
output = output .. frame:expandTemplate{title = 'efn', args = {equivalents, group='svara'}}
end
end
return output
return output
end
end


-- Currently cleans up and returns the input.
function p.sanitiseArgs(frame, capitalise)
function p.sanitiseArgs(frame, capitalise)
local args = getArgs(frame)
local args = getArgs(frame)
Line 117: Line 120:
if (capitalise) then
if (capitalise) then
for key, value in pairs(args) do
for key, value in pairs(args) do
args[key] = mw.ustring.upper(args[key]);
args[key] = mw.ustring.upper(args[key]);
end
end
end
end


Line 124: Line 127:
end
end


-- Called by the svara template.
function p.main(frame)
function p.main(frame)
local args = p.sanitiseArgs(frame)
local args = p.sanitiseArgs(frame)

Revision as of 09:26, 5 October 2018

local mSep = require('Module:Separated entries')
local getArgs = require('Module:Arguments').getArgs

local p = {}

-- Some of the characters used do not render properly on all browsers.
local svaraDesc = mw.loadData('Module:Svara/equivalents')
local svaraResolve = mw.loadData('Module:Svara/resolve')

-- Convert shorthand notation into standard notation.
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

-- Get the equivalent note in other notation standards.
-- print(p.getEquivalents({'S', 'R₂', 'G₃', 'M₁', 'P', 'D₂', 'N₃', 'Ṡ'}, 'carnatic'))
function p.getEquivalents(frame, args, type)
	local output = ''
	local western = {}
	local alternate = {}
	local altType = ""
	local altText = ""
	local entry

	if (type == "carnatic") then
		altType = "hindustani"
		altText = "Hindustani"
	else 
		altType = "carnatic"
		altText = "Carnatic"
	end

	for key, value in pairs(args) do
		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

-- Generates the output.
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

-- Currently cleans up and returns the input.
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

-- Called by the svara template.
function p.main(frame)
	local args = p.sanitiseArgs(frame)
	
	return p._main(frame, args)
end

return p