-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Description
I have a MIDI effect that, after a while, errors out with the message
error calling plugin_processBlock() : not enough memory
and stops doing anything.
My code is the following:
require "include/protoplug"
-- Use CC 4 to interfere with dynamics on CC 1.
CC = {}
CC.dynamic = 1
CC.interferic = 4
outEvents = {}
Channel = {}
function Channel:new(channelNumber)
self.__index = self
local o = {dynamic = 64, interferic = 64, channel = channelNumber}
setmetatable(o, self)
return o
end
function Channel:dynamicEvent(pos)
local value = math.min(127, math.max(0, self.dynamic + (self.interferic - 64)))
-- print(self.dynamic, self.interferic, value)
return midi.Event.control(self.channel, CC.dynamic, value, pos)
end
chan = {}
for i=1, 16 do
chan[i] = Channel:new(i)
end
function plugin.processBlock(samples, buffer_size, midiBuf)
for i=0, #outEvents do outEvents[i] = nil end -- Clear the list
for ev in midiBuf:eachEvent() do
if ev:isControl() then
if CC.dynamic == ev:getControlNumber() then
chan[ev:getChannel()].dynamic = ev:getControlValue()
table.insert(outEvents, chan[ev:getChannel()]:dynamicEvent(ev.time))
elseif CC.interferic == ev:getControlNumber() then
chan[ev:getChannel()].interferic = ev:getControlValue()
table.insert(outEvents, chan[ev:getChannel()]:dynamicEvent(ev.time))
else
table.insert(outEvents, midi.Event(ev))
end
else
--print(ev)
table.insert(outEvents, midi.Event(ev))
end
end
refillMIDIBuffer(midiBuf)
end
function refillMIDIBuffer(midiBuf)
midiBuf:clear()
for _, e in ipairs(outEvents) do
midiBuf:addEvent(e)
end
end
I really don't see why this would complain about memory. Any help appreciated.
Metadata
Metadata
Assignees
Labels
No labels