Page 1 of 1

Creating a singleton Max object in Live?

Posted: Thu Nov 05, 2009 11:03 pm
by TomSwirly
Hello. I'm working on a show control system in Max mainly using the Javascript box.

Essentially, I need to have just one copy of a central program running - even if the device is instantiated multiple times within Live.

My thought was to actually create the Max Javascript box on the fly the first time the m4l device is created... later instantiations will detect by using Max's send/receive that an instance already exists and simply delegate their commands to that box.

Will this work? Can I use sends to speak between separate m4l boxes reliably? (Yes, I'm going to go off and try it... :-D) Is there some better way? Am I flirting with trouble?

Re: Creating a singleton Max object in Live?

Posted: Thu Nov 05, 2009 11:34 pm
by andrewbenson
There are lots of ways to do this (like everything in Max), but I have 2 possible suggestions.
First, you might consider just consider using separate master and slave devices, and use the appropriate one as needed. This would be easiest to program.
If you need to check whether something is already loaded, you could create some sort of storage container in global namespace (e.g. buffer~,value) and check to see if some value has been written. If it hasn't, send a message to load the JS and then set the value.

Something like this:

<pre><code>
----------begin_max5_patcher----------
982.3oc0Yt0aaBCEG+4jOEV7bWE9B2l1KqpOrJs8IXZZh.lDuxkHvIqcUce1
G1lPRZCfCgPxdwHLDy+yOe74bryKSmXLK6IZgA3ifuClL4koSlH6Rzwjp6mX
j3+TPreg70LBxRRnobiaTOiSehK6mufBR7K3z7MOJJKkWv9CU7Xn4slUcuzm
GrfkN+m4z.t5KicbKeL.RfhK1xVXYWfeT8aXgxuQ1re8ADd2wO0OQN9FeNm4
GCtKKNbyiSWkvRioborga6LaEeSulhNec5TQyMZZ+7r4yioa9HpAi+7RpxRL
XknoV1GvTIXOkoJ.B.U2dPSkbD1BrG1RBsnveN8cykvFMus1l9ytDWhvJwNx
VzsVklucCVLpOStnACHozeWJi2wiBZLvrQlLyOctwM8jMUtClxKXbqd9lCGb
PCGbhZDLQwY97SfJtV63wz.TfdWkdLbvLvrN8XjW6Oev5vGmgKb4.5zT5YDp
nPaH5vnAoAZjwZrMaa4Dz9fj4Kz30TNKv+LG6sAvr1OdEEDk6m93vFD1RFaw
RAlViy.GvLr8gLmiJLftUocwcWgAz5+5JLPVJ2dBp6JLftWFu7y1xenmzdIZ
r7mbMt7+jyanCcfPUhCRq7wbv3C5JoRLcXimBM1sgFbOHyvUFVSEsaBf2dro
LZkHHj66pxng51cGLhLjaiwbPwQkChN3v5hhiFV5rjRe7ufn9UttNjwQRFq1
qs.1CzfO2nY1pnHZt.N.XG34Dh9hHVawjsaqXBcQC91TEXeBb2JVbH34rU4f
u8v8O.nkfKfCVPyqW9EyRoAYqR465UqekZdxPu1jsa.D4cXHQtrko0Djtmtl
EPAqo4hYpXPLKgU+VKXggzzcEh9jQk61oJEdq9Osro3KDUjdK7LvWYqq8Thx
mOaioguQzPDskMvcLq8.DrFPhQNHKNKu6Q3Pm3nJAOVtQ.GUHqFby5ZCzfG3
9wrfKIWixyRtZHak+ob8qaaf09p.rMjRHgExJGYidbZmJ6Wt6KhSqGn2kM.V
KVNKUusedrXAqnR6aL67b5CxOkL4za96NjhUz+9npnLGWvFitRWfsBNjVvYo
9bVV5NuCZu2Yav9MfojsKyJIXkD.+3fSaZqnxBbAvNjjXK9GilPPhrz1p+fB
Ku56NU0Rz.fViO.6RRGI+fdJhoxvfQpMYu2cpPjHri3EwmNYwZXEuwTO6jUm
UK3QURt5PI3nJIqqOIINU7t0jy3pIGchyMtdSPsVz4smvGENoklFQN4oSZyw
M3DRmv9niLWNorBGq5sTP7v02cppEoyrJ9JjfjSPSk275z+AL2X8J.
-----------end_max5_patcher-----------
</code></pre>

Re: Creating a singleton Max object in Live?

Posted: Thu Nov 05, 2009 11:48 pm
by TomSwirly
Nice idea - but why not go even further then, and use a "value" box instead of the buffer~ (which is probably a lot heavier)?

This is fun. And tomorrow I get a launchpad!

Re: Creating a singleton Max object in Live?

Posted: Sat Nov 07, 2009 5:40 am
by DarwinGrosse
It's getting late. On first read, I thought you said that tomorrow you are getting a lunchbox.

Oh man...

[ddg]