示例#1
0
文件: x_misc.c 项目: danomatika/ofxPd
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);
}
示例#2
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 */
}
示例#3
0
文件: g_rtext.c 项目: geeetarguy/pd
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);
}
// ------------- 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;
}
示例#5
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");
}
示例#6
0
 std::string Comment::getText() const
 {
     if(isValid())
     {
         char* text = nullptr;
         int size = 0;
         binbuf_gettext(reinterpret_cast<t_text *>(m_ptr)->te_binbuf, &text, &size);
         if(text && size)
         {
             return std::string(text, size);
         }
     }
     return std::string();
 }
示例#7
0
文件: g_rtext.c 项目: geeetarguy/pd
t_rtext *rtext_new(t_glist *glist, t_text *who)
{
    t_rtext *x = (t_rtext *)getbytes(sizeof *x);
    int w = 0, h = 0, indx;
    x->x_height = -1;
    x->x_text = who;
    x->x_glist = glist;
    x->x_next = glist->gl_editor->e_rtext;
    x->x_selstart = x->x_selend = x->x_active =
        x->x_drawnwidth = x->x_drawnheight = 0;
    binbuf_gettext(who->te_binbuf, &x->x_buf, &x->x_bufsize);
    glist->gl_editor->e_rtext = x;
    sprintf(x->x_tag, ".x%lx.t%lx", (t_int)glist_getcanvas(x->x_glist),
        (t_int)x);
    return (x);
}
示例#8
0
文件: g_rtext.c 项目: cviejo/mPD
t_rtext *rtext_new(t_glist *glist, t_text *who)
{
    t_rtext *x = (t_rtext *)getbytes(sizeof *x);
    x->x_text = who;
    x->x_glist = glist;
    x->x_next = glist->gl_editor->e_rtext;
    x->x_selstart = x->x_selend = x->x_active =
        x->x_drawnwidth = x->x_drawnheight = 0;
    binbuf_gettext(who->te_binbuf, &x->x_buf, &x->x_bufsize);
    glist->gl_editor->e_rtext = x;
    // here we use a more complex tag which will later help us properly
    // select objects inside a gop on its parent that are otherwise not
    // supposed to be there (they don't belong to that canvas). See
    // in pd.tk pdtk_select_all_gop_widgets function and how it affects
    // draw data structures that are displayed via gop (Ico 20140831)
    sprintf(x->x_tag, ".x%lx.t%lx", (t_int)glist_getcanvas(x->x_glist),
        (t_int)x);
    return (x);
}
示例#9
0
文件: zmq.c 项目: sansculotte/pd-zmq
/**
 * 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;
}
示例#10
0
static void popen_list(t_popen *x, t_symbol *s,
    int argc, t_atom *argv)
{
	t_binbuf *bb;
	char *buf;
	int l;

	if(!x->x_file) return;

	bb=binbuf_new();
	binbuf_add(bb,argc,argv);
	//binbuf_print(bb);
	binbuf_gettext(bb, &buf,&l);
	buf[l]=0;

	//printf("popen list: %s\n",buf);
	fprintf(x->x_file,"%s\n",buf);fflush(x->x_file);

	freebytes(buf,l);
	binbuf_free(bb);
}
示例#11
0
文件: a2s.c 项目: Angeldude/pd
void a2s_list(t_pd_obj_a2s *x, t_symbol *s, int argc, t_atom *argv)
{
  char      buffer[MAXPDSTRING] ;
  char     *a_string    ;
  int       a_string_l  ;
  t_binbuf *bbuf        ;
  int       i,l=0,k=0   ;
  
  bbuf = binbuf_new() ;
  for (i=0;i<argc;i++)
  {
    binbuf_clear(bbuf);
    binbuf_add(bbuf, 1, argv++);
    binbuf_gettext(bbuf, &a_string, &a_string_l);
    memcpy(&buffer[k],a_string,a_string_l) ;
    freebytes(a_string,a_string_l);
    k+=a_string_l ;
  }  
  buffer[k]=0;
  outlet_symbol(x->x_obj.ob_outlet,gensym(&buffer[0]));
  binbuf_free(bbuf);  
}
示例#12
0
static void espeak_text(t_espeak *x, t_symbol*s, int argc, t_atom*argv) {
  t_binbuf*bb=binbuf_new();
  int size=0;
  char*text=NULL;

  binbuf_add(bb, argc, argv);
  binbuf_gettext(bb, &text, &size);
  binbuf_free(bb);

  text[size]=0;

  verbose(1, "speak '%s'", text);

  espeak_Synth(text,
	       strlen(text),
	       0,
	       POS_CHARACTER,
	       0,
	       espeakCHARS_AUTO,
	       NULL,
	       x);
}
示例#13
0
static void popen_open(t_popen *x, t_symbol *s,int argc, t_atom *argv)
{
    char cmd[512],*text;
    int cmd_len;

    t_binbuf *bb=binbuf_new();

    popen_close(x);

    //post("argc=%d",argc);
    //post("argv[0]=%s",atom_getsymbol(&argv[0])->s_name);

    binbuf_add(bb,argc,argv);
    binbuf_gettext(bb, &text,&cmd_len);
    binbuf_free(bb);

    strncpy(cmd,text,cmd_len);
    cmd[cmd_len]=0;
    //post("cmd=%s",cmd);

    x->x_file=popen(cmd,"w");

}
示例#14
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));
	
}
示例#15
0
static void comment_validate(t_comment *x, t_glist *glist)
{
    if (!x->x_ready)
    {
	t_text *t = (t_text *)x;
	binbuf_free(t->te_binbuf);
	t->te_binbuf = x->x_binbuf;
	if (x->x_textbuf) freebytes(x->x_textbuf, x->x_textbufsize);
	binbuf_gettext(x->x_binbuf, &x->x_textbuf, &x->x_textbufsize);
	x->x_ready = 1;
#ifdef COMMENT_DEBUG
	loudbug_post("validation done");
#endif
    }
    if (glist)
    {
	if (glist != x->x_glist)
	{
	    loudbug_bug("comment_getcanvas");
	    x->x_glist = glist;
	}
	x->x_canvas = glist_getcanvas(glist);
    }
}
示例#16
0
文件: netserver.c 项目: IcaroL2ORK/pd
/* send message to client using client number 
   note that the client numbers might change in case a client disconnects! */
