source: roaraudio/roard/midi.c @ 1895:75c65d7cfe60

Last change on this file since 1895:75c65d7cfe60 was 1895:75c65d7cfe60, checked in by phi, 15 years ago

also count ticks on output streams

File size: 16.1 KB
RevLine 
[169]1//midi.c:
2
[668]3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
[169]25#include "roard.h"
26
[1751]27#if defined(ROAR_HAVE_IO_POSIX) && !defined(ROAR_TARGET_WIN32)
28#define _HAVE_CONSOLE
29#endif
30
[185]31int midi_init (void) {
[1843]32
33 if ( midi_cb_init() == -1 ) {
34  ROAR_WARN("Can not initialize MIDI subsystem component CB");
35 }
36
[1848]37 if ( midi_clock_init() == -1 ) {
38  ROAR_WARN("Can not initialize MIDI subsystem component clock");
39 }
40
[1863]41 g_midi_mess.buf = NULL;
42
[1843]43 return 0;
44}
[1848]45
[1843]46int midi_free (void) {
47 return midi_cb_free();
48}
49
50int midi_update(void) {
[1848]51
[1850]52 if ( g_midi_clock.stream != -1 )
53  midi_check_bridge(g_midi_clock.stream);
[1848]54
[1843]55 return midi_cb_update();
56}
57
[1855]58int midi_reinit(void) {
[1868]59
60 if ( g_midi_mess.buf != NULL )
61  roar_buffer_free(g_midi_mess.buf);
62
63 g_midi_mess.buf = NULL;
64
[1855]65 return 0;
66}
67
[1845]68// STREAMS:
69
70int midi_check_stream  (int id) {
[1846]71 struct roar_stream        *   s;
72 struct roar_stream_server *  ss;
[1858]73 struct roar_buffer        *   b;
74 char                      * buf;
75 ssize_t                     len;
[1859]76 int                           i;
[1846]77
78 if ( g_streams[id] == NULL )
79  return -1;
80
81 ROAR_DBG("midi_check_stream(id=%i) = ?", id);
82
83 s = ROAR_STREAM(ss = g_streams[id]);
84
[1848]85 if ( s->dir == ROAR_DIR_BRIDGE )
86  return midi_check_bridge(id);
87
[1846]88 switch (s->info.codec) {
[1858]89  case ROAR_CODEC_MIDI:
90   break;
91  default:
92    streams_delete(id);
93    return -1;
94 }
95
96 if ( roar_buffer_new(&b, MIDI_READ_SIZE) == -1 ) {
97  ROAR_ERR("midi_check_stream(*): Can not alloc buffer space!");
98  ROAR_DBG("midi_check_stream(*) = -1");
99  return -1;
100 }
101
102 roar_buffer_get_data(b, (void **)&buf);
103
104 if ( (len = stream_vio_s_read(ss, buf, MIDI_READ_SIZE)) < 1 ) {
105  streams_delete(id);
[1862]106  roar_buffer_free(b);
[1858]107  return -1;
108 }
109
110 roar_buffer_set_len(b, len);
111
[1859]112 if ( stream_add_buffer(id, b) == -1 ) {
113  roar_buffer_free(b);
114  streams_delete(id);
115  return -1;
116 }
117
118 for (i = 0; i < ROAR_STREAMS_MAX; i++) {
119  if ( g_streams[i] != NULL && ROAR_STREAM(g_streams[i])->pos_rel_id == id ) {
120   if ( ROAR_STREAM(g_streams[i])->dir == ROAR_DIR_THRU ) {
121    if ( stream_vio_write(i, buf, len) != len ) {
122     streams_delete(i);
123    }
124   }
[1858]125  }
[1859]126 }
[1858]127
128 switch (s->info.codec) {
129  case ROAR_CODEC_MIDI:
130    return midi_conv_midi2mes(id);
131   break;
[1846]132  default:
133    streams_delete(id);
134    return -1;
135 }
136
137 return 0;
[1845]138}
[1846]139
[1845]140int midi_send_stream   (int id) {
[1846]141 struct roar_stream        *   s;
142 struct roar_stream_server *  ss;
143
144 if ( g_streams[id] == NULL )
145  return -1;
146
147 ROAR_DBG("midi_send_stream(id=%i) = ?", id);
148
149 s = ROAR_STREAM(ss = g_streams[id]);
150
151 switch (s->info.codec) {
[1877]152  case ROAR_CODEC_MIDI:
153    return midi_conv_mes2midi(id);
154   break;
[1846]155  default:
156    streams_delete(id);
157    return -1;
158 }
159
160 return 0;
[1845]161}
162
[1858]163int midi_conv_midi2mes (int id) {
[1863]164 unsigned char * data;
165 struct roar_stream        *   s;
166 struct roar_stream_server *  ss;
167 struct roar_buffer        * buf = NULL;
168 struct midi_message       * mes = NULL;
[1879]169 size_t need = 0, have = 0, last_have = 0, old_have = 0;
[1863]170 int alive = 1;
171
172 if ( g_streams[id] == NULL )
173  return -1;
174
175 ROAR_DBG("midi_conv_midi2mes(id=%i) = ?", id);
176
177 s = ROAR_STREAM(ss = g_streams[id]);
178
179 while (ss->buffer != NULL && alive) {
180  if ( roar_buffer_get_data(ss->buffer, (void**)&data) == -1 ) {
181   alive = 0;
182   continue;
183  }
184
185  if ( roar_buffer_get_len(ss->buffer, &have) == -1 ) {
186   alive = 0;
187   continue;
188  }
[1879]189  old_have = have;
[1863]190
191  while (have && alive) {
192   if ( *data & 0x80 ) {
[1865]193    if ( buf != NULL ) {
[1866]194     midi_add_buf(id, buf);
[1865]195     buf = NULL;
196    }
197
[1879]198    last_have = have;
199
[1863]200    need = 0;
201    if ( midi_new_bufmes(&buf, &mes) == -1 ) {
202     alive = 0;
203     continue;
204    }
[1865]205
206    if (*data == MIDI_TYPE_CLOCK_TICK || *data == MIDI_TYPE_CLOCK_START || *data == MIDI_TYPE_CLOCK_STOP ) {
207     mes->type = *data;
[1891]208
209     if ( *data == MIDI_TYPE_CLOCK_TICK ) {
210      s->pos = ROAR_MATH_OVERFLOW_ADD(s->pos, 1);
211     }
[1865]212    } else {
213     mes->type    = *data & 0xF0;
214     mes->channel = *data & 0x0F;
215     switch (*data & 0xF0) {
216      case MIDI_TYPE_NOTE_ON:
217      case MIDI_TYPE_NOTE_OFF:
218        need = 2;
219       break;
220      case MIDI_TYPE_PA:
221        need = 2;
222       break;
223      case MIDI_TYPE_CONTROLER:
224        need = 2;
225       break;
226      case MIDI_TYPE_PROGRAM:
227        need = 1;
228       break;
229      case MIDI_TYPE_MA:
230        need = 1;
231       break;
232      case MIDI_TYPE_PB:
233      case MIDI_TYPE_SYSEX:
234        need = 1;
235       break;
236     }
237    }
238
[1863]239   } else {
[1871]240
241    if ( mes == NULL ) {
242     ROAR_WARN("midi_conv_midi2mes(id=%i): Lost sync.", id);
243     data++;
244     have--;
245     continue;
246    }
247
248    switch (mes->type) {
[1873]249      case MIDI_TYPE_NOTE_ON:
250      case MIDI_TYPE_NOTE_OFF:
[1881]251       if ( need == 2 ) {
252        roar_midi_note_from_midiid(&(mes->d.note), *data);
253       }
[1874]254      case MIDI_TYPE_PA:
255      case MIDI_TYPE_CONTROLER:
[1873]256        if ( need == 2 ) {
257         mes->kk = *data;
258        } else {
259         mes->vv = *data;
260        }
261       break;
262      case MIDI_TYPE_PROGRAM:
263      case MIDI_TYPE_MA:
[1874]264        mes->vv = *data;
265       break;
[1873]266      case MIDI_TYPE_PB:
267      case MIDI_TYPE_SYSEX:
[1874]268        ROAR_WARN("midi_conv_midi2mes(id=%i): Message of Type 0x%.2X (PB or SysEx) not yet supported", id, mes->type);
[1873]269       break;
[1871]270    }
271
[1863]272    if ( need )
273     need--;
[1893]274
275    if ( !need ) {
276     switch (mes->type) {
277      case MIDI_TYPE_CONTROLER:
278       switch (mes->kk) {
279        case MIDI_CCE_MAIN_VOL:
280         if ( 516 * mes->vv > 65100 ) { // max volume
281          ss->mixer.mixer[mes->channel] = 65535;
282         } else {
283          ss->mixer.mixer[mes->channel] = 516 * mes->vv;
284         }
285         break;
286       }
287      break;
288     }
289    }
290
[1863]291   }
292   data++;
293   have--;
294  }
295
[1865]296  if ( need ) {
[1879]297   if ( roar_buffer_set_offset(ss->buffer, old_have - last_have) == -1 ) {
298    ROAR_ERR("midi_conv_midi2mes(*): FIXME: BUG!!! Need to restore buffer here with corrected length");
299   }
[1865]300  } else if ( !have ) {
[1863]301   roar_buffer_next(&(ss->buffer));
302  }
303
304  if ( need && buf != NULL ) {
305   roar_buffer_free(buf);
306   buf = NULL;
307  } else if ( buf != NULL ) {
[1866]308   midi_add_buf(id, buf);
[1863]309   buf = NULL;
310  }
311 }
312
313 return 0;
[1858]314}
315
[1877]316#define _nb  len++; *(d++)
[1858]317int midi_conv_mes2midi (int id) {
[1877]318 struct roar_stream        *   s;
319 struct roar_stream_server *  ss;
320 struct roar_buffer        * buf = g_midi_mess.buf;
321 struct midi_message       * mes = NULL;
322 unsigned char               data[3];
323 unsigned char             * d;
324 int                         len;
325
326 if ( g_streams[id] == NULL )
327  return -1;
328
329 ROAR_DBG("midi_conv_mes2midi(id=%i) = ?", id);
330
331 s = ROAR_STREAM(ss = g_streams[id]);
332
333 while (buf != NULL) {
334  if ( roar_buffer_get_data(buf, (void**)&mes) == -1 ) {
335   return -1;
336  }
337
338  if (mes->type == MIDI_TYPE_CLOCK_TICK || mes->type == MIDI_TYPE_CLOCK_START || mes->type == MIDI_TYPE_CLOCK_STOP ) {
339   if ( stream_vio_s_write(ss, &(mes->type), 1) != 1 ) {
340    streams_delete(id);
341    return -1;
342   }
343  } else {
344   len = 0;
345   d   = data;
346
347   _nb = (mes->type & 0xF0) | (mes->channel & 0x0F);
348
349   switch (mes->type) {
350    case MIDI_TYPE_NOTE_ON:
351    case MIDI_TYPE_NOTE_OFF:
352    case MIDI_TYPE_PA:
353    case MIDI_TYPE_CONTROLER:
354      _nb = mes->kk;
355      _nb = mes->vv;
356     break;
357    case MIDI_TYPE_PROGRAM:
358    case MIDI_TYPE_MA:
359      _nb = mes->vv;
360     break;
361    case MIDI_TYPE_PB:
362    case MIDI_TYPE_SYSEX:
363     break;
[1895]364    case MIDI_TYPE_CLOCK_TICK:
365      s->pos = ROAR_MATH_OVERFLOW_ADD(s->pos, 1);
366     break;
[1877]367   }
368
369   if ( stream_vio_s_write(ss, data, len) != len ) {
370    streams_delete(id);
371    return -1;
372   }
373  }
374
375  if ( roar_buffer_get_next(buf, &buf) == -1 )
376   buf = NULL;
377 }
378
379 return 0;
[1858]380}
[1877]381#undef _nb
[1858]382
[1863]383int midi_new_bufmes    (struct roar_buffer ** buf, struct midi_message ** mes) {
384 if ( buf == NULL || mes == NULL )
385  return -1;
386
[1867]387 *buf = (void*)(*mes = NULL);
[1863]388
389 if ( roar_buffer_new(buf, sizeof(struct midi_message)) == -1 )
390  return -1;
391
392 if ( roar_buffer_get_data(*buf, (void**)mes) == -1 ) {
393  roar_buffer_free(*buf);
[1867]394  *buf = (void*)(*mes = NULL);
[1863]395  return -1;
396 }
397
398 memset((void*)*mes, 0, sizeof(struct midi_message));
399
400 (*mes)->type = MIDI_TYPE_NONE;
401
402 return 0;
403}
404
[1866]405int midi_add_buf       (int id, struct roar_buffer * buf) {
[1869]406 struct midi_message * mes;
407
[1866]408 if ( id == -1 || buf == NULL )
409  return -1;
410
[1872]411 if ( roar_buffer_get_data(buf, (void**)&mes) == -1 )
[1869]412  return -1;
413
[1878]414 ROAR_DBG("midi_add_buf(id=%i, buf=%p) = ?", id, buf);
415 ROAR_DBG("midi_add_buf(*): MIDI Message of Type 0x%.2X", mes->type);
416 ROAR_DBG("midi_add_buf(*): Channel: %i", mes->channel);
417 ROAR_DBG("midi_add_buf(*): flags=0x%.2X", mes->flags);
418 ROAR_DBG("midi_add_buf(*): kk=0x%.2X, vv=0x%.2X", mes->kk, mes->vv);
[1869]419
[1866]420 if ( g_midi_mess.buf == NULL ) {
421  g_midi_mess.buf = buf;
422 } else {
423  roar_buffer_add(g_midi_mess.buf, buf);
424 }
425
426 return 0;
427}
428
[1848]429// bridges:
430int midi_check_bridge  (int id) {
[1851]431
[1860]432 ROAR_DBG("midi_check_bridge(id=%i) = ?", id);
[1851]433
434 if ( id == g_midi_clock.stream ) {
435  midi_clock_tick();
436
437  return 0;
438 }
439
[1848]440 return -1;
441}
442
443// clock:
444
445int midi_clock_init (void) {
446 struct roar_stream * s;
447 struct roar_stream_server * ss;
448
[1850]449 if ( (g_midi_clock.stream = streams_new()) == -1 ) {
[1848]450  ROAR_WARN("Error while initializing MIDI subsystem component clock");
451  return -1;
452 }
453
[1850]454 midi_vio_set_dummy(g_midi_clock.stream);
[1848]455
[1850]456 streams_get(g_midi_clock.stream, &ss);
[1848]457 s = ROAR_STREAM(ss);
458
459 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
460
[1850]461 s->pos_rel_id    =  g_midi_clock.stream;
[1848]462
463 s->info.codec    =  ROAR_CODEC_MIDI;
464 ss->codec_orgi   =  ROAR_CODEC_MIDI;
465
466 s->info.channels =  0;
467 s->info.rate     = MIDI_RATE;
468 s->info.bits     =  8;
469
[1850]470 if ( streams_set_dir(g_midi_clock.stream, ROAR_DIR_BRIDGE, 1) == -1 ) {
[1848]471  ROAR_WARN("Error while initializing MIDI subsystem component clock");
472  return -1;
473 }
474
[1850]475 streams_set_name(g_midi_clock.stream, "MIDI Clock");
[1848]476
[1850]477 streams_set_flag(g_midi_clock.stream, ROAR_FLAG_PRIMARY);
478 streams_set_flag(g_midi_clock.stream, ROAR_FLAG_SYNC);
[1848]479
[1851]480 midi_clock_set_bph(3600); // one tick per sec
481
482 return 0;
483}
484
485int midi_clock_set_bph (uint_least32_t bph) {
486 uint_least32_t sph = g_sa->rate/2 * 75 * g_sa->channels; // samples per houre
487
488 g_midi_clock.bph  = bph;
489
490 g_midi_clock.spt  = sph/bph;
491
492 g_midi_clock.nt   = ROAR_MATH_OVERFLOW_ADD(g_pos, g_midi_clock.spt);
493
494 return 0;
495}
496
497int midi_clock_tick (void) {
[1875]498 struct roar_buffer  * buf;
499 struct midi_message * mes;
[1888]500 struct roar_stream_server * ss;
[1851]501 unsigned int diff;
502
[1888]503 if ( streams_get(g_midi_clock.stream, &ss) == -1 ) {
504  ROAR_ERR("midi_clock_tick(void): Something very BAD happend: can not get stream object of my own stream!");
505  g_midi_clock.stream = -1;
506  ROAR_WARN("midi_clock_tick(void): Disabled MIDI Clock");
507  return -1;
508 }
509
[1851]510 while ( g_pos >= g_midi_clock.nt ) {
511  diff = g_pos - g_midi_clock.nt;
[1860]512  ROAR_DBG("midi_clock_tick(void): g_pos is %u samples (%5.2f%%) ahead of nt.", diff, (float)diff/g_midi_clock.spt);
[1851]513
514  g_midi_clock.nt   = ROAR_MATH_OVERFLOW_ADD(g_midi_clock.nt, g_midi_clock.spt);
515
516  if ( streams_get_flag(g_midi_clock.stream, ROAR_FLAG_SYNC) ) {
[1860]517   ROAR_DBG("midi_clock_tick(void): TICK! (nt=%lu)", g_midi_clock.nt);
[1875]518   if ( midi_new_bufmes(&buf, &mes) == -1 ) {
519    ROAR_ERR("midi_clock_tick(void): Can not create Clock-Tick-Message");
520   }
521
522   mes->type = MIDI_TYPE_CLOCK_TICK;
523
524   if ( midi_add_buf(g_midi_clock.stream, buf) == -1 ) {
525    ROAR_ERR("midi_clock_tick(void): Can not add Clock-Tick-Message");
526    roar_buffer_free(buf);
527    return -1;
528   }
[1888]529
530   ROAR_STREAM(ss)->pos = ROAR_MATH_OVERFLOW_ADD(ROAR_STREAM(ss)->pos, 1);
[1851]531  } else {
[1860]532   ROAR_DBG("midi_clock_tick(void): silent tick. (nt=%lu)", g_midi_clock.nt);
[1851]533  }
534 }
535
[1848]536 return 0;
537}
538
[1845]539// CB:
[1843]540
541int midi_cb_init (void) {
[1751]542#ifdef _HAVE_CONSOLE
[1843]543 struct roar_stream * s;
544 struct roar_stream_server * ss;
[185]545 int i;
546 char * files[] = {
547                   "/dev/console",
548#ifdef __linux__
549                   "/dev/tty0",
550                   "/dev/vc/0",
551#endif
552                   NULL
553                  };
554
[1853]555 g_midi_cb.console  = -1;
556 g_midi_cb.stream   = -1;
557 g_midi_cb.stoptime =  0;
558 g_midi_cb.playing  =  0;
[185]559
560 for (i = 0; files[i] != NULL; i++) {
[1853]561  if ( (g_midi_cb.console = open(files[i], O_WRONLY|O_NOCTTY, 0)) != -1 )
[185]562   break;
563 }
564
[1853]565 if ( g_midi_cb.console == -1 )
[1843]566  return -1;
567
[1853]568 if ( (g_midi_cb.stream = streams_new()) == -1 ) {
[1843]569  ROAR_WARN("Error while initializing MIDI subsystem component CB");
570  midi_cb_free();
[187]571  return -1;
572 }
[1843]573
[1853]574 midi_vio_set_dummy(g_midi_cb.stream);
[1848]575
[1853]576 streams_get(g_midi_cb.stream, &ss);
[1843]577 s = ROAR_STREAM(ss);
578
579 memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info));
580
581 s->pos_rel_id    = -1;
582
583 s->info.codec    =  0;
584 ss->codec_orgi   =  0;
585
586 s->info.channels =  1;
587 s->info.rate     = 1193180;
588 s->info.bits     =  8;
589
[1853]590 if ( streams_set_dir(g_midi_cb.stream, ROAR_DIR_BRIDGE, 1) == -1 ) {
[1843]591  ROAR_WARN("Error while initializing MIDI subsystem component CB");
592  midi_cb_free();
593  return -1;
594 }
595
[1853]596 streams_set_name(g_midi_cb.stream, "Console speaker bridge");
[1843]597
[1853]598 streams_set_flag(g_midi_cb.stream, ROAR_FLAG_OUTPUT);
599 streams_set_flag(g_midi_cb.stream, ROAR_FLAG_PRIMARY);
600 streams_set_flag(g_midi_cb.stream, ROAR_FLAG_HWMIXER);
[1885]601 streams_set_flag(g_midi_cb.stream, ROAR_FLAG_MUTE);
[1843]602
603 return 0;
[1485]604#else
[1853]605 g_midi_cb.console  = -1;
606 g_midi_cb.stream   = -1;
[1843]607
[1485]608 return -1;
609#endif
[185]610}
611
[1843]612int midi_cb_free (void) {
[1751]613#ifdef _HAVE_CONSOLE
[1843]614
615 midi_cb_stop();
616
[1853]617 if ( g_midi_cb.stream != -1 )
618  streams_delete(g_midi_cb.stream);
[1843]619
[1853]620 if ( g_midi_cb.console != -1 )
621  close(g_midi_cb.console);
[1843]622
[185]623 return 0;
[1485]624#else
625 return -1;
626#endif
[185]627}
628
629int midi_cb_play(float t, float freq, int override) {
[191]630 float samples_per_sec /* S/s */ = g_sa->rate * g_sa->channels;
631
[189]632/*
633#define MIDI_CB_NOOVERRIDE 0
634#define MIDI_CB_OVERRIDE   1
635*/
[1853]636 if ( g_midi_cb.playing && override != MIDI_CB_OVERRIDE )
[191]637  return -1;
638
[1853]639 g_midi_cb.stoptime = ROAR_MATH_OVERFLOW_ADD(g_pos, samples_per_sec*t);
[191]640 midi_cb_start(freq);
641
642 return 0;
[185]643}
644
[190]645int midi_cb_update (void) {
[1884]646
647 if ( !streams_get_flag(g_midi_cb.stream, ROAR_FLAG_MUTE) ) {
648  if ( midi_cb_readbuf() == -1 )
649   return -1;
650 } else if ( g_midi_cb.playing ) {
651  midi_cb_stop();
652 }
[1882]653
[1853]654 if ( !g_midi_cb.playing )
[192]655  return 0;
656
[1884]657/*
[1853]658 if ( g_midi_cb.stoptime <= g_pos )
[189]659  midi_cb_stop();
[1884]660*/
[189]661
[1882]662 ROAR_DBG("midi_cb_update(void) = ?");
663
[189]664 return 0;
665}
666
[185]667int midi_cb_start(float freq) {
668// On linux this uses ioctl KIOCSOUND
[188]669#ifdef __linux__
[1853]670 if ( g_midi_cb.console == -1 )
[188]671  return -1;
672
[1853]673 if ( ioctl(g_midi_cb.console, KIOCSOUND, freq == 0 ? 0 : (int)(1193180.0/freq)) == -1 )
[188]674  return -1;
675
[1884]676 g_midi_cb.playing = 1;
677
[188]678 return 0;
679#else
[185]680 return -1;
[188]681#endif
[185]682}
683
684int midi_cb_stop (void) {
685#ifdef __linux__
[1884]686 int ret;
687
688 ret = midi_cb_start(0);
[1853]689 g_midi_cb.playing = 0;
[1884]690
691 return ret;
[185]692#else
693 return -1;
694#endif
695}
696
[1882]697int midi_cb_readbuf(void) {
698 struct roar_buffer        * buf = g_midi_mess.buf;
699 struct midi_message       * mes = NULL;
700
701 ROAR_DBG("midi_cb_readbuf(void) = ?");
702
703 while (buf != NULL) {
704  ROAR_DBG("midi_cb_readbuf(void): buf=%p", buf);
705
706  if ( roar_buffer_get_data(buf, (void**)&mes) == -1 ) {
707   return -1;
708  }
709
710  switch (mes->type) {
711   case MIDI_TYPE_NOTE_ON:
712     midi_cb_start(mes->d.note.freq);
713    break;
714   case MIDI_TYPE_NOTE_OFF:
715     midi_cb_stop();
716    break;
[1890]717   case MIDI_TYPE_CONTROLER:
[1894]718     if ( mes->kk == MIDI_CCE_ALL_NOTE_OFF ) /* all note off */
[1890]719      midi_cb_stop();
720    break;
[1882]721  }
722
723  if ( roar_buffer_get_next(buf, &buf) == -1 )
724   buf = NULL;
725 }
726
727 return 0;
728}
729
[1848]730// VIO:
731
732int     midi_vio_set_dummy(int stream) {
733 struct roar_stream_server * ss;
734
735 if ( streams_get(stream, &ss) == -1 )
736  return -1;
737
738 ss->vio.read     = NULL;
739 ss->vio.write    = NULL;
740 ss->vio.lseek    = NULL;
[1849]741 ss->vio.nonblock = (int (*)(struct roar_vio_calls * vio, int state))midi_vio_ok;
742 ss->vio.sync     = (int (*)(struct roar_vio_calls * vio))midi_vio_ok;
[1848]743 ss->vio.ctl      = NULL;
[1849]744 ss->vio.close    = (int (*)(struct roar_vio_calls * vio))midi_vio_ok;
745
746 return 0;
[1848]747}
748
749int     midi_vio_ok(struct roar_vio_calls * vio, ...) {
750 return 0;
751}
752
[169]753//ll
Note: See TracBrowser for help on using the repository browser.