summaryrefslogtreecommitdiff
path: root/dalos-limiter.lua
diff options
context:
space:
mode:
authorunknown <Pixel@.(none)>2010-01-05 22:22:01 -0800
committerunknown <Pixel@.(none)>2010-01-05 22:22:01 -0800
commit628ed8138210d0f67cc35835f6fba96fcc7d932f (patch)
tree0357420e905b42533170ad2d71961373d82c7803 /dalos-limiter.lua
parent36624b05efae3fa82280a945fa2eb1dedc84e0b0 (diff)
parent69836d15333d9d48aecf3e0aef139c7eacf59214 (diff)
Merge branch 'master' of ssh+git://git.grumpycoder.net/pub/repo.git/Dalos
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")