Changeset 1863:76178443318a in roaraudio


Ignore:
Timestamp:
05/23/09 15:49:21 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

do very ruimentary MIDI analysis, need to implement the protocol next

Location:
roard
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • roard/include/midi.h

    r1858 r1863  
    7575}; 
    7676 
     77struct { 
     78 struct roar_buffer * buf; 
     79} g_midi_mess; 
    7780 
    7881struct { 
     
    105108int midi_conv_mes2midi (int id); 
    106109 
     110int midi_new_bufmes    (struct roar_buffer ** buf, struct midi_message ** mes); 
     111 
    107112// bridges: 
    108113int midi_check_bridge  (int id); 
  • roard/midi.c

    r1862 r1863  
    3939 } 
    4040 
     41 g_midi_mess.buf = NULL; 
     42 
    4143 return 0; 
    4244} 
     
    151153 
    152154int midi_conv_midi2mes (int id) { 
    153  return -1; 
     155 unsigned char * data; 
     156 struct roar_stream        *   s; 
     157 struct roar_stream_server *  ss; 
     158 struct roar_buffer        * buf = NULL; 
     159 struct midi_message       * mes = NULL; 
     160 size_t need = 0, have = 0; 
     161 int alive = 1; 
     162 
     163 if ( g_streams[id] == NULL ) 
     164  return -1; 
     165 
     166 ROAR_DBG("midi_conv_midi2mes(id=%i) = ?", id); 
     167 
     168 s = ROAR_STREAM(ss = g_streams[id]); 
     169 
     170 while (ss->buffer != NULL && alive) { 
     171  if ( roar_buffer_get_data(ss->buffer, (void**)&data) == -1 ) { 
     172   alive = 0; 
     173   continue; 
     174  } 
     175 
     176  if ( roar_buffer_get_len(ss->buffer, &have) == -1 ) { 
     177   alive = 0; 
     178   continue; 
     179  } 
     180 
     181  while (have && alive) { 
     182   printf("%.2x=", *data); 
     183   if ( *data & 0x80 ) { 
     184    need = 0; 
     185    printf("S\n"); 
     186    if ( midi_new_bufmes(&buf, &mes) == -1 ) { 
     187     alive = 0; 
     188     continue; 
     189    } 
     190   } else { 
     191    printf("D\n"); 
     192    if ( need ) 
     193     need--; 
     194   } 
     195   data++; 
     196   have--; 
     197  } 
     198 
     199  if ( !have ) { 
     200   roar_buffer_next(&(ss->buffer)); 
     201  } 
     202 
     203  if ( need && buf != NULL ) { 
     204   roar_buffer_free(buf); 
     205   buf = NULL; 
     206  } else if ( buf != NULL ) { 
     207   if ( g_midi_mess.buf == NULL ) { 
     208    g_midi_mess.buf = buf; 
     209   } else { 
     210    roar_buffer_add(g_midi_mess.buf, buf); 
     211   } 
     212 
     213   buf = NULL; 
     214  } 
     215 } 
     216 
     217 return 0; 
    154218} 
    155219 
    156220int midi_conv_mes2midi (int id) { 
    157221 return -1; 
     222} 
     223 
     224int midi_new_bufmes    (struct roar_buffer ** buf, struct midi_message ** mes) { 
     225 if ( buf == NULL || mes == NULL ) 
     226  return -1; 
     227 
     228 *buf = *mes = NULL; 
     229 
     230 if ( roar_buffer_new(buf, sizeof(struct midi_message)) == -1 ) 
     231  return -1; 
     232 
     233 if ( roar_buffer_get_data(*buf, (void**)mes) == -1 ) { 
     234  roar_buffer_free(*buf); 
     235  *buf = *mes = NULL; 
     236  return -1; 
     237 } 
     238 
     239 memset((void*)*mes, 0, sizeof(struct midi_message)); 
     240 
     241 (*mes)->type = MIDI_TYPE_NONE; 
     242 
     243 return 0; 
    158244} 
    159245 
Note: See TracChangeset for help on using the changeset viewer.