Пример #1
0
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);
    }
}
Пример #2
0
static void netrec_socketreceiver_read(t_netrec_socketreceiver *x, int fd)
{
    if (x->sr_udp)   /* UDP ("datagram") socket protocol */
    	netrec_socketreceiver_getudp(x, fd);
    else  /* TCP ("streaming") socket protocol */
    {
		char *semi;
		int readto =
			(x->sr_inhead >= x->sr_intail ? INBUFSIZE : x->sr_intail-1);
		int ret;

		t_netrec *y = x->sr_owner;

		y->x_sock_fd = fd;

    			/* the input buffer might be full.  If so, drop the whole thing */
		if (readto == x->sr_inhead)
		{
    			fprintf(stderr, "netrec: dropped message");
    			x->sr_inhead = x->sr_intail = 0;
    			readto = INBUFSIZE;
		}
		else
		{
			ret = recv(fd, x->sr_inbuf + x->sr_inhead,
	    		readto - x->sr_inhead, 0);
			if (ret < 0)
			{
				sys_sockerror("recv");
	    		if (x->sr_notifier) (*x->sr_notifier)(x->sr_owner);
	    		sys_rmpollfn(fd);
	    		sys_closesocket(fd);
			}
			else if (ret == 0)
			{
	    		post("netrec: connection closed on socket %d", fd);
				if (x->sr_notifier) (*x->sr_notifier)(x->sr_owner);
	    		sys_rmpollfn(fd);
	    		sys_closesocket(fd);
			}
			else
			{
    			x->sr_inhead += ret;
    			if (x->sr_inhead >= INBUFSIZE) x->sr_inhead = 0;
    			while (netrec_socketreceiver_doread(x))
				{
					outlet_setstacklim();
					if (x->sr_socketreceivefn)
		    			(*x->sr_socketreceivefn)(x->sr_owner, inbinbuf);
    				else binbuf_eval(inbinbuf, 0, 0, 0);
 	    		}
			}
		}
    }
}
Пример #3
0
static void netserver_socketreceiver_read(t_netserver_socketreceiver *x, int fd)
{
   char *semi;
   int readto = (x->sr_inhead >= x->sr_intail ? INBUFSIZE : x->sr_intail-1);
   int ret;

   t_netserver *y = x->sr_owner;

   y->x_sock_fd = fd;

   /* the input buffer might be full.  If so, drop the whole thing */
   if (readto == x->sr_inhead)
   {
	  if (y->x_log_pri >= LOG_ERR)
		  post("netserver: dropped message");
	  x->sr_inhead = x->sr_intail = 0;
	  readto = INBUFSIZE;
   }
   else
   {
	  ret = recv(fd, x->sr_inbuf + x->sr_inhead,
				 readto - x->sr_inhead, 0);
	  if (ret < 0)
	  {
		 sys_sockerror("recv");
		 if (x->sr_notifier) (*x->sr_notifier)(x->sr_owner);
		 sys_rmpollfn(fd);
		 sys_closesocket(fd);
	  }
	  else if (ret == 0)
	  {
		 if (y->x_log_pri >= LOG_NOTICE) 
			post("netserver: << connection closed on socket %d", fd);
		 if (x->sr_notifier) (*x->sr_notifier)(x->sr_owner);
		 sys_rmpollfn(fd);
		 sys_closesocket(fd);
	  }
	  else
	  {
		 x->sr_inhead += ret;
		 if (x->sr_inhead >= INBUFSIZE) x->sr_inhead = 0;
		 while (netserver_socketreceiver_doread(x))
		 {
			outlet_setstacklim();
			if (x->sr_socketreceivefn)
			   (*x->sr_socketreceivefn)(x->sr_owner, inbinbuf);
			else binbuf_eval(inbinbuf, 0, 0, 0);
		 }
	  }
   }
}
Пример #4
0
    /* take the scheduler forward one DSP tick, also handling clock timeouts */
