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

    Jan 10 2009 | 1:09 pm
    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 chanfrault | aka | personal computer music > >>>>>> > >>>>>> | film soundtracks, sound art, music |

    • Jan 10 2009 | 2:10 pm
    • Jan 11 2009 | 9:57 am
      Cool patch, Julien. Meanwhile i was working on a JS solution that also takes care of deleted instances.
      Put this in the bpatcher :
      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 chanfrault | aka | personal computer music > >>>>>> > >>>>>> | film soundtracks, sound art, music |
    • Jan 12 2009 | 10:45 am
      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.
      //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 ""."; outlet(1, msg); outlet(0, mycount); } } //EOF
    • Jan 13 2009 | 11:32 am
    • Jan 14 2009 | 6:45 pm
      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 :-)
    • Jan 14 2009 | 7:45 pm
      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!
    • Jan 15 2009 | 9:39 am
    • Jan 15 2009 | 2:25 pm
      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 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.
    • Jan 15 2009 | 2:42 pm
      Quote: wrote on Thu, 15 January 2009 15:25 ----------------------------------------------------
      > I'm working on some "regular expressions in max" basic tutorials using 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
      Best, Joerg
    • Jan 15 2009 | 3:39 pm
      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!
    • Jan 19 2009 | 2:48 pm
      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.