static void netserver_client_send(t_netserver *x, t_symbol *s, int argc, t_atom *argv)
{
   int sockfd, client;
   if(x->x_nconnections < 0)
   {
	  if (x->x_log_pri >= LOG_WARNING)
		 post("netserver: no clients connected");
	  return;
   }
   if(argc < 2)
   {
	  if (x->x_log_pri >= LOG_WARNING)
		 post("netserver: nothing to send");
	  return;
   }
   /* get number of client (first element in list) */
   if(argv[0].a_type == A_FLOAT)
	  client = atom_getfloatarg(0, argc, argv);
   else
   {
	  if (x->x_log_pri >= LOG_WARNING)
		 post("netserver: no client specified");
	  return;
   }
   sockfd = x->x_fd[client - 1];	/* get socket number for that client */

   /* process & send data */
   if(sockfd > 0)
   {
	  t_binbuf *b = binbuf_new();
	  char *buf, *bp;
	  int length, sent;
	  t_atom at;
	  binbuf_add(b, argc - 1, argv + 1);	/* skip first element */
	  SETSEMI(&at);
	  binbuf_add(b, 1, &at);
	  binbuf_gettext(b, &buf, &length);

	  if (x->x_log_pri >= LOG_DEBUG)
	  {
		 post("netserver: sending data to client %d on socket %d", client, sockfd);
		 post("netserver: >> sending \"%s\"", buf);
	  }

	  for (bp = buf, sent = 0; sent < length;)
	  {
		 static double lastwarntime;
		 static double pleasewarn;
		 double timebefore = clock_getlogicaltime();
		 int res = send(sockfd, buf, length-sent, 0);
		 double timeafter = clock_getlogicaltime();
		 int late = (timeafter - timebefore > 0.005);
		 if (late || pleasewarn)
		 {
			if (timeafter > lastwarntime + 2)
			{
			   if (x->x_log_pri >= LOG_WARNING)
				  post("netserver blocked %d msec",
					   (int)(1000 * ((timeafter - timebefore) + pleasewarn)));
			   pleasewarn = 0;
			   lastwarntime = timeafter;
			}
			else if (late) pleasewarn += timeafter - timebefore;
		 }
		 if (res <= 0)
		 {
			sys_sockerror("netserver");
			if (x->x_log_pri >= LOG_ERR)
			   post("netserver: could not send data to cient");
			break;
		 }
		 else
		 {
			sent += res;
			bp += res;
		 }
	  }
	  t_freebytes(buf, length);
	  binbuf_free(b);
   }
   else if (x->x_log_pri >= LOG_CRIT)
	  post("netserver: not a valid socket number (%d)", sockfd);
}
示例#17
0
文件: x_net.c 项目: pedebt/pd-vanilla
static int netsend_dosend(t_netsend *x, int sockfd,
    t_symbol *s, int argc, t_atom *argv)
{
    char *buf, *bp;
    int length, sent, fail = 0;
    t_binbuf *b = 0;
    if (x->x_bin)
    {
        int i;
        buf = alloca(argc);
        for (i = 0; i < argc; i++)
            ((unsigned char *)buf)[i] = atom_getfloatarg(i, argc, argv);
        length = argc;
    }
    else
    {
        t_atom at;
        b = binbuf_new();
        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(sockfd, bp, length-sent, 0);
        double timeafter = sys_getrealtime();
        int late = (timeafter - timebefore > 0.005);
        if (late || pleasewarn)
        {
            if (timeafter > lastwarntime + 2)
            {
                 post("netsend/netreceive blocked %d msec",
                    (int)(1000 * ((timeafter - timebefore) +
                        pleasewarn)));
                 pleasewarn = 0;
                 lastwarntime = timeafter;
            }
            else if (late) pleasewarn += timeafter - timebefore;
        }
        if (res <= 0)
        {
            sys_sockerror("netsend");
            fail = 1;
            break;
        }
        else
        {
            sent += res;
            bp += res;
        }
    }
    done:
    if (!x->x_bin)
    {
        t_freebytes(buf, length);
        binbuf_free(b);
    }
    return (fail);
}