PlugOutPtr PlugOutNew(SymbolPtr msg, AtomCount argc, AtomPtr argv) { PlugOutPtr self = PlugOutPtr(object_alloc(sPlugOutClass)); TTValue v; TTErr err; if (self) { v.setSize(2); v.set(0, TT("plugtastic.output")); v.set(1, 2); err = TTObjectBaseInstantiate(TT("audio.object"), (TTObjectBasePtr*)&self->audioGraphObject, v); v = TTPtr(self->audioGraphObject); object_obex_store((void*)self, _sym_dumpout, (object*)outlet_new(self, NULL)); self->audioGraphOutlet = outlet_new(self, "audio.connect"); self->qelem = qelem_new(self, (method)PlugOutQFn); object_obex_lookup(self, GENSYM("#P"), &self->patcher); self->pluginName = object_attr_getsym(self->patcher, _sym_name); self->pluginVersion = GENSYM("1.0"); self->pluginVersionHex = GENSYM("0x00010000"); self->pluginManufacturer = GENSYM("Plugtastic"); self->pluginManufacturerCode = GENSYM("74Ob"); self->pluginID = GENSYM("ftmp"); attr_args_process(self, argc, argv); } return self; }
t_osc_bndl_u *ocontext_processPatcher(t_object *patcher) { t_osc_bndl_u *patcher_bndl = osc_bundle_u_alloc(); if(patcher == NULL){ // return empty bundle---this is intentional return patcher_bndl; } long nattrs = 0; t_symbol **attrs = NULL; object_attr_getnames(patcher, &nattrs, &attrs); for(int i = 0; i < nattrs; i++){ t_atom *av = NULL; long ac = 0; object_attr_getvalueof(patcher, attrs[i], &ac, &av); if(av && ac){ long addresslen = strlen(attrs[i]->s_name) + 2; char address[addresslen]; snprintf(address, addresslen, "/%s", attrs[i]->s_name); t_osc_msg_u *msg = NULL; if(ac == 1 && atom_gettype(av) == A_OBJ){ //printf("%s has object: %p %p\n", address, patcher, atom_getobj(av)); continue; t_osc_bndl_u *b = ocontext_processPatcher(atom_getobj(av)); if(b){ msg = osc_message_u_allocWithAddress(address); osc_message_u_appendBndl_u(msg, b); osc_bundle_u_addMsg(patcher_bndl, msg); } }else{ omax_util_maxAtomsToOSCMsg_u(&msg, gensym(address), ac, av); if(msg){ osc_bundle_u_addMsg(patcher_bndl, msg); } } } } sysmem_freeptr(attrs); t_symbol *maxclass = object_attr_getsym(patcher, gensym("maxclass")); if(maxclass && maxclass == gensym("jpatcher")){ patcher = jpatcher_get_parentpatcher(patcher); t_osc_bndl_u *parent_bndl = ocontext_processPatcher(patcher); t_osc_msg_u *msg = osc_message_u_allocWithAddress("/parent"); osc_message_u_appendBndl_u(msg, parent_bndl); osc_bundle_u_addMsg(patcher_bndl, msg); } return patcher_bndl; }
void return_makesend(t_return *x) { t_atom a; char osc[512]; t_symbol* module_name = object_attr_getsym(x->common.hub, _sym_name); if (module_name && module_name != _sym_nothing) { strcpy(osc, module_name->s_name); strcat(osc, "/"); strcat(osc, x->common.attr_name->s_name); atom_setsym(&a, gensym(osc)); x->send = (t_object*)object_new_typed(_sym_box, jps_jcom_send, 1, &a); } else defer_low(x, (method)return_makesend, 0, 0, 0); }
void cc_edclose(t_cc *x, char **text, long size){ t_symbol *path = object_attr_getsym(x->ed, gensym("filepath")); x->ed = NULL; if(path){ if(path == gensym("")){ return; } char *ptr = path->s_name; while(*ptr != ':'){ ptr++; } ptr++; strcpy(x->cfile_fullpath, ptr); //post("%s cfile: %s", __PRETTY_FUNCTION__, x->cfile_fullpath); x->have_valid_filename = 1; cc_get_basename(x->cfile_fullpath, 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); } }
// Registering with the jcom.hub object t_object *jcom_core_subscribe(t_object *x, t_symbol *name, t_object *container, t_symbol *object_type) { t_object *patcher = container; t_object *box; t_symbol *objclass = NULL; t_object *hub = NULL; again5: box = object_attr_getobj(patcher, _sym_firstobject); while (box) { objclass = object_attr_getsym(box, _sym_maxclass); if (objclass == jps_jcom_hub) { hub = object_attr_getobj(box, _sym_object); object_method(hub, jps_subscribe, name, x, object_type); return hub; } box = object_attr_getobj(box, _sym_nextobject); } patcher = object_attr_getobj(patcher, _sym_parentpatcher); if (patcher) goto again5; return NULL; }
// TODO: When running in the debugger, it seems like we are iterating through this function a whole bunch of times! // Can we put it in a qelem or something so that it only gets called once? [TAP] // But actually, maybe it is just a Max 4.6 funky Runtime thing? Let's take a look again when we get to Max 5 void hub_examine_context(t_hub *x) { AtomCount argc = 0; AtomPtr argv = NULL; SymbolPtr context = jamoma_patcher_getcontext(x->container); // Try to get OSC Name of module from an argument jamoma_patcher_getargs(x->container, &argc, &argv); // <-- this call allocates memory for argv if(argc){ x->osc_name = atom_getsym(argv+(argc-1)); sysmem_freeptr(argv); } else x->osc_name = _sym_nothing; // Try to get OSC Name of module from scripting name if(x->osc_name == _sym_nothing) x->osc_name = jamoma_patcher_getvarname(x->container); // In this case we overwrite whatever happened above if(context == gensym("toplevel")){ x->osc_name = gensym("/editing_this_module"); x->editing = true; } else{ t_object* patcher = jamoma_object_getpatcher((t_object*)x); t_object* box = object_attr_getobj(patcher, jps_box); t_object* ui = NULL; t_symbol* objclass = NULL; x->editing = false; ui = object_attr_getobj(patcher, gensym("firstobject")); while(ui){ objclass = object_attr_getsym(ui, gensym("maxclass")); if(objclass == gensym("jcom.ui")) break; ui = object_attr_getobj(ui, gensym("nextobject")); } if(ui){ t_rect boxRect; t_rect uiRect; if(context == gensym("bpatcher")){ object_attr_get_rect(ui, _sym_presentation_rect, &uiRect); object_attr_get_rect(box, _sym_patching_rect, &boxRect); boxRect.width = uiRect.width; boxRect.height = uiRect.height; object_attr_set_rect(box, _sym_patching_rect, &boxRect); object_attr_get_rect(box, _sym_presentation_rect, &boxRect); boxRect.width = uiRect.width; boxRect.height = uiRect.height; object_attr_set_rect(box, _sym_presentation_rect, &boxRect); } else if(context == gensym("subpatcher")){ object_attr_get_rect(ui, _sym_presentation_rect, &uiRect); object_attr_get_rect(patcher, _sym_defrect, &boxRect); boxRect.width = uiRect.width; boxRect.height = uiRect.height; object_attr_set_rect(patcher, _sym_defrect, &boxRect); object_attr_setchar(patcher, _sym_toolbarvisible, 0); } } } object_attr_setsym(x, _sym_name, x->osc_name); hub_subscriptions_refresh(x); hub_internals_create(x); qelem_unset(x->init_qelem); // clear the last thing to make sure we don't call into this a bunch of times qelem_set(x->init_qelem); // flag the queue for initialization }
void *hub_new(t_symbol *s, long argc, t_atom *argv) { short i; long attrstart = attr_args_offset(argc, argv); t_hub *x = (t_hub *)object_alloc(s_hub_class); t_symbol *name = _sym_nothing; t_atom a[2]; if(attrstart && argv) atom_arg_getsym(&name, 0, attrstart, argv); else{ t_object* patcher = jamoma_object_getpatcher((t_object*)x); t_symbol* filepath = object_attr_getsym(patcher, _sym_filepath); char pathstr[MAX_PATH_CHARS]; char* filename = 0; strncpy_zero(pathstr, filepath->s_name, MAX_PATH_CHARS); filename = strrchr(pathstr, '.'); if(filename) { *filename = 0; // strip the suffix by setting '.' to terminating NULL char filename = strrchr(pathstr, '/'); if (filename) { // Our module name is the patchers name since the patcher is typically located // at /some/where/nameToUseForModule.maxpat filename++; // get rid of slash name = gensym(filename); } else name = gensym(pathstr); } else { // We are an unnamed jcom.hub inserted into an unsaved max patcher which has // no '.' in it's filename. Just leave as untitled, at least until it is saved. name = gensym("Untitled"); } } if(x){ for(i=k_num_outlets; i > 0; i--) x->outlets[i-1] = outlet_new(x, 0); object_obex_store((void *)x, _sym_dumpout, (t_object *)x->outlets[k_outlet_dumpout]); x->init_qelem = qelem_new(x, (method)hub_qfn_init); // set default attributes x->attr_name = name; x->osc_name = _sym_nothing; x->attr_type = jps_control; x->attr_description = _sym_nothing; x->attr_algorithm_type = jps_default; // poly for audio, jitter for video, control for control x->attr_size = jps_1U_half; x->attr_inspector = 0; x->using_wildcard = false; x->in_object = NULL; // module MUST have a jcom.in object x->out_object = NULL; // the jcom.out object is optional x->gui_object = NULL; // jcom.remote in the gui x->num_parameters = 0; for(i=0; i<MAX_NUM_CHANNELS; i++) x->meter_object[i] = NULL; x->preset = new presetList; // begin with no presets x->subscriber = new subscriberList; // ... and no subscribers attr_args_process(x, argc, argv); // handle attribute args x->jcom_send = NULL; x->jcom_receive = NULL; atom_setsym(a, jps_jcom_remote_fromModule); x->jcom_send = (t_object*)object_new_typed(_sym_box, jps_jcom_send, 1, a); atom_setsym(a, jps_jcom_remote_toModule); x->jcom_receive = (t_object*)object_new_typed(_sym_box, jps_jcom_receive, 1, a); object_method(x->jcom_receive, jps_setcallback, &hub_receive_callback, x); if(!g_jcom_send_notifications){ atom_setsym(a, gensym("notifications")); g_jcom_send_notifications = (t_object*)object_new_typed(_sym_box, jps_jcom_send, 1, a); } x->container = jamoma_object_getpatcher((t_object*)x); // The following must be deferred because we have to interrogate our box, // and our box is not yet valid until we have finished instantiating the object. // Trying to use a loadbang method instead is also not fully successful (as of Max 5.0.6) defer_low(x, (method)hub_examine_context, 0, 0, 0); } return x; }
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); }
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); } }