source: roaraudio/roard/midi.c @ 2487:10020ba41793

Last change on this file since 2487:10020ba41793 was 2487:10020ba41793, checked in by phi, 15 years ago

support to disable CB completly

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