aboutsummaryrefslogtreecommitdiff
path: root/examples/ldemux.pd_lua
blob: 2c4301f6e3441bb70e718deda0b133e680d64ac0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
-- contributed by Frank Barknecht

local LDemux = pd.Class:new():register("ldemux")

function LDemux:initialize(name, atoms)
    local n = atoms[1] or 2 -- default to 2 outlets.
    if type(n) ~= "number" or n < 2 then
        pd.post("ldemux: wrong outlet-count argument, using 2 outlets instead")
        n = 2
    end
    self.outlets = n
    self.inlets = 2
    self.to = 1
    -- second arg, if a number, selects default outlet
    if type(atoms[2]) == "number" then
        self:in_2_float(atoms[2])
    end
    return true
end

function LDemux:in_2_float(f)
    -- clip selection between left- and rightmost outlet
    self.to = math.max(1, math.min(self.outlets, f))
end

function LDemux:in_1(s, m)
  self:outlet(self.to, s, m)
end