Is there some way to provide the equivalent of closebang for an abstraction

Dec 29, 2011 at 7:27am

Is there some way to provide the equivalent of closebang for an abstraction

I have a lot of abstractions that initialize themselves with loadbang messages. I’d like them to be be able to clean themselves up as well but apparently closebang doesn’t get triggered inside abstractions.

Is there any alternative? This seems like a strange oversight.

Thanks,

#60904
Dec 29, 2011 at 12:16pm

It seems that abstractions are basically handled like function calls and don’t “know” when closed.
As a workaround you could try sending closebang from the parent patcher to the abstraction.

#219291
Dec 29, 2011 at 2:42pm

What you suggest as an oversight is how I would have guessed things worked.

It appears closebang is for when the patcher window is closed, not when the patcher is unloaded (if you open and close your patcher many times you will see many closebangs).

I’m not sure, but off the top of my head is to have some mxj or js that performs some special actions when deleted (which would happen when the abstraction is unloaded). I’ve got no idea if that will do what you want.

#219292
Dec 29, 2011 at 2:52pm

I’m not sure, but you’re maybe looking for [freebang]

#219293
Dec 29, 2011 at 3:04pm

That’s what I’m doing now — but the point is to have the abstraction be responsible for itself…..same concept as having a constructor and matching destructor in C++
—————
As a workaround you could try sending closebang

I’m not sure what the difference is between being closed and being unloaded. When I close a patcher, it stops responding to data, which is EXACTLY what I want. The closebang does the job. I just want it to work for the abstraction as well. I don’t really care if the objects are still in memory somewhere.
—————
It appears closebang is for when the patcher window is closed, not when the patcher is unloaded

Correct — and if that patcher contains an abstraction, I want that abstraction to do its initialization (triggered by its own loadbang) and cleanup (triggered by????) many times.
—————
if you open and close your patcher many times you will see many closebangs

#219294
Dec 29, 2011 at 3:05pm

So I guess the question is whether there is any mechanism available that can live inside an abstraction that detects when the abstraction is closed (because its parent was closed)?

#219295
Jan 28, 2012 at 4:57am

I’ve just discovered that if I have patcher A (containing a closebang object) inside bpatcher B,

and then I put bpatcher B into a main top-level patcher P, the closebang inside A will trigger when I close P.

That seems like a useful temporary workaround.

#219296
Jan 28, 2012 at 4:25pm

ehm … why do you need to clean up an abstraction before it is unloaded? in order to make
it send something out to main?

#219297
Jan 28, 2012 at 4:31pm

It could be, or it could be about saving any data created inside the abstraction, or any number of other things.

The point however is to allow an abstraction to be responsible for both its own construction and destruction without having to explicitly be told to do so from somewhere else.

Consider for example why most OO languages have constructors AND destructors. Same reason.

#219298
Jan 28, 2012 at 5:06pm

Sorry for the delay, just saw your answer to my previous post.

That’s what I’m doing now

Just in case you misread me : I was suggesting [freebang] (it seems you are using [closebang]).

#219299
Jan 28, 2012 at 5:17pm

Does that work inside an abstraction? What I found with closebang is that it only worked at the toplevel patcher. If I put the closebang INSIDE an abstraction, it was not triggered when the toplevel patcher closed.

I assumed freebang would behave the same way.

#219300
Jan 28, 2012 at 5:34pm

Try it out. I think it works inside an abstraction, and that it’s what you’re looking for :
[freebang] should bang when it is freed, wherever it is.

#219301
Jan 31, 2012 at 7:31am

I had an idea about some solution that may work using an MXJ, but never had time to try it out. Turns out I didn’t know about freebang (I thought at one point I had gone through and checked out all the standard Max and MSP objects but I guess I should do it again because this is the second new object I’ve heard about this month).

I’m curious, is freebang doing what you need? If not maybe I am misunderstanding what you need. I’m just curious because if freebang doesn’t do what you need it sounds like a fun problem to try to solve.

#219302
Jan 31, 2012 at 12:37pm

Haven’t had a chance to try it yet — the bpatcher trick was good enough and I have a much bigger problem where ‘load’ to pcontrol has stopped working (posted that yesterday) that I’m trying to solve.

#219303

You must be logged in to reply to this topic.