Ejemplo n.º 1
0
static void fudiformat_any(t_fudiformat *x, t_symbol*s, int argc, t_atom*argv) {
  char *buf;
  int length;
  int i;
  t_atom at;
  t_binbuf*bbuf = binbuf_new();
  SETSYMBOL(&at, s);
  binbuf_add(bbuf, 1, &at);

  binbuf_add(bbuf, argc, argv);

  if(!x->x_udp) {
    SETSEMI(&at);
    binbuf_add(bbuf, 1, &at);
  }
  binbuf_gettext(bbuf, &buf, &length);
  binbuf_free(bbuf);

  if((size_t)length>x->x_numatoms) {
    freebytes(x->x_atoms, sizeof(*x->x_atoms) * x->x_numatoms);
    x->x_numatoms = length;
    x->x_atoms = getbytes(sizeof(*x->x_atoms) * x->x_numatoms);
  }

  for(i=0; i<length; i++) {
    SETFLOAT(x->x_atoms+i, buf[i]);
  }
  freebytes(buf, length);
  outlet_list(x->x_msgout, 0, length, x->x_atoms);
}
Ejemplo n.º 2
0
static int imaction_P2_scope(t_port *x, char *name)
{
    if (x->x_inatoms > 6)
    {
	t_atom *out = x->x_outmess;
	int i, xpix, ypix;
	SETSYMBOL(out, gensym("#X")); out++;
	SETSYMBOL(out, gensym("obj")); out++;
	port_setxy(x, 3, out);
	xpix = (int)out++->a_w.w_float;
	ypix = (int)out->a_w.w_float;
	binbuf_add(x->x_outbb, 4, x->x_outmess);
	import_addclassname(x, name, &x->x_inmess[2]);
	out = x->x_outmess;
	port_setxy(x, 5, out);
	out++->a_w.w_float -= xpix;
	out++->a_w.w_float -= ypix;
	out = import_copyatoms(out, x->x_inmess + 7, x->x_inatoms - 7);
	SETSEMI(out);
	binbuf_add(x->x_outbb, x->x_inatoms - 4, x->x_outmess);
	x->x_nobj++;
	return (PORT_NEXT);
    }
    else return (PORT_CORRUPT);
}
static void qlist_add(t_qlist *x, t_symbol *s, int ac, t_atom *av)
{
    t_atom a;
    SETSEMI(&a);
    binbuf_add(x->x_binbuf, ac, av);
    binbuf_add(x->x_binbuf, 1, &a);
}
Ejemplo n.º 4
0
static void netsend_send(t_netsend *x, t_symbol *s, int argc, t_atom *argv)
{
#ifdef ROCKBOX
    (void) x;
    (void) s;
    (void) argc;
    (void) argv;
#else /* ROCKBOX */
    if (x->x_fd >= 0)
    {
	t_binbuf *b = binbuf_new();
	char *buf, *bp;
	int length, sent;
	t_atom at;
	binbuf_add(b, argc, argv);
	SETSEMI(&at);
	binbuf_add(b, 1, &at);
	binbuf_gettext(b, &buf, &length);
	for (bp = buf, sent = 0; sent < length;)
	{
	    static double lastwarntime;
	    static double pleasewarn;
	    double timebefore = sys_getrealtime();
    	    int res = send(x->x_fd, buf, length-sent, 0);
    	    double timeafter = sys_getrealtime();
    	    int late = (timeafter - timebefore > 0.005);
    	    if (late || pleasewarn)
    	    {
    	    	if (timeafter > lastwarntime + 2)
    	    	{
    	    	     post("netsend blocked %d msec",
    	    	     	(int)(1000 * ((timeafter - timebefore) + pleasewarn)));
    	    	     pleasewarn = 0;
    	    	     lastwarntime = timeafter;
    	    	}
    	    	else if (late) pleasewarn += timeafter - timebefore;
    	    }
    	    if (res <= 0)
    	    {
    		sys_sockerror("netsend");
    		netsend_disconnect(x);
    		break;
    	    }
    	    else
    	    {
    		sent += res;
    		bp += res;
    	    }
	}
	t_freebytes(buf, length);
	binbuf_free(b);
    }
    else error("netsend: not connected");
#endif /* ROCKBOX */
}
Ejemplo n.º 5
0
static void import_addclassname(t_port *x, char *outname, t_atom *inatom)
{
    t_atom at;
    if (outname)
	SETSYMBOL(&at, gensym(outname));
    else
    {
	t_symbol *insym = 0;
	if (inatom->a_type == A_SYMBOL)
	{
	    /* LATER bash inatom to lowercase (CHECKME first) */
	    insym = inatom->a_w.w_symbol;
	    if (import_mapping && import_mapsize)
	    {
		char **fromp = import_mapping, **top = import_mapping + 1;
		int cnt = import_mapsize;
		while (cnt--)
		{
		    if (strcmp(*fromp, insym->s_name))
		    {
			fromp += 2;
			top += 2;
		    }
		    else
		    {
			insym = gensym(*top);
			inatom = 0;
			break;
		    }
		}
	    }
	    if (insym != &s_bang && insym != &s_float &&
		insym != &s_symbol && insym != &s_list &&
		(insym == portps_inlet || insym == portps_outlet ||
		 zgetfn(&pd_objectmaker, insym) == 0))
	    {
		x->x_withbogus = 1;
		SETSYMBOL(&at, portps_bogus);
		binbuf_add(x->x_outbb, 1, &at);
	    }
	}
	if (inatom)
	    import_copyatoms(&at, inatom, 1);
	else if (insym)
	    SETSYMBOL(&at, insym);
	else
	{
	    loudbug_bug("import_addclassname");
	    SETSYMBOL(&at, gensym("???"));
	}
    }
    binbuf_add(x->x_outbb, 1, &at);
}
Ejemplo n.º 6
0
static void netdist_send(t_netdist *x, t_symbol *s, int argc, t_atom *argv)
{
	int i = 0;

	for(i = 0; i <= x->x_numconnect; i++)
	{
		if (x->x_fd[i] >= 0)
		{
			t_binbuf *b = binbuf_new();
			char *buf, *bp;
			int length, sent;
			t_atom at;
			binbuf_add(b, argc, argv);
			SETSEMI(&at);
			binbuf_add(b, 1, &at);
			binbuf_gettext(b, &buf, &length);
			for (bp = buf, sent = 0; sent < length;)
			{
				static double lastwarntime;
				static double pleasewarn;
				double timebefore = clock_getlogicaltime();
    				int res = send(x->x_fd[i], buf, length-sent, 0);
    				double timeafter = clock_getlogicaltime();
    				int late = (timeafter - timebefore > 0.005);
    				if (late || pleasewarn)
    				{
    	    			if (timeafter > lastwarntime + 2)
    	    			{
    	    				 post("netdist blocked %d msec",
    	    	     			(int)(1000 * ((timeafter - timebefore) + pleasewarn)));
    	    				 pleasewarn = 0;
    	    				 lastwarntime = timeafter;
    	    			}
    	    			else if (late) pleasewarn += timeafter - timebefore;
    				}
    				if (res <= 0)
    				{
    					sys_sockerror("netdist");
    					netdist_disconnect(x, gensym(x->x_hostname[i]), x->x_port[i]);
    					break;
    				}
    				else
    				{
    					sent += res;
    					bp += res;
    				}
			}
			t_freebytes(buf, length);
			binbuf_free(b);
		}
	}
	if(x->x_numconnect == -1) error("netdist: not connected");
}
Ejemplo n.º 7
0
// ------------- SEND ANYTHING
void broadcastsend_message_anything_method(t_broadcastsend *x, t_symbol *s, int argc, t_atom *argv){
   t_binbuf *b = binbuf_new();
   char *buf;
   int length;
   t_atom message;
   SETSYMBOL(&message, s);
   binbuf_add(b, 1, &message); // message name
   binbuf_add(b, argc, argv); // message parameters
   binbuf_gettext(b, &buf, &length);
   int size = sendto(x->socket, buf, length, 0,(struct sockaddr *) &x->their_addr, sizeof(x->their_addr));
   (void) size;
}
Ejemplo n.º 8
0
static int import_emadd(t_port *x, t_symbol *state, int ac, t_atom *av)
{
    if (import_emcheck(x, state))
    {
	t_atom at;
	SETSYMBOL(&at, gensym("#C"));
	binbuf_add(x->x_embb, 1, &at);
	binbuf_add(x->x_embb, ac, av);
	binbuf_addsemi(x->x_embb);
	return (1);
    }
    else return (0);
}
Ejemplo n.º 9
0
void binbuf_addbinbuf(t_binbuf *x, t_binbuf *y)
{
    t_binbuf *z = binbuf_new();
    int i;
    t_atom *ap;
    binbuf_add(z, y->b_n, y->b_vec);
    for (i = 0, ap = z->b_vec; i < z->b_n; i++, ap++)
    {
    	char tbuf[MAXPDSTRING];
    	switch (ap->a_type)
    	{
    	case A_FLOAT:
    	    break;
    	case A_SEMI:
    	    SETSYMBOL(ap, gensym(";"));
    	    break;
    	case A_COMMA:
    	    SETSYMBOL(ap, gensym(","));
    	    break;
    	case A_DOLLAR:
#ifdef ROCKBOX
            snprintf(tbuf, sizeof(tbuf), "$%d", ap->a_w.w_index);
#else /* ROCKBOX */
    	    sprintf(tbuf, "$%d", ap->a_w.w_index);
#endif /* ROCKBOX */
    	    SETSYMBOL(ap, gensym(tbuf));
    	    break;
    	case A_DOLLSYM:
#ifdef ROCKBOX
            snprintf(tbuf, sizeof(tbuf), "$%s", ap->a_w.w_symbol->s_name);
#else /* ROCKBOX */
    	    sprintf(tbuf, "$%s", ap->a_w.w_symbol->s_name);
#endif /* ROCKBOX */
    	    SETSYMBOL(ap, gensym(tbuf));
    	    break;
    	case A_SYMBOL:
    	    	/* FIXME make this general */
    	    if (!strcmp(ap->a_w.w_symbol->s_name, ";"))
    	    	SETSYMBOL(ap, gensym(";"));
    	    else if (!strcmp(ap->a_w.w_symbol->s_name, ","))
    	    	SETSYMBOL(ap, gensym(","));
    	    break;
    	default:
    	    bug("binbuf_addbinbuf");
    	}
    }
    
    binbuf_add(x, z->b_n, z->b_vec);
}
Ejemplo n.º 10
0
Archivo: mtr.c Proyecto: EQ4/PdPulpito
static void mtrack_doadd(t_mtrack *tp, int ac, t_atom *av)
{
    if (tp->tr_prevtime > 0.)
    {
	t_binbuf *bb = tp->tr_binbuf;
	t_atom at;
    	float elapsed = clock_gettimesince(tp->tr_prevtime);
	SETFLOAT(&at, elapsed);
	binbuf_add(bb, 1, &at);
	binbuf_add(bb, ac, av);
	SETSEMI(&at);
	binbuf_add(bb, 1, &at);
	tp->tr_prevtime = clock_getlogicaltime();
    }
}
Ejemplo n.º 11
0
static int import_emaddv(t_port *x, t_symbol *state, char *fmt, ...)
{
    va_list ap;
    t_atom arg[64], *at = arg;
    int nargs = 0;
    char *fp = fmt;
    va_start(ap, fmt);
    SETSYMBOL(at, gensym("#C"));
    at++; nargs++;
    if (import_emcheck(x, state)) while (1)
    {
	switch(*fp++)
	{
	case 'i': SETFLOAT(at, va_arg(ap, t_int)); break;
	case 'f': SETFLOAT(at, va_arg(ap, double)); break;
	case 's': SETSYMBOL(at, va_arg(ap, t_symbol *)); break;
	case ';': SETSEMI(at); break;
	case 0: goto done;
	default: nargs = 0; goto done;
	}
	at++; nargs++;
    }
done:
    va_end(ap);
    if (nargs > 1)
    {
	binbuf_add(x->x_embb, nargs, arg);
	return (1);
    }
    else return (0);
}
Ejemplo n.º 12
0
    /* a series of "data" messages rebuilds a scalar */
