static void iem_image_save(t_gobj *z, t_binbuf *b) { t_iem_image *x = (t_iem_image *)z; int *ip1, *ip2; t_symbol *srl[3]; srl[0] = x->x_gui.x_snd; srl[1] = x->x_gui.x_rcv; srl[2] = gensym("empty"); iemgui_all_unique2dollarzero(&x->x_gui, srl); iemgui_all_sym2dollararg(&x->x_gui, srl); ip1 = (int *)(&x->x_gui.x_isa); ip2 = (int *)(&x->x_gui.x_fsf); if(x->x_gifsym) binbuf_addv(b, "ssiissiiss", gensym("#X"),gensym("obj"), (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix, atom_getsymbol(binbuf_getvec(x->x_gui.x_obj.te_binbuf)), x->x_gifsym, (*ip1)&IEM_INIT_ARGS_ALL, (*ip2)&IEM_FSTYLE_FLAGS_ALL, srl[0], srl[1]); else binbuf_addv(b, "ssiisiiiss", gensym("#X"),gensym("obj"), (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix, atom_getsymbol(binbuf_getvec(x->x_gui.x_obj.te_binbuf)), 0, (*ip1)&IEM_INIT_ARGS_ALL, (*ip2)&IEM_FSTYLE_FLAGS_ALL, srl[0], srl[1]); binbuf_addv(b, ";"); }
static void exciter_save(t_gobj *z, t_binbuf *b) { t_exciter *x = (t_exciter *)z; int ei,gi; binbuf_addv(b, "ssiisiiifii", gensym("#X"),gensym("obj"), (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix, atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)), x->x_width, x->x_height, x->x_nbevents, x->x_timegrain, x->x_loop, x->x_save ); if ( x->x_save ) { for ( ei=0; ei<x->x_nbevents; ei++ ) { for ( gi=0; gi<(x->x_width/EXCITER_PIXEL_GRAIN); gi++ ) { if( *(x->x_sbangs+ei*(x->x_width/EXCITER_PIXEL_GRAIN)+gi) == 1 ) { // post( "exciter : saving ( %d, %d )", ei, gi ); binbuf_addv(b, "ii", ei, gi ); } } } } binbuf_addv(b, ";"); }
void breakpoints_init(t_breakpoints *x, t_binbuf *d) { int i; long ac = binbuf_getnatom(d); t_atom* av = binbuf_getvec(d); breakpoints_erase(x); for(i = 0; i < ac; i++) { if(atom_gettype(av+i) == A_SYM && atom_getsym(av+i) == gensym("@points")) { i++; for(;i < ac-1; i += 2) { if(atom_gettype(av+i) == A_FLOAT && atom_gettype(av+i+1) == A_FLOAT) { breakpoints_add(x, NULL, 2, av+i); } else if(atom_gettype(av+i) == A_SYM || atom_gettype(av+i+1) == A_SYM) { //return; } } } } }
static void textfile_bang(t_textfile *x) { int argc = binbuf_getnatom(x->x_binbuf), count, onset = x->x_onset, onset2; t_atom *argv = binbuf_getvec(x->x_binbuf); t_atom *ap = argv + onset, *ap2; while (onset < argc && (ap->a_type == A_SEMI || ap->a_type == A_COMMA)) onset++, ap++; onset2 = onset; ap2 = ap; while (onset2 < argc && (ap2->a_type != A_SEMI && ap2->a_type != A_COMMA)) onset2++, ap2++; if (onset2 > onset) { x->x_onset = onset2; if (ap->a_type == A_SYMBOL) outlet_anything(x->x_ob.ob_outlet, ap->a_w.w_symbol, onset2-onset-1, ap+1); else outlet_list(x->x_ob.ob_outlet, 0, onset2-onset, ap); } else { x->x_onset = 0x7fffffff; outlet_bang(x->x_bangout); } }
void gobj_recreate(t_glist *gl, t_gobj *ob, t_binbuf *bb) { /* LATER revisit all gobj calls, and sort out the gop case */ t_text *newt; int xpix = ((t_text *)ob)->te_xpix, ypix = ((t_text *)ob)->te_ypix; t_binbuf *bb1 = binbuf_new(); int ac = binbuf_getnatom(bb); t_atom *av = binbuf_getvec(bb); canvas_setcurrent(gl); gobj_totail(gl, ob); gobj_stowconnections(gl, ob, bb1); glist_delete(gl, ob); if (newt = (t_text *)forky_newobject(av->a_w.w_symbol, ac - 1, av + 1)) { newt->te_binbuf = bb; newt->te_xpix = xpix; newt->te_ypix = ypix; newt->te_width = 0; newt->te_type = T_OBJECT; glist_add(gl, (t_gobj *)newt); gobj_restoreconnections(gl, bb1); } else bug("gobj_recreate"); binbuf_free(bb1); canvas_unsetcurrent(gl); }
/* save as MAXTEXT */ void binport_write(t_binbuf *bb, char *filename, char *dirname) { int result; FILE *fp; char namebuf[MAXPDSTRING]; namebuf[0] = 0; if (*dirname) strcat(namebuf, dirname), strcat(namebuf, "/"); strcat(namebuf, filename); sys_bashfilename(namebuf, namebuf); if (fp = fopen(namebuf, "w")) { char buf[BINPORT_MAXSTRING]; t_atom *ap = binbuf_getvec(bb); int cnt = 0, ac = binbuf_getnatom(bb); while (ac--) { if (ap->a_type == A_SEMI) { fputs(";\n", fp); cnt = 0; } else if (ap->a_type != A_NULL) { if (cnt++) fputc(' ', fp); lex_atomstring(ap, buf, BINPORT_MAXSTRING, A_INT); fputs(buf, fp); } ap++; } fclose(fp); } }
t_pd_err binbuf_get_attribute_symbol(t_binbuf *d, t_symbol *key, t_symbol **value) { if(d) return atoms_get_attribute_symbol(binbuf_getnatom(d), binbuf_getvec(d), key, value); else return -1; }
t_pd_err binbuf_get_attribute(t_binbuf *d, t_symbol *key, int *argc, t_atom **argv) { if(d) return atoms_get_attribute(binbuf_getnatom(d), binbuf_getvec(d), key, argc, argv); else return -1; }
t_pd_err binbuf_has_attribute(t_binbuf *d, t_symbol *key) { if(d) return atoms_has_attribute(binbuf_getnatom(d), binbuf_getvec(d), key); else return -1; }
static void fudiparse_binbufout(t_fudiparse *x, t_binbuf *b) { int msg, natom = binbuf_getnatom(b); t_atom *at = binbuf_getvec(b); for (msg = 0; msg < natom;) { int emsg; for (emsg = msg; emsg < natom && at[emsg].a_type != A_COMMA && at[emsg].a_type != A_SEMI; emsg++) ; if (emsg > msg) { int i; /* check for illegal atoms */ for (i = msg; i < emsg; i++) if (at[i].a_type == A_DOLLAR || at[i].a_type == A_DOLLSYM) { pd_error(x, "fudiparse: got dollar sign in message"); goto nodice; } if (at[msg].a_type == A_FLOAT) { if (emsg > msg + 1) outlet_list(x->x_msgout, 0, emsg-msg, at + msg); else outlet_float(x->x_msgout, at[msg].a_w.w_float); } else if (at[msg].a_type == A_SYMBOL) { outlet_anything(x->x_msgout, at[msg].a_w.w_symbol, emsg-msg-1, at + msg + 1); } } nodice: msg = emsg + 1; } }
static void netsend_doit(void *z, t_binbuf *b) { t_atom messbuf[1024]; t_netsend *x = (t_netsend *)z; int msg, natom = binbuf_getnatom(b); t_atom *at = binbuf_getvec(b); for (msg = 0; msg < natom;) { int emsg; for (emsg = msg; emsg < natom && at[emsg].a_type != A_COMMA && at[emsg].a_type != A_SEMI; emsg++) ; if (emsg > msg) { int i; for (i = msg; i < emsg; i++) if (at[i].a_type == A_DOLLAR || at[i].a_type == A_DOLLSYM) { pd_error(x, "netreceive: got dollar sign in message"); goto nodice; } if (at[msg].a_type == A_FLOAT) { if (emsg > msg + 1) outlet_list(x->x_msgout, 0, emsg-msg, at + msg); else outlet_float(x->x_msgout, at[msg].a_w.w_float); } else if (at[msg].a_type == A_SYMBOL) outlet_anything(x->x_msgout, at[msg].a_w.w_symbol, emsg-msg-1, at + msg + 1); } nodice: msg = emsg + 1; } }
static int xeqlocator_lookatfirst(t_xeqlocator *x) { t_atom *ap; if (!x->l_binbuf || (x->l_natoms = binbuf_getnatom(x->l_binbuf)) <= 0) return (XEQ_FAIL_EMPTY); ap = x->l_firstatom = binbuf_getvec(x->l_binbuf); x->l_atprevious = -1; x->l_atdelta = -1; for (x->l_atnext = 0; x->l_atnext < x->l_natoms; x->l_atnext++, ap++) { switch (ap->a_type) { case A_FLOAT: if (x->l_atdelta < 0) { if ((x->l_delta = ap->a_w.w_float) < 0) x->l_delta = 0; x->l_atdelta = x->l_atnext; } break; case A_SYMBOL: x->l_when = x->l_delta; return (XEQ_FAIL_OK); case A_SEMI: break; default: return (XEQ_FAIL_CORRUPT); } } return (XEQ_FAIL_CORRUPT); }
static void xeq_edit(t_xeq *x) { t_atom *ap = binbuf_getvec(x->x_binbuf); int natoms = binbuf_getnatom(x->x_binbuf); char buf[MAXPDSTRING+2]; int buflen = 0; int i, newline = 1; xeq_window(x, 0, ""); *buf = '\0'; for (i = 0; i < natoms; i++, ap++) { if (i) { if (newline) { strcat(buf, "\n"); xeq_window_append(x, buf); *buf = '\0'; buflen = 0; } else { strcat(buf, " "); buflen++; } } if (buflen < MAXPDSTRING) atom_string(ap, buf + buflen, MAXPDSTRING - buflen); buflen = strlen(buf); newline = ap->a_type == A_SEMI; } if (natoms) strcat(buf, "\n"); if (*buf) xeq_window_append(x, buf); }
void loudbug_postbinbuf(t_binbuf *bb) { int ac = binbuf_getnatom(bb); t_atom *aprev = 0, *ap = binbuf_getvec(bb); while (ac--) { char buf[MAXPDSTRING]; atom_string(ap, buf, MAXPDSTRING); if (aprev) { if (aprev->a_type == A_SEMI) fprintf(stderr, "\n%s", buf); else fprintf(stderr, " %s", buf); } else fprintf(stderr, "%s", buf); #ifdef MSW fflush(stderr); #endif aprev = ap++; } if (aprev) { fputs("\n", stderr); #ifdef MSW fflush(stderr); #endif } }
/* return true if the "canvas" object is a "table". */ int canvas_istable(const t_canvas *x) { t_atom *argv = (x->gl_obj.te_binbuf? binbuf_getvec(x->gl_obj.te_binbuf):0); int argc = (x->gl_obj.te_binbuf? binbuf_getnatom(x->gl_obj.te_binbuf) : 0); int istable = (argc && argv[0].a_type == A_SYMBOL && argv[0].a_w.w_symbol == gensym("table")); return (istable); }
/** * fetch a message */ static void _zmq_receive(t_zmq *x) { if ( ! _can_receive(x)) { return; } int r, err; char buf[MAXPDSTRING]; t_binbuf *b; int msg; r=zmq_recv (x->zmq_socket, buf, MAXPDSTRING, ZMQ_DONTWAIT); if(r != -1) { if (r > MAXPDSTRING) r = MAXPDSTRING; // brutally cut off excessive bytes buf[r - 1] = 0; // terminate string if(r > 0) { b = binbuf_new(); binbuf_text(b, buf, r); // the following code is cp'ed from x_net.c::netreceive_doit int natom = binbuf_getnatom(b); t_atom *at = binbuf_getvec(b); for (msg = 0; msg < natom;) { int emsg; for (emsg = msg; emsg < natom && at[emsg].a_type != A_COMMA && at[emsg].a_type != A_SEMI; emsg++) ; if (emsg > msg) { int i; for (i = msg; i < emsg; i++) if (at[i].a_type == A_DOLLAR || at[i].a_type == A_DOLLSYM) { pd_error(x, "zmq_receive: got dollar sign in message"); goto nodice; } if (at[msg].a_type == A_FLOAT) { if (emsg > msg + 1) outlet_list(x->s_out, 0, emsg-msg, at + msg); else outlet_float(x->s_out, at[msg].a_w.w_float); } else if (at[msg].a_type == A_SYMBOL) outlet_anything(x->s_out, at[msg].a_w.w_symbol, emsg-msg-1, at + msg + 1); } nodice: msg = emsg + 1; } } else { outlet_bang(x->s_out); } if((err=zmq_errno())!=EAGAIN) { _zmq_error(err); } } }
static void image_save(t_gobj *z, t_binbuf *b) { t_image *x = (t_image *)z; binbuf_addv(b, "ssiissi", gensym("#X"), gensym("obj"), x->x_obj.te_xpix, x->x_obj.te_ypix, atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)), x->x_fname, x->x_gop_spill); binbuf_addv(b, ";"); }
static void hammereditor_end(t_hammerfile *f) { if (f->f_editorfn) { (*f->f_editorfn)(f->f_master, 0, binbuf_getnatom(f->f_binbuf), binbuf_getvec(f->f_binbuf)); binbuf_clear(f->f_binbuf); } }
static void xeq_doclone(t_xeq *x, t_symbol *name, int append) { t_xeq *otherhost = (t_xeq *)hyphen_findhost((t_hyphen *)x, name); if (otherhost && otherhost->x_binbuf) { if (!append) xeq_clear(x); binbuf_add(x->x_binbuf, binbuf_getnatom(otherhost->x_binbuf), binbuf_getvec(otherhost->x_binbuf)); } }
DYN_EXPORT int dyn_NewMessageStr(int sched,dyn_id *oid,dyn_callback cb,dyn_id sid,const char *msg) { t_binbuf *b = binbuf_new(); binbuf_text(b,(char *)msg,strlen(msg)); int argc = binbuf_getnatom(b); t_atom *argv = binbuf_getvec(b); int ret = dyn_NewMessage(sched,oid,cb,sid,argc,argv); binbuf_free(b); return ret; }
static void sliderh_save(t_gobj *z, t_binbuf *b) { t_fatom *x = (t_fatom *)z; binbuf_addv(b, "ssiisiii", gensym("#X"), gensym("obj"), x->x_obj.te_xpix, x->x_obj.te_ypix , atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)), x->x_max,x->x_min,x->x_width); binbuf_addv(b, ";"); }
void rtext_retext(t_rtext *x) { int w = 0, h = 0, indx; t_text *text = x->x_text; t_freebytes(x->x_buf, x->x_bufsize); binbuf_gettext(text->te_binbuf, &x->x_buf, &x->x_bufsize); /* special case: for number boxes, try to pare the number down to the specified width of the box. */ if (text->te_width > 0 && text->te_type == T_ATOM && x->x_bufsize > text->te_width) { t_atom *atomp = binbuf_getvec(text->te_binbuf); int natom = binbuf_getnatom(text->te_binbuf); int bufsize = x->x_bufsize; if (natom == 1 && atomp->a_type == A_FLOAT) { /* try to reduce size by dropping decimal digits */ int wantreduce = bufsize - text->te_width; char *decimal = 0, *nextchar, *ebuf = x->x_buf + bufsize, *s1, *s2; int ndecimals; for (decimal = x->x_buf; decimal < ebuf; decimal++) if (*decimal == '.') break; if (decimal >= ebuf) goto giveup; for (nextchar = decimal + 1; nextchar < ebuf; nextchar++) if (*nextchar < '0' || *nextchar > '9') break; if (nextchar - decimal - 1 < wantreduce) goto giveup; for (s1 = nextchar - wantreduce, s2 = s1 + wantreduce; s2 < ebuf; s1++, s2++) *s1 = *s2; x->x_buf = t_resizebytes(x->x_buf, bufsize, text->te_width); bufsize = text->te_width; goto done; giveup: /* give up and bash it to "+" or "-" */ x->x_buf[0] = (atomp->a_w.w_float < 0 ? '-' : '+'); x->x_buf = t_resizebytes(x->x_buf, bufsize, 1); bufsize = 1; } else if (bufsize > text->te_width) { x->x_buf[text->te_width - 1] = '>'; x->x_buf = t_resizebytes(x->x_buf, bufsize, text->te_width); bufsize = text->te_width; } done: x->x_bufsize = bufsize; } rtext_senditup(x, SEND_UPDATE, &w, &h, &indx); }
static void hfadl_scale_save(t_gobj *z, t_binbuf *b) { t_hfadl_scale *x = (t_hfadl_scale *)z; binbuf_addv(b, "ssiisi", gensym("#X"),gensym("obj"), (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix, atom_getsymbol(binbuf_getvec(x->x_gui.x_obj.te_binbuf)), -1 - (((0xfc0000 & x->x_gui.x_lcol) >> 6)| ((0xfc00 & x->x_gui.x_lcol) >> 4)|((0xfc & x->x_gui.x_lcol) >> 2))); binbuf_addv(b, ";"); }
static void scratcher_save(t_gobj *z, t_binbuf *b) { t_scratcher *x = (t_scratcher *)z; binbuf_addv(b, "ssiisiiiiff", gensym("#X"),gensym("obj"), (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix, atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)), x->x_size, x->x_width, x->x_height, x->x_sensibility, x->x_maxspeed, x->x_inertia ); binbuf_addv(b, ";"); }
static void funbuff_dowrite(t_funbuff *x, t_symbol *fn) { t_binbuf *bb = binbuf_new(); char buf[MAXPDSTRING]; t_hammernode *np; binbuf_addv(bb, "s", atom_getsymbol(binbuf_getvec(x->x_ob.te_binbuf))); for (np = x->x_tree.t_first; np; np = np->n_next) binbuf_addv(bb, "if", np->n_key, HAMMERNODE_GETFLOAT(np)); canvas_makefilename(x->x_canvas, fn->s_name, buf, MAXPDSTRING); binbuf_write(bb, buf, "", 0); binbuf_free(bb); }
static void import_emflush(t_port *x, t_symbol *state, t_symbol *name) { int ac = binbuf_getnatom(x->x_embb); if (import_emcheckend(x, state, name) && ac) binbuf_add(x->x_outbb, ac, binbuf_getvec(x->x_embb)); x->x_emstate = 0; x->x_emname = 0; x->x_emsize = 0; x->x_emcount = 0; if (ac) binbuf_clear(x->x_embb); binbuf_addv(x->x_outbb, "ss;", gensym("#C"), gensym("restore")); }
static void scrolllist_save(t_gobj *z, t_binbuf *b) { t_scrolllist *x = (t_scrolllist *)z; // post( "saving scrolllist : %d", x->x_capacity ); binbuf_addv(b, "ssiisiiissss", gensym("#X"), gensym("obj"), (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix, atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)), x->x_capacity, x->x_width, x->x_height, gensym(x->x_font), gensym(x->x_bgcolor), gensym(x->x_fgcolor), gensym(x->x_secolor) ); binbuf_addv(b, ";"); }
static void toany_output(t_toany *x, int argc, t_atom *argv){ t_toany_atoms src = {argv, argc, argc}; toany_get_atoms(&(x->x_char_code), &src, x->x_eos); convert_toany(NULL, &(x->x_char_code), x->x_binbuf); int x_argc; t_atom *x_argv; x_argc = binbuf_getnatom(x->x_binbuf); x_argv = binbuf_getvec(x->x_binbuf); if(x_argc && x_argv->a_type == A_SYMBOL) outlet_anything(x->x_outlet, x_argv->a_w.w_symbol, x_argc-1, x_argv+1); else outlet_anything(x->x_outlet, &s_list, x_argc, x_argv); }
static void iem_image_save(t_gobj *z, t_binbuf *b) { t_iem_image *x = (t_iem_image *)z; t_symbol *srl[3]; srl[0] = x->x_gui.x_snd; srl[1] = x->x_gui.x_rcv; srl[2] = gensym("empty"); if(x->x_gifsym) binbuf_addv(b, "ssiissiiss", gensym("#X"),gensym("obj"), (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix, atom_getsymbol(binbuf_getvec(x->x_gui.x_obj.te_binbuf)), x->x_gifsym, iem_symargstoint(&x->x_gui.x_isa), iem_fstyletoint(&x->x_gui.x_fsf), srl[0], srl[1]); else binbuf_addv(b, "ssiisiiiss", gensym("#X"),gensym("obj"), (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix, atom_getsymbol(binbuf_getvec(x->x_gui.x_obj.te_binbuf)), 0, iem_symargstoint(&x->x_gui.x_isa), iem_fstyletoint(&x->x_gui.x_fsf), srl[0], srl[1]); binbuf_addv(b, ";"); }
/* CHECKED there is only one copy of state variables, the same, whether modified with messages, or in the inspector */ static void scope_save(t_gobj *z, t_binbuf *b) { t_scope *x = (t_scope *)z; t_text *t = (t_text *)x; binbuf_addv(b, "ssiisiiiiiffififiiiiiii;", gensym("#X"), gensym("obj"), (int)t->te_xpix, (int)t->te_ypix, atom_getsymbol(binbuf_getvec(t->te_binbuf)), x->x_width, x->x_height, x->x_period, 3, x->x_bufsize, x->x_minval, x->x_maxval, x->x_delay, 0., x->x_trigmode, x->x_triglevel, x->x_fgred, x->x_fggreen, x->x_fgblue, x->x_bgred, x->x_bggreen, x->x_bgblue, 0); }