void glob_initfromgui(void *dummy, t_symbol *s, int argc, t_atom *argv) { char *cwd = atom_getsymbolarg(0, argc, argv)->s_name; t_namelist *nl; unsigned int i; int did_fontwarning = 0; int j; sys_oldtclversion = atom_getfloatarg(1, argc, argv); if (argc != 2 + 3 * NZOOM * NFONT) bug("glob_initfromgui"); for (j = 0; j < NZOOM; j++) for (i = 0; i < NFONT; i++) { int size = atom_getfloatarg(3 * (i + j * NFONT) + 2, argc, argv); int width = atom_getfloatarg(3 * (i + j * NFONT) + 3, argc, argv); int height = atom_getfloatarg(3 * (i + j * NFONT) + 4, argc, argv); if (!(size && width && height)) { size = (j+1)*sys_fontspec[i].fi_pointsize; width = (j+1)*sys_fontspec[i].fi_width; height = (j+1)*sys_fontspec[i].fi_height; if (!did_fontwarning) { verbose(1, "ignoring invalid font-metrics from GUI"); did_fontwarning = 1; } } sys_gotfonts[j][i].fi_pointsize = size; sys_gotfonts[j][i].fi_width = width; sys_gotfonts[j][i].fi_height = height; #if 0 fprintf(stderr, "font (%d %d %d)\n", sys_gotfonts[j][i].fi_pointsize, sys_gotfonts[j][i].fi_width, sys_gotfonts[j][i].fi_height); #endif } /* load dynamic libraries specified with "-lib" args */ if (sys_oktoloadfiles(0)) { for (nl = STUFF->st_externlist; nl; nl = nl->nl_next) if (!sys_load_lib(0, nl->nl_string)) post("%s: can't load library", nl->nl_string); sys_oktoloadfiles(1); } /* open patches specifies with "-open" args */ for (nl = sys_openlist; nl; nl = nl->nl_next) openit(cwd, nl->nl_string); namelist_free(sys_openlist); sys_openlist = 0; /* send messages specified with "-send" args */ for (nl = sys_messagelist; nl; nl = nl->nl_next) { t_binbuf *b = binbuf_new(); binbuf_text(b, nl->nl_string, strlen(nl->nl_string)); binbuf_eval(b, 0, 0, 0); binbuf_free(b); } namelist_free(sys_messagelist); sys_messagelist = 0; }
/*------------------------------------ map1dLoadRangeList ---*/ bool map1dLoadRangeList(Map1dData * xx, t_symbol * fileName) { bool result = false; t_filehandle fileRef; if (path_opensysfile(fileName->s_name, path_getdefault(), &fileRef, PATH_READ_PERM)) { LOG_ERROR_2(xx, OUTPUT_PREFIX "problem opening file '%s'", fileName->s_name) } else { t_handle fileContents = sysmem_newhandle(0); if (sysfile_readtextfile(fileRef, fileContents, 0, TEXT_LB_NATIVE)) { LOG_ERROR_2(xx, OUTPUT_PREFIX "problem reading file '%s'", fileName->s_name) } else if (binbuf_text(xx->fBuffer, fileContents, sysmem_handlesize(fileContents))) { post("problem processing"); LOG_ERROR_2(xx, OUTPUT_PREFIX "problem converting file '%s'", fileName->s_name) } else {
void rockbox_receive_callback(struct datagram* dg) { /* Check whether there is a receiver. */ if(!receiver) return; /* Limit string. */ dg->data[dg->size] = '\0'; /* If complete line... */ if(dg->data[dg->size-1] == '\n') { char* semi = strchr(dg->data, ';'); /* Limit message. */ if(semi) *semi = '\0'; /* Create binary buffer. */ binbuf_text(inbinbuf, dg->data, strlen(dg->data)); /* Limit outlet stack. */ outlet_setstacklim(); /* Execute receive function. */ netreceive_doit(receiver, inbinbuf); } }
void glob_initfromgui(void *dummy, t_symbol *s, int argc, t_atom *argv) { char *cwd = atom_getsymbolarg(0, argc, argv)->s_name; t_namelist *nl; unsigned int i; int j; int nhostfont = (argc-2)/3; sys_oldtclversion = atom_getfloatarg(1, argc, argv); if (argc != 2 + 3 * nhostfont) bug("glob_initfromgui"); for (i = 0; i < NFONT; i++) { int best = 0; int wantheight = sys_fontlist[i].fi_maxheight; int wantwidth = sys_fontlist[i].fi_maxwidth; for (j = 1; j < nhostfont; j++) { if (atom_getintarg(3 * j + 4, argc, argv) <= wantheight && atom_getintarg(3 * j + 3, argc, argv) <= wantwidth) best = j; } /* best is now the host font index for the desired font index i. */ sys_fontlist[i].fi_hostfontsize = atom_getintarg(3 * best + 2, argc, argv); sys_fontlist[i].fi_width = atom_getintarg(3 * best + 3, argc, argv); sys_fontlist[i].fi_height = atom_getintarg(3 * best + 4, argc, argv); } #if 0 for (i = 0; i < 6; i++) fprintf(stderr, "font (%d %d %d) -> (%d %d %d)\n", sys_fontlist[i].fi_fontsize, sys_fontlist[i].fi_maxwidth, sys_fontlist[i].fi_maxheight, sys_fontlist[i].fi_hostfontsize, sys_fontlist[i].fi_width, sys_fontlist[i].fi_height); #endif /* auto-load anything in that is in startupdir */ if(!sys_nostartup) sys_loadstartup(); /* load dynamic libraries specified with "-lib" args */ for (nl = sys_externlist; nl; nl = nl->nl_next) if (!sys_load_lib(0, nl->nl_string)) post("%s: can't load library", nl->nl_string); /* open patches specifies with "-open" args */ for (nl = sys_openlist; nl; nl = nl->nl_next) openit(cwd, nl->nl_string); namelist_free(sys_openlist); sys_openlist = 0; /* send messages specified with "-send" args */ for (nl = sys_messagelist; nl; nl = nl->nl_next) { t_binbuf *b = binbuf_new(); binbuf_text(b, nl->nl_string, strlen(nl->nl_string)); binbuf_eval(b, 0, 0, 0); binbuf_free(b); } namelist_free(sys_messagelist); sys_messagelist = 0; }
/** * 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); } } }
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 ofxPd::sendRawMessage( const string& message ) { // senda message to pd t_binbuf *b = binbuf_new(); static char msg_buf[MAXPDSTRING+1]; strncpy( msg_buf, message.c_str(), message.size() ); binbuf_text(b, msg_buf, message.size() ); sys_lock(); binbuf_eval(b, 0, 0, 0); sys_unlock(); binbuf_free(b); }
static void autoabstraction_initialize(void) { if(s_bb) binbuf_free(s_bb); s_bb=binbuf_new(); /* try to read a template file */ if(binbuf_read(s_bb, s_templatefilename, "", 0)) { /* if this fails, use the default template */ size_t length=strlen(s_templatestring); binbuf_text(s_bb, s_templatestring, length); } s_state=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; } }
DYN_EXPORT int dyn_NewObjectStr(int sched,dyn_id *oid,dyn_callback cb,dyn_id sid,const char *args) { t_binbuf *b = binbuf_new(); binbuf_text(b,(char *)args,strlen(args)); int argc = binbuf_getnatom(b); t_atom *argv = binbuf_getvec(b); int ret; if(argc) { t_symbol *sym; if(argv->a_type == A_SYMBOL) { sym = atom_getsymbol(argv); argc--,argv++; } else sym = &s_list; ret = dyn_NewObject(sched,oid,cb,sid,sym,argc,argv); } else ret = DYN_ERROR_PARAMS; binbuf_free(b); return ret; }
static void popen_read(t_popen *x,int fd) { int len,i=0; unsigned char b; unsigned char buffer[BUFSIZE]; if((len=read(fd,buffer,BUFSIZE))> 0){ for(i=0;i<len;i++){ if(x->x_count>=BUFSIZE) x->x_count=0; x->x_data[x->x_count++]=buffer[i]; if(buffer[i]==';') { binbuf_text(inbinbuf, x->x_data, x->x_count); x->x_count=0; popen_out(x,inbinbuf); } } } }
static int readasciimessage(t_binbuf *b) { int fill = 0, c; binbuf_clear(b); while ((c = getchar()) != EOF) { if (c == ';') { binbuf_text(b, ascii_inbuf, fill); return (1); } else if (fill < BUFSIZE) ascii_inbuf[fill++] = c; else if (fill == BUFSIZE) fprintf(stderr, "pd-extern: input buffer overflow\n"); } return (0); }
static void fudiparse_list(t_fudiparse *x, t_symbol*s, int argc, t_atom*argv) { size_t len = argc; t_binbuf* bbuf = binbuf_new(); char*cbuf; if((size_t)argc > x->x_numbytes) { freebytes(x->x_bytes, x->x_numbytes); x->x_numbytes = argc; x->x_bytes = getbytes(x->x_numbytes); } cbuf = x->x_bytes; while(argc--) { char b = atom_getfloat(argv++); *cbuf++ = b; } binbuf_text(bbuf, x->x_bytes, len); fudiparse_binbufout(x, bbuf); binbuf_free(bbuf); }
/* this is in a separately called subroutine so that the buffer isn't sitting on the stack while the messages are getting passed. */ static int netserver_socketreceiver_doread(t_netserver_socketreceiver *x) { char messbuf[INBUFSIZE], *bp = messbuf; int indx; int inhead = x->sr_inhead; int intail = x->sr_intail; char *inbuf = x->sr_inbuf; if (intail == inhead) return (0); for (indx = intail; indx != inhead; indx = (indx+1)&(INBUFSIZE-1)) { char c = *bp++ = inbuf[indx]; if (c == ';' && (!indx || inbuf[indx-1] != '\\')) { intail = (indx+1)&(INBUFSIZE-1); binbuf_text(inbinbuf, messbuf, bp - messbuf); x->sr_inhead = inhead; x->sr_intail = intail; return (1); } } return (0); }
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 void netrec_socketreceiver_getudp(t_netrec_socketreceiver *x, int fd) { char buf[INBUFSIZE+1]; int ret = recv(fd, buf, INBUFSIZE, 0); if (ret < 0) { sys_sockerror("recv"); sys_rmpollfn(fd); sys_closesocket(fd); } else if (ret > 0) { buf[ret] = 0; #if 0 post("%s", buf); #endif if (buf[ret-1] != '\n') { #if 0 buf[ret] = 0; error("dropped bad buffer %s\n", buf); #endif } else { char *semi = strchr(buf, ';'); if (semi) *semi = 0; binbuf_text(inbinbuf, buf, strlen(buf)); outlet_setstacklim(); if (x->sr_socketreceivefn) (*x->sr_socketreceivefn)(x->sr_owner, inbinbuf); else bug("netrec_socketreceiver_getudp"); } } }
static void mtr_doread(t_mtr *x, t_mtrack *target, t_symbol *fname) { char path[MAXPDSTRING]; FILE *fp; /* FIXME use open_via_path() */ if (x->x_glist) canvas_makefilename(x->x_glist, fname->s_name, path, MAXPDSTRING); else { strncpy(path, fname->s_name, MAXPDSTRING); path[MAXPDSTRING-1] = 0; } /* CHECKED no global message */ if (fp = sys_fopen(path, "r")) { t_mtrack *tp = 0; char linebuf[MTR_FILEBUFSIZE]; t_binbuf *bb = binbuf_new(); while (fgets(linebuf, MTR_FILEBUFSIZE, fp)) { char *line = linebuf; int linelen; while (*line && (*line == ' ' || *line == '\t')) line++; if (linelen = strlen(line)) { if (tp) { if (!strncmp(line, "end;", 4)) { post("ok"); tp = 0; } else { int ac; binbuf_text(bb, line, linelen); if (ac = binbuf_getnatom(bb)) { t_atom *ap = binbuf_getvec(bb); if (!binbuf_getnatom(tp->tr_binbuf)) { if (ap->a_type != A_FLOAT) { t_atom at; SETFLOAT(&at, 0.); binbuf_add(tp->tr_binbuf, 1, &at); } else if (ap->a_w.w_float < 0.) ap->a_w.w_float = 0.; } binbuf_add(tp->tr_binbuf, ac, ap); } } } else if (!strncmp(line, "track ", 6)) { int id = strtol(line + 6, 0, 10); startpost("Track %d... ", id); if (id < 1 || id > x->x_ntracks) post("no such track"); /* LATER rethink */ else if (target) { if (id == target->tr_id) tp = target; post("skipped"); /* LATER rethink */ } else tp = x->x_tracks[id - 1]; if (tp) { binbuf_clear(tp->tr_binbuf); } } } } fclose(fp); binbuf_free(bb); } else { /* CHECKED no complaint, open dialog not presented... */ /* LATER rethink */ hammerpanel_open(target ? target->tr_filehandle : x->x_filehandle, 0); } }
int pd_extern_sched(char *flags) { int naudioindev, audioindev[MAXAUDIOINDEV], chindev[MAXAUDIOINDEV]; int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV]; int i, j, rate, advance, callback, chin, chout, fill = 0, c, blocksize; t_binbuf *b = binbuf_new(); sys_get_audio_params(&naudioindev, audioindev, chindev, &naudiooutdev, audiooutdev, choutdev, &rate, &advance, &callback, &blocksize); chin = (naudioindev < 1 ? 0 : chindev[0]); chout = (naudiooutdev < 1 ? 0 : choutdev[0]); /* fprintf(stderr, "Pd plug-in scheduler called, chans %d %d, sr %d\n", chin, chout, (int)rate); */ sys_setchsr(chin, chout, rate); sys_audioapi = API_NONE; while ((c = getchar()) != EOF) { if (c == ';') { int n; t_atom *ap; binbuf_text(b, inbuf, fill); n = binbuf_getnatom(b); ap = binbuf_getvec(b); fill = 0; if (n > 0 && ap[0].a_type == A_FLOAT) { /* a list -- take it as incoming signals. */ int chan, nchan = n/DEFDACBLKSIZE; t_sample *fp; for (i = chan = 0, fp = sys_soundin; chan < nchan; chan++) for (j = 0; j < DEFDACBLKSIZE; j++) *fp++ = atom_getfloat(ap++); for (; chan < chin; chan++) for (j = 0; j < DEFDACBLKSIZE; j++) *fp++ = 0; sched_tick(sys_time+sys_time_per_dsp_tick); sys_pollgui(); #if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__GNU__) pollwatchdog(); #endif printf(";\n"); for (i = chout*DEFDACBLKSIZE, fp = sys_soundout; i--; fp++) { printf("%g\n", *fp); *fp = 0; } printf(";\n"); fflush(stdout); } else if (n > 1 && ap[0].a_type == A_SYMBOL) { t_pd *whom = ap[0].a_w.w_symbol->s_thing; if (!whom) error("%s: no such object", ap[0].a_w.w_symbol->s_name); else if (ap[1].a_type == A_SYMBOL) typedmess(whom, ap[1].a_w.w_symbol, n-2, ap+2); else pd_list(whom, 0, n-1, ap+1); } } else if (fill < BUFSIZE) inbuf[fill++] = c; else if (fill == BUFSIZE) fprintf(stderr, "pd-extern: input buffer overflow\n"); } return (0); }
static void freadln_readline (t_freadln *x) { int min_length=(x->x_textbuf_length < 1)?1:x->x_textbuf_length; int linebreak_pos=0; int items_read; t_binbuf *bbuf; t_atom *abuf; int abuf_length; int rewind_after; if (!x->x_file) { pd_error(x, "no file opened for reading"); freadln_done(x); return; } do { if (linebreak_pos==-1) { min_length<<=1; fseek(x->x_file,-(long)(x->x_textbuf_length),SEEK_CUR); } if (!enlarge_cstr_if_required((const char**) &x->x_textbuf, &x->x_textbuf_length, min_length)) { pd_error(x, "out of memory"); x->x_textbuf_length=0; freadln_close(x); freadln_done(x); return; } if (!(items_read=fread(x->x_textbuf,sizeof(char),x->x_textbuf_length,x->x_file))) { freadln_close(x); freadln_done(x); return; } x->x_textbuf[x->x_textbuf_length-1]=0; } while (((linebreak_pos=cstr_char_pos(x->x_textbuf,x->linebreak_chr[0]))==-1) && !(items_read < x->x_textbuf_length)); if (linebreak_pos-1 < items_read - strlen(x->linebreak_chr)) { rewind_after=items_read-linebreak_pos; fseek(x->x_file,-(long)(rewind_after),SEEK_CUR); } if (linebreak_pos==-1) linebreak_pos=items_read; x->x_textbuf[linebreak_pos-1]='\0'; if (!(bbuf=binbuf_new())) { pd_error(x, "out of memory"); freadln_close(x); freadln_done(x); return; } binbuf_text(bbuf, x->x_textbuf, linebreak_pos-1); abuf = binbuf_getvec(bbuf); abuf_length = binbuf_getnatom(bbuf); if (abuf_length>0) { if (abuf->a_type==A_SYMBOL) { outlet_anything(x->x_message_outlet, atom_getsymbol(abuf), abuf_length-1, abuf+1); } else { outlet_list(x->x_message_outlet, gensym("list"), abuf_length, abuf); } } else { outlet_list(x->x_message_outlet, atom_getsymbol(abuf), 0, abuf); } /* NOTE: the following line might be a problem in recursions * and could be performed before to outlet_* as well, * but(!) atom buffer abuf must be copied if doing so. */ binbuf_free(bbuf); }