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; } }
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 } }
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); }
/* 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); } }
static void preset_store(t_presetobj *x, float f) { int index = (int)f; if(index >= 1 && index < CREAM_MAXITEMS) { index -= 1; char id[MAXPDSTRING]; t_atom av[2]; t_binbuf *b = x->f_binbuf[index]; if(binbuf_getnatom(b)) { binbuf_clear(b); } /* for(t_gobj *y = eobj_getcanvas(x)->gl_list; y; y = y->g_next) { t_ebox *z = (t_ebox *)y; t_gotfn mpreset = zgetfn(&y->g_pd, cream_sym_preset); if(mpreset && z->b_preset_id) { if(z->b_preset_id != cream_sym_nothing) { sprintf(id, "@%s", z->b_preset_id->s_name); atom_setsym(av, gensym(id)); atom_setsym(av+1, eobj_getclassname(z)); binbuf_add(b, 2, av); mpreset(z, b); } } mpreset = NULL; } */ } }
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); }
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); } }
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); }
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; }
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; } } } } }
/* 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 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 draw_background(t_presetobj *x, t_object *view, t_rect *rect) { int i, xc, yc; char number[256]; t_rgba color; t_elayer *g = ebox_start_layer((t_ebox *)x, cream_sym_background_layer, rect->width, rect->height); t_etext *jtl = etext_layout_create(); if (g && jtl) { for(xc = x->f_font.size * 1.25, yc = x->f_font.size * 1.25, i = 1; yc + x->f_font.size / 2. < rect->height; ) { if(x->f_binbuf_selected == i-1 && binbuf_getnatom(x->f_binbuf[i-1])){ color = rgba_addContrast(x->f_color_button_selected, 0.1);} else if(!binbuf_getnatom(x->f_binbuf[i-1])) color = rgba_addContrast(x->f_color_button_empty, 0.1); else if(binbuf_getnatom(x->f_binbuf[i-1])) color = rgba_addContrast(x->f_color_button_stored, -0.1); egraphics_set_color_rgba(g, &color); if(x->f_binbuf_hover != i) { egraphics_circle(g, xc, yc, x->f_font.size); egraphics_fill(g); } sprintf(number, "%i", i); etext_layout_set(jtl, number, &x->f_font, xc, yc, rect->width, 0, ETEXT_CENTRED, ETEXT_NOWRAP); etext_layout_settextcolor(jtl, &x->f_color_text); etext_layout_draw(jtl, g); xc += x->f_font.size * 2.5; if(xc + x->f_font.size / 2. > rect->width) { xc = x->f_font.size * 1.25; yc += x->f_font.size * 2.5; } i++; } ebox_end_layer((t_ebox*)x, cream_sym_background_layer); } ebox_paint_layer((t_ebox *)x, cream_sym_background_layer, 0., 0.); }
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; }
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 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 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 preset_save(t_presetobj *x, t_binbuf *d) { binbuf_addv(d, (char *)"ss", cream_sym_atpreset, cream_sym_left_bracket); for(int i = 0; i < CREAM_MAXITEMS; i++) { if(binbuf_getnatom(x->f_binbuf[i])) { binbuf_addv(d, (char *)"sf", cream_sym_atindex, (float)i); binbuf_addbinbuf(d, x->f_binbuf[i]); } } binbuf_addv(d, (char *)"s", cream_sym_right_bracket); }
static void convert_toany(t_toany_atoms *dst, t_toany_char_code *src, t_binbuf *x_binbuf){ int bb_is_tmp = 0; // create temporary binbuf? if(!x_binbuf){ x_binbuf = binbuf_new(); bb_is_tmp = 1; } binbuf_clear(x_binbuf); // populate binbuf binbuf_text(x_binbuf, (char*)src->b_buf, src->b_len); // populate atom list if(bb_is_tmp){ // temporary binbuf: copy atoms t_atom *argv = binbuf_getvec(x_binbuf); int argc = binbuf_getnatom(x_binbuf); if(dst->a_alloc < (size_t)argc) // reallocate? toany_atoms_realloc(dst, argc + 256); memcpy(dst->a_buf, argv, argc*sizeof(t_atom)); // copy dst->a_len = argc; binbuf_free(x_binbuf); // cleanup } else if(dst){ // permanent binbuf: clobber dst dst->a_buf = binbuf_getvec(x_binbuf); dst->a_len = binbuf_getnatom(x_binbuf); dst->a_alloc = 0; // don't try to free this } }
static t_atom *mtrack_getdelay(t_mtrack *tp) { int natoms = binbuf_getnatom(tp->tr_binbuf); if (natoms) { t_atom *ap = binbuf_getvec(tp->tr_binbuf); while (natoms--) { if (ap->a_type == A_FLOAT) return (ap); ap++; } loudbug_bug("mtrack_getdelay"); } return (0); }
static void netserver_doit(void *z, t_binbuf *b) { t_atom messbuf[1024]; t_netserver *x = (t_netserver *)z; int msg, natom = binbuf_getnatom(b); t_atom *at = binbuf_getvec(b); int i; /* output clients IP and socket no. */ for(i = 0; i < x->x_nconnections; i++) /* search for corresponding IP */ { if(x->x_fd[i] == x->x_sock_fd) { outlet_symbol(x->x_connectionip, x->x_host[i]); break; } } outlet_float(x->x_clientno, x->x_sock_fd); /* the socket number */ /* process data */ 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 ii; for (ii = msg; ii < emsg; ii++) if (at[ii].a_type == A_DOLLAR || at[ii].a_type == A_DOLLSYM) { pd_error(x, "netserver: 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; } }
float xeqlocator_skipnotes(t_xeqlocator *x, int count) { int natoms; t_atom *ap; float lastdelay = 0; float nexttime = x->l_when + x->l_delay; int ndx = x->l_atnext; int prv = x->l_atprevious; int checkdelay, checktarget; if (count < 0) return (-1); xeqlocator_hide(x); if (!x->l_binbuf || (natoms = binbuf_getnatom(x->l_binbuf)) <= 0) return (-1); ap = binbuf_getvec(x->l_binbuf) + ndx; checkdelay = 0; checktarget = 1; for (; ndx < natoms; ndx++, ap++) { if (checkdelay && ap->a_type == A_FLOAT) { lastdelay = ap->a_w.w_float; checkdelay = 0; checktarget = 1; } else if (checktarget && ap->a_type == A_SYMBOL) { if (ap[1].a_type == A_FLOAT && (int)ap[1].a_w.w_float == 144 && ap[3].a_type == A_FLOAT && (int)ap[3].a_w.w_float > 0 && count-- <= 0) { x->l_delay = 0; x->l_delta = lastdelay; x->l_atnext = ndx; x->l_atprevious = prv; return (x->l_delay); } prv = ndx; lastdelay = 0; checkdelay = checktarget = 0; } /* LATER sort out semi/comma rules and check again... */ else checkdelay = checktarget = ap->a_type == A_SEMI; } return (-1); }
// Force output even if eof has not been received static void from_ascii_code_bang(t_from_ascii_code *x) { if ( x->size ) { binbuf_clear(from_ascii_code_binbuf); binbuf_text(from_ascii_code_binbuf, x->text, x->size); t_atom *argv = binbuf_getvec(from_ascii_code_binbuf); int argc = binbuf_getnatom(from_ascii_code_binbuf); if ( argc) { if ( (argv->a_type == A_SYMBOL) ) { outlet_anything(x->outlet_left,atom_getsymbol(argv),argc-1,argv+1); } else { outlet_anything(x->outlet_left,&s_list,argc,argv); } } x->size = 0; } }
float xeqlocator_move(t_xeqlocator *x, float interval) { int natoms; t_atom *ap; float lastdelay = 0; float nexttime = x->l_when + x->l_delay; int ndx = x->l_atnext; int prv = x->l_atprevious; int checkdelay, checktarget; x->l_when += interval; if (interval < 0 || ndx <= 0) return (xeqlocator_settotime(x, x->l_when)); xeqlocator_hide(x); if (!x->l_binbuf || (natoms = binbuf_getnatom(x->l_binbuf)) <= 0) return (-1); ap = binbuf_getvec(x->l_binbuf) + ndx; checkdelay = 0; checktarget = 1; for (; ndx < natoms; ndx++, ap++) { if (checkdelay && ap->a_type == A_FLOAT) { lastdelay = ap->a_w.w_float; checkdelay = 0; checktarget = 1; } else if (checktarget && ap->a_type == A_SYMBOL) { if ((nexttime += lastdelay) >= x->l_when) { x->l_delay = nexttime - x->l_when; x->l_delta = lastdelay; x->l_atnext = ndx; x->l_atprevious = prv; return (x->l_delay); } prv = ndx; lastdelay = 0; checkdelay = checktarget = 0; } /* LATER sort out semi/comma rules and check again... */ else checkdelay = checktarget = ap->a_type == A_SEMI; } return (-1); }
/* initialize a single symbol in unexpanded form. We reach into the binbuf to grab them; if there's nothing there, set it to the fallback; if still nothing, set to "empty". */ static void iemgui_init_sym2dollararg(t_iemgui *x, t_symbol **symp, int indx, t_symbol *fallback) { if (!*symp) { t_binbuf *b = x->x_obj.ob_binbuf; if (binbuf_getnatom(b) > indx) { char buf[80]; atom_string(binbuf_getvec(b) + indx, buf, 80); *symp = gensym(buf); } else if (fallback) *symp = fallback; else *symp = s_empty; } }