File: ldemux.pd_lua

package info (click to toggle)
pd-lua 0.12.23%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,912 kB
  • sloc: ansic: 3,733; lisp: 66; makefile: 64
file content (28 lines) | stat: -rw-r--r-- 740 bytes parent folder | download | duplicates (7)
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