2337
|
1 /*
|
|
2 * Schism Tracker - a cross-platform Impulse Tracker clone
|
|
3 * copyright (c) 2003-2005 chisel <schism@chisel.cjb.net>
|
|
4 * copyright (c) 2005-2006 Mrs. Brisby <mrs.brisby@nimh.org>
|
|
5 * URL: http://nimh.org/schism/
|
|
6 * URL: http://rigelseven.com/schism/
|
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
2835
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2337
|
21 */
|
|
22
|
|
23 #ifndef MIDI_H
|
|
24 #define MIDI_H
|
|
25
|
|
26 #ifdef __cplusplus
|
|
27 extern "C" {
|
|
28 #endif
|
|
29
|
|
30 struct midi_provider;
|
|
31 struct midi_port;
|
|
32
|
|
33 struct midi_driver {
|
|
34 unsigned int flags;
|
|
35 #define MIDI_PORT_CAN_SCHEDULE 1
|
|
36
|
|
37 void (*poll)(struct midi_provider *m);
|
|
38 int (*thread)(struct midi_provider *m);
|
|
39
|
|
40 int (*enable)(struct midi_port *d);
|
|
41 int (*disable)(struct midi_port *d);
|
|
42
|
|
43 void (*send)(struct midi_port *d,
|
|
44 unsigned char *seq, unsigned int len, unsigned int delay);
|
|
45 void (*drain)(struct midi_port *d);
|
|
46 };
|
|
47
|
|
48 struct midi_provider {
|
|
49 const char *name;
|
|
50 void (*poll)(struct midi_provider *);
|
|
51 void *thread; /*actually SDL_Thread* */
|
|
52
|
|
53 struct midi_provider *next;
|
|
54
|
|
55 /* forwarded; don't touch */
|
|
56 int (*enable)(struct midi_port *d);
|
|
57 int (*disable)(struct midi_port *d);
|
|
58
|
|
59 void (*send_now)(struct midi_port *d,
|
|
60 unsigned char *seq, unsigned int len, unsigned int delay);
|
|
61 void (*send_later)(struct midi_port *d,
|
|
62 unsigned char *seq, unsigned int len, unsigned int delay);
|
|
63 void (*drain)(struct midi_port *d);
|
|
64 };
|
|
65 struct midi_port {
|
|
66 int io, iocap;
|
|
67 #define MIDI_INPUT 1
|
|
68 #define MIDI_OUTPUT 2
|
|
69 char *name;
|
|
70 int num;
|
|
71
|
|
72 void *userdata;
|
|
73 int free_userdata;
|
|
74 int (*enable)(struct midi_port *d);
|
|
75 int (*disable)(struct midi_port *d);
|
|
76 void (*send_now)(struct midi_port *d,
|
|
77 unsigned char *seq, unsigned int len, unsigned int delay);
|
|
78 void (*send_later)(struct midi_port *d,
|
|
79 unsigned char *seq, unsigned int len, unsigned int delay);
|
|
80 void (*drain)(struct midi_port *d);
|
|
81
|
|
82 struct midi_provider *provider;
|
|
83 };
|
|
84
|
|
85
|
|
86 /* schism calls these directly */
|
|
87 int midi_engine_start(void);
|
|
88 void midi_engine_reset(void);
|
|
89 void midi_engine_stop(void);
|
|
90 void midi_engine_poll_ports(void);
|
|
91
|
|
92 /* some parts of schism call this; it means "immediately" */
|
|
93 void midi_send_now(unsigned char *seq, unsigned int len);
|
|
94
|
|
95 /* ... but the player calls this */
|
|
96 void midi_send_buffer(unsigned char *data, unsigned int len, unsigned int pos);
|
|
97 void midi_send_flush(void);
|
|
98
|
|
99 /* from the SDL event mechanism (x is really SDL_Event) */
|
|
100 int midi_engine_handle_event(void *x);
|
|
101
|
|
102 struct midi_port *midi_engine_port(int n, const char **name);
|
|
103 int midi_engine_port_count(void);
|
|
104
|
|
105 /* midi engines register a provider (one each!) */
|
|
106 struct midi_provider *midi_provider_register(const char *name, struct midi_driver *f);
|
|
107
|
|
108
|
|
109 /* midi engines list ports this way */
|
|
110 int midi_port_register(struct midi_provider *p,
|
|
111 int inout, const char *name, void *userdata, int free_userdata);
|
|
112
|
|
113 int midi_port_foreach(struct midi_provider *p, struct midi_port **cursor);
|
|
114 void midi_port_unregister(int num);
|
|
115
|
|
116 /* only call these if the event isn't really MIDI but you want most of the system
|
|
117 to act like it is...
|
|
118
|
|
119 midi drivers should never all these...
|
|
120 */
|
|
121 enum midi_note {
|
|
122 MIDI_NOTEOFF,
|
|
123 MIDI_NOTEON,
|
|
124 MIDI_KEYPRESS,
|
|
125 };
|
|
126 void midi_event_note(enum midi_note mnstatus, int channel, int note, int velocity);
|
|
127 void midi_event_controller(int channel, int param, int value);
|
|
128 void midi_event_program(int channel, int value);
|
|
129 void midi_event_aftertouch(int channel, int value);
|
|
130 void midi_event_pitchbend(int channel, int value);
|
|
131 void midi_event_tick(void);
|
|
132 void midi_event_sysex(const unsigned char *data, unsigned int len);
|
|
133 void midi_event_system(int argv, int param);
|
|
134
|
|
135 /* midi drivers call this when they received an event */
|
|
136 void midi_received_cb(struct midi_port *src, unsigned char *data, unsigned int len);
|
|
137
|
|
138
|
|
139 #ifdef USE_NETWORK
|
|
140 int ip_midi_setup(void);
|
|
141 #endif
|
|
142 #ifdef USE_OSS
|
|
143 int oss_midi_setup(void);
|
|
144 #endif
|
|
145 #ifdef USE_ALSA
|
|
146 int alsa_midi_setup(void);
|
|
147 #endif
|
|
148 #ifdef USE_WIN32MM
|
|
149 int win32mm_midi_setup(void);
|
|
150 #endif
|
|
151 #ifdef MACOSX
|
|
152 int macosx_midi_setup(void);
|
|
153 #endif
|
|
154
|
|
155
|
|
156
|
|
157 #define MIDI_TICK_QUANTIZE 0x00000001
|
|
158 #define MIDI_BASE_PROGRAM1 0x00000002
|
|
159 #define MIDI_RECORD_NOTEOFF 0x00000004
|
|
160 #define MIDI_RECORD_VELOCITY 0x00000008
|
|
161 #define MIDI_RECORD_AFTERTOUCH 0x00000010
|
|
162 #define MIDI_CUT_NOTE_OFF 0x00000020
|
|
163 #define MIDI_PITCH_BEND 0x00000040
|
|
164 #define MIDI_EMBED_DATA 0x00000080
|
|
165 #define MIDI_RECORD_SDX 0x00000100
|
|
166 #define MIDI_DISABLE_RECORD 0x00010000
|
|
167
|
|
168 /* configurable midi stuff */
|
|
169 int midi_flags = MIDI_TICK_QUANTIZE | MIDI_RECORD_NOTEOFF
|
|
170 | MIDI_RECORD_VELOCITY | MIDI_RECORD_AFTERTOUCH
|
|
171 | MIDI_PITCH_BEND;
|
|
172
|
|
173 int midi_pitch_depth = 12;
|
|
174 int midi_amplification = 100;
|
|
175 int midi_c5note = 60;
|
|
176
|
|
177 /* only available with networks */
|
|
178 void ip_midi_setports(int n);
|
|
179 int ip_midi_getports(void);
|
|
180
|
|
181 #ifdef __cplusplus
|
|
182 };
|
|
183 #endif
|
|
184
|
|
185 #endif
|