Forums > MaxMSP

(simple question) detect if a patcher is a parent patcher or a subpatcher ?

February 2, 2012 | 6:12 pm

hello,
a rather straightforward question : is there such an object, that would detect if the patcher within which it is has a parent patcher at all ? IE something that would allow us to route audio output towards either this patcher’s outlets, or directly towards dsp ? it seems a little bit silly for me not to find it.
The IO abstraction should do this, but i can’t figure out how…


February 2, 2012 | 8:25 pm

Of the top of my head, a simple Javascript object should do this. Send the message ‘hasParent’ to it and you’ll get a 1 if it has a parent or a 0 if it doesn’t.

E.g,

inlets = 1;
outlets = 1;

function hasParent()
{
   var p = this.patcher;
   if (p.parentpatcher)
      //then
         outlet(0, 1);
      else
         outlet(0, 0);
}

February 4, 2012 | 10:53 pm

Thanks ! i don’t know a thing about js. This seems to work perfectly.


May 31, 2012 | 3:36 am

Hum, this does not seem to work with a loadbang.

For example, add this code to a js object connected to a loadbang that sends out the hasParent message.

On loadbang, the javascript return that the patcher does not have a parent. On subsequent bangs it does!


May 31, 2012 | 4:03 am

Sounds like at the point that the loadbang is triggered, the parent-child relationship has not been fully established. I don’t know if that was a deliberate decision or whether it’s just a bug (e.g. the relationship is setup after all calls to loadbang have completed rather than before it)


Viewing 5 posts - 1 through 5 (of 5 total)