midiEngine_t.c
// return value
// 0: caller should sleep
// 1: did some work
return value
0: caller should sleep
1: did some work
return value 0 : caller should sleep 1 : did some work
int midiEngine_run(midiEngine_t* self){
  int retVal = 0;
  while (1){
    char c;
    int n = read(self->fd, (void*)&c, 1);
    if (n < -1){
      fprintf(stderr, "MIDI read: IO error %i\n", n);
      exit(EXIT_FAILURE);
    }
    if (n < 1)
      goto breakReadDone;
    retVal = 1;
    if (self->msgInbound == NULL)
      self->msgInbound = midimsg_new(32);
    if (c == 0xF0)
      midimsg_clear(self->msgInbound);
    midimsg_add(self->msgInbound, 1, (int)c);
    if (c == 0xF7){
      midimsg_queuePush(self->queueInbound, self->msgInbound);
      self->msgInbound = NULL;
    }    
  }
 breakReadDone:
  if (!midimsg_queueIsEmpty(self->queueOutbound)){
    midimsg_t* m = midimsg_queuePop(self->queueOutbound);
    midimsg_send(m, self->fd);
    midimsg_delete(m);
    retVal = true;
  }
  return retVal;
}
int midiEngine_run ( midiEngine_t * self ) { int retVal = 0 ; while ( 1 ) { char c ; int n = read ( self -> fd , ( void * ) & c , 1 ) ; if ( n < -1 ) { fprintf ( stderr , " \n " , n ) ; exit ( EXIT_FAILURE ) ; } if ( n < 1 ) goto breakReadDone ; retVal = 1 ; if ( self -> msgInbound == NULL ) self -> msgInbound = midimsg_new ( 32 ) ; if ( c == 0xF0 ) midimsg_clear ( self -> msgInbound ) ; midimsg_add ( self -> msgInbound , 1 , ( int ) c ) ; if ( c == 0xF7 ) { midimsg_queuePush ( self -> queueInbound , self -> msgInbound ) ; self -> msgInbound = NULL ; } } breakReadDone : if ( ! midimsg_queueIsEmpty ( self -> queueOutbound ) ) { midimsg_t * m = midimsg_queuePop ( self -> queueOutbound ) ; midimsg_send ( m , self -> fd ) ; midimsg_delete ( m ) ; retVal = true ; } return retVal ; }
return value
0: caller should sleep
1: did some work
return value 0 : caller should sleep 1 : did some work
// === read all available data === /*count*/ /*data*/ // === write one message === //printf("sending "); midimsg_dump(m);