source: roaraudio/roard/midi.c @ 2915:80026c7bf0b5

Last change on this file since 2915:80026c7bf0b5 was 2915:80026c7bf0b5, checked in by phi, 15 years ago

set client of stream

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