Thanks a lot, Christof and Sebastian, for your answers!
On Fri, Nov 20, 2020 at 8:40 PM Christof Ressi wrote:
[...]
However, my external accepts an "open" message which might allocate a new internal buffer, and I would like Pd to call my dsp function in order to update a few pointers so that the "perform" function can access the new buffer.
If the buffer can change, you shouldn't directly pass it to the perform method. Instead you should pass the object which contains the buffer, then the perform method will always see the most recent state.
Generally, most externals pass the object, the individual signals and finally the vector size.
I know that's the canonical way, but I need to "insert" a few additional channels between the existing ones. And this changes with the "open" message.
But now I found a different (and better!) solution where I store the pointers to the signals within my object instead of directly passing them to the perform function (I pass only the object itself).
This solves my problem and it also makes the code much simpler at the same time!
Will the "perform" function be called even if the "open" handler isn't finished yet?
No, all methods are executed *synchronously*.
Thanks for confirming this.
I suspected this to be true, but I wasn't quite sure.
[...]
Christof
On Fri, Nov 20, 2020 at 9:48 PM Sebastian Shader wrote:
why don't you just have a function that does the things that you want to have happen when the dsp graph changes and when the open message is received? then just call that function from both the dsp function and the open handler
Yes, that's exactly what I was thinking of after reading Christof's response.
As so often, the problem can be solved by adding another level of indirection!
But it seems like in your case you just want to send the new allocated buffer to perform, so why not just store a pointer to it in the object and then access that in perform?
Because my buffer is actually storing pointers to channels. And those pointers have to be updated using the pointers to the outlet signals that are provided in the "dsp" function. But my buffer also contains pointers that are not related to outlets and that have to be updated in the "open" handler.
In the meantime I have updated my object to contain a list of pointers to the outlet signals, which is kept up-to-date in the "dsp" function. And I've created a function that moves those pointers around to another list of pointers, and this function is called from both the "dsp" function and the "open" handler.
Now everything works as expected, no more segfaults (at least for now ...).
In case somebody is interested, this is the mentioned change: https://github.com/AudioSceneDescriptionFormat/asdf-rust/commit/ef81f91c6f87...
cheers, Matthias
if your open handler takes awhile it will stop pd entirely until it's finished I believe, unless it's threaded somehow.
-seb
-----Original Message----- From: Matthias Geier matthias.geier@gmail.com To: Pd-List Pd-list@lists.iem.at Sent: Fri, Nov 20, 2020 10:37 am Subject: [PD] external: How to force calling the "dsp" function?
Dear list.
I'm working on a Pd external (https://github.com/AudioSceneDescriptionFormat/asdf-rust/tree/master/pure-da...) which uses class_addmethod() with gensym("dsp") to register a "dsp" function.
I guess this function is called whenever the audio graph changes, and that works fine.
However, my external accepts an "open" message which might allocate a new internal buffer, and I would like Pd to call my dsp function in order to update a few pointers so that the "perform" function can access the new buffer.
So my question is: Can I somehow, after handling my "open" message, force the "dsp" method to be called?
And a related question: What happens when my handling of the "open" message takes longer than expected? Will the "perform" function be called even if the "open" handler isn't finished yet?
Or can I somehow tell Pd that it should stop calling my "perform" function for a little bit while I allocate a new buffer and then tell it to call the "dsp" function and afterwards resume calling the "perform" function?
BTW, with "perform" function I mean the function that has been registered with dsp_addv().
cheers, Matthias