void jsusfx_compile(t_jsusfx *x, t_symbol *notused, long argc, t_atom *argv) { // new file if ( argc >= 1 && atom_gettype(argv) == A_SYM ) { t_fourcc filetype = 'TEXT', outtype; short path; char filename[MAX_PATH_CHARS]; strcpy(filename, atom_getsym(argv)->s_name); if (locatefile_extended(filename, &path, &outtype, &filetype, 1)) { error("jsusfx~: script %s not found", filename); return; } if ( x->m_editor ) { object_method(x->m_editor, gensym("w_close")); x->m_editor = NULL; } strncpy(x->scriptname, filename, MAX_PATH_CHARS); x->path = path; } char fullpath[1024]; path_toabsolutesystempath(x->path, x->scriptname, fullpath); std::ifstream is(fullpath); if ( ! is.is_open() ) { error("jsusfx~: error opening file %s", fullpath); return; } critical_enter(x->critical); if ( x->fx->compile(is) == true ) { x->fx->prepare(sys_getsr(), sys_getmaxblksize()); } critical_exit(x->critical); }
void filein_doread(t_filein *x, t_symbol *s) { short vol,err; char ps[MAX_PATH_CHARS]; long type; short savelock; filein_close(x); if (s==ps_nothing) { if (open_dialog(ps,&vol,&type,0L,0)) return; } else { strcpy(ps,s->s_name); if (locatefile_extended(ps,&vol,&type,&type,-1)) { object_error((t_object *)x, "%s: can't find file",ps); return; } } err = path_opensysfile(ps,vol,&x->f_fh,READ_PERM); if (err) { object_error((t_object *)x, "%s: error %d opening file",ps,err); return; } filein_open(x,ps); savelock = lockout_set(1); outlet_bang(x->f_readdone); lockout_set(savelock); }
void pictmeter_doread(t_pictmeter *x, t_symbol *s, long argc, t_atom *argv) { char filename[MAX_PATH_CHARS]; t_fourcc *type, outtype; long ntype; t_max_err err; char alloc; short path; t_jsurface *surface; jgraphics_getfiletypes(x, &ntype, &type, &alloc); if (s == gensym("")) { err = open_dialog(filename, &path, &outtype, type, ntype); if (err) return; } else { strcpy(filename,s->s_name); err = locatefile_extended(filename, &path, &outtype, type, ntype); if (err) return; } surface = jgraphics_image_surface_create_referenced(filename, path); if (surface) x->p_surface = surface; if (alloc) sysmem_freeptr((char *)type); }
void ui_preset_interface(t_ui *x) { char filename[MAX_FILENAME_CHARS]; short path; t_fourcc type; t_fourcc filetype = 'JSON'; t_dictionary* d; t_object* p; t_atom a; strncpy_zero(filename, "j.preset_interface.maxpat", MAX_FILENAME_CHARS); locatefile_extended(filename, &path, &type, &filetype, 1); dictionary_read(filename, path, &d); atom_setobj(&a, d); p = (t_object*)object_new_typed(_sym_nobox, _sym_jpatcher, 1, &a); object_attr_setlong(p, _sym_locked, 1); // start out locked object_attr_setchar(p, _sym_enablehscroll, 0); // turn off scroll bars object_attr_setchar(p, _sym_enablevscroll, 0); object_attr_setchar(p, _sym_openinpresentation, 1); object_attr_setchar(p, _sym_toolbarvisible, 0); object_attr_setsym(p, _sym_title, gensym("preset_interface")); object_method_parse(p, _sym_window, "constrain 5 320 179 595", NULL); object_attach_byptr_register(x, p, _sym_nobox); object_method(p, _sym_vis); // "vis" happens immediately, "front" is defer_lowed object_attr_setobj(jpatcher_get_firstview(p), _sym_owner, (t_object*)x); // become the owner OBJ_ATTR_SYM(p, "arguments", 0, gensym((char*)x->modelAddress.c_str())); // the patch needs a [j.interfaceArguments.js] object_method(p, _sym_loadbang); }
t_max_err cc_cfile_set(t_cc *x, t_object *attr, long argc, t_atom *argv){ if(argc == 0){ // should put up an open file editor window here return 1; } t_symbol *arg = atom_getsym(argv); if(arg == gensym("")){ return 0; } char *f = arg->s_name; FILE *fp; if(*f == '/'){ // full path. read it if it exists, otherwise write a template strcpy(x->cfile_fullpath, f); if(fp = fopen(f, "r")){ x->code_len = fread(x->code_buf, sizeof(char), BUFSIZE, fp); }else{ if(fp = fopen(f, "w")){ x->code_len = cc_write_template(x, x->code_buf); fwrite(x->code_buf, x->code_len, sizeof(char), fp); fclose(fp); } } }else{ // not a full path. try to find it in the search path and bail if not found short outvol;//, binflag; long outtype; //if(locatefile(f, &outvol, &binflag)){ if(locatefile_extended(f, &outvol, &outtype, NULL, 0)){ error("cc: couldn't locate %s", f); return 1; }else{ char buf[MAX_PATH_CHARS]; char *ptr = buf; path_topathname(outvol, f, buf); while(*ptr++ != ':'){} strcpy(x->cfile_fullpath, ptr); } } cc_get_basename(f, x->basename); sprintf(x->ofile_fullpath, "%s/%s.o", x->build_path, x->basename); sprintf(x->dfile_fullpath, "%s/%s.dylib", x->build_path, x->basename); sprintf(x->logfile_fullpath, "%s/%s.log", x->build_path, x->basename); x->have_valid_filename = 1; return 0; }
void model_preset_default(TTPtr self) { WrappedModularInstancePtr x = (WrappedModularInstancePtr)self; short outvol; t_fourcc outtype, filetype = 'TEXT'; char fullpath[MAX_PATH_CHARS]; // path and name passed on to the xml parser char posixpath[MAX_PATH_CHARS]; t_atom a; t_symbol* textfile; if (x->patcherClass != kTTSymEmpty) { if (EXTRA->attr_presets != kTTSym_none) { textfile = gensym(EXTRA->attr_presets.c_str()); } else if (x->patcherContext == kTTSym_model) jamoma_edit_filename(*ModelPresetFormat, x->patcherClass, &textfile); else if (x->patcherContext == kTTSym_view) jamoma_edit_filename(*ViewPresetFormat, x->patcherClass, &textfile); else return object_error((t_object*)x, "preset_default : can't get the context of the patcher"); if (locatefile_extended((char*)textfile->s_name, &outvol, &outtype, &filetype, 1)) { //object_warn((t_object*)x, "preset_default : can't find %s file in the Max search path", textfile.data()); return; } path_topathname(outvol, (char*)textfile->s_name, fullpath); path_nameconform(fullpath, posixpath, PATH_STYLE_NATIVE, PATH_TYPE_BOOT); atom_setsym(&a, gensym(posixpath)); defer_low(self, (method)model_preset_doread, gensym("read"), 1, &a); // recall the default preset if exists atom_setsym(&a, gensym("default")); defer_low((t_object*)x, (method)model_preset_dorecall, NULL, 1, &a); // replace filewatcher if (EXTRA->filewatcher) { filewatcher_stop(EXTRA->filewatcher); object_free(EXTRA->filewatcher); } EXTRA->filewatcher = filewatcher_new((t_object*)x, outvol, (char*)textfile->s_name); filewatcher_start(EXTRA->filewatcher); } else object_error((t_object*)x, "preset_default : can't get the class of the patcher"); }
int lua_importfile(lua_State *L) { const char *filename; long outtype; short file_volume, err; if(!lua_isstring(L, 1)) luaL_error(L, "argument 1 for outlet must be a string"); filename = lua_tostring(L, 1); err = locatefile_extended(filename, &file_volume, &outtype, 0, 0); if(err) { error("jit.gl.lua: can't find file %s", filename); } else { // read file from disk long count; char **texthandle; t_filehandle fh; err = path_opensysfile(filename, file_volume, &fh, READ_PERM); if (err) { error("jit.gl.lua: %s: error %d opening file", filename, err); return 0; } texthandle = sysmem_newhandle(0); sysfile_readtextfile(fh, texthandle, 0, TEXT_LB_NATIVE); sysfile_close(fh); count = sysmem_handlesize(texthandle); sysmem_resizehandle(texthandle, count + 1); (*texthandle)[count] = 0; //NULL terminate, '\0'? //run file in Lua err = luaL_loadstring(L, *texthandle); err = lua_pcall(L, 0, LUA_MULTRET, 0); if (err) { post("lua pcall error %s", lua_tostring(L, -1)); lua_pop(L, 1); } sysmem_lockhandle(texthandle, false); sysmem_freehandle(texthandle); } return 0; }
// Method called by collective and standalone builder void tap_folder_fileusage(t_folder *x, void *w) { short err; short path_id; char filename[MAX_FILENAME_CHARS]; t_fourcc filetype; strncpy_zero(filename, "tap.applescript.mxo", MAX_FILENAME_CHARS); err = locatefile_extended(filename, &path_id, &filetype, NULL, -1); // FIND THE FILE if (err) { object_error((t_object *)x, "cannot locate file: %s", filename); return; } fileusage_addfile(w, 0, filename, path_id); }
unsigned long XObjGetModDate( const char* iClassName) { char fName[256]; short err, fPath; long fType; unsigned long modDate = 0; strcpy(fName, iClassName); strcat(fName, ".mxe"); err = locatefile_extended(fName, &fPath, &fType, NULL, 0); if (err == noErr) path_getmoddate(fPath, &modDate); return modDate; }
void jit_gl_hap_read(t_jit_gl_hap *x, t_symbol *s, long ac, t_atom *av) { t_atom a[2]; char fname[MAX_FILENAME_CHARS] = ""; short vol; t_fourcc type; short ret; x->newfile = 0; if (ac && av) { strcpy(fname, atom_getsym(av)->s_name); ret = locatefile_extended(fname, &vol, &type, NULL, 0); } else { ret = open_dialog(fname, &vol, &type, NULL, 0); // limit to movie files? } if (!ret) { jit_gl_hap_read_native(x, fname, vol); if(x->newfile) { jit_attr_user_touch(x, gensym("fps")); jit_attr_user_touch(x, gensym("duration")); jit_attr_user_touch(x, gensym("timescale")); jit_attr_user_touch(x, gensym("framecount")); // if user didn't modify looppoints, reset them //if(!x->userloop) { x->looppoints[0] = x->looppoints[1] = -1; //} // set attributes here jit_gl_hap_do_loop(x); // rate must init after playback starts } } jit_atom_setsym(a, x->file); jit_atom_setlong(a+1, x->newfile ? 1 : 0); defer_low(x, (method)jit_gl_hap_notify_atomarray_prep, s, 2, a); }
void max_jit_openni_XMLConfig_read(t_max_jit_openni *x, t_symbol *s, short argc, t_atom *argv) { long i; t_atom OutAtoms[2]; short filePathID; long fileType = 'TEXT', outType; char filename[MAX_FILENAME_CHARS]; char fullyQualifiedPathname[MAX_PATH_CHARS]; XnStatus nRetVal = XN_STATUS_OK; #ifdef _DEBUG t_object *mypatcher; t_symbol *mypatcherpath; if (object_obex_lookup(x, gensym("#P"), &mypatcher) != MAX_ERR_NONE) LOG_ERROR("error getting patcher for jit.openni"); mypatcherpath = object_attr_getsym(mypatcher, gensym("filepath")); if ((mypatcherpath) && (mypatcherpath != gensym(""))) // if I use _sym_nothing rather than gensym("") then I get linker error LNK2001: unresolved external symbol __common_symbols { LOG_COMMENT2("The patcher path is %s", mypatcherpath->s_name); } else { LOG_COMMENT("error getting filepath symbol for max.jit.openni"); return; } #endif if (argc == 0) // if no argument supplied, ask for file { if (open_dialog(filename, &filePathID, &outType, &fileType, 1)) { // non-zero: user cancelled or error LOG_DEBUG("error getting XML config file from dialog box for max.jit.openni"); atom_setsym(OutAtoms, gensym("<none>")); atom_setlong(OutAtoms + 1, 0); max_jit_obex_dumpout(x, gensym("read"), 2, OutAtoms); return; } } else if ((argc != 1) || (atom_gettype(argv) != A_SYM)) { LOG_DEBUG("read must have only one symbol argument"); atom_setsym(OutAtoms, gensym("<none>")); atom_setlong(OutAtoms + 1, 0); max_jit_obex_dumpout(x, gensym("read"), 2, OutAtoms); return; } else // we have exactly one symbol argument { strncpy_zero(filename, atom_getsym(argv)->s_name, MAX_FILENAME_CHARS); if (locatefile_extended(filename, &filePathID, &outType, &fileType, 1)) { LOG_DEBUG2("Could not find file", atom_getsym(argv)->s_name); atom_setsym(OutAtoms, atom_getsym(argv)); atom_setlong(OutAtoms + 1, 0); max_jit_obex_dumpout(x, gensym("read"), 2, OutAtoms); return; } } //Load file atom_setsym(OutAtoms, gensym(filename)); if (path_topathname(filePathID, filename, fullyQualifiedPathname) == 0) { LOG_DEBUG2("asking Jitter object to load file %s", fullyQualifiedPathname); jit_object_method(max_jit_obex_jitob_get(x), gensym("init_from_xml"), gensym(fullyQualifiedPathname), &nRetVal); if (nRetVal) { atom_setlong(OutAtoms + 1, 0); } else { atom_setlong(OutAtoms + 1, 1); } max_jit_obex_dumpout(x, gensym("read"), 2, OutAtoms); } else { atom_setlong(OutAtoms + 1, 0); max_jit_obex_dumpout(x, gensym("read"), 2, OutAtoms); } }
void filecontainer_doopen(t_filecontainer *x, t_symbol *arg) { t_atom a[4]; int err = 0; char filename[256]; short path; t_fourcc outtype = 0; t_fourcc type = 'cO0p'; #ifdef MAC_VERSION char *temppath; FSRef ref; Boolean isDir; FSCatalogInfo catalogInfo; #else // WIN_VERSION char temppath[512]; #endif char fullpath[512]; t_object *result = NULL; t_object *result2 = NULL; char **record = NULL; // sqlite records char **record2 = NULL; // sqlite records t_filehandle file_handle; t_ptr_size len = 0; char *blob; char sql[512]; if(!arg || !arg->s_name[0]) { if(open_dialog(filename, &path, &outtype, NULL, -1)) // Returns 0 if successful return; } else { t_fourcc typelist[1]; typelist[0] = 'cO0p'; strcpy(filename, arg->s_name); path = 0; locatefile_extended(filename, &path, &type, typelist, 0); } path_topotentialname(path, filename, fullpath, 0); #ifdef MAC_VERSION temppath = strchr(fullpath, ':'); temppath += 1; #else // WIN_VERSION path_nameconform(fullpath, temppath, PATH_STYLE_NATIVE_WIN, PATH_TYPE_ABSOLUTE); #endif x->name = gensym(temppath); // Create our temp folder for extracted files filecontainer_gettemppath(x); // Create the SQLite instance atom_setsym(&a[0], gensym("@rambased")); atom_setlong(&a[1], 0); atom_setsym(&a[2], gensym("@db")); atom_setsym(&a[3], x->name); x->sqlite = object_new_typed(CLASS_NOBOX, _sym_sqlite, 4, a); // Operate on the open DB if(x->sqlite) { object_method(x->sqlite, ps_starttransaction); object_method(x->sqlite, _sym_execstring, TABLEDEF_FILES, NULL); object_method(x->sqlite, _sym_execstring, TABLEDEF_ATTRS, NULL); object_method(x->sqlite, _sym_execstring, "UPDATE files SET valid = 1", NULL); object_method(x->sqlite, _sym_execstring, "SELECT file_id, filename, moddate FROM files", &result); while(record = (char **)object_method(result, _sym_nextrecord)) { // Here we check for the optional 'platform' attr for this file. // If a flag exists for the other platform, but not for the current platform, then we ignore this file. #ifdef MAC_VERSION sprintf(sql, "SELECT file_id_ext FROM attrs \ WHERE attr_name = 'platform' AND attr_value = 'windows' AND file_id_ext = %s ", record[0]); object_method(x->sqlite, _sym_execstring, sql, &result2); record2 = (char **)object_method(result2, _sym_nextrecord); if(record2) { sprintf(sql, "SELECT file_id_ext FROM attrs \ WHERE attr_name = 'platform' AND attr_value = 'mac' AND file_id_ext = %s ", record[0]); object_method(x->sqlite, _sym_execstring, sql, &result2); record2 = (char **)object_method(result2, _sym_nextrecord); if(!record2) { sprintf(sql, "UPDATE files SET valid = 0 WHERE file_id = %s ", record[0]); object_method(x->sqlite, _sym_execstring, sql, NULL); continue; } } #else // WIN_VERSION snprintf(sql, 512, "SELECT file_id_ext FROM attrs \ WHERE attr_name = 'platform' AND attr_value = 'mac' AND file_id_ext = %s ", record[0]); object_method(x->sqlite, _sym_execstring, sql, &result2); record2 = (char **)object_method(result2, _sym_nextrecord); if(record2) { snprintf(sql, 512, "SELECT file_id_ext FROM attrs \ WHERE attr_name = 'platform' AND attr_value = 'windows' AND file_id_ext = %s ", record[0]); object_method(x->sqlite, _sym_execstring, sql, &result2); record2 = (char **)object_method(result2, _sym_nextrecord); if(!record2) { snprintf(sql, 512, "UPDATE files SET valid = 0 WHERE file_id = %s ", record[0]); object_method(x->sqlite, _sym_execstring, sql, NULL); continue; } } #endif // At this point we have a file (record[0]), and we have determined that it is indeed a file we want to cache // So cache it to a new file in our temp path err = path_createsysfile(record[1], x->temp_path, type, &file_handle); if(err) { // Handle any errors that occur object_error((t_object *)x, "%s - error %d creating file", filename, err); } else { snprintf(sql, 512, "SELECT content FROM files WHERE file_id = %s", record[0]); object_method(x->sqlite, ps_getblob, sql, &blob, &len); err = sysfile_write(file_handle, &len, blob); if(err) { object_error((t_object *)x, "sysfile_write error (%d)", err); } } err = sysfile_seteof(file_handle, len); if(err) { object_error((t_object *)x, "%s - error %d setting EOF", filename, err); } sysfile_close(file_handle); // close file reference sysmem_freeptr(blob); blob = NULL; // Set the moddate #ifdef MAC_VERSION // FSCatalogInfo catalogInfo; // Boolean status; CFGregorianDate gdate; CFAbsoluteTime abstime; CFTimeZoneRef tz; UTCDateTime utc; sscanf(record[2], "%4ld-%02hd-%02hd %02hd:%02hd:%02lf", &gdate.year, (signed short*)&gdate.month, (signed short*)&gdate.day, (signed short*)&gdate.hour, (signed short*)&gdate.minute, &gdate.second); tz = CFTimeZoneCopySystem(); abstime = CFGregorianDateGetAbsoluteTime(gdate, tz); UCConvertCFAbsoluteTimeToUTCDateTime(abstime, &utc); catalogInfo.contentModDate = utc; strcpy(s_tempstr, x->temp_fullpath->s_name); temppath = strchr(s_tempstr, ':'); temppath++; strcat(temppath, "/"); strcat(temppath, record[1]); FSPathMakeRef((UInt8*)temppath, &ref, &isDir); err = FSSetCatalogInfo(&ref, kFSCatInfoContentMod, &catalogInfo); #else // WIN_VERSION char winpath[512]; HANDLE hFile; FILETIME fileTime; SYSTEMTIME systemTime; sscanf(record[2], "%4lu-%02lu-%02lu %02lu:%02lu:%02lu", &systemTime.wYear, &systemTime.wMonth, &systemTime.wDay, &systemTime.wHour, &systemTime.wMinute, &systemTime.wSecond); err = SystemTimeToFileTime(&systemTime, &fileTime); strcpy(s_tempstr, x->temp_fullpath->s_name); path_nameconform(s_tempstr, winpath, PATH_STYLE_NATIVE_WIN, PATH_TYPE_ABSOLUTE); strcat(winpath, "\\"); strcat(winpath, record[1]); hFile = CreateFile((LPCSTR)winpath , GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if(hFile == INVALID_HANDLE_VALUE) { object_error((t_object *)x, "invalid handle value"); goto out; } err = SetFileTime(hFile, &fileTime, &fileTime, &fileTime); if(err == 0) { err = GetLastError(); object_error((t_object *)x, "Error setting date: %i", err); } CloseHandle(hFile); out: ; #endif } object_method(x->sqlite, ps_endtransaction); }
void *jsusfx_new(t_symbol *notused, long argc, t_atom *argv) { if ( argc < 1 || atom_gettype(argv) != A_SYM ) { error("jsusfx~: missing script name"); return NULL; } t_jsusfx *x = reinterpret_cast<t_jsusfx *>(object_alloc(jsusfx_class)); t_symbol *s = atom_getsym(argv); t_fourcc filetype = 'TEXT', outtype; short path; char filename[MAX_PATH_CHARS]; strcpy(filename, s->s_name); if (locatefile_extended(filename, &path, &outtype, &filetype, 1)) { t_object *mypatcher; object_obex_lookup(x, gensym("#P"), &mypatcher); t_symbol *checkExists = object_attr_getsym(mypatcher, gensym("filepath")); if ( checkExists->s_name[0] == 0 ) { error("jsusfx~: patch needs to be saved in order to create new jsusfx script file"); return NULL; } path = path_getdefault(); t_fourcc type = 'TEXT'; t_filehandle ref; if ( path_createsysfile(filename, path, type, &ref) ) { error("jsusfx~: unable to create file"); return NULL; } char initText[] = "@sample\nspl0=1\nspl1=-1\n"; t_handle h = sysmem_newhandle(0); sysmem_ptrandhand(initText,h,strlen(initText)); if ( sysfile_writetextfile(ref, h, TEXT_LB_NATIVE) ) { error("jsusfx~: unable to write file"); return NULL; } sysfile_close(ref); sysmem_freehandle(h); } strcpy(x->scriptname, filename); x->path = path; char fullpath[MAX_PATH_CHARS]; path_toabsolutesystempath(path, filename, fullpath); std::ifstream is(fullpath); if ( ! is.is_open() ) { error("jsusfx~: error opening file %s", fullpath); return NULL; } x->bypass = false; dsp_setup((t_pxobject *)x, 2); x->outlet1 = outlet_new((t_object *)x, NULL); outlet_new((t_object *)x, "signal"); outlet_new((t_object *)x, "signal"); critical_new(&(x->critical)); x->m_editor = NULL; JsusFxMax *fx = new JsusFxMax(); fx->compile(is); x->fx = fx; /*if ( argc >= 2 && atom_gettype(argv+1) == A_LONG ) { x->fx->normalizeSliders = atom_getlong(argv+1); } else { x->fx->normalizeSliders = 1; } post("normalizer sl %x", x->fx->normalizeSliders);*/ return (x); }
int main(void) { common_symbols_init(); PlugtasticInit(); plugtastic_classinit(); sPlugtasticObject = (t_object*)plugtastic_new(); ps_plugtastic = GENSYM("plugtastic"); ps_plugtastic->s_thing = sPlugtasticObject; sMaxObject = _sym_max->s_thing; ps_objectfile = GENSYM("objectfile"); ps_db_object_addinternal = GENSYM("db.object_addinternal"); ps_oblist = GENSYM("oblist"); ps_db_addmetadata = GENSYM("db.addmetadata"); //defer_low(sMaxObject, (method)plug_setup_db, NULL, 0, NULL); plug_setup_db(); post("Plugtastic Version %s | 74Objects.com", PLUGTASTIC_VERSION); // This tells Max 5.0.6 and higher that we want the patcher files to be saved such that they are sorted. // Having the saved this way makes our SVN diffs much more meaningful. object_method_long(sMaxObject, GENSYM("sortpatcherdictonsave"), 1, NULL); // This tells Max 4.5.7 and higher to take any posts to the Max window and also make the // post to the system console, which greatly aids in debugging problems and crashes object_method_long(sMaxObject, GENSYM("setmirrortoconsole"), 1, NULL); // OPEN THE SPLASH if (sPlugtasticSplash) { char name[MAX_FILENAME_CHARS]; short path = 0; long type = 0; long typelist[2] = {'JSON', 'TEXT'}; short err; t_dictionary* d; t_object* p; t_atom a[2]; strncpy_zero(name, "Plugtastic.maxpat", MAX_FILENAME_CHARS); err = locatefile_extended(name, &path, &type, typelist, 2); dictionary_read(name, path, &d); atom_setobj(a, d); p = (t_object*)object_new_typed(_sym_nobox, _sym_jpatcher, 1, a); object_attr_setlong(p, _sym_locked, 1); // start out locked object_attr_setchar(p, _sym_enablehscroll, 0); // turn off scroll bars object_attr_setchar(p, _sym_enablevscroll, 0); object_attr_setchar(p, _sym_toolbarvisible, 0); object_attr_setsym(p, _sym_title, gensym("Welcome to Plugtastic")); object_attr_setparse(p, _sym_rect, "271 170 799 489"); object_attr_setparse(p, _sym_defrect, "271 170 799 489"); object_method(p, _sym_vis); // "vis" happens immediately, "front" is defer_lowed object_method(p, _sym_loadbang); // object_method_parse(p, _sym_window, "constrain 799 489 799 489", NULL); object_method_parse(p, _sym_window, "flags nozoom", NULL); object_method_parse(p, _sym_window, "flags nogrow", NULL); object_method_parse(p, _sym_window, "exec", NULL); } return 0; }
int cc_doload(t_cc *x, t_symbol *lib){ while(x->ok_to_compile == 0){} x->compiling = 1; int ret = 0; t_symbol *dfile_sym = lib; if(!dfile_sym){ if(x->dfile_fullpath){ dfile_sym = gensym(x->dfile_fullpath); }else{ goto out; } } char dfile[MAX_PATH_CHARS]; strcpy(dfile, dfile_sym->s_name); //char *ptr = dfile->s_name; //if(*ptr != '/'){ short outvol; long outtype; if(locatefile_extended(dfile, &outvol, &outtype, NULL, 0)){ error("cc: couldn't locate %s", dfile); ret = 1; goto out; }else{ char buf[MAX_PATH_CHARS]; path_topathname(outvol, dfile, buf); char *ptr = buf; while(*ptr++ != ':'){} dfile_sym = gensym(ptr); strcpy(dfile, dfile_sym->s_name); } x->handle = dlopen(dfile, RTLD_NOW); if(!x->handle){ error("cc: %s", dlerror()); ret = 1; goto out; } // read the symbols from the dylib hashtab_clear(x->ht); char *err; char st[MAX_PATH_CHARS]; sprintf(st, "%s/.%s", x->build_path, x->basename); char compbuf[1024]; sprintf(compbuf, "nm %s | awk '$2 ~ /T/ {print $3}' > %s", dfile, st); if(system(compbuf)){ error("cc: couldn't parse symbol table"); ret = 1; goto out; } FILE *fp = fopen(st, "r"); if(!fp){ error("cc: couldn't read symbol table"); ret = 1; goto out; } char buf[LINE_MAX]; int i = 0; while(fgets(buf, LINE_MAX, fp)){ buf[strlen(buf) - 1] = '\0'; // get rid of the newline char //ccmethod f = (ccmethod)dlsym(x->handle, buf + 1); long f = (long)dlsym(x->handle, buf + 1); if((err = dlerror()) == NULL){ x->function_names[i] = gensym(buf + 1); // skip over the leading underscore hashtab_store(x->ht, x->function_names[i], (t_object *)f); #if defined(CC_JBOX) if(!strcmp(buf + 1, "my_paint")){ x->user_paint = (ccpaint_method)f; } #endif post("%s", buf + 1); } } fclose(fp); remove(st); void (*f)(t_object *, char *); hashtab_lookup(x->ht, gensym("my_new"), (t_object **)&f); if(f){ f((t_object *)x, x->user_obj); } out: x->compiling = 0; #if defined(CC_JBOX) jbox_redraw((t_jbox *)x); #endif return ret; }
static bool getmodulesub(const char *mod,char *dir,int len,const char *ext) { #if FLEXT_SYS == FLEXT_SYS_PD char *name; int fd = open_via_path("",mod,ext,dir,&name,len,0); if(fd >= 0) { fileclose(fd); FLEXT_ASSERT(name && *name); } else { // look for mod/__init__.py std::string tmp(mod); int l = tmp.size(); tmp += "/__init__"; fd = open_via_path("",tmp.c_str(),ext,dir,&name,len,0); if(fd >= 0) { fileclose(fd); FLEXT_ASSERT(name && *name); // we must remove the module name from dir char *t = dir+strlen(dir)-l; FLEXT_ASSERT(!strcmp(mod,t) && t[-1] == '/'); t[-1] = 0; } else name = NULL; } // if dir is current working directory... name points to dir if(dir == name) strcpy(dir,"."); return name != NULL; #elif FLEXT_SYS == FLEXT_SYS_MAX short path; long type; char smod[1024]; strcpy(smod,mod); strcat(smod,ext); bool ok = !locatefile_extended(smod,&path,&type,&type,0); if(ok) // convert pathname to unix style path_topathname(path,NULL,smod); else { // do path/file.ext combinations work at all under Max? strcpy(smod,mod); short path; type = 'fold'; ok = !locatefile_extended(smod,&path,&type,&type,1); if(ok) { // convert pathname to unix style (including trailing slash) path_topathname(path,NULL,smod); char *end = smod+strlen(smod); strcpy(end,mod); strcat(end,"/__init__"); strcat(end,ext); // check if file is really existing: try to open it FILE *f = fopen(smod,"r"); if(f) { *end = 0; // clear module part ... we only need base path fclose(f); } else ok = false; } } if(ok) { // convert path into slash style needed for Python #if 0 // Max API function uses Volume:/Path notation path_nameconform(smod,dir,PATH_STYLE_SLASH,PATH_TYPE_ABSOLUTE); #else #if FLEXT_OS == FLEXT_OS_WIN char *colon = NULL; #else char *colon = strchr(smod,':'); #endif if(colon) { *colon = 0; strcpy(dir,"/Volumes/"); strcat(dir,smod); strcat(dir,colon+1); } else strcpy(dir,smod); #endif return true; } else // not found return false; #else #pragma message("Not implemented"); return false; #endif }
void jamoma_init(void) { short outvol = 0; t_fourcc outtype, filetype = 'TEXT'; char name[MAX_PATH_CHARS], fullname[MAX_PATH_CHARS]; if (!initialized) { t_object *max = SymbolGen("max")->s_thing; TTString JamomaConfigurationFilePath; t_atom a[4]; TTValue v, out; TTErr err; if (maxversion() < 1798) { error("Jamoma %s | build %s can't run under Max version ealier than 7.0.6", JAMOMA_MAX_VERSION, JAMOMA_MAX_REV); return; } // Initialize the Modular library TTModularInit(); #ifdef TTSCORE_IMPORT // Initialize the Score framework TTScoreInit(); #endif // Prepare a symbol for Max application kTTSym_Max = TTSymbol("Max"); // Create an application manager MaxApplicationManager = TTObject("ApplicationManager"); // Create a local application called "Max" and get it back err = MaxApplicationManager.send("ApplicationInstantiateLocal", kTTSym_Max, out); if (err) { TTLogError("Error : can't create Jamoma application \n"); return; } else MaxApplication = out[0]; // check if the JamomaConfiguration.xml file exists strncpy_zero(name, "JamomaConfiguration.xml", MAX_PATH_CHARS); if (locatefile_extended(name, &outvol, &outtype, &filetype, 1)) return error("Jamoma not loaded : can't find %s", name); path_topathname(outvol, name, fullname); // MaxApplication have to read JamomaConfiguration.xml TTObject anXmlHandler(kTTSym_XmlHandler); anXmlHandler.set(kTTSym_object, MaxApplication); std::string path = fullname; #if ( __APPLE__ ) // remove drive name prefix size_t pos = path.find(":/"); path = path.substr(pos+1); v = TTSymbol(path); #else v = TTSymbol(fullname); #endif anXmlHandler.send(kTTSym_Read, v, out); // Initialize common symbols common_symbols_init(); jamomaSymbolsInit(); // Initialize common regex ttRegexForJmod = new TTRegex("(jmod.)"); ttRegexForJcom = new TTRegex("(j\\.)"); ttRegexForModel = new TTRegex("(.model)"); ttRegexForModule = new TTRegex("(.module)"); ttRegexForView = new TTRegex("(.view)"); ttRegexForMaxpat = new TTRegex("(.maxpat)"); ttRegexForMaxhelp = new TTRegex("(.maxhelp)"); ttRegexForBracket = new TTRegex("\\[(\\d|\\d\\d|\\d\\d\\d)\\]"); // parse until 999 ModelPatcherFormat = new TTString("%s.model.maxpat"); ModelPresetFormat = new TTString("%s.model.presets.txt"); ViewPresetFormat = new TTString("%s.view.presets.txt"); HelpPatcherFormat = new TTString("%s.model"); RefpageFormat = new TTString("%s.model"); DocumentationFormat = new TTString("%s.model.html"); // Create Required Global Instances hash_modules = (t_hashtab*)hashtab_new(0); // TODO: Use quittask_install() to set up a destructor for this to free it before Max exits // Add Jamoma Key Commands // J -- Jamoma: a new object box with "j." in it atom_setsym(a+0, SymbolGen("k")); atom_setsym(a+1, SymbolGen("patcher")); atom_setsym(a+2, SymbolGen("inserttextobj")); atom_setsym(a+3, SymbolGen("j.")); object_method_typed(max, SymbolGen("definecommand"), 4, a, NULL); // // M -- Module: a new object box with ".model" in it // atom_setsym(a+0, SymbolGen("M")); // atom_setsym(a+1, SymbolGen("patcher")); // atom_setsym(a+2, SymbolGen("inserttextobj")); // atom_setsym(a+3, SymbolGen(".model")); // object_method_typed(max, SymbolGen("definecommand"), 4, a, NULL); // // // B -- BPatcher: a new module in a bpatcher // object_method_parse(max, SymbolGen("definecommand"), (char*)"B patcher inserttextobj \"bpatcher @name .module @args myModule\"", NULL); // // D -- Demo: a new module in a bpatcher, but with the args reverse which is handy for super-fast demos when you don't care about the OSC name // object_method_parse(max, SymbolGen("definecommand"), (char*)"D patcher inserttextobj \"bpatcher @name .module\"", NULL); // // X -- Continuous Mapper module // object_method_parse(max, SymbolGen("definecommand"), (char*)"X patcher insertobj bpatcher @name mapper.module.maxpat @args mapper", NULL); // now the jamoma object { t_symbol *jamomaSymbol = SymbolGen("jamoma"); jamoma_object_initclass(); jamomaSymbol->s_thing = jamoma_object_new(); } post("Jamoma %s | build %s", JAMOMA_MAX_VERSION, JAMOMA_MAX_REV ); initialized = true; } }