void sched_tick(double next_sys_time)
{
    int countdown = 5000;
    while (clock_setlist && clock_setlist->c_settime < next_sys_time)
    {
        t_clock *c = clock_setlist;
        sys_time = c->c_settime;
        clock_unset(clock_setlist);
        outlet_setstacklim();
        (*c->c_fn)(c->c_owner);
        if (!countdown--)
        {
            countdown = 5000;
            sys_pollgui();
        }
        if (sys_quit)
            return;
    }
    sys_time = next_sys_time;
    dsp_tick();
    sched_diddsp++;
}
Пример #5
0
/* take the scheduler forward one DSP tick, also handling clock timeouts */
void sched_tick( void)
{
    double next_sys_time = pd_this->pd_systime + sys_time_per_dsp_tick;
    int countdown = 5000;
    while (pd_this->pd_clock_setlist &&
            pd_this->pd_clock_setlist->c_settime < next_sys_time)
    {
        t_clock *c = pd_this->pd_clock_setlist;
        pd_this->pd_systime = c->c_settime;
        clock_unset(pd_this->pd_clock_setlist);
        outlet_setstacklim();
        (*c->c_fn)(c->c_owner);
        if (!countdown--)
        {
            countdown = 5000;
            sys_pollgui();
        }
        if (sys_quit)
            return;
    }
    pd_this->pd_systime = next_sys_time;
    dsp_tick();
    sched_diddsp++;
}
Пример #6
0
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");
    	}
    }
}
Пример #7
0
static void sys_dispatchnextmidiin( void)
{
    static t_midiparser parser[MAXMIDIINDEV], *parserp;
    int portno = midi_inqueue[midi_intail].q_portno,
    	byte = midi_inqueue[midi_intail].q_byte1;
    if (!midi_inqueue[midi_intail].q_onebyte)
    	bug("sys_dispatchnextmidiin");
    if (portno < 0 || portno >= MAXMIDIINDEV)
    	bug("sys_dispatchnextmidiin 2");
    parserp = parser + portno;
    outlet_setstacklim();
    
    if (byte >= 0xf8)
    	inmidi_realtimein(portno, byte);
    else
    {
    	inmidi_byte(portno, byte);
	if (byte & 0x80)
	{
	    if (byte == MIDITUNEREQUEST || byte == MIDIRESERVED1 ||
	    	byte == MIDIRESERVED2)
	    	    parserp->mp_status = 0;
	    else if (byte == MIDISTARTSYSEX)
	    {
	    	inmidi_sysex(portno, byte);
	    	parserp->mp_status = byte;
	    }
	    else if (byte == MIDIENDSYSEX)
	    {
	    	inmidi_sysex(portno, byte);
	    	parserp->mp_status = 0;
	    }
	    else
	    {
	    	parserp->mp_status = byte;
	    }
	    parserp->mp_gotbyte1 = 0;
	}
	else
	{
	    int cmd = (parserp->mp_status >= 0xf0 ? parserp->mp_status :
	    	(parserp->mp_status & 0xf0));
	    int chan = (parserp->mp_status & 0xf);
	    int byte1 = parserp->mp_byte1, gotbyte1 = parserp->mp_gotbyte1;
	    switch (cmd)
	    {
	    case MIDINOTEOFF:
		if (gotbyte1)
		    inmidi_noteon(portno, chan, byte1, 0),
			parserp->mp_gotbyte1 = 0;
		else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
		break;
	    case MIDINOTEON:
		if (gotbyte1)
		    inmidi_noteon(portno, chan, byte1, byte),
			parserp->mp_gotbyte1 = 0;
		else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
		break;
	    case MIDIPOLYTOUCH:
		if (gotbyte1)
		    inmidi_polyaftertouch(portno, chan, byte1, byte),
			parserp->mp_gotbyte1 = 0;
		else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
		break;
	    case MIDICONTROLCHANGE:
		if (gotbyte1)
		    inmidi_controlchange(portno, chan, byte1, byte),
			parserp->mp_gotbyte1 = 0;
		else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
		break;
	    case MIDIPROGRAMCHANGE:
		inmidi_programchange(portno, chan, byte);
		break;
	    case MIDICHANNELTOUCH:
		inmidi_aftertouch(portno, chan, byte);
		break;
	    case MIDIPITCHBEND:
		if (gotbyte1)
		    inmidi_pitchbend(portno, chan, ((byte << 7) + byte1)),
			parserp->mp_gotbyte1 = 0;
		else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
		break;
    	    case MIDISTARTSYSEX:
	    	inmidi_sysex(portno, byte);
		break;
		
		/* other kinds of messages are just dropped here.  We'll
		need another status byte before we start letting MIDI in
		again (no running status across "system" messages). */
	    case MIDITIMECODE:     /* 1 data byte*/
	    	break;
	    case MIDISONGPOS:       /* 2 */
	    	break;
	    case MIDISONGSELECT:    /* 1 */
	    	break;
	    }
	}
    }  
    midi_intail  = (midi_intail + 1 == MIDIQSIZE ? 0 : midi_intail + 1);
}