Moduuli:Musiikin taulukot/Poikkeusjako

Tämän moduulin ohjeistuksen voi tehdä sivulle Moduuli:Musiikin taulukot/Poikkeusjako/ohje

local p = {}

local tekstipohja = require "Moduuli:Tekstipohja"

local templ = require "Moduuli:Musiikin taulukot/Poikkeusjako/pohja"
local scoreText_template = templ.text


function p.esimerkki(frame)
    if frame.args.frame == "malline" then
        frame = frame:getParent()
    end

    local nowiki = frame.args.nowiki and (frame.args.nowiki ~= "")
    local time_signature = frame.args.tahtilaji or "4/4"
    local tempo = frame.args.tempo or "120"
    local repeats = frame.args.toistoja or "4"
    assert(tonumber(repeats) .. "" == repeats, "Toisojen määrän pitää olla numero")

    local notes = frame.args.nuotit:gsub("¦", "|")
    local notes_bd = frame.args.nuotit_basso:gsub("¦", "|")

    if not mw.ustring.match(time_signature, "^%d+/%d$") then
        error("Virheellinen tahtilaji: " .. time_signature)
    end

    if not mw.ustring.match(tempo, "^%d+$") then
        error("Virheellinen tempo: " .. tempo)
    end

    local score = tekstipohja.korvaaMuuttujat(scoreText_template, {
						  ["TAHTILAJI"] = time_signature,
						  ["TEMPO"] = tempo,
						  ["CLAVENUOTIT"] = notes,
						  ["BASSORUMPU"] = notes_bd,
						  ["TOISTOJA"] = repeats })

    local args = { raw = "1", sound = "1" }

    local pref = ""

    if nowiki then
        return "<pre>" .. pref .. score .. "</pre>"
    else
        return pref .. frame:extensionTag{ name = "score", content = score, args = args }
    end
end

return p