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 15:02, 29 September 2018 (fineprint expand.). 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 = {}
local f -- A global frame variable.

-- This is still missing most lower and higher octave notes.
local svaraDesc = {
	["Ṣ"]  = {desc = "Ṣ", carnatic = "Ṣ", hindustani = "Ṣ", western = "C"},
	["S"]  = {desc = "S", carnatic = "S", hindustani = "S", western = "C"},
	["Ṡ"]  = {desc = "Ṡ", carnatic = "Ṡ", hindustani = "Ṡ", western = "C"},
	["R₁"] = {desc = "R₁", carnatic = "R₁", hindustani = "R₁", western = "C"},
	["R₂"] = {desc = "R₂", carnatic = "R₂", hindustani = "R₂", western = "C"},
	["R₃"] = {desc = "R₃", carnatic = "R₃", hindustani = "R₃", western = "C"},
	["G₁"] = {desc = "G₁", carnatic = "G₁", hindustani = "G₁", western = "C"},
	["G₂"] = {desc = "G₂", carnatic = "G₂", hindustani = "G₂", western = "C"},
	["G₃"] = {desc = "G₃", carnatic = "G₃", hindustani = "G₃", western = "C"},
	["M₁"] = {desc = "M₁", carnatic = "M₁", hindustani = "M₁", western = "C"},
	["M₂"] = {desc = "M₂", carnatic = "M₂", hindustani = "M₂", western = "C"},
	["P"]  = {desc = "P", carnatic = "P", hindustani = "P", western = "C"},
	["D₁"] = {desc = "D₁", carnatic = "D₁", hindustani = "D₁", western = "C"},
	["D₂"] = {desc = "D₂", carnatic = "D₂", hindustani = "D₂", western = "C"},
	["D₃"] = {desc = "D₃", carnatic = "D₃", hindustani = "D₃", western = "C"},
	["N₁"] = {desc = "N₁", carnatic = "N₁", hindustani = "N₁", western = "C"},
	["N₂"] = {desc = "N₂", carnatic = "N₂", hindustani = "N₂", western = "C"},
	["N₃"] = {desc = "N₃", carnatic = "N₃", hindustani = "N₃", western = "C"},
	["Ṟ"]  = {desc = "Ṟ", carnatic = "Ṟ", hindustani = "Ṟ", western = "C"},
	["R"]  = {desc = "R", carnatic = "R", hindustani = "R", western = "C"},
	["G̱"]  = {desc = "G̱", carnatic = "G̱", hindustani = "G̱", western = "C"},
	["G"]  = {desc = "G", carnatic = "G", hindustani = "G", western = "C"},
	["M"]  = {desc = "M", carnatic = "M", hindustani = "M", western = "C"},
	["M̄"]  = {desc = "M̄", carnatic = "M̄", hindustani = "M̄", western = "C"},
	["Ḏ"]  = {desc = "Ḏ", carnatic = "Ḏ", hindustani = "Ḏ", western = "C"},
	["D"]  = {desc = "D", carnatic = "D", hindustani = "D", western = "C"},
	["Ṉ"]  = {desc = "Ṉ", carnatic = "Ṉ", hindustani = "Ṉ", western = "C"},
	["N"]  = {desc = "N", carnatic = "N", hindustani = "N", western = "C"},
}

function p.convertCarnaticHindustani(input)
	local svaras = {
		["'S"] = 'Ṣ',
		['S']  = 'S',
		['R1'] = 'Ṟ',
		['R2'] = 'R',
		['R3'] = 'G̱',
		['G1'] = 'R',
		['G2'] = 'G̱',
		['G3'] = 'G',
		['M1'] = 'M',
		['M2'] = 'M̄',
		['P']  = 'P',
		['D1'] = 'Ḏ',
		['D2'] = 'D',
		['D3'] = 'Ṉ',
		['N1'] = 'D',
		['N2'] = 'Ṉ',
		['N3'] = 'N',
		["S'"] = 'Ṡ',
	}
	for key, value in pairs(input) do
      input[key] = svaras[value];
    end
    
	return input
end

function p.resolveCarnatic(input)
	local svaras = {
		["'S"] = 'Ṣ',
		['S']  = 'S',
		['R1'] = 'R₁',
		['R2'] = 'R₂',
		['R3'] = 'R₃',
		['G1'] = 'G₁',
		['G2'] = 'G₂',
		['G3'] = 'G₃',
		['M1'] = 'M₁',
		['M2'] = 'M₂',
		['P']  = 'P',
		['D1'] = 'D₁',
		['D2'] = 'D₂',
		['D3'] = 'D₃',
		['N1'] = 'N₁',
		['N2'] = 'N₂',
		['N3'] = 'N₃',
		["S'"] = 'Ṡ',
	}
	for key, value in pairs(input) do
		if (key ~= 'foot') then
    		input[key] = svaras[value];
    	end
    end
    
	return input
end

function p.resolveHindustani(input)
	local svaras = {
		["'s"] = 'Ṣ',
		["'S"] = 'Ṣ',
		['s']  = 'S',
		['S']  = 'S',
		['r']  = 'Ṟ',
		['R']  = 'R',
		['g']  = 'G̱',
		['G']  = 'G',
		['m']  = 'M',
		['M']  = 'M̄',
		['p']  = 'P',
		['P']  = 'P',
		['d']  = 'Ḏ',
		['D']  = 'D',
		['n']  = 'Ṉ',
		['N']  = 'N',
		["S'"] = 'Ṡ',
	}
	for key, value in pairs(input) do
      input[key] = svaras[value];
    end

	return input
end

-- Called by the svaraC template
function p.carnatic(frame)
	-- Carnatic notation is case-insensitive. Enable the capitalise option.
	local args = p.sanitiseArgs(frame, true)
	args = p.resolveCarnatic(args)

	return p._main(args, 'carnatic')
end

-- Called by the svaraH template
function p.hindustani(frame)
	local args = p.sanitiseArgs(frame)
	args = p.resolveHindustani(args)

	return p._main(args, 'hindustani')
end

function p.getEquivalents(args, type)
	return "foo"
end
	
function p._main(args, type)
	local foot = nil
	
	if (args['foot']) then
		foot = true
		args['foot'] = nil
	end
	
	for key, value in pairs(args) do
		-- Use the abbr tag to add a description; avoid the default dotted
		-- underline style as it messes up the macrons.
		args[key] = f:expandTemplate{title = 'abbr', args = {value, svaraDesc[value]['desc'], style="text-decoration:none;"}};
    end
    
	args['separator'] = " "
	local output = mSep.main(args)
	
	if (foot) then
		local equivalents = p.getEquivalents(args, type)
		output = f:expandTemplate{title = 'finedetail', args = {output, '', equivalents}}
	end
	
    return output
end

function p.sanitiseArgs(frame, capitalise)
	f = frame
	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(args)
end

return p