static void gfxstub_data(t_gfxstub *x, t_symbol *s, int argc, t_atom *argv)
{
    if (!gfxstub_binbuf)
        gfxstub_binbuf = binbuf_new();
    binbuf_add(gfxstub_binbuf, argc, argv);
    binbuf_addsemi(gfxstub_binbuf);
}
Ejemplo n.º 13
0
void binbuf_addv(t_binbuf *x, char *fmt, ...)
{
    va_list ap;
    t_atom arg[MAXADDMESSV], *at =arg;
    int nargs = 0;
    char *fp = fmt;

    va_start(ap, fmt);
    while (1)
    {
    	if (nargs >= MAXADDMESSV)
    	{
    	    error("binbuf_addmessv: only %d allowed", MAXADDMESSV);
    	    break;
    	}
    	switch(*fp++)
    	{
    	case 'i': SETFLOAT(at, va_arg(ap, t_int)); break;
    	case 'f': SETFLOAT(at, va_arg(ap, double)); break;
    	case 's': SETSYMBOL(at, va_arg(ap, t_symbol *)); break;
    	case ';': SETSEMI(at); break;
    	case ',': SETCOMMA(at); break;
    	default: goto done;
    	}
    	at++;
    	nargs++;
    }
done:
    va_end(ap);
    binbuf_add(x, nargs, arg);
}
Ejemplo n.º 14
0
t_binbuf* binbuf_via_atoms(int ac, t_atom *av)
{
    t_binbuf* dico = binbuf_new();
    if(dico)
    {
        binbuf_add(dico, ac, av);
    }
    return dico;
}
Ejemplo n.º 15
0
static int binport_tobinbuf(t_binport *bp, t_binbuf *bb)
{
    t_atom at;
    if (bp->b_old)
	bp->b_old->o_ndx = 0;
    while (binport_nextatom(bp, &at))
	if (at.a_type != A_NULL)
	    binbuf_add(bb, 1, &at);
    return (1);
}
Ejemplo n.º 16
0
Archivo: xeq.c Proyecto: pure-data/xeq
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));
    }
}
Ejemplo n.º 17
0
static int two_stub(const char* repository, binbuf_t c, binbuf_t o) {
  struct packfile_object* obj;

  fail_unless(strcmp(repository, "xxx") == 0);
  fail_unless(c == commits);
  fail_unless(binbuf_get_size(o) == 0);

  obj = binbuf_add(o);
  obj->type = 1;
  obj->content = buffer_create();
  buffer_append(obj->content, "123", 3);

  obj = binbuf_add(o);
  obj->type = 2;
  obj->content = buffer_create();
  buffer_append(obj->content, "456", 3);

  return 0;
}
Ejemplo n.º 18
0
/**
 * send a message
 */
