Module:Svara/sandbox
Appearance
![]() | This is the module sandbox page for Module:Svara (diff). See also the companion subpage for test cases (run). |
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 = {
["Ṣ"] = {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)
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'"] = 'Ṡ',
["S'"] = 'Ṡ',
}
for key, value in pairs(input) do
if (key ~= 'foot') 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.resolveCarnatic(input)
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)
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 svaras = {}
if (input['foot']) then
foot = true
input['foot'] = nil
end
for key, value in pairs(input) do
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;"}}
else
svaras[key] = value
end
end
svaras['separator'] = " "
local output = mSep.main(svaras)
if (foot) then
local equivalents = p.getEquivalents(frame, input, type)
output = frame:expandTemplate{title = 'finedetail', args = {output, '', equivalents}}
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