Jump to content

Module:Svara/sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Use efn instead of finedetail
Use mw.loadData and also make abbr optional.
Line 5: Line 5:


-- This is still missing most lower and higher octave notes.
-- This is still missing most lower and higher octave notes.
local svaraDesc = {
local svaraDesc = mw.loadData('Module:Svara/equivalents')
local svaraResolve = mw.loadData('Module:Svara/resolve')
["Ṣ"] = {desc = "Shadja (Sa, lower octave)", carnatic = "Ṣ", hindustani = "Ṣ", western = "C"},
["S"] = {desc = "Shadja (Sa)", carnatic = "S", hindustani = "S", western = "C"},
["Ṡ"] = {desc = "Shadja (Sa, higher octave)", carnatic = "Ṡ", hindustani = "Ṡ", western = "C"},
["R₁"] = {desc = "Shuddha Rishabha", carnatic = "R₁", hindustani = "Ṟ", western = "C#"},
["R₂"] = {desc = "Chatushruti Rishabha", carnatic = "R₂", hindustani = "R", western = "D"},
["R₃"] = {desc = "Shatshruti Rishabha", carnatic = "R₃", hindustani = "G̱", western = "D#"},
["G₁"] = {desc = "Shuddha Gandhara", carnatic = "G₁", hindustani = "R", western = "D"},
["G₂"] = {desc = "Sadharana Gandhara", carnatic = "G₂", hindustani = "G̱", western = "D#"},
["G₃"] = {desc = "Antara Gandhara", carnatic = "G₃", hindustani = "G", western = "E"},
["M₁"] = {desc = "Shuddha Madhyama", carnatic = "M₁", hindustani = "M", western = "F"},
["M₂"] = {desc = "Prati Madhyama", carnatic = "M₂", hindustani = "M̄", western = "F#"},
["P"] = {desc = "Pancham (Pa)", carnatic = "P", hindustani = "P", western = "G"},
["D₁"] = {desc = "Shuddha Dhaivata", carnatic = "D₁", hindustani = "Ḏ", western = "G#"},
["D₂"] = {desc = "Chatushruti Dhaivata", carnatic = "D₂", hindustani = "D", western = "A"},
["D₃"] = {desc = "Shatshruti Dhaivata", carnatic = "D₃", hindustani = "Ṉ", western = "A#"},
["N₁"] = {desc = "Shuddha Nishada", carnatic = "N₁", hindustani = "D", western = "A"},
["N₂"] = {desc = "Kaishiki Nishada", carnatic = "N₂", hindustani = "Ṉ", western = "A#"},
["N₃"] = {desc = "Kakali Nishada", carnatic = "N₃", hindustani = "N", western = "B"},
["Ṟ"] = {desc = "Komal Re", carnatic = "R₁", hindustani = "Ṟ", western = "C#"},
["R"] = {desc = "Shuddha Re", carnatic = "R₂", hindustani = "R", western = "D"},
["G̱"] = {desc = "Komal Gandhara", carnatic = "G₂", hindustani = "G̱", western = "D#"},
["G"] = {desc = "Shuddha Gandhara", carnatic = "G₃", hindustani = "G", western = "E"},
["M"] = {desc = "Madhyama", carnatic = "M₁", hindustani = "M", western = "F"},
["M̄"] = {desc = "Tivra Ma", carnatic = "M₂", hindustani = "M̄", western = "F#"},
["Ḏ"] = {desc = "Komal Dhaivata", carnatic = "D₁", hindustani = "Ḏ", western = "G#"},
["D"] = {desc = "Shuddha Dhaivata", carnatic = "D₂", hindustani = "D", western = "A"},
["Ṉ"] = {desc = "Komal Nishada", carnatic = "N₂", hindustani = "Ṉ", western = "A#"},
["N"] = {desc = "Shuddha Nishada", carnatic = "N₃", hindustani = "N", western = "B"},
}


function p.resolveCarnatic(input)
function p.resolve(input, type)
local svaras = {
local svaras = svaraResolve[type]
["'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'"] = 'Ṡ',
["S'"] = 'Ṡ',
}
for key, value in pairs(input) do
for key, value in pairs(input) do
if (key ~= 'foot') then
if svaras[value] then
input[key] = svaras[value];
input[key] = svaras[value];
end
end
Line 100: Line 24:
-- Carnatic notation is case-insensitive. Enable the capitalise option.
-- Carnatic notation is case-insensitive. Enable the capitalise option.
local input = p.sanitiseArgs(frame, true)
local input = p.sanitiseArgs(frame, true)
input = p.resolveCarnatic(input)
input = p.resolve(input, "carnatic")


return p._main(frame, input, 'carnatic')
return p._main(frame, input, 'carnatic')
Line 108: Line 32:
function p.hindustani(frame)
function p.hindustani(frame)
local input = p.sanitiseArgs(frame)
local input = p.sanitiseArgs(frame)
input = p.resolveHindustani(input)
input = p.resolveHindustani(input, "hindustani")


return p._main(frame, input, 'hindustani')
return p._main(frame, input, 'hindustani')
Line 149: Line 73:
function p._main(frame, input, type)
function p._main(frame, input, type)
local foot = nil
local foot = nil
local abbr = true
local svaras = {}
local svaras = {}
if (input['foot']) then
if input['foot'] then
foot = true
foot = true
input['foot'] = nil
input['foot'] = nil
end

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

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

Revision as of 17:33, 3 October 2018

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
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
function p.hindustani(frame)
	local input = p.sanitiseArgs(frame)
	input = p.resolveHindustani(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