1 /*(LGPL)
2 ---------------------------------------------------------------------------
3 a_midisock.c - Generic Interface for Modular MIDI Management
4 ---------------------------------------------------------------------------
5 * Copyright (C) 2001, David Olofson
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or (at
10 * your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include <stdio.h>
23 #include "a_midisock.h"
24 #include "kobolog.h"
25
26
27 /*----------------------------------------------------------
28 Dummy MIDI Socket implementation
29 ----------------------------------------------------------*/
dummy_note_off(unsigned ch,unsigned pitch,unsigned vel)30 static void dummy_note_off(unsigned ch, unsigned pitch, unsigned vel) {}
dummy_note_on(unsigned ch,unsigned pitch,unsigned vel)31 static void dummy_note_on(unsigned ch, unsigned pitch, unsigned vel) {}
dummy_poly_pressure(unsigned ch,unsigned pitch,unsigned press)32 static void dummy_poly_pressure(unsigned ch, unsigned pitch, unsigned press) {}
dummy_control_change(unsigned ch,unsigned ctrl,unsigned amt)33 static void dummy_control_change(unsigned ch, unsigned ctrl, unsigned amt) {}
dummy_program_change(unsigned ch,unsigned prog)34 static void dummy_program_change(unsigned ch, unsigned prog) {}
dummy_channel_pressure(unsigned ch,unsigned press)35 static void dummy_channel_pressure(unsigned ch, unsigned press) {}
dummy_pitch_bend(unsigned ch,int amt)36 static void dummy_pitch_bend(unsigned ch, int amt) {}
37
38 midisock_t dummy_midisock = {
39 dummy_note_off,
40 dummy_note_on,
41 dummy_poly_pressure,
42 dummy_control_change,
43 dummy_program_change,
44 dummy_channel_pressure,
45 dummy_pitch_bend
46 };
47
48
49 /*----------------------------------------------------------
50 Monitor MIDI Socket implementation
51 ----------------------------------------------------------*/
52 static const char notenames[12][4] = {
53 "C-", "C#", "D-", "D#", "E-",
54 "F-", "F#", "G-", "G#", "A-", "A#", "B-"
55 };
56
57 static const char *controlnames[128] = {
58 /*0..7*/
59 "Bank Select MSB",
60 "Modulation",
61 "Breath Controller",
62 NULL,
63 "Foot Controller",
64 "Portamento Time",
65 "Data Entry MSB",
66 "Volume",
67 /*8..15*/
68 "Balance",
69 NULL,
70 "Pan",
71 "Expression",
72 "FX Control 1",
73 "FX Control 2",
74 NULL,
75 NULL,
76 /*16..23*/
77 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
78 /*24..31*/
79 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
80 /*32..39*/
81 "Bank Select LSB",
82 NULL,
83 NULL,
84 NULL,
85 NULL,
86 NULL,
87 "Data Entry LSB",
88 "BC: Select Insert Slot",
89 /*40..47*/
90 "BC: IFX Type",
91 "BC: IFX Param 1 (Time 1)",
92 "BC: IFX Param 2 (Time 2)",
93 "BC: IFX Param 3 (Depth 1)",
94 "BC: IFX Param 4 (Depth 2)",
95 "BC: IFX Param 5 (Rate)",
96 "BC: IFX Param 6 (Mode)",
97 "BC: Send to Master",
98 /*48..55*/
99 "BC: Send to Bus 1",
100 "BC: Send to Bus 2",
101 "BC: Send to Bus 3",
102 "BC: Send to Bus 4",
103 "BC: Send to Bus 5",
104 "BC: Send to Bus 6",
105 "BC: Send to Bus 7",
106 "BC: Send to Bus 8",
107 /*56..63*/
108 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
109 /*64..71*/
110 "Hold 1",
111 "Portamento",
112 "Sostenuto",
113 "Soft Pedal",
114 "Legato",
115 "Hold 2",
116 "SC 1",
117 "SC 2: Harmonic Content",
118 /*72..79*/
119 "SC 3: Release Time",
120 "SC 4: Attack Time",
121 "SC 5: Brightness",
122 NULL,
123 NULL,
124 NULL,
125 NULL,
126 NULL,
127 /*80..87*/
128 NULL,
129 NULL,
130 NULL,
131 NULL,
132 "Portamento Control",
133 NULL,
134 NULL,
135 NULL,
136 /*88..95*/
137 "BC: Primary Bus Select",
138 "BC: Send Bus Select",
139 NULL,
140 "FX 1 Depth: Reverb",
141 "FX 2 Depth",
142 "FX 3 Depth: Chorus",
143 "FX 4 Depth: Variation",
144 "FX 5 Depth",
145 /*96..103*/
146 "RPN Increment",
147 "RPN Decrement",
148 "NRPN LSB",
149 "NRPN MSB",
150 "RPN LSB",
151 "RPN MSB",
152 NULL,
153 NULL,
154 /*104..111*/
155 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
156 /*112..119*/
157 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
158 /*120..127*/
159 "All Sound Off",
160 "Reset All Controllers",
161 NULL,
162 "All Notes Off",
163 "Omni Off",
164 "Omni On",
165 "Mono",
166 "Poly"
167 };
168
169 #if 0
170 #define KNOWN_RPNS 5
171 static const char RPNnames[KNOWN_RPNS][24] = {
172 "Pitch Bend Sensitivity",
173 "Fine Tuning",
174 "Coarse Tuning",
175 "Tuning Program Select",
176 "Tuning Bank Select"
177 };
178 #endif
179
monitor_note_off(unsigned ch,unsigned pitch,unsigned vel)180 static void monitor_note_off(unsigned ch, unsigned pitch, unsigned vel)
181 {
182 log_printf(DLOG, "NoteOff(%u, %s%u(%u), %u)\n", ch,
183 notenames[pitch % 12], pitch / 12,
184 pitch, vel);
185 }
186
monitor_note_on(unsigned ch,unsigned pitch,unsigned vel)187 static void monitor_note_on(unsigned ch, unsigned pitch, unsigned vel)
188 {
189 log_printf(DLOG, "NoteOn(%u, %s%u(%u), %u)\n", ch,
190 notenames[pitch % 12], pitch / 12,
191 pitch, vel);
192 }
193
monitor_poly_pressure(unsigned ch,unsigned pitch,unsigned press)194 static void monitor_poly_pressure(unsigned ch, unsigned pitch, unsigned press)
195 {
196 log_printf(DLOG, "PolyPress(%u, %s%u(%u), %u)\n", ch,
197 notenames[pitch % 12], pitch / 12,
198 pitch, press);
199 }
200
monitor_control_change(unsigned ch,unsigned ctrl,unsigned amt)201 static void monitor_control_change(unsigned ch, unsigned ctrl, unsigned amt)
202 {
203 const char *cn = controlnames[ctrl];
204 if(!cn)
205 cn = "<unknown>";
206 log_printf(DLOG, "ControlChg(%u, %s(%u), %u)\n", ch,
207 controlnames[ctrl], ctrl,
208 amt);
209 }
210
monitor_program_change(unsigned ch,unsigned prog)211 static void monitor_program_change(unsigned ch, unsigned prog)
212 {
213 log_printf(DLOG, "ProgramChg(%u, %u)\n", ch, prog);
214 }
215
monitor_channel_pressure(unsigned ch,unsigned press)216 static void monitor_channel_pressure(unsigned ch, unsigned press)
217 {
218 log_printf(DLOG, "ChannelPress(%u, %u)\n", ch, press);
219 }
220
monitor_pitch_bend(unsigned ch,int amt)221 static void monitor_pitch_bend(unsigned ch, int amt)
222 {
223 log_printf(DLOG, "PitchBend(%u, %d)\n", ch, amt);
224 }
225
226 midisock_t monitor_midisock = {
227 monitor_note_off,
228 monitor_note_on,
229 monitor_poly_pressure,
230 monitor_control_change,
231 monitor_program_change,
232 monitor_channel_pressure,
233 monitor_pitch_bend
234 };
235