Forums > MaxMSP

dynamic object instantiation ?

Feb 25 2009 | 8:36 am


I recently implemented pitchshifting using the elasticx~ objects which I can’t distribute together with the rest of my code. In order to avoid maintaining two versions, I’d like to transparently instantiate the elastic object, and if that fails, use a common max object instead (such as wave~ or groove~).

Is there a way to do that ?

Feb 25 2009 | 10:52 am


obviously, javascript is the way to go.

Unfortunately, newdefault() will allow me to create the object, I just didn’t find a way to test whether the object creation was successful or not. If the external doesn’t exist, an error message is posted to the Max window. But testing the object reference (which should be null) with "if (myobject)" or "if (myobject.valid)" doesn’t really work out and seems to report true in any case.

I did succeed using the File object and the isopen method. Still, not the preferred solution as I would have to make explicit checks for OSX and WIN, due to different filetypes for externals (mxe vs. mxo).

any idea how to programmatically test for successful object creation ?

Feb 25 2009 | 11:26 am

just in case anyone is interested.

using newdefault() obviously always creates a valid max object, therefore valid returns true.

Whether creating the object was successful can be tested using the maxclass method of the object to be tested. If not successful, the call will return "jbogus" which can be tested for.

cheers, nick

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

Forums > MaxMSP