From 1eef19bf7577799096f9133f38e8a9c8f0d65248 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 19 Dec 2009 21:08:42 -0800 Subject: Adding limiter. --- dalos-limiter.lua | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ dalos.lua | 1 + 2 files changed, 87 insertions(+) create mode 100644 dalos-limiter.lua 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) diff --git a/dalos.lua b/dalos.lua index 4e61c2e..b0b9aee 100644 --- a/dalos.lua +++ b/dalos.lua @@ -664,6 +664,7 @@ dalos.objtype = { load "dalos-hexview.lua" load "dalos-binaryops.lua" +load "dalos-limiter.lua" ---------------- -- cgit v1.2.3