void howbigisyourp_dump(t_howbigisyourp *x) { t_an_item *item; t_atom a; t_linklist *list = linklist_new(); linklist_flags(list, OBJ_FLAG_MEMORY); // will use sysmem_freeptr on the objects // first item of list contains the totalnumberofobjects item = an_item_new(gensym("totalnumberofobjects"), 0); linklist_append(list, item); // copy the hash table to a linklist, and count the total number of object hashtab_funall(x->hash, (method)howbigisyourp_cp_to_linklist, list); // get the first item totalnumberofobjects which now contains the total number of objects item = linklist_getindex(list, 0); post("The total number of objects is %d", item->val); linklist_deleteindex(list, 0); // remove it so we can proceed // sorting is nicer linklist_sort(list, linklist_ascending); // iterate through the linklist and output {name, instances} out the outlet. item = linklist_getindex(list, 0); while (item) { atom_setlong(&a, item->val); outlet_anything(x->out, item->name, 1, &a); linklist_next(list, item, (void **)&item); } // free the linklist items, the hashtab items are not removed). if (list) object_free(list); }
void paramui_menu_qfn(t_paramui *x) { t_symobject *item = (t_symobject *)linklist_getindex(x->menu_items, x->menu_selection); if(item->sym == gensym("Set Parameter to Default Value")) object_method(x->obj_parameter, gensym("reset")); }
void cmmjl_osc_sendMsg(void *x, t_symbol *msg, int argc, t_atom *argv){ t_linklist *ll = cmmjl_obj_osc_address_methods_get(x); t_symbol *m = gensym(basename(msg->s_name)); char *osc_address; int i; method func; void *r; if(msg == ps_OSCTimeTag){ return; } if(!ll){ return; } osc_address = linklist_getindex(ll, 0); for(i = 0; i < linklist_getsize(ll); i++){ if(!osc_address){ post("no OSC address--breaking"); break; } if(!cmmjl_osc_match(x, msg->s_name, osc_address)){ func = zgetfn((t_object *)x, m); if(func){ r = typedmess(x, m, argc, argv); //return; } }else{ } linklist_next(ll, osc_address, (void **)&osc_address); } CMMJL_ERROR(x, CMMJL_ENOFUNC, "couldn't send message %s to object", m->s_name); }
void ar_swap_keys(t_ar *x, t_symbol *msg, long argc, t_atom *argv){ if(argc != 2){ error("hashtab: swap_keys requires 2 arguments, not %d", argc); return; } t_linklist *ll; if(!(ll = (t_linklist *)x->iname_ll->s_thing)){ return; } t_symbol *key1 = ar_encode_key(argv); t_symbol *key2 = ar_encode_key(argv + 1); t_symbol *test_key = (t_symbol *)linklist_getindex(ll, 0); int l1 = -1; int l2 = -1; int i = 0; while((l1 == -1 || l2 == -1) && i < linklist_getsize(ll)){ if(test_key == key1){ l1 = i; } if(test_key == key2){ l2 = i; } i++; linklist_next(ll, (void *)test_key, (void **)(&test_key)); } // this function will check to make sure that l1 and l2 are both greater than 0 ar_swap_indices(x, l1, l2); }
void ar_prev(t_ar *x){ t_hashtab *ht; t_linklist *ll; if(!(ht = (t_hashtab *)x->iname_ht->s_thing) || !(ll = (t_linklist *)x->iname_ll->s_thing)){ return; } if(!(x->current_item)){ x->current_item = linklist_getindex(ll, hashtab_getsize(ht) - 1); }else{ linklist_prev(ll, x->current_item, &(x->current_item)); if(!(x->current_item)){ //x->current_item = linklist_getindex(ll, hashtab_getsize(ht) - 1); outlet_anything(x->outlets[3], _sym_bang, 0, NULL); } } if(x->current_item){ t_atombuf *ab; t_atom a; ar_decode_key((t_symbol *)(x->current_item), &a); hashtab_lookup(ht, (t_symbol *)(x->current_item), (t_object **)(&ab)); if(ab){ outlet_list(x->outlets[1], NULL, 1, &a); outlet_list(x->outlets[0], NULL, ab->a_argc, ab->a_argv); } } }
void howbigisyourp_cp_to_linklist(t_hashtab_entry *e, void *list) { if (e->key && e->value) { t_an_item *item = an_item_new(e->key, (long)e->value); // copy the object name and the number of instances to the linklist linklist_append(list, item); item = linklist_getindex(list, 0); // that's totalnumberofobjects item->val += (long)e->value; // increment the totalnumberofobjects by the number of instances of this object } }
void ar_remove_index(t_ar *x, long i){ t_hashtab *ht; t_linklist *ll; if(!(ht = (t_hashtab *)x->iname_ht->s_thing) || !(ll = (t_linklist *)x->iname_ll->s_thing)){ return; } t_symbol *key = (t_symbol *)linklist_getindex(ll, i); if(key){ ar_remove_encoded_key(ht, ll, key); } }
void ar_goto(t_ar *x, long n){ t_hashtab *ht; t_linklist *ll; if(!(ht = (t_hashtab *)x->iname_ht->s_thing) || !(ll = (t_linklist *)x->iname_ll->s_thing)){ return; } x->current_item = linklist_getindex(ll, n); if(x->current_item){ t_atombuf *ab; t_atom a; ar_decode_key((t_symbol *)(x->current_item), &a); hashtab_lookup(ht, (t_symbol *)(x->current_item), (t_object **)(&ab)); if(ab){ outlet_list(x->outlets[1], NULL, 1, &a); outlet_list(x->outlets[0], NULL, ab->a_argc, ab->a_argv); } } }
void ar_random(t_ar *x){ t_hashtab *ht; t_linklist *ll; if(!(ht = (t_hashtab *)x->iname_ht->s_thing) || !(ll = (t_linklist *)x->iname_ll->s_thing)){ return; } int n = hashtab_getsize(ht) - 1; int r = (int)round(((double)rand() / (double)RAND_MAX) * n); x->current_item = linklist_getindex(ll, r); if(x->current_item){ t_atombuf *ab; t_atom a; ar_decode_key((t_symbol *)(x->current_item), &a); hashtab_lookup(ht, (t_symbol *)(x->current_item), (t_object **)(&ab)); if(ab){ outlet_list(x->outlets[1], NULL, 1, &a); outlet_list(x->outlets[0], NULL, ab->a_argc, ab->a_argv); } } }
void paramui_menu_do(t_paramui *x, t_object *patcherview, t_pt px, long modifiers) { t_jpopupmenu *p; t_symobject *item; long size, i; int selectedId; t_jfont *font; int coord_x=0, coord_y=0; t_pt pt; jbox_set_mousedragdelta((t_object *)x, 0); p = jpopupmenu_create(); font = jfont_create(JAMOMA_MENU_FONT, JGRAPHICS_FONT_SLANT_NORMAL, JGRAPHICS_FONT_WEIGHT_NORMAL, JAMOMA_MENU_FONTSIZE); jpopupmenu_setfont(p, font); jfont_destroy(font); size = linklist_getsize(x->menu_items); for(i=0; i<size; i++){ item = (t_symobject *)linklist_getindex(x->menu_items, i); if(!item->sym || (item->sym->s_name[0] == '\0') || item->sym->s_name[0] == '-')//{ jpopupmenu_addseperator(p); else jpopupmenu_additem(p, i+1, item->sym->s_name, NULL, 0, item->flags, NULL); } object_method(patcherview, gensym("canvastoscreen"), 0.0, 0.0, &coord_x, &coord_y); coord_x += x->box.b_patching_rect.x; coord_y += x->box.b_patching_rect.y; pt.x = coord_x; pt.y = coord_y; selectedId = jpopupmenu_popup_nearbox(p, (t_object*)x, patcherview, x->menu_selection+1); if(selectedId){ x->menu_selection = selectedId -1; qelem_set(x->menu_qelem); } jpopupmenu_destroy(p); }