Line | |
---|
1 | //midi.c: |
---|
2 | |
---|
3 | #include "roard.h" |
---|
4 | |
---|
5 | int midi_init (void) { |
---|
6 | int i; |
---|
7 | char * files[] = { |
---|
8 | "/dev/console", |
---|
9 | #ifdef __linux__ |
---|
10 | "/dev/tty0", |
---|
11 | "/dev/vc/0", |
---|
12 | #endif |
---|
13 | NULL |
---|
14 | }; |
---|
15 | |
---|
16 | g_console = -1; |
---|
17 | |
---|
18 | for (i = 0; files[i] != NULL; i++) { |
---|
19 | if ( (g_console = open(files[i], O_WRONLY|O_NOCTTY, 0)) != -1 ) |
---|
20 | break; |
---|
21 | } |
---|
22 | |
---|
23 | if ( g_console != -1 ) { |
---|
24 | return 0; |
---|
25 | } else { |
---|
26 | return -1; |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | int midi_free (void) { |
---|
31 | if ( g_console != -1 ) |
---|
32 | close(g_console); |
---|
33 | return 0; |
---|
34 | } |
---|
35 | |
---|
36 | int midi_cb_play(float t, float freq, int override) { |
---|
37 | /* |
---|
38 | #define MIDI_CB_NOOVERRIDE 0 |
---|
39 | #define MIDI_CB_OVERRIDE 1 |
---|
40 | */ |
---|
41 | return -1; |
---|
42 | } |
---|
43 | |
---|
44 | int midi_cb_update (void) { |
---|
45 | if ( g_midi_cb_stoptime <= g_pos ) |
---|
46 | midi_cb_stop(); |
---|
47 | |
---|
48 | return 0; |
---|
49 | } |
---|
50 | |
---|
51 | int midi_cb_start(float freq) { |
---|
52 | // On linux this uses ioctl KIOCSOUND |
---|
53 | #ifdef __linux__ |
---|
54 | if ( g_console == -1 ) |
---|
55 | return -1; |
---|
56 | |
---|
57 | if ( ioctl(g_console, KIOCSOUND, (int)(1193180.0/freq)) == -1 ) |
---|
58 | return -1; |
---|
59 | |
---|
60 | return 0; |
---|
61 | #else |
---|
62 | return -1; |
---|
63 | #endif |
---|
64 | } |
---|
65 | |
---|
66 | int midi_cb_stop (void) { |
---|
67 | #ifdef __linux__ |
---|
68 | return midi_cb_start(0); |
---|
69 | #else |
---|
70 | return -1; |
---|
71 | #endif |
---|
72 | } |
---|
73 | |
---|
74 | //ll |
---|
Note: See
TracBrowser
for help on using the repository browser.