Module:Svara/sandbox: Difference between revisions
Appearance
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. |
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 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return input |
|||
end |
|||
function p.resolveHindustani(input) |
|||
⚫ | |||
["'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 |
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. |
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 svaras = {} |
local svaras = {} |
||
if |
if input['foot'] then |
||
foot = true |
foot = true |
||
input['foot'] = nil |
input['foot'] = nil |
||
⚫ | |||
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 |
||
⚫ | |||
if type ~= "western" then |
|||
⚫ | |||
if (abbr) then |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
else |
|||
⚫ | |||
svaras[key] = value |
|||
⚫ | |||
⚫ | |||
end |
end |
||
end |
end |
Revision as of 17:33, 3 October 2018
![]() | 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 = 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