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

Nov 7, 2011 at 11:05pm

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

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?

Thanks

#59875
Nov 7, 2011 at 11:30pm

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;
}
#215553
Nov 8, 2011 at 10:17am

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

#215554
Nov 8, 2011 at 11:38am

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?

#215555
Nov 8, 2011 at 11:50am

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.

Cheers,
Tim

#215556
Nov 9, 2011 at 2:19am

@David
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);
        }
    }
}
#215557

You must be logged in to reply to this topic.