void iterator_notify(t_iterator *x, t_symbol *s, t_symbol *msg, void *sender, void *data) { // post("got %s message from %X (%s)", msg->s_name, sender, s->s_name); if (msg == gensym("attr_modified") && sender == x->a_patcherview) { // sent when an attribute of the sender changes t_symbol *attrname; // 'data' arg is the modified attribute object // get its name: attrname = (t_symbol *)object_method(data, gensym("getname")); post("'%s' attribute was modified", attrname->s_name); if (attrname == gensym("rect")) { t_atom *av = NULL; long ac = 0; object_attr_getvalueof(sender, attrname, &ac, &av); if (ac && av) { t_object *jb; post("new rect: %ld %ld %ld %ld", atom_getlong(av), atom_getlong(av+1), atom_getlong(av+2), atom_getlong(av+3)); object_obex_lookup(x, gensym("#B"), &jb); if (jb) { t_atom *rv = NULL; long rc = 0; object_attr_getvalueof(jb, gensym("patching_rect"), &rc, &rv); if (rc && rv) { // we have box rect // compare cached view size to current view long dx = atom_getlong(av+2) - x->a_cached.x; long dy = atom_getlong(av+3) - x->a_cached.y; long boxw = atom_getlong(rv+2); long boxh = atom_getlong(rv+3); // recache new size x->a_cached.x = atom_getlong(av+2); x->a_cached.y = atom_getlong(av+3); // modify my box width atom_setlong(rv+2, boxw + dx); // (height is ignored by jnewobj) atom_setlong(rv+3, boxh + dy); object_attr_setvalueof(jb, gensym("patching_rect"), rc, rv); freebytes(rv, sizeof(t_atom) * rc); } } freebytes(av, sizeof(t_atom) * ac); } } } }
t_max_err paramui_getUIFreeze(t_paramui *x, void *attr, long *argc, t_atom **argv) { t_symbol *attrName = (t_symbol*)object_method(attr, _sym_getname); // to - this have to be removed because it is not an attribute of TTData class return object_attr_getvalueof(x->obj_parameter, attrName, argc, argv); }
void jamoma_class_attr_get(t_object *o, t_symbol *attrName, long, t_atom *) { char cAttrName[256]; t_symbol *sAttrName; char *temp; long ac = 0; t_atom *av = NULL; t_jcom_core_subscriber_common *x = (t_jcom_core_subscriber_common*)o; strcpy(cAttrName, attrName->s_name); temp = strrchr(cAttrName, '/'); if(temp) *temp = 0; sAttrName = gensym(cAttrName); object_attr_getvalueof(o, sAttrName, &ac, &av); object_obex_dumpout(o, sAttrName, ac, av); if(x->hub != NULL){ char s[256]; t_atom a[4]; snprintf(s, 256, "%s:/%s", x->attr_name->s_name, attrName->s_name); atom_setsym(a+0, gensym(s)); sysmem_copyptr(av, a+1, sizeof(t_atom) * ac); object_method_typed(x->hub, jps_feedback, ac + 1, a, NULL); } if(ac) sysmem_freeptr(av); }
void hub_getstate(t_hub *x) { subscriberList* subscriber = x->subscriber; // head of the linked list subscriberIterator i; t_subscriber* t; char* text = NULL; long textsize = 0; if(!x->textEditor) x->textEditor = (t_object*)object_new(_sym_nobox, _sym_jed, x, 0); if(!x->textSize){ x->textSize = 4096; x->text = (char*)malloc(sizeof(char) * x->textSize); } x->text[0] = 0; critical_enter(0); for(i = subscriber->begin(); i != subscriber->end(); ++i) { t = *i; if(t->type == jps_subscribe_parameter){ long ac = NULL; t_atom* av = NULL; object_attr_getvalueof(t->object, jps_value, &ac, &av); // get atom_gettext(ac, av, &textsize, &text, 0); // this is a really lame way to do this... if(strlen(x->text) > (x->textSize - 1024)){ x->textSize += 4096; x->text = (char*)realloc(x->text, x->textSize); } strncat_zero(x->text, x->osc_name->s_name, x->textSize); strncat_zero(x->text, "/", x->textSize); strncat_zero(x->text, t->name->s_name, x->textSize); strncat_zero(x->text, " ", x->textSize); strncat_zero(x->text, text, x->textSize); strncat_zero(x->text, "\n", x->textSize); sysmem_freeptr(text); text = NULL; textsize = 0; } } critical_exit(0); object_method(x->textEditor, _sym_settext, x->text, _sym_utf_8); object_attr_setchar(x->textEditor, gensym("scratch"), 1); object_attr_setsym(x->textEditor, _sym_title, gensym("jamoma module state")); sysmem_freeptr(text); }
// deferred function for registering with the jcom.hub object void out_subscribe(void *z) { long argc; t_atom a; t_atom *argv = &a; t_out *x = (t_out *)z; if(x->common.hub != NULL){ object_attr_getvalueof(x->common.hub, jps_name, &argc, &argv); x->common.module_name = atom_getsym(argv); } }
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; }
static void LiliTell( objLili* me, Symbol* iTarget, Symbol* iAttrName) { long argC = 0; Atom* argV = NIL; if (object_attr_getvalueof(me, iAttrName, &argC, &argV) == MAX_ERR_NONE) { ForwardAnything(iTarget, iAttrName, argC, argV); freebytes(argV, argC * sizeof(Atom)); // ASSERT (argC > 0 && argV != NIL) } }
void iterator_attach(t_iterator *x) { t_atom *av = NULL; long ac = 0; x->a_patcherview = object_attr_getobj(x->a_patcher, gensym("firstview")); object_attach_byptr_register(x, x->a_patcherview, CLASS_NOBOX); // get the bounds of the first patcherview and cache them object_attr_getvalueof(x->a_patcherview, gensym("rect"), &ac, &av); if (ac && av) { x->a_cached.x = atom_getfloat(av+2); // width x->a_cached.y = atom_getfloat(av+3); // height freebytes(av, sizeof(t_atom) * ac); // or sysmem_freeptr() } }
// Don't pass memory in for this function! It will allocate what it needs // -- then the caller is responsible for freeing void jamoma_patcher_getargs(t_object *patcher, long *argc, t_atom **argv) { t_symbol *context = jamoma_patcher_getcontext(patcher); t_object *box = object_attr_getobj(patcher, jps_box); t_object *textfield = NULL; char *text = NULL; unsigned long textlen = 0; if(context == gensym("bpatcher")) object_attr_getvalueof(box, gensym("args"), argc, argv); else if(context == gensym("subpatcher")){ textfield = object_attr_getobj(box, gensym("textfield")); object_method(textfield, gensym("gettextptr"), &text, &textlen); atom_setparse(argc, argv, text); } else{ *argc = 0; *argv = NULL; } }
void inquisitor_get(t_inquisitor *x, t_symbol *name) { if(!x->subject){ t_object* b = jpatcher_get_firstobject(x->patcher); while(b){ if(x->name == jbox_get_varname(b)){ x->subject = jbox_get_object(b); break; } b = jbox_get_nextobject(b); } } if(x->subject && !NOGOOD(x->subject)){ t_atom* av = NULL; long ac = 0; t_max_err err; err = object_attr_getvalueof(x->subject, name, &ac, &av); if(!err && ac && av){ for(long i=0; i<ac; i++){ if(atom_gettype(av+i) != A_LONG && atom_gettype(av+i) != A_FLOAT && atom_gettype(av+i) != A_SYM){ object_error((t_object*)x, "The type of data returned for this attribute value is not usable by tap.inquisitor: %s", name->s_name); err = MAX_ERR_GENERIC; break; } } if(!err) outlet_anything(x->outlet, name, ac, av); } else{ object_error((t_object*)x, "problem getting attribute value for %s", name->s_name); } if(ac && av) sysmem_freeptr(av); } }
// Return a list of parameters and message for this module void hub_paramvalues_get(t_hub *x) { subscriberList *subscriber = x->subscriber; // head of the linked list t_atom *av; long ac; char osc[512]; subscriberIterator i; t_subscriber* t; short num_params_with_priority = 0; short num_params_recalled = 0; short p; hub_outlet_return(x, jps_parameter_values_start, 0, NULL); // Count the number of parameters with a priority critical_enter(0); for(i = subscriber->begin(); i != subscriber->end(); ++i) { t = *i; if(t->type == jps_subscribe_parameter){ ac = NULL; av = NULL; object_attr_getvalueof(t->object, jps_priority, &ac, &av); if(atom_getlong(av) > 0) num_params_with_priority++; } } critical_exit(0); if(num_params_with_priority > 0){ p=1; while(num_params_with_priority > num_params_recalled){ critical_enter(0); for(i = subscriber->begin(); i != subscriber->end(); ++i) { t = *i; if(t->type == jps_subscribe_parameter){ ac = NULL; av = NULL; object_attr_getvalueof(t->object, jps_priority, &ac, &av); // post("Priority" + atom_getlong(av)); if(atom_getlong(av) == p){ ac = NULL; av = NULL; // init object_attr_getvalueof(t->object, jps_value, &ac, &av); // get snprintf(osc, 512, "%s/%s", jps_parameter_value->s_name, t->name->s_name); hub_outlet_return(x, gensym(osc), ac, av); num_params_recalled++; } } } critical_exit(0); p++; } // Recall items with priority 0 now critical_enter(0); for(i = subscriber->begin(); i != subscriber->end(); ++i) { t = *i; if(t->type == jps_subscribe_parameter){ ac = NULL; av = NULL; object_attr_getvalueof(t->object, jps_priority, &ac, &av); if(atom_getlong(av) == 0) { ac = NULL; av = NULL; // init object_attr_getvalueof(t->object, jps_value, &ac, &av); // get snprintf(osc, 512, "%s/%s", jps_parameter_value->s_name, t->name->s_name); hub_outlet_return(x, gensym(osc), ac, av); } } } critical_exit(0); } else{ critical_enter(0); for(i = subscriber->begin(); i != subscriber->end(); ++i) { t = *i; if(t->type == jps_subscribe_parameter){ ac = NULL; av = NULL; object_attr_getvalueof(t->object, jps_priority, &ac, &av); if(atom_getlong(av) == 0) { ac = NULL; av = NULL; // init object_attr_getvalueof(t->object, jps_value, &ac, &av); // get snprintf(osc, 512, "%s/%s", jps_parameter_value->s_name, t->name->s_name); hub_outlet_return(x, gensym(osc), ac, av); } } } critical_exit(0); } hub_outlet_return(x, jps_parameter_values_end, 0, NULL); }
// Return a list of parameters and message for this module void hub_paramnames_get(t_hub *x) { subscriberList *subscriber = x->subscriber; // head of the linked list t_atom a; t_atom *av; long ac; subscriberIterator i; t_subscriber* t; short num_params_with_priority = 0; short num_params_recalled = 0; short p; hub_outlet_return(x, jps_parameter_names_start, 0, NULL); // Count the number of parameters with a priority critical_enter(0); for(i = subscriber->begin(); i != subscriber->end(); ++i) { t = *i; if(t->type == jps_subscribe_parameter){ ac = NULL; av = NULL; object_attr_getvalueof(t->object, jps_priority, &ac, &av); if(atom_getlong(av) > 0) num_params_with_priority++; } } critical_exit(0); if(num_params_with_priority > 0){ p=1; while(num_params_with_priority > num_params_recalled){ critical_enter(0); for(i = subscriber->begin(); i != subscriber->end(); ++i) { t = *i; if(t->type == jps_subscribe_parameter){ ac = NULL; av = NULL; object_attr_getvalueof(t->object, jps_priority, &ac, &av); if(atom_getlong(av) == p){ ac = NULL; av = NULL; // init atom_setsym(&a, t->name); if(t->type == jps_subscribe_parameter) hub_outlet_return(x, jps_parameter_name, 1, &a); num_params_recalled++; } } } critical_exit(0); p++; } // Recall items with priority 0 now critical_enter(0); for(i = subscriber->begin(); i != subscriber->end(); ++i) { t = *i; if(t->type == jps_subscribe_parameter){ ac = NULL; av = NULL; object_attr_getvalueof(t->object, jps_priority, &ac, &av); if(atom_getlong(av) == 0) { ac = NULL; av = NULL; // init atom_setsym(&a, t->name); if(t->type == jps_subscribe_parameter) hub_outlet_return(x, jps_parameter_name, 1, &a); } } } critical_exit(0); } else{ critical_enter(0); for(i = subscriber->begin(); i != subscriber->end(); ++i) { t = *i; if(t->type == jps_subscribe_parameter){ ac = NULL; av = NULL; object_attr_getvalueof(t->object, jps_priority, &ac, &av); if(atom_getlong(av) == 0) { ac = NULL; av = NULL; // init atom_setsym(&a, t->name); if(t->type == jps_subscribe_parameter) hub_outlet_return(x, jps_parameter_name, 1, &a); } } } critical_exit(0); } hub_outlet_return(x, jps_parameter_names_end, 0, NULL); }
void connect_notify(t_connect *x, t_symbol *s, t_symbol *msg, void *sender, void *data) { int i, j, k, tabcheck; if (msg == hoa_sym_attr_modified && sender == x->f_patcherview) { t_symbol *attrname; attrname = (t_symbol *)object_method(data, hoa_sym_getname); if (attrname == hoa_sym_selectedboxes) { t_atom *av = NULL; long current_nb_selected = 0; object_attr_getvalueof(sender, attrname, ¤t_nb_selected, &av); if (current_nb_selected && av) { // on supprime tous les objets du tableau qui ne sont plus dans la selection if(x->f_nbSelected < 0) x->f_nbSelected = 0; if(current_nb_selected < x->f_nbSelected) { for(i = 0 ; i < current_nb_selected ; i++) { tabcheck = 0; for(j = 0; j < x->f_nbSelected; j++) { if (atom_gettype(av+i) == A_OBJ && x->f_objects[j] == (t_object*)atom_getobj(av+i)) { tabcheck = 1; break; } } if (!tabcheck) x->f_objects[j] = NULL; } // puis on retrie le tableau for(i = 0; i < x->f_nbSelected; i++) { if (x->f_objects[i] == NULL) { for(k = i; k < x->f_nbSelected; k++) x->f_objects[k] = x->f_objects[k+1]; x->f_nbSelected--; break; } } } else if(current_nb_selected > x->f_nbSelected) { for(i = 0 ; i < current_nb_selected ; i++) { tabcheck = 0; for(j = 0; j < x->f_nbSelected; j++) { if (atom_gettype(av+i) == A_OBJ && x->f_objects[j] == (t_object*)atom_getobj(av+i)) { tabcheck = 1; } } if (!tabcheck) x->f_objects[x->f_nbSelected] = (t_object*)atom_getobj(av+i); } x->f_nbSelected++; } } freebytes(av, sizeof(t_atom) * current_nb_selected); } } if (msg == hoa_sym_startdrag) { if (jkeyboard_getcurrentmodifiers() != 18) // shift key { for(i = 0; i < CONNECT_MAX_TAB; i++) x->f_objects[i] = NULL; x->f_nbSelected = 0; } } }
void paramui_paint(t_paramui *x, t_object *view) { t_rect rect; t_jgraphics *g; double middle; double border_thickness = 1.5; double cornersize = 13.0; g = (t_jgraphics*) patcherview_get_jgraphics(view); jbox_get_rect_for_view((t_object*) &x->box, view, &rect); // clear the background jgraphics_rectangle_rounded(g, border_thickness, border_thickness, rect.width - (border_thickness * 2.0), rect.height - (border_thickness * 2.0), cornersize, cornersize); jgraphics_set_source_rgba(g, 0.1, 0.1, 0.1, 1.0); jgraphics_fill(g); // draw the inspector icon jgraphics_set_source_rgb(g, 0.2, 0.2, 0.2); jgraphics_set_line_width(g, 1.5); jgraphics_oval(g, border_thickness, border_thickness, rect.height - (border_thickness * 2.0), rect.height - (border_thickness * 2.0)); jgraphics_fill(g); jgraphics_rectangle_fill_fast(g, border_thickness + rect.height / 2 - (border_thickness), border_thickness, border_thickness + rect.height / 2, rect.height - (border_thickness * 2.0)); jgraphics_set_source_rgb(g, 0.4, 0.4, 0.4); middle = 6.0; jgraphics_move_to(g, 9.5, middle + 4.0); jgraphics_line_to(g, 13.0, middle); jgraphics_line_to(g, 6.0, middle); jgraphics_close_path(g); jgraphics_fill(g); if(x->attr_dataspace != jps_none) { char data[64]; strncpy(data, x->attr_unitActive->s_name, 64); // draw the unit display jgraphics_set_source_rgb(g, 0.2, 0.2, 0.2); jgraphics_set_line_width(g, 1.5); jgraphics_oval(g, rect.width - (rect.height - (border_thickness * 2.0)) - 2.0, border_thickness, rect.height - (border_thickness * 2.0), rect.height - (border_thickness * 2.0)); jgraphics_fill(g); jgraphics_rectangle_fill_fast(g, rect.width - ((border_thickness + rect.height / 2 - (border_thickness)) * 3.0) - 2.0, border_thickness, border_thickness + rect.height / 1, rect.height - (border_thickness * 2.0)); jtextlayout_settextcolor(x->layout_unit, &s_light_gray); jtextlayout_set(x->layout_unit, data, jfont_create(JAMOMA_DEFAULT_FONT, JGRAPHICS_FONT_SLANT_NORMAL, JGRAPHICS_FONT_WEIGHT_NORMAL, JAMOMA_DEFAULT_FONTSIZE), rect.width - 28.0, 0.0, 28.0, rect.height - 1.0, JGRAPHICS_TEXT_JUSTIFICATION_CENTERED, JGRAPHICS_TEXTLAYOUT_USEELLIPSIS); jtextlayout_draw(x->layout_unit, g); } { char data[256]; t_atom *av = NULL; long ac = 0; if(x->obj_parameter){ object_attr_getvalueof(x->obj_parameter, gensym("value"), &ac, &av); if(ac){ if(x->attr_type == jps_decimal) snprintf(data, 256, "%.4f", atom_getfloat(av)); else if(x->attr_type == jps_integer || x->attr_type == jps_boolean) snprintf(data, 256, "%ld", atom_getlong(av)); else if(x->attr_type == jps_string) strcpy(data, atom_getsym(av)->s_name); jtextlayout_settextcolor(x->layout_value, &s_light_gray); jtextlayout_set(x->layout_value, data, jfont_create(JAMOMA_DEFAULT_FONT, JGRAPHICS_FONT_SLANT_NORMAL, JGRAPHICS_FONT_WEIGHT_NORMAL, JAMOMA_DEFAULT_FONTSIZE), 84.0, 2.0, rect.width - 84.0 - 20.0, rect.height - 1.0, JGRAPHICS_TEXT_JUSTIFICATION_LEFT, JGRAPHICS_TEXTLAYOUT_USEELLIPSIS); jtextlayout_draw(x->layout_value, g); sysmem_freeptr(av); } } } // draw borders jgraphics_rectangle_rounded(g, border_thickness, border_thickness, rect.width - (border_thickness * 2.0), rect.height - (border_thickness * 2.0), cornersize, cornersize); jgraphics_set_source_rgb(g, 0.3, 0.3, 0.3); jgraphics_set_line_width(g, 1.5); jgraphics_stroke(g); jgraphics_set_line_width(g, 1.0); jgraphics_move_to(g, border_thickness, 19.5); jgraphics_line_to(g, rect.width - (border_thickness * 1.0), 19.5); jgraphics_stroke(g); }
t_max_err paramui_getRampFunction(t_paramui *x, void *attr, long *argc, t_atom **argv) { t_symbol *attrName = (t_symbol*)object_method(attr, _sym_getname); return object_attr_getvalueof(x->obj_parameter, attrName, argc, argv); }