protoplug
protoplug copied to clipboard
error calling plugin_processBlock() : not enough memory
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.
By the way, this is happening when running Protoplug in Reaper.
Can anyone help?
This is the last time I am asking for help on this in 2021.
I can't reproduce it. I'm sending it LFOs on CC1 and CC4, and I tried stress-testing it by wrapping the midiBuf:eachEvent loop in another loop that repeats it 1000 times. Haven't tried in Reaper yet. It probably won't help, but you could try running "collectgarbage"
Accidentally closed and submitted a comment with an unfinished sentence, but I guess the message was there!