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

vichug's icon

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...

dhjdhjdhj's icon

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);
}

vichug's icon

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

mrtof's icon

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!

dhjdhjdhj's icon

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)