summaryrefslogtreecommitdiff
path: root/dalos-limiter.lua
blob: 5643f3068d580c865971620e9dde02f55a359bfd (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
dalosp.limiter = {   
    configure = function (self)
        local accept, limit = iup.GetParam(self.name .. " configuration", nil, [[
Limit: %i{The actual size this limiter is going to produce}
]], self.op or 0, self.maximize and 1 or 0)
        if accept then
            self.extra.limit = limit
            self:input_change()
        end
    end,
    
    get_settings = function (self)
        return { limit = self.extra.limit }
    end,
    
    input_change = function (self, ind)
        local h = self:get_linked_input(1)
        if h then
            self.color = cd.GREEN
            local obj = {
                h = h,
                size = math.min(h:getsize(), self.extra.limit),
                getname = function () return self.name end,
                do_read = function (self, count, userdata)
                    return self.h:read(count, userdata)
                end,
                do_seek = function (self)
                    self.h:seek(self.offset, SEEK_SET)
                end,
            }
            self:set_houtput(dalos.luahandle(obj))
            self.dcanvas:draw()
        else
            self.color = cd.YELLOW
            self:set_houtput(nil)
            self.dcanvas:draw()
        end
    end,
    
    create = function (d, tab, settings)
        tab.ninputs = 1
        tab.noutputs = 1
        tab.otype = dalos.objtype.LUA_FILTER
        tab.configure = dalosp.limiter.configure
        tab.input_change = dalosp.limiter.input_change
        tab.default_name = "Limiter"
        tab.ntype = "Limiter"
        tab.get_settings = dalosp.limiter.get_settings
        local extra = { }
        if not settings then settings = {} end
        extra.limit = settings.limit or 0
        
        local obj = dalos.object(d, tab, extra)
        
        return obj
    end,
}

dalos.limiter = dalosp.limiter.create
dalos:register_obj("Limiter", dalos.limiter, "Basic Filters")