How to know how many instances of the same patcher are loaded ?

Jan 10, 2009 at 1:09pm

How to know how many instances of the same patcher are loaded ?

Hello,

Is there a way to know how many instances of a patchers (in my case,
bpatchers) are loaded ? I’m trying to figure out how to autoname the
receive~ signal input channels of the tracks of my mixer built with
several bpatchers (one for each channel). This way, any time a bpatcher
channel is added, it’ll check its instance number and set the receive~
object accordingly (L1, R1, L2, R2…).

Thanks for all your crazy ideas

Best wishes

f.e


f.e chanfrault | aka | personal computer music
> >>>>>> http://www.personal-computer-music.com
> >>>>>> | film soundtracks, sound art, music |

#41628
Jan 10, 2009 at 2:10pm

#148337
Jan 11, 2009 at 9:57am

Cool patch, Julien. Meanwhile i was working on a JS solution that also
takes care of deleted instances.

Put this in the bpatcher :

– Pasted Max Patch, click to expand. –

With this instance_counter.js :

——————————————-
autowatch = 1;
var me;
g=new Global(“inst_num”);

if (!g.alreadyhere)
{
g.num = 1;
me = g.num;
g.alreadyhere = true;
}
else {
g.num = g.num + 1;
me = g.num;
}

function bang()
{
outlet(0, me);
}

function notifydeleted() {
//post(“argh, i’m deleted”);
if (g.num >> 1) g.num = g.num -1;
else g.num = 0;
}
——————————————-

All is cool, but… how to reverse the right to left Max creation
direction ? It’s really annoying to have the tracks of your mixer named
from 16 to 1…

Any ideas of a mechanism to name the objects in the opposite way they
were created ?

Best wishes

f.e

f.e chanfrault | aka | personal computer music
> >>>>>> http://www.personal-computer-music.com
> >>>>>> | film soundtracks, sound art, music |

#148338
Jan 11, 2009 at 1:42pm

#148339
Jan 12, 2009 at 10:45am

Here’s a completly different approach. It analyses the text contents of the patcher file on the filesystem. In order to run it you’d have to save the patcher before running it. Don’t know if it works in every situation (with collectives e.g.) as it relies on the patch beeing written in a form like that:
{
“patcher” : {
“fileversion” : 1,
“rect” : [ 259.0, 76.0, 1016.0, 832.0 ],
“bglocked” : 0,
“defrect” : [ 259.0, 76.0, 1016.0, 832.0 ],
“openrect” : [ 0.0, 0.0, 0.0, 0.0 ],



}

Here’s an example, save it to disk and make sure the js file below is also saved in your searchpaths.

– Pasted Max Patch, click to expand. –

//save this as getsubpatchers.js
outlets = 2;
inlets = 1;
autowatch = 1;

function anything(){
mycount = 0;
mysearch = messagename;

owner = this.patcher;
myfile = new File(owner.filepath);
if (myfile.isopen){
while ((line = myfile.readline()) != null) {
//
if((line.indexOf(mysearch) > -1) &&(line.indexOf(“”name”") > -1)){
//post(line + “n”);
mycount ++;
}

}
msg = “You have ” + mycount +” instances of ” + mysearch + ” patchers in ” +owner.name+”.”;
outlet(1, msg);
outlet(0, mycount);
}
}
//EOF

#148340
Jan 13, 2009 at 11:32am

#148341
Jan 14, 2009 at 12:28am

#148342
Jan 14, 2009 at 6:45pm

Holy moly, I did not even know there’s such a thing as an getattr method… Is there some “secret functions in max js documentation” that accidently was not bundled with my Max Installation :-)

#148343
Jan 14, 2009 at 7:45pm

I’m just starting to learn javascript, previously I’ve used other people’s scripts in conjuntion with my own xhtml and css on websites but haven’t really delved into how they work.

I’ve decided to try to learn how to use it in max but the max specific documentation is not all that helpful (js tutorials 1-4 and the “js in max” section). I think I found out about the getattr() method in a post by Emmanuel Jourdan somewhere on the js forum.

If you happen to know of any max-specific tutorials that go above and beyond the ones I mentioned above then let me know, and good luck!

lh

#148344
Jan 15, 2009 at 9:39am

#148345
Jan 15, 2009 at 2:25pm

Ah yes that’s probably a better way to go about it.

By way of a quick explanation: inside the character class [square brackets] the caret ^ means “anything except”. So [^0123] will block 0,1,2,3 and pass any other character.

I’m working on some “regular expressions in max” basic tutorials using regular-expressions.info and the mozilla dev site to guide me. Perhaps when they’re done you would want to have a look and see if you think they might be helpful to other max users.

lh

#148346
Jan 15, 2009 at 2:42pm

Quote: thereishopeforus@hotmail.com wrote on Thu, 15 January 2009 15:25
—————————————————-

> I’m working on some “regular expressions in max” basic tutorials using regular-expressions.info and the mozilla dev site to guide me.
—————————————————-

I find the tutorial included in Text Wrangler a very good and comprehensive one. You might check it out http://www.barebones.com/products/textwrangler/

Best, Joerg

#148347
Jan 15, 2009 at 3:39pm

Thankyou Joerg.

I’ve just had a look and the regular expression section of the pdf help file and it is indeed helpful. Probably the most easy-to-understand explanation I have come across so far and the example regexes with descriptions are useful too. Now if only I could remember to use escaping slashes in max when I need to!

lh

#148348
Jan 15, 2009 at 4:34pm

#148349
Jan 19, 2009 at 2:48pm

you can do this with 110.loadinstance.

i reside in an internet cafe in a strange country and can t post you the patch because here is no macs but my abs is basically a
value
which is doing +1 to itself – after spitting the current number out when loaded. so the first instance of “110.loadinstance bubu” is loadbanging “1″ to the parent and the next one “2″.
its even counting backwards if needed …

oh and there is also 110.loadunisym: this is an even simpler patch, it is just spitting out “#0#1″ (well something of that manner)

sorry again that i dont just submit the stuff instead of talking. i dont even know how to make a tilda on the windwos keyboard.

-110

#148350

You must be logged in to reply to this topic.