Max 5 API Reference
00001 /* 00002 jit.kernel.c 00003 00004 Copyright 2001-2005 - Cycling '74 00005 Joshua Kit Clayton jkc@cycling74.com 00006 00007 */ 00008 00009 #include "jit.common.h" 00010 #include "ext_obex.h" 00011 #include "ext_systhread.h" 00012 #include "parallel.h" 00013 #include "jit.altivec.h" 00014 #include "jit.gl.ob3d.internal.h" 00015 #ifndef WIN_VERSION //win_todo 00016 #if !TARGET_RT_MAC_MACHO 00017 #include <InternetConfig.h> 00018 #endif 00019 #if (TARGET_API_MAC_CARBON) && !TARGET_RT_MAC_MACHO 00020 #include <LaunchServices.h> 00021 #endif 00022 #endif //WIN_VERSION 00023 00024 #define JIT_QUEUETHROTTLE_DEFAULT 10 00025 00026 #if (TARGET_API_MAC_CARBON) 00027 #define ICFindConfigFile(a,b,c) 0; 00028 #endif 00029 00030 typedef struct _jit_kernel 00031 { 00032 t_jit_object ob; 00033 } t_jit_kernel; 00034 00035 static void *_jit_kernel_class; 00036 static long _jit_cursor = 1; 00037 long _jit_cord_pattern = 0; 00038 extern long _jit_glerrorcheck; 00039 extern long _jit_glattribpush; 00040 extern long _jit_glmatrixdebug; 00041 extern char *_jit_version_str; 00042 extern long _jit_nosplash; 00043 extern t_parallel_task *_jit_parallel_task; 00044 extern long _jit_parallel; 00045 extern long _jit_parallelthreads; 00046 extern long _jit_parallelthresh; 00047 extern long _jit_paralleldebug; 00048 extern long _jit_javaload; 00049 extern long _jit_qt_optimize; 00050 extern long _jit_memreg; 00051 t_symbol *_jit_glreadback; 00052 extern t_atom _jit_spigot_cache; 00053 extern long _jit_spigot_cachesize; 00054 extern long _jit_gl_texture_verbose; 00055 long _jit_gl_texture_verbose = false; 00056 extern long _cfm_in_ub; 00057 00058 void jit_kernel_about(t_jit_kernel *x); 00059 void jit_kernel_doabout(t_jit_kernel *x); 00060 #ifndef WIN_VERSION 00061 void jit_kernel_altivec(t_jit_kernel *x, long c); 00062 #endif 00063 void jit_kernel_pollthrottle(t_jit_kernel *x, long c); 00064 void jit_kernel_queuethrottle(t_jit_kernel *x, long c); 00065 #ifndef WIN_VERSION //win_todo 00066 void jit_kernel_menubar(t_jit_kernel *x, long c); 00067 void jit_kernel_cord_pattern(t_jit_kernel *x, long c); 00068 #endif 00069 void jit_kernel_cursor(t_jit_kernel *x, long c); 00070 void jit_kernel_glerrorcheck(t_jit_kernel *x, long c); 00071 void jit_kernel_glattribpush(t_jit_kernel *x, long c); 00072 void jit_kernel_glmatrixdebug(t_jit_kernel *x, long c); 00073 void jit_kernel_launch_browser(t_jit_kernel *x, t_symbol *s, long argc, t_atom *argv); 00074 void jit_kernel_dolaunch_browser(t_jit_kernel *x, t_symbol *s, long argc, t_atom *argv); 00075 void jit_kernel_html_ref(t_jit_kernel *x, t_symbol *s, long argc, t_atom *argv); 00076 void jit_kernel_dohtml_ref(t_jit_kernel *x, t_symbol *s, long argc, t_atom *argv); 00077 void jit_kernel_postversion(t_jit_kernel *x); 00078 void jit_kernel_dopostversion(t_jit_kernel *x); 00079 void jit_kernel_nosplash(t_jit_kernel *x, long c); 00080 void jit_kernel_parallel(t_jit_kernel *x, long c); 00081 void jit_kernel_parallelthreads(t_jit_kernel *x, long c); 00082 void jit_kernel_parallelthresh(t_jit_kernel *x, long c); 00083 void jit_kernel_paralleldebug(t_jit_kernel *x, long c); 00084 void jit_kernel_javaload(t_jit_kernel *x, long c); 00085 void jit_kernel_javainit(t_jit_kernel *x); 00086 void jit_kernel_qtoptimize(t_jit_kernel *x, long c); 00087 void jit_kernel_memdebug(t_jit_kernel *x, long c); 00088 void jit_kernel_glreadback(t_jit_kernel *x, t_symbol *s); 00089 void jit_kernel_gl_texture_verbose(t_jit_kernel *x, long c); 00090 00091 void *jit_kernel_new(void); 00092 void jit_kernel_free(void); 00093 void jit_kernel_max_tune(t_jit_kernel *x); 00094 00095 long jit_localpath2url(char *input, char *output); 00096 long jit_urlencode(char *input, char *output); 00097 00098 void brag(void *x, short hold); 00099 t_jit_err jit_java_init(void); 00100 00101 void jit_kernel_spigot_clearcache(t_jit_kernel *x); 00102 void jit_kernel_spigot_getcache(t_jit_kernel *x, t_symbol *s); 00103 void jit_kernel_spigot_cache(t_jit_kernel *x, t_symbol *s, long ac, t_atom *av); 00104 void jit_kernel_spigot_cachesize(t_jit_kernel *x, long n); 00105 void jit_kernel_spigot_getcachesize(t_jit_kernel *x, t_symbol *s); 00106 void jit_kernel_spigot_locatecache(t_jit_kernel *x); 00107 void jit_kernel_spigot_purgecache(t_jit_kernel *x); 00108 00109 // probe protos 00110 extern void max_jit_mop_jit_matrix_endprobe(t_object *o); 00111 extern void max_jit_mop_jit_matrix_showprobe(); 00112 00113 // classex export 00114 extern void *max_jit_classex_get(void *x); 00115 extern void max_jit_usurp_method(void *x, t_symbol *s, short argc, t_atom *argv); 00116 extern void max_defer_method(void *x, t_symbol *s, long argc, t_atom *argv); 00117 00118 void jit_kernel_init(void) 00119 { 00120 t_jit_kernel *x; 00121 00122 _jit_kernel_class = jit_class_new("jit_kernel",(method)jit_kernel_new,(method)jit_kernel_free, 00123 sizeof(t_jit_kernel),A_CANT,0L); 00124 00125 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_about, "about", 0L); 00126 #ifndef WIN_VERSION //not applicable 00127 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_altivec, "altivec", A_LONG, 0L); 00128 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_menubar, "menubar", A_LONG, 0L); 00129 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_cord_pattern, "cordpattern", A_LONG, 0L); 00130 CLASS_METHOD_ATTR_PARSE(_jit_kernel_class, "cordpattern", "undocumented", _jit_sym_long, 0L, "1"); 00131 #endif 00132 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_pollthrottle, "pollthrottle", A_LONG, 0L); 00133 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_queuethrottle, "queuethrottle", A_LONG, 0L); 00134 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_launch_browser, "launch_browser", A_GIMME, 0L); 00135 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_html_ref, "html_ref", A_GIMME, 0L); 00136 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_cursor, "cursor", A_LONG, 0L); 00137 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_glerrorcheck, "glerrorcheck", A_LONG, 0L); 00138 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_glattribpush, "glattribpush", A_LONG, 0L); 00139 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_glmatrixdebug, "glmatrixdebug", A_LONG, 0L); 00140 CLASS_METHOD_ATTR_PARSE(_jit_kernel_class, "glmatrixdebug", "undocumented", _jit_sym_long, 0L, "1"); 00141 // weak link exports to assist things like sketch image to/frommatrix use zgetfn on gensym("jitter")->s_thing 00142 jit_class_addmethod(_jit_kernel_class, (method)jit_object_method, "exp_jit_object_method", A_CANT, 0L); 00143 jit_class_addmethod(_jit_kernel_class, (method)jit_object_getmethod, "exp_jit_object_getmethod", A_CANT, 0L); 00144 jit_class_addmethod(_jit_kernel_class, (method)jit_object_findregistered, "exp_jit_object_findregistered", A_CANT, 0L); 00145 jit_class_addmethod(_jit_kernel_class, (method)max_jit_obex_jitob_get, "exp_max_jit_obex_jitob_get", A_CANT, 0L); 00146 jit_class_addmethod(_jit_kernel_class, (method)max_jit_method_is_attr, "exp_max_jit_method_is_attr", A_CANT, 0L); 00147 jit_class_addmethod(_jit_kernel_class, (method)max_jit_obex_attrlist_get, "exp_max_jit_obex_attrlist_get", A_CANT, 0L); 00148 jit_class_addmethod(_jit_kernel_class, (method)jit_mop_ioproc_tosym, "exp_jit_mop_ioproc_tosym", A_CANT, 0L); 00149 jit_class_addmethod(_jit_kernel_class, (method)max_jit_classex_get, "exp_max_jit_classex_get", A_CANT, 0L); 00150 jit_class_addmethod(_jit_kernel_class, (method)max_jit_usurp_method, "exp_max_jit_usurp_method", A_CANT, 0L); 00151 jit_class_addmethod(_jit_kernel_class, (method)max_defer_method, "exp_max_defer_method", A_CANT, 0L); 00152 00153 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_postversion, "postversion", 0L); 00154 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_nosplash, "nosplash", A_LONG, 0L); 00155 CLASS_METHOD_ATTR_PARSE(_jit_kernel_class, "nosplash", "undocumented", _jit_sym_long, 0L, "1"); 00156 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_parallel, "parallel", A_LONG, 0L); 00157 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_parallelthreads, "parallelthreads", A_LONG, 0L); 00158 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_parallelthresh, "parallelthreshold", A_LONG, 0L); 00159 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_paralleldebug, "paralleldebug", A_LONG, 0L); 00160 CLASS_METHOD_ATTR_PARSE(_jit_kernel_class, "paralleldebug", "undocumented", _jit_sym_long, 0L, "1"); 00161 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_javaload, "java", A_LONG, 0L); 00162 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_javainit, "javainit", 0L); 00163 CLASS_METHOD_ATTR_PARSE(_jit_kernel_class, "javainit", "undocumented", _jit_sym_long, 0L, "1"); 00164 // jb added to enable/disable quicktime matrix wrapping optimizations for testing and troubleshooting 00165 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_qtoptimize, "qtoptimize", A_LONG, 0L); 00166 CLASS_METHOD_ATTR_PARSE(_jit_kernel_class, "qtoptimize", "undocumented", _jit_sym_long, 0L, "1"); 00167 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_qtoptimize, "qtoptimise", A_LONG, 0L); 00168 CLASS_METHOD_ATTR_PARSE(_jit_kernel_class, "qtoptimise", "undocumented", _jit_sym_long, 0L, "1"); 00169 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_memdebug, "memdebug", A_LONG, 0L); 00170 CLASS_METHOD_ATTR_PARSE(_jit_kernel_class, "memdebug", "undocumented", _jit_sym_long, 0L, "1"); 00171 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_glreadback, "glreadback", A_SYM, 0L); 00172 CLASS_METHOD_ATTR_PARSE(_jit_kernel_class, "glreadback", "undocumented", _jit_sym_long, 0L, "1"); 00173 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_gl_texture_verbose, "texture_verbose", A_LONG, 0L); 00174 CLASS_METHOD_ATTR_PARSE(_jit_kernel_class, "texture_verbose", "undocumented", _jit_sym_long, 0L, "1"); 00175 00176 // spigot-cache 00177 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_spigot_cache, "spigot_cache", A_GIMME, 0L); 00178 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_spigot_getcache, "spigot_getcache", A_SYM, 0L); 00179 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_spigot_locatecache, "spigot_locatecache", 0L); 00180 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_spigot_purgecache, "spigot_purgecache", 0L); 00181 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_spigot_cachesize, "spigot_cachesize", A_LONG, 0L); 00182 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_spigot_getcachesize, "spigot_getcachesize", A_SYM, 0L); 00183 // we can leave this undocumented for now ///////////// 00184 jit_class_addmethod(_jit_kernel_class, (method)jit_kernel_spigot_clearcache, "spigot_clearcache", 0L); 00185 CLASS_METHOD_ATTR_PARSE(_jit_kernel_class, "spigot_clearcache", "undocumented", _jit_sym_long, 0L, "1"); 00186 /////////////////////////////////////////////////////// 00187 00188 // probe 00189 jit_class_addmethod(_jit_kernel_class, (method)max_jit_mop_jit_matrix_endprobe, "endprobe", 0L); 00190 CLASS_METHOD_ATTR_PARSE(_jit_kernel_class, "endprobe", "undocumented", _jit_sym_long, 0L, "1"); 00191 gensym("matrixprobe_show")->s_thing=(void *)max_jit_mop_jit_matrix_showprobe; 00192 00193 00194 #ifdef WIN_VERSION 00195 _jit_glreadback = gensym("ctt"); 00196 #else 00197 { 00198 long minor_version = 0; 00199 Gestalt(gestaltSystemVersionMinor, &minor_version); 00200 if(minor_version >= 6) { 00201 //_jit_glreadback = gensym("fbo"); 00202 _jit_glreadback = gensym("rtt"); 00203 } 00204 else { 00205 _jit_glreadback = gensym("rtt"); 00206 } 00207 } 00208 // _jit_glreadback = gensym("fbo"); // need to test fallback cases exhaustively prior to deploying for OS X. 00209 #endif 00210 00211 if (x=jit_kernel_new()) { 00212 if (!_cfm_in_ub||!gensym("jitter")->s_thing) { 00213 gensym("jit")->s_thing=(t_object *)x; 00214 gensym("jitter")->s_thing=(t_object *)x; 00215 } else if (_cfm_in_ub) { 00216 gensym("jitterCFM")->s_thing=(t_object *)x; 00217 } 00218 } else { 00219 post("couldn't create jit kernel object"); 00220 } 00221 00222 class_register(CLASS_NOBOX, _jit_kernel_class); 00223 } 00224 00225 // goes through the cache log, and "intelligently" 00226 // prunes the cache down to the requested size 00227 void jit_kernel_spigot_purgecache(t_jit_kernel *x) 00228 { 00229 jit_qt_movie_purgecache(); 00230 } 00231 00232 // just kills everything in the folder 00233 void jit_kernel_spigot_clearcache(t_jit_kernel *x) 00234 { 00235 jit_qt_movie_clearcache(); 00236 } 00237 00238 void jit_kernel_spigot_getcache(t_jit_kernel *x, t_symbol *s) 00239 { 00240 t_atom a; 00241 short vol; 00242 char outname[MAX_PATH_CHARS]; 00243 00244 if (s && s->s_thing) { 00245 vol = jit_qt_movie_getcachepath(0); 00246 if (!vol) 00247 strcpy(outname, "moviepath"); 00248 else 00249 path_topathname(vol, "", outname); 00250 typedmess(s->s_thing, gensym(outname), 0, NULL); 00251 } 00252 } 00253 00254 void jit_kernel_spigot_locatecache(t_jit_kernel *x) 00255 { 00256 short vol; 00257 00258 vol = jit_qt_movie_getcachepath(0); 00259 if (!vol) 00260 jit_object_post((t_object *)x,"spigot~ is caching audio files at the location of the source movie; nothing to locate."); 00261 else 00262 jit_qt_movie_locatecache(vol); 00263 } 00264 00265 void jit_kernel_spigot_cache(t_jit_kernel *x, t_symbol *s, long ac, t_atom *av) 00266 { 00267 /* 00268 0 = next to original movie 00269 1 = user domain common folder (default) 00270 2 = system domain common folder 00271 3 = temporary folder 00272 sym = path/to/common/folder 00273 */ 00274 if (ac && av) { 00275 if (av->a_type == A_SYM) { 00276 t_symbol *path = jit_atom_getsym(av); 00277 char outname[MAX_PATH_CHARS]; 00278 00279 // verify valid path 00280 if (path_topathname(0, path->s_name, outname)) { 00281 jit_object_error((t_object *)x,"spigot_cache: bad path name as spigot_cache"); 00282 } else { 00283 if (jit_qt_movie_xml_test_writability(path->s_name) != JIT_ERR_NONE) { 00284 jit_object_error((t_object *)x,"spigot_cache: specified directory is write-protected and can't be used"); 00285 } else 00286 jit_atom_setsym(&_jit_spigot_cache, path); 00287 } 00288 } else { 00289 long which = jit_atom_getlong(av); 00290 t_atom old = _jit_spigot_cache; 00291 short vol; 00292 00293 jit_atom_setlong(&_jit_spigot_cache, CLAMP(which, 0, 3)); 00294 vol = jit_qt_movie_getcachepath(0); 00295 if (vol) { 00296 char outname[MAX_PATH_CHARS]; 00297 00298 path_topathname(vol, "", outname); 00299 if (jit_qt_movie_xml_test_writability(outname) != JIT_ERR_NONE) { 00300 jit_object_error((t_object *)x,"spigot_cache: specified directory is write-protected and can't be used"); 00301 _jit_spigot_cache = old; 00302 } 00303 } 00304 } 00305 } 00306 } 00307 00308 void jit_kernel_spigot_cachesize(t_jit_kernel *x, long n) 00309 { 00310 if (n < 0) 00311 _jit_spigot_cachesize = -1; 00312 else 00313 _jit_spigot_cachesize = n; 00314 00315 jit_kernel_spigot_purgecache(x); 00316 } 00317 00318 void jit_kernel_spigot_getcachesize(t_jit_kernel *x, t_symbol *s) 00319 { 00320 t_atom a; 00321 00322 if (s && s->s_thing) { 00323 jit_atom_setlong(&a, _jit_spigot_cachesize); 00324 typedmess(s->s_thing, gensym("int"), 1, &a); 00325 } 00326 } 00327 00328 void jit_kernel_gl_texture_verbose(t_jit_kernel *x, long c) 00329 { 00330 if (c > 0) 00331 _jit_gl_texture_verbose = true; 00332 else 00333 _jit_gl_texture_verbose = false; 00334 } 00335 00336 void jit_kernel_max_tune(t_jit_kernel *x) 00337 { 00338 if (gensym("max")->s_thing) { 00339 t_atom a; 00340 jit_atom_setlong(&a,2); 00341 typedmess(gensym("max")->s_thing,gensym("seteventinterval"),1,&a); 00342 typedmess(gensym("max")->s_thing,gensym("setsleep"),1,&a); 00343 } else { 00344 jit_object_error((t_object *)x,"jitter could not find max object"); 00345 } 00346 } 00347 00348 void jit_kernel_about(t_jit_kernel *x) 00349 { 00350 defer_medium(x,(method)jit_kernel_doabout,NULL,0,NULL); 00351 } 00352 00353 void jit_kernel_doabout(t_jit_kernel *x) 00354 { 00355 brag(x,1); 00356 } 00357 00358 00359 #ifndef WIN_VERSION 00360 void jit_kernel_altivec(t_jit_kernel *x, long c) 00361 { 00362 if (jit_altivec_capable()&&c) 00363 _jit_altivec = 1; 00364 else 00365 _jit_altivec = 0; 00366 } 00367 #endif //WIN_VERSION 00368 00369 void jit_kernel_pollthrottle(t_jit_kernel *x, long c) 00370 { 00371 t_atom a[1]; 00372 00373 if (c<1) c=1; 00374 jit_atom_setlong(a,c); 00375 typedmess(gensym("max")->s_thing,gensym("setpollthrottle"),1,a); 00376 } 00377 00378 void jit_kernel_queuethrottle(t_jit_kernel *x, long c) 00379 { 00380 t_atom a[1]; 00381 00382 if (c<1) c=1; 00383 jit_atom_setlong(a,c); 00384 typedmess(gensym("max")->s_thing,gensym("setqueuethrottle"),1,a); 00385 } 00386 00387 #ifndef WIN_VERSION //win_todo 00388 void jit_kernel_domenubar(t_jit_kernel *x, long c); 00389 void jit_kernel_domenubar(t_jit_kernel *x, long c) 00390 { 00391 long vis=IsMenuBarVisible(); 00392 00393 if (c&&!vis) 00394 ShowMenuBar(); 00395 else if (!c&&vis) 00396 HideMenuBar(); 00397 } 00398 00399 void jit_kernel_menubar(t_jit_kernel *x, long c) 00400 { 00401 defer_low(x,(method)jit_kernel_domenubar,(t_symbol *)c,0,NULL); 00402 } 00403 #endif 00404 00405 void jit_kernel_docursor(t_jit_kernel *x, long c); 00406 void jit_kernel_docursor(t_jit_kernel *x, long c) 00407 { 00408 if (c&&!_jit_cursor) { 00409 #ifdef MAC_VERSION 00410 ShowCursor(); 00411 #else 00412 ShowCursor(TRUE); 00413 #endif 00414 _jit_cursor=1; 00415 } else if (!c&&_jit_cursor) { 00416 #ifdef MAC_VERSION 00417 HideCursor(); 00418 #else 00419 ShowCursor(FALSE); 00420 #endif 00421 _jit_cursor=0; 00422 } 00423 } 00424 00425 void jit_kernel_cursor(t_jit_kernel *x, long c) 00426 { 00427 defer_low(x,(method)jit_kernel_docursor,(t_symbol *)c,0,NULL); 00428 } 00429 00430 void jit_kernel_cord_pattern(t_jit_kernel *x, long c) 00431 { 00432 _jit_cord_pattern = c; 00433 } 00434 00435 void jit_kernel_glerrorcheck(t_jit_kernel *x, long c) 00436 { 00437 _jit_glerrorcheck = c; 00438 } 00439 00440 void jit_kernel_glattribpush(t_jit_kernel *x, long c) 00441 { 00442 _jit_glattribpush = c; 00443 } 00444 00445 void jit_kernel_glmatrixdebug(t_jit_kernel *x, long c) 00446 { 00447 _jit_glmatrixdebug = c; 00448 } 00449 00450 void jit_kernel_postversion(t_jit_kernel *x) 00451 { 00452 defer_low(x,(method)jit_kernel_dopostversion,NULL,0,NULL); 00453 } 00454 00455 void jit_kernel_dopostversion(t_jit_kernel *x) 00456 { 00457 jit_object_post((t_object *)x,"Jitter version %s", _jit_version_str); 00458 } 00459 00460 void jit_kernel_nosplash(t_jit_kernel *x, long c) 00461 { 00462 _jit_nosplash = c; 00463 } 00464 00465 void jit_kernel_parallel(t_jit_kernel *x, long c) 00466 { 00467 _jit_parallel = (c!=0); 00468 } 00469 00470 void jit_kernel_parallelthreads(t_jit_kernel *x, long c) 00471 { 00472 _jit_parallelthreads = CLIP(c,0,8); 00473 if (_jit_parallel_task) { 00474 parallel_task_free(_jit_parallel_task); 00475 _jit_parallel_task = NULL; 00476 } 00477 } 00478 00479 void jit_kernel_parallelthresh(t_jit_kernel *x, long c) 00480 { 00481 _jit_parallelthresh = MAX(c,1); 00482 } 00483 00484 void jit_kernel_paralleldebug(t_jit_kernel *x, long c) 00485 { 00486 _jit_paralleldebug = (c!=0); 00487 } 00488 00489 void jit_kernel_javaload(t_jit_kernel *x, long c) 00490 { 00491 _jit_javaload = c; 00492 } 00493 00494 void jit_kernel_qtoptimize(t_jit_kernel *x, long c) 00495 { 00496 _jit_qt_optimize = c; 00497 } 00498 00499 void jit_kernel_memdebug(t_jit_kernel *x, long c) 00500 { 00501 _jit_memreg = c; 00502 } 00503 00504 void jit_kernel_javainit(t_jit_kernel *x) 00505 { 00506 //defer_low(x,(method)jit_kernel_javainit,0L,0,0L); 00507 jit_java_init(); 00508 } 00509 00510 void jit_kernel_glreadback(t_jit_kernel *x, t_symbol *s) 00511 { 00512 _jit_glreadback = s; 00513 } 00514 00515 void *jit_kernel_new(void) 00516 { 00517 t_jit_kernel *x; 00518 00519 x=(t_jit_kernel *)jit_object_alloc(_jit_kernel_class); 00520 00521 return x; 00522 } 00523 00524 void jit_kernel_free(void) 00525 { 00526 //nada 00527 } 00528 00529 00530 void jit_kernel_launch_browser(t_jit_kernel *x, t_symbol *s, long argc, t_atom *argv) 00531 { 00532 defer(x,(method)jit_kernel_dolaunch_browser,s,argc,argv); 00533 } 00534 00535 void jit_kernel_html_ref(t_jit_kernel *x, t_symbol *s, long argc, t_atom *argv) 00536 { 00537 defer(x,(method)jit_kernel_dohtml_ref,s,argc,argv); 00538 } 00539 00540 void jit_kernel_dohtml_ref(t_jit_kernel *x, t_symbol *s, long argc, t_atom *argv) 00541 { 00542 char tmpstr[MAX_PATH_CHARS], outname[MAX_PATH_CHARS]; 00543 t_atom a; 00544 short path; 00545 long type; 00546 long filetype; 00547 00548 if (argc&&argv&&(argv->a_type==A_SYM)) { 00549 sprintf(tmpstr, "%s.maxref.xml", argv->a_w.w_sym->s_name); 00550 if ((!locatefile_extended(tmpstr, &path, &type, &filetype, 0L)) && 00551 (!path_topathname(path, tmpstr, outname))) { 00552 atom_setsym(&a, gensym(outname)); 00553 typedmess(gensym("max")->s_thing, gensym("showdoc"), 1, &a); 00554 } else { 00555 jit_object_post((t_object *)x,"Jitter could not locate %s.maxref.xml", argv->a_w.w_sym->s_name); 00556 jit_object_post((t_object *)x,"Please make sure that the xml object "); 00557 jit_object_post((t_object *)x,"reference is in the Max search path."); 00558 } 00559 } 00560 } 00561 00562 #ifdef MAC_VERSION 00563 void jit_kernel_dolaunch_browser(t_jit_kernel *x, t_symbol *s, long argc, t_atom *argv) 00564 { 00565 OSStatus err; 00566 ICInstance inst; 00567 long startSel; 00568 long endSel; 00569 t_symbol *urlsym; 00570 00571 urlsym = jit_atom_getsym(argv); 00572 00573 if (ICStart==0) { 00574 jit_object_error((t_object *)x,"InternetConfig could not be loaded"); 00575 return; 00576 } 00577 00578 err = ICStart(&inst, '????'); 00579 if (err == noErr) { 00580 err = ICFindConfigFile(inst, 0, nil); 00581 if (err == noErr) { 00582 startSel = 0; 00583 endSel = strlen(urlsym->s_name); 00584 err = ICLaunchURL(inst, "\p", urlsym->s_name, 00585 strlen(urlsym->s_name), &startSel, &endSel); 00586 if (err) 00587 jit_object_post((t_object *)x,"Jitter could not launch URL. err = %d", err); 00588 } 00589 ICStop(inst); 00590 } 00591 } 00592 00593 #if 0 00594 void jit_kernel_dohtml_ref(t_jit_kernel *x, t_symbol *s, long argc, t_atom *argv) 00595 { 00596 char tmpstr[MAX_PATH_CHARS],tmpstr2[MAX_PATH_CHARS],outname[MAX_PATH_CHARS]; 00597 t_atom a; 00598 short path; 00599 short refnum; 00600 long type; 00601 long filetype; 00602 OSStatus err; 00603 ICInstance inst; 00604 long startSel; 00605 long endSel; 00606 t_symbol *urlsym; 00607 00608 if (argc&&argv&&(argv->a_type==A_SYM)) { 00609 00610 sprintf(tmpstr, "%s.html", argv->a_w.w_sym->s_name); 00611 00612 if ((!locatefile_extended(tmpstr, &path, &type, &filetype, 0L)) && 00613 (!path_topathname(path, tmpstr, outname))) { 00614 00615 #if (TARGET_API_MAC_CARBON) 00616 if ((UInt32)LSOpenCFURLRef!=(UInt32)kUnresolvedCFragSymbolAddress) // OS X version 00617 { 00618 FSRef fsRef; 00619 CFURLRef url = NULL; 00620 00621 err = path_tofsref(path, tmpstr, &fsRef); 00622 if (!err) 00623 { 00624 LSLaunchFSRefSpec inLaunchSpec; 00625 FSRef outAppRef; 00626 CFURLRef outAppURL; 00627 00628 err = LSGetApplicationForInfo( 00629 kLSUnknownType, 00630 kLSUnknownCreator, 00631 CFSTR("html"), 00632 kLSRolesViewer, 00633 &outAppRef, 00634 &outAppURL); 00635 00636 inLaunchSpec.appRef = &outAppRef; 00637 inLaunchSpec.numDocs = 1; 00638 inLaunchSpec.itemRefs = &fsRef; 00639 inLaunchSpec.passThruParams = NULL; 00640 inLaunchSpec.launchFlags = kLSLaunchDefaults; 00641 inLaunchSpec.asyncRefCon = NULL; 00642 00643 err = LSOpenFromRefSpec( &inLaunchSpec, NULL ); 00644 00645 if (err) 00646 jit_object_post((t_object *)x,"Jitter could not launch URL. err = %d", err); 00647 00648 } else { 00649 jit_object_post((t_object *)x,"Jitter could not launch URL. err = %d", err); 00650 } 00651 } else { 00652 #endif 00653 jit_localpath2url(outname,tmpstr); 00654 00655 if (ICStart==0) { 00656 jit_object_error((t_object *)x,"InternetConfig could not be loaded"); 00657 return; 00658 } 00659 00660 err = ICStart(&inst, '????'); 00661 if (err == noErr) { 00662 err = ICFindConfigFile(inst, 0, nil); 00663 if (err == noErr) { 00664 startSel = 0; 00665 endSel = strlen(tmpstr); 00666 err = ICLaunchURL(inst, "\p", tmpstr, strlen(tmpstr), &startSel, &endSel); 00667 if (err) 00668 jit_object_post((t_object *)x,"Jitter could not launch URL. err = %d", err); 00669 } 00670 ICStop(inst); 00671 } 00672 00673 #if (TARGET_API_MAC_CARBON) 00674 } 00675 #endif 00676 00677 } else { 00678 jit_object_post((t_object *)x,"Jitter could not locate %s.html", argv->a_w.w_sym->s_name); 00679 jit_object_post((t_object *)x,"Please make sure that the html object "); 00680 jit_object_post((t_object *)x,"reference is in the Max search path."); 00681 } 00682 } 00683 } 00684 #endif // 0 00685 #endif //MAC_VERSION 00686 00687 #ifdef WIN_VERSION 00688 void jit_kernel_dolaunch_browser(t_jit_kernel *x, t_symbol *s, long argc, t_atom *argv) 00689 { 00690 t_symbol *urlsym; 00691 SHELLEXECUTEINFO shExInfo; 00692 00693 urlsym = jit_atom_getsym(argv); 00694 00695 ZeroMemory( &shExInfo, sizeof( SHELLEXECUTEINFO ) ); 00696 shExInfo.cbSize = sizeof( SHELLEXECUTEINFO ); 00697 shExInfo.lpFile = urlsym->s_name; 00698 shExInfo.lpVerb = "open"; 00699 shExInfo.hwnd = main_get_client(); 00700 00701 if (!ShellExecuteEx( &shExInfo )) { 00702 jit_object_post((t_object *)x,"Jitter could not launch URL. err = %d", GetLastError()); 00703 } 00704 } 00705 00706 #if 0 00707 void jit_kernel_dohtml_ref(t_jit_kernel *x, t_symbol *s, long argc, t_atom *argv) 00708 { 00709 char tmpstr[MAX_PATH_CHARS],tmpstr2[MAX_PATH_CHARS],outname[MAX_PATH_CHARS]; 00710 t_atom a; 00711 short path; 00712 short refnum; 00713 long type; 00714 long filetype; 00715 00716 if (argc&&argv&&(argv->a_type==A_SYM)) { 00717 00718 sprintf(tmpstr, "%s.html", argv->a_w.w_sym->s_name); 00719 00720 if ((!locatefile_extended(tmpstr, &path, &type, &filetype, 0L)) && 00721 (!path_topathname(path, tmpstr, outname))) 00722 { 00723 SHELLEXECUTEINFO shExInfo; 00724 00725 path_nameconform(outname,tmpstr2,PATH_STYLE_NATIVE_WIN,PATH_TYPE_ABSOLUTE); 00726 00727 ZeroMemory( &shExInfo, sizeof( SHELLEXECUTEINFO ) ); 00728 shExInfo.cbSize = sizeof( SHELLEXECUTEINFO ); 00729 shExInfo.lpFile = tmpstr2; 00730 shExInfo.lpVerb = "open"; 00731 shExInfo.hwnd = main_get_client(); 00732 00733 if (!ShellExecuteEx( &shExInfo )) { 00734 jit_object_post((t_object *)x,"Jitter could not launch URL. err = %d", GetLastError()); 00735 } 00736 } else { 00737 jit_object_post((t_object *)x,"Jitter could not locate %s.html", argv->a_w.w_sym->s_name); 00738 jit_object_post((t_object *)x,"Please make sure that the html object "); 00739 jit_object_post((t_object *)x,"reference is in the Max search path."); 00740 } 00741 } 00742 } 00743 #endif // 0 00744 #endif //WIN_VERSION 00745 00746 00747 static Boolean URLUtils_IsDelimiterChar (char theChar); 00748 static Boolean URLUtils_IsDelimiterChar (char theChar) 00749 { 00750 if ((theChar == '<') || (theChar == '>') || (theChar == '#')) 00751 return(true); 00752 00753 return(false); 00754 } 00755 00756 static Boolean URLUtils_IsUnsafeChar (char theChar); 00757 static Boolean URLUtils_IsUnsafeChar (char theChar) 00758 { 00759 if ((theChar == '{') || (theChar == '}') || (theChar == '|') || (theChar == '\\') || (theChar == '^') || 00760 (theChar == '~') || (theChar == '[') || (theChar == ']') || (theChar == '\`') || (theChar == '%') || 00761 (theChar == '(') || (theChar == ')')) 00762 return(true); 00763 00764 return(false); 00765 } 00766 00767 static Boolean URLUtils_IsEncodableChar (char theChar); 00768 static Boolean URLUtils_IsEncodableChar (char theChar) 00769 { 00770 // all control characters and high-ASCII characters are encodable 00771 if ((theChar <= 0x1f) || (theChar >= 0x7f)) 00772 return(true); 00773 00774 // the space character is encodable 00775 if (theChar == 0x20) 00776 return(true); 00777 00778 // all delimiters are encodable 00779 if (URLUtils_IsDelimiterChar(theChar)) 00780 return(true); 00781 00782 // all unsafe characters are encodable 00783 if (URLUtils_IsUnsafeChar(theChar)) 00784 return(true); 00785 00786 return(false); 00787 } 00788 00789 long jit_urlencode(char *input, char *output) 00790 { 00791 char myChar; 00792 long myCount; 00793 long myIndex; 00794 00795 if (!input||!output) 00796 return -1; 00797 00798 // traverse the URL, encoding encodable characters as we go 00799 for (myCount = 0, myIndex = 0; myIndex < (long)strlen(input); myIndex++) { 00800 if (URLUtils_IsEncodableChar(input[myIndex])) { 00801 output[myCount + 0] = '%'; 00802 myChar = (input[myIndex] >> 4) & 0x0f; 00803 output[myCount + 1] = myChar + ((myChar <= 9) ? '0' : ('A' - 10)); 00804 myChar = input[myIndex] & 0x0f; 00805 output[myCount + 2] = myChar + ((myChar <= 9) ? '0' : ('A' - 10)); 00806 myCount += 3; 00807 } else { 00808 output[myCount] = input[myIndex]; 00809 myCount++; 00810 } 00811 } 00812 output[myCount] = '\0'; 00813 00814 return 0; 00815 } 00816 00817 #ifdef MAC_VERSION 00818 long jit_localpath2url(char *input, char *output) 00819 { 00820 char myChar; 00821 long myCount; 00822 long myIndex; 00823 long netscape=0; 00824 OSStatus err; 00825 ICInstance inst; 00826 ICAttr attr; 00827 char buf[4096]; 00828 long size=4096; 00829 long len; 00830 00831 if (!input||!output) 00832 return -1; 00833 00834 sprintf(output, "file:///"); 00835 00836 if (ICStart!=0) { 00837 err = ICStart(&inst, '????'); 00838 if (err == noErr) { 00839 err = ICFindConfigFile(inst, 0, nil); 00840 ICGetPref(inst, "\pHelper�file", &attr, &buf, &size); //kICHelper 00841 if ((buf[0]=='M')&&(buf[1]=='O')&&(buf[2]=='S')&&(buf[3]=='S')) { 00842 netscape=1; 00843 } 00844 00845 ICStop(inst); 00846 } 00847 } 00848 00849 // traverse the URL, encoding encodable characters as we go 00850 len = strlen(input); 00851 for (myCount = 8, myIndex = 0; myIndex < len; myIndex++) { 00852 if (input[myIndex]==':') { 00853 output[myCount] = '/'; 00854 myCount++; 00855 } else if (input[myIndex]=='/') { 00856 output[myCount + 0] = '%'; 00857 if (netscape) { 00858 output[myCount + 1] = '3'; 00859 output[myCount + 2] = 'A'; 00860 } else { 00861 output[myCount + 1] = '2'; 00862 output[myCount + 2] = 'F'; 00863 } 00864 myCount += 3; 00865 } else if (URLUtils_IsEncodableChar(input[myIndex])) { 00866 output[myCount + 0] = '%'; 00867 myChar = (input[myIndex] >> 4) & 0x0f; 00868 output[myCount + 1] = myChar + ((myChar <= 9) ? '0' : ('A' - 10)); 00869 myChar = input[myIndex] & 0x0f; 00870 output[myCount + 2] = myChar + ((myChar <= 9) ? '0' : ('A' - 10)); 00871 myCount += 3; 00872 } else { 00873 output[myCount] = input[myIndex]; 00874 myCount++; 00875 } 00876 } 00877 output[myCount] = '\0'; 00878 len = strlen(output); 00879 00880 return 0; 00881 } 00882 #endif //MAC_VERSION
Copyright © 2008, Cycling '74