diff options
author | Pixel <pixel@nobis-crew.org> | 2009-12-19 21:08:42 -0800 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2009-12-19 21:08:42 -0800 |
commit | 1eef19bf7577799096f9133f38e8a9c8f0d65248 (patch) | |
tree | 8d2174e9acd77a0448bff89c10e9f3db525c8029 | |
parent | 25b0166dca330f1bce022e015e04965220ea0a01 (diff) |
Adding limiter.
-rw-r--r-- | dalos-limiter.lua | 86 | ||||
-rw-r--r-- | dalos.lua | 1 |
2 files changed, 87 insertions, 0 deletions
diff --git a/dalos-limiter.lua b/dalos-limiter.lua new file mode 100644 index 0000000..8f1a863 --- /dev/null +++ b/dalos-limiter.lua @@ -0,0 +1,86 @@ +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,
+
+ input_change = function (self, ind)
+ local h = self:get_linked_input(1)
+ if h then
+ self.color = cd.GREEN
+ local obj = {
+ h = h,
+ offset = 0,
+ size = math.max(h:getsize(), self.limit),
+ canread = function (self) return true end,
+ canwrite = function (self) return false end,
+ canseek = function (self) return true end,
+ canwatch = function (self) return false end,
+ getname = function (self) return end,
+ tell = function (self) return self.offset end,
+ getsize = function (self) return self.size end,
+ getmodif = function (self) return 0 end,
+ flush = function (self) return true end,
+ seek = function (self, offset, wheel)
+ if wheel == SEEK_SET then
+ self.offset = offset
+ elseif wheel == SEEK_CUR then
+ self.offset = self.offset + offset
+ elseif wheel == SEEK_END then
+ self.offset = self.size + offset
+ else
+ error "Unknown wheel"
+ end
+ if self.offset < 0 then self.offset = 0 end
+ if self.offset >= self.size then self.offset = self.size end
+ self.h:seek(self.offset)
+ return self.offset
+ end,
+ read = function (self, userdata, count)
+ count = math.min(count, self.size - self.offset)
+
+ if count == 0 then
+ if self.got_eof then self.lh:close() end
+ self.got_eof = true
+ return 0
+ end
+
+ self.got_eof = false
+
+ local r = self.h:read(count, userdata)
+ self.offset = self.offset + r
+ return r
+ end,
+ }
+ local newh = HandleLua(obj)
+ obj.lh = newh
+ self:set_houtput(newh)
+ self.dcanvas:draw()
+ else
+ self.color = cd.YELLOW
+ self:set_houtput(nil)
+ self.dcanvas:draw()
+ end
+ end,
+
+
+ create = function (d, tab)
+ 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"
+ local extra = { }
+
+ local obj = dalos.object(d, tab, extra)
+ end,
+}
+
+dalos.limiter = dalosp.limiter.create
+dalos:register_obj("Limiter", dalos.limiter)
@@ -664,6 +664,7 @@ dalos.objtype = { load "dalos-hexview.lua" load "dalos-binaryops.lua" +load "dalos-limiter.lua" ---------------- |