static void _zmq_send(t_zmq *x, t_symbol *s, int argc, t_atom* argv) {

   if ( ! x->zmq_socket) {
      post("[!] create and connect socket before sending");
      return;
   }

   if ( ! _can_send(x)) {
       return;
   }

   int r;
   int length;
   char *buf;
   t_binbuf *b = 0;

   t_atom at;
   b = binbuf_new();
   binbuf_add(b, argc, argv);
   SETSEMI(&at);
   binbuf_add(b, 1, &at);
   binbuf_gettext(b, &buf, &length);
   //post("msg length %i", length);

   //s_send(x->zmq_socket, buf);
   r=zmq_send (x->zmq_socket, buf, strlen(buf), 0);

   t_freebytes(buf, length);
   binbuf_free(b);

   if(r == -1) {
      _zmq_error(zmq_errno());
      return;
   }

   // if REQ socket wait for reply
   if(x->socket_type==ZMQ_REQ) {
      _zmq_receive(x);
   }

   return;
}
Ejemplo n.º 19
0
t_pd_err binbuf_append_attribute(t_binbuf *d, t_symbol *key, int argc, t_atom *argv)
{
    if(d && key && argc && argv)
    {
        format_atoms(argc, argv);
        binbuf_addv(d, "s", key);
        binbuf_add(d, argc, argv);
        return 0;
    }
    return -1;
}
Ejemplo n.º 20
0
static int import_objarg(t_port *x, char *name)
{
    int ndx = (x->x_inmess[1].a_w.w_symbol == gensym("user") ? 3 : 2);
    if (x->x_inatoms > 6
	|| (ndx == 3 && x->x_inatoms > 4))
    {
	t_atom *out = x->x_outmess;
	SETSYMBOL(out, gensym("#X")); out++;
	SETSYMBOL(out, gensym("obj")); out++;
	port_setxy(x, ndx, out);
	binbuf_add(x->x_outbb, 4, x->x_outmess);
	import_addclassname(x, name, &x->x_inmess[ndx == 2 ? 6 : 2]);
	out = import_copyatoms(x->x_outmess, x->x_inmess + 7, x->x_inatoms - 7);
	SETSEMI(out);
	binbuf_add(x->x_outbb, x->x_inatoms - 6, x->x_outmess);
	x->x_nobj++;
	return (PORT_NEXT);
    }
    else return (PORT_CORRUPT);
}
Ejemplo n.º 21
0
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"));
}
Ejemplo n.º 22
0
void breakpoints_function(t_breakpoints *x, t_symbol* s, int argc, t_atom* argv)
{
    t_binbuf* b = binbuf_new();

    if(argc && argv)
    {
        binbuf_addv(b, "s", gensym("@points"));
        binbuf_add(b, argc, argv);
        breakpoints_init(x, b);
        binbuf_free(b);

    }
}
Ejemplo n.º 23
0
static int import_emcopy(t_port *x, t_symbol *state)
{
    if (import_emcheck(x, state))
    {
	t_atom *out = x->x_outmess;
	SETSYMBOL(out, gensym("#C")); out++;
	out = import_copyatoms(out, x->x_inmess + 1, x->x_inatoms - 1);
	SETSEMI(out);
	binbuf_add(x->x_embb, x->x_inatoms + 1, x->x_outmess);
	return (1);
    }
    else return (0);
}
Ejemplo n.º 24
0
static void canvasargs_list(t_canvasargs *x, t_symbol*s, int argc, t_atom*argv)
{
  t_binbuf*b=0;
  t_atom name[1];

  if(!x || !x->x_canvas) return;
  b=x->x_canvas->gl_obj.te_binbuf;

  if(!b)return;

  /* if this method is called with a non-special selector, we *rename* the object */
  if(s==0 || s==gensym("") || s==&s_list || s==&s_bang || s==&s_float || s==&s_symbol || s==&s_) {
    /* keep the given name */
    t_atom*ap=binbuf_getvec(b);
    s=atom_getsymbol(ap);
  }
  SETSYMBOL(name, s);
  
  binbuf_clear(b);
  binbuf_add(b, 1, name);
  binbuf_add(b, argc, argv);
}
Ejemplo n.º 25
0
Archivo: xeq.c Proyecto: pure-data/xeq
static void xeq_addline(t_xeq *x, t_symbol *s, int ac, t_atom *av)
{
    int i;
    for (i = 0; i < ac; i++)
    {
    	if (av[i].a_type == A_SYMBOL)
	{
	    if (!strcmp(av[i].a_w.w_symbol->s_name, "_semi_"))
	    	SETSEMI(&av[i]);
	    else if (!strcmp(av[i].a_w.w_symbol->s_name, "_comma_"))
	    	SETCOMMA(&av[i]);
    	}
    }
    binbuf_add(x->x_binbuf, ac, av);
}
Ejemplo n.º 26
0
static void to_ascii_code_anything(t_to_ascii_code *x, t_symbol *s, int ac, t_atom *av) {
	
	binbuf_clear(to_ascii_code_binbuf);
	// Add selector if it is not standard
	if ( s != &s_list && s !=  &s_float && s != &s_symbol && s != &s_) {
		t_atom a;
		SETSYMBOL(&a, s);
		binbuf_add(to_ascii_code_binbuf,1,&a);
	}
	// Add all the atoms to the binbuf
	binbuf_add(to_ascii_code_binbuf, ac, av);
	
	
	
	// Get the contents as a text
	int size=0;
	binbuf_gettext(to_ascii_code_binbuf, &to_ascii_code_text, &size); //void binbuf_gettext(t_binbuf *x, char **bufp, int *lengthp);
	
	// Convert to a list of floats
	
	t_atom *list_floats = getbytes((size+1)*sizeof(*list_floats));	// Add some space for the eof character 
	int i;
	for ( i=0; i < size; i++ ) {
		SETFLOAT(list_floats+i,(t_float)to_ascii_code_text[i]);
	}
	if ( x->eof_is_set ) { // Append eof if set
		SETFLOAT(list_floats+size, x->eof);
		//outlet_float(x->outlet_right,size+1);
		outlet_list(x->outlet_left,&s_list,size+1,list_floats);
	} else {
		//outlet_float(x->outlet_right,size);
		outlet_list(x->outlet_left,&s_list,size,list_floats);
	}
	freebytes(list_floats, (size+1)*sizeof(*list_floats));
	
}
Ejemplo n.º 27
0
t_pd_err binbuf_append_attribute(t_binbuf *d, t_symbol *key, long argc, t_atom *argv)
{
    int i;

    long ac = argc+1;
    t_atom* av = (t_atom *)calloc(ac, sizeof(t_atom));
    atom_setsym(av, key);
    argv = fatoms_from_atoms(argc, argv);
    for(i = 0; i < argc; i++)
    {
        av[i+1] = argv[i];
    }

    binbuf_add(d, (int)ac, av);
    return 0;
}
Ejemplo n.º 28
0
static int readbinmessage(t_binbuf *b)
{
    binbuf_clear(b);
    while (1)
    {
        t_atom at;
        if (!pd_tilde_getatom(&at, stdin))
        {
            fprintf(stderr, "pd-extern: EOF on input\n");
            return (0);
        }
        else if (at.a_type == A_SEMI)
            return (1);
        else binbuf_add(b, 1, &at);
    }
}
Ejemplo n.º 29
0
static int imaction_P6_coll(t_port *x, char *arg)
{
    t_symbol *collname = port_getsymbol(x, 7);
    binbuf_addv(x->x_outbb, "ssffs",
		gensym("#X"), gensym("obj"),
		port_getx(x, 2), port_gety(x, 3), portps_coll);
    if (collname != &s_)
    {
	t_atom at;
	SETSYMBOL(&at, collname);
	binbuf_add(x->x_outbb, 1, &at);
    }
    binbuf_addsemi(x->x_outbb);
    import_emflush(x, portps_coll, collname);
    x->x_nobj++;
    return (PORT_NEXT);
}
Ejemplo n.º 30
0
static void preset_init(t_presetobj *x, t_binbuf *d)
{
	int check;
    long index;
    int ac = binbuf_getnatom(d);
    t_atom* av = binbuf_getvec(d);
    for(int i = 0; i < ac; i++)
    {
        if(atom_gettype(av+i) == A_SYMBOL && atom_getsymbol(av+i) == cream_sym_atpreset)
        {
            for(;i < ac; i++)
            {
                if(atom_gettype(av+i) == A_SYMBOL && atom_getsymbol(av+i) == cream_sym_atindex)
                {
                    i++;
                    if(i+1 < ac && atom_gettype(av+i) == A_FLOAT)
                    {
                        index = atom_getlong(av+i);
                        binbuf_clear(x->f_binbuf[index]);
                        i++;
                        check = 1;
                        for(; i < ac && check; i++)
                        {
                            if(atom_gettype(av+i) == A_SYMBOL && atom_getsymbol(av+i) == cream_sym_atindex)
                            {
                                i -=  2;
                                check = 0;
                            }
                            else if(atom_gettype(av+i) == A_SYMBOL && atom_getsymbol(av+i) == cream_sym_right_bracket)
                            {
                                return;
                            }
                            else
                            {
                                binbuf_add(x->f_binbuf[index], 1, av+i);
                            }
                        }

                    }
                }
            }
        }
    }

}