Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error calling plugin_processBlock() : not enough memory #47

Open
nandoflorestan opened this issue Dec 17, 2021 · 4 comments
Open

error calling plugin_processBlock() : not enough memory #47

nandoflorestan opened this issue Dec 17, 2021 · 4 comments

Comments

@nandoflorestan
Copy link

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.

@nandoflorestan
Copy link
Author

By the way, this is happening when running Protoplug in Reaper.

Can anyone help?

@nandoflorestan
Copy link
Author

This is the last time I am asking for help on this in 2021.

@pac-dev
Copy link
Owner

pac-dev commented Dec 31, 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"

@pac-dev pac-dev closed this as completed Dec 31, 2021
@pac-dev
Copy link
Owner

pac-dev commented Dec 31, 2021

Accidentally closed and submitted a comment with an unfinished sentence, but I guess the message was there!

@pac-dev pac-dev reopened this Dec 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants