Seq

Seq

Seq is a very simple microlanguage for creating generic sequences inside a morpheme. This was adapted from an adhoc scripting language built with morpho.

<<seq.lua>>=
S = {}

<<functions>>

return S

The seqfun function will return a function that uses morpho to parse a string and return a sequence.

<<functions>>=
step16 = {
    a = 0,
    b = 1,
    c = 2,
    d = 3,
    e = 4,
    f = 5,
    g = 6,
    h = 7,
    h = 8,
    i = 9,
    j = 10,
    k = 11,
    l = 12,
    m = 13,
    n = 14,
    o = 15,
    p = 16,
}

function S.seqfun(morpho, str)
    return function (str)
        return morpho.eval(str, step16)
    end
end

The gatefun function will return a function that uses morpho to create a gate signal.

<<functions>>=
gates = {
    o = 1,
    c = 0,
}

function S.gatefun(morpho, str)
    return function (str)
        return morpho.eval(str, gates)
    end
end

More words needed here. This is related to the notation system being developed.

<<functions>>=
function S.parse_tree(tree)
    local btab = {
        linear = 0,
        step = 1,
        gliss_medium = 2,
        gliss_big = 3,
        gliss_small = 4,
    }

    local behavior = btab["linear"]
    local dur = 1

    local gpath = {}

    for _,leaf in pairs(tree) do
        local v = {}

        if leaf.value == nil then
            error("leaf value is nil")
        end

        if leaf.behavior ~= nil then
            behavior = btab[leaf.behavior]
        end

        if leaf.dur ~= nil then
            local r = 0
            for _, digit in pairs(leaf.dur) do
                r = r * 8 + tonumber(digit)
            end
            dur = r
        end

        v[1] = tonumber(leaf.value)
        v[2] = dur
        v[3] = behavior
        table.insert(gpath, v)
    end

    return gpath
end