summaryrefslogtreecommitdiff
path: root/dalos-limiter.lua
diff options
context:
space:
mode:
Diffstat (limited to 'dalos-limiter.lua')
-rw-r--r--dalos-limiter.lua60
1 files changed, 60 insertions, 0 deletions
diff --git a/dalos-limiter.lua b/dalos-limiter.lua
new file mode 100644
index 0000000..5643f30
--- /dev/null
+++ b/dalos-limiter.lua
@@ -0,0 +1,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")