1 | //midi.h: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012 |
---|
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, 51 Franklin Street, Fifth Floor, |
---|
22 | * Boston, MA 02110-1301, USA. |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | #ifndef _MIDI_H_ |
---|
27 | #define _MIDI_H_ |
---|
28 | |
---|
29 | #include <roaraudio.h> |
---|
30 | |
---|
31 | // CB has MIDI as dep |
---|
32 | #if defined(ROAR_WITHOUT_DCOMP_MIDI) && !defined(ROAR_WITHOUT_DCOMP_CB) |
---|
33 | #define ROAR_WITHOUT_DCOMP_CB |
---|
34 | #endif |
---|
35 | |
---|
36 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
37 | |
---|
38 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
39 | #ifdef __linux__ |
---|
40 | #include <sys/ioctl.h> |
---|
41 | #include <linux/kd.h> |
---|
42 | #endif |
---|
43 | |
---|
44 | #define MIDI_CB_NOOVERRIDE 0 |
---|
45 | #define MIDI_CB_OVERRIDE 1 |
---|
46 | #endif |
---|
47 | |
---|
48 | #define MIDI_RATE 31250 |
---|
49 | |
---|
50 | // standard MIDI commands: |
---|
51 | #define MIDI_TYPE_NOTE_OFF 0x80 |
---|
52 | #define MIDI_TYPE_NOTE_ON 0x90 |
---|
53 | #define MIDI_TYPE_PA 0xA0 |
---|
54 | #define MIDI_TYPE_CONTROLER 0xB0 |
---|
55 | #define MIDI_TYPE_PROGRAM 0xC0 |
---|
56 | #define MIDI_TYPE_MA 0xD0 |
---|
57 | #define MIDI_TYPE_PB 0xE0 |
---|
58 | #define MIDI_TYPE_SYSEX 0xF0 |
---|
59 | #define MIDI_TYPE_CLOCK_TICK 0xF8 |
---|
60 | #define MIDI_TYPE_CLOCK_START 0xFA |
---|
61 | #define MIDI_TYPE_CLOCK_STOP 0xFC |
---|
62 | |
---|
63 | // RoarAudio MIDI Commands: |
---|
64 | #define MIDI_TYPE_NONE 0x00 |
---|
65 | #define MIDI_TYPE_RAW_PASS 0x10 |
---|
66 | #define MIDI_TYPE_RAW_NOPASS 0x20 |
---|
67 | |
---|
68 | // controller events: |
---|
69 | #define MIDI_CCE_MAIN_VOL 7 |
---|
70 | #define MIDI_CCE_BALANCE 8 |
---|
71 | #define MIDI_CCE_PANORAMA 10 |
---|
72 | #define MIDI_CCE_LOCAL_CONTR 122 |
---|
73 | #define MIDI_CCE_ALL_NOTE_OFF 123 |
---|
74 | |
---|
75 | |
---|
76 | #define MIDI_MES_BUFSIZE 4 |
---|
77 | #define MIDI_READ_SIZE 256 /* this should be big enoth in both cfreq=20..100Hz mode */ |
---|
78 | |
---|
79 | #define MIDI_MFLAG_FREE_DP (1<<0) |
---|
80 | |
---|
81 | #define MIDI_INITED_MAIN 0x01 |
---|
82 | #define MIDI_INITED_CB 0x02 |
---|
83 | #define MIDI_INITED_CLOCK 0x04 |
---|
84 | |
---|
85 | extern struct midi_config { |
---|
86 | int init; |
---|
87 | int inited; |
---|
88 | |
---|
89 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
90 | int init_cb; |
---|
91 | char * console_dev; |
---|
92 | #endif |
---|
93 | } midi_config; |
---|
94 | |
---|
95 | struct midi_message { |
---|
96 | unsigned char type; |
---|
97 | unsigned char channel; |
---|
98 | unsigned char flags; |
---|
99 | unsigned char kk; |
---|
100 | unsigned char vv; |
---|
101 | size_t datalen; |
---|
102 | unsigned char * dataptr; |
---|
103 | union { |
---|
104 | unsigned char ldata[MIDI_MES_BUFSIZE]; |
---|
105 | struct roar_note_octave note; |
---|
106 | } d; |
---|
107 | }; |
---|
108 | |
---|
109 | extern struct midi_state_mess { |
---|
110 | struct roar_buffer * buf; |
---|
111 | } g_midi_mess; |
---|
112 | |
---|
113 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
114 | extern struct midi_state_cb { |
---|
115 | int console; |
---|
116 | int stream; |
---|
117 | uint32_t stoptime; |
---|
118 | int playing; |
---|
119 | } g_midi_cb; |
---|
120 | #endif |
---|
121 | |
---|
122 | extern struct midi_clock { |
---|
123 | int stream; |
---|
124 | uint_least32_t bph; // beats per hour |
---|
125 | uint_least32_t spt; // samples per tick |
---|
126 | uint32_t nt; // time of next tick |
---|
127 | } g_midi_clock; |
---|
128 | |
---|
129 | extern struct midi_mixer { |
---|
130 | int stream; |
---|
131 | } g_midi_mixer; |
---|
132 | |
---|
133 | |
---|
134 | // general midi interface: |
---|
135 | int midi_init_config(void); |
---|
136 | |
---|
137 | int midi_init (void); |
---|
138 | int midi_free (void); |
---|
139 | |
---|
140 | int midi_update(void); |
---|
141 | int midi_reinit(void); |
---|
142 | |
---|
143 | // streams: |
---|
144 | int midi_check_stream (int id); |
---|
145 | int midi_send_stream (int id); |
---|
146 | |
---|
147 | int midi_conv_midi2mes (int id); |
---|
148 | int midi_conv_mes2midi (int id); |
---|
149 | |
---|
150 | int midi_conv_mes2ssynth(void); |
---|
151 | |
---|
152 | int midi_new_bufmes (struct roar_buffer ** buf, struct midi_message ** mes); |
---|
153 | int midi_add_buf (int id, struct roar_buffer ** buf); |
---|
154 | |
---|
155 | // bridges: |
---|
156 | int midi_check_bridge (int id); |
---|
157 | |
---|
158 | // clock: |
---|
159 | int midi_clock_init (void); |
---|
160 | int midi_clock_set_bph (uint_least32_t bph); |
---|
161 | int midi_clock_tick (void); |
---|
162 | |
---|
163 | // cb = console beep |
---|
164 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
165 | int midi_cb_init(void); |
---|
166 | int midi_cb_free(void); |
---|
167 | int midi_cb_play(float t, float freq, int override); |
---|
168 | int midi_cb_update (void); |
---|
169 | int midi_cb_start(float freq); |
---|
170 | int midi_cb_stop (void); |
---|
171 | int midi_cb_readbuf(void); |
---|
172 | #endif |
---|
173 | |
---|
174 | // dummys: |
---|
175 | int midi_vio_set_dummy(int stream); |
---|
176 | |
---|
177 | #endif |
---|
178 | |
---|
179 | #endif |
---|
180 | |
---|
181 | //ll |
---|