Forums > Dev

Change in window implementation in Max 6 (Mac OS X)

Nov 07 2011 | 11:05 pm

I have been using

mess1( patcherview, gensym( "nativewindow" ), (void **)&viewWindow );

to get access to the native patcher window reference.

It used to return a WindowRef referring to a window implementing an HIView hierarchy. It appears that this has changed in Max6 as any HIView related calls I make fail
-50 – paramErr or
-5600 – errInvalidWindowRef

I have been using this to embed an OpenGL context in the patcher window directly to create a video display object (for softVNS, not jitter).

What kind of structure or object am I now getting back from this native window message?
Is there now in Max6 a sanctioned and documented way of embedding a custom OpenGL context in a patcher?


Nov 07 2011 | 11:30 pm

Hi David,
Max6 is Cocoa all the way on OSX. "nativewindow" is now giving you back an NSView *. Use this to convert it to a WindowRef:

WindowRef jit_gl_cocoa_windowref_from_nsview(NSView *view)
       WindowRef ref=NULL;
       if (view) {
               NSWindow *win = [view window];
               if (win) {
                       ref = [win windowRef];
       return ref;
Nov 08 2011 | 10:17 am

i guess that has to be done in a .m file cause it uses ObjectiveC. correct?

Nov 08 2011 | 11:38 am

Thanks Wesley,

That helps a lot.

I had to work around the fact that the titlebar is now included in the frame of the windowRef which messed up my positioning, but I fixed that.

This brings up a second and somewhat separate question: How can I get an appropriate clipping rectangle for the patching area of the window so that my OpenGL context does not spill into the bottom bar or inspector area on the right?

Nov 08 2011 | 11:50 am

Yes, @Oli, a .m (or .mm) file is the recommended way for Objective-C. There are other ways of forcing the compiler to make it work, but my experience is that those other ways always come back and bite you later on.


Nov 09 2011 | 2:19 am

You have to listen for notifications from the patcherview. Use jpatcher_get_firstview to get the view and then use object_attach_byptr to get notifications. What you need to listen for are changed attributers on the patcherview and in your case, you need to list for the "rect" attribute.

for a notification function that looks like:

notify(t_jit_gl_window *x, void *sender, void *data) {
    if(msg == gensym("attr_modified")) {
        t_symbol *name = (t_symbol *)object_method((t_object *)data, gensym("getname"));
        if(name == gensym("rect")) {
            double r[4] = {0., 0., 1., 1.};
		// patcher comes from your object
		object_attr_getdouble_array(patcher, gensym("rect"), 4, r);
Viewing 6 posts - 1 through 6 (of 6 total)

Forums > Dev