source: roaraudio/roard/midi.c @ 2495:61b6587c286a

Last change on this file since 2495:61b6587c286a was 2489:266b1a6c9683, checked in by phi, 15 years ago

support to disable ssynth

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