source: roaraudio/roard/midi.c @ 1750:e1745c2a2f8c

Last change on this file since 1750:e1745c2a2f8c was 1485:9030423a497c, checked in by phi, 15 years ago

console beeper only works with POSIX file IO

File size: 2.4 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
27int midi_init (void) {
28#ifdef ROAR_HAVE_IO_POSIX
29 int i;
30 char * files[] = {
31                   "/dev/console",
32#ifdef __linux__
33                   "/dev/tty0",
34                   "/dev/vc/0",
35#endif
36                   NULL
37                  };
38
39 g_console          = -1;
40 g_midi_cb_stoptime = 0;
41 g_midi_cb_playing  = 0;
42
43 for (i = 0; files[i] != NULL; i++) {
44  if ( (g_console = open(files[i], O_WRONLY|O_NOCTTY, 0)) != -1 )
45   break;
46 }
47
48 if ( g_console != -1 ) {
49  return 0;
50 } else {
51  return -1;
52 }
53#else
54 return -1;
55#endif
56}
57
58int midi_free (void) {
59#ifdef ROAR_HAVE_IO_POSIX
60 if ( g_console != -1 )
61  close(g_console);
62 return 0;
63#else
64 return -1;
65#endif
66}
67
68int midi_cb_play(float t, float freq, int override) {
69 float samples_per_sec /* S/s */ = g_sa->rate * g_sa->channels;
70
71/*
72#define MIDI_CB_NOOVERRIDE 0
73#define MIDI_CB_OVERRIDE   1
74*/
75 if ( g_midi_cb_playing && override != MIDI_CB_OVERRIDE )
76  return -1;
77
78 g_midi_cb_stoptime = ROAR_MATH_OVERFLOW_ADD(g_pos, samples_per_sec*t);
79 midi_cb_start(freq);
80 g_midi_cb_playing = 1;
81
82 return 0;
83}
84
85int midi_cb_update (void) {
86 if ( !g_midi_cb_playing )
87  return 0;
88
89 if ( g_midi_cb_stoptime <= g_pos )
90  midi_cb_stop();
91
92 return 0;
93}
94
95int midi_cb_start(float freq) {
96// On linux this uses ioctl KIOCSOUND
97#ifdef __linux__
98 if ( g_console == -1 )
99  return -1;
100
101 if ( ioctl(g_console, KIOCSOUND, freq == 0 ? 0 : (int)(1193180.0/freq)) == -1 )
102  return -1;
103
104 return 0;
105#else
106 return -1;
107#endif
108}
109
110int midi_cb_stop (void) {
111#ifdef __linux__
112 g_midi_cb_playing = 0;
113 return midi_cb_start(0);
114#else
115 return -1;
116#endif
117}
118
119//ll
Note: See TracBrowser for help on using the repository browser.