Debian Codegraph @

src/seqmidi.c

raw symbols SCIP
1 /*
2 * File: seqmidi.m - convert to the sequencer events
3 *
4 * Copyright (C) 1999 Steve Ratcliffe
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16
17 #include "glib.h"cxx . . $ `<file>/src/glib.h`/
18 #include "elements.h"cxx . . $ `<file>/src/elements.h`/
19 #include "except.h"cxx . . $ `<file>/src/except.h`/
20 #include "intl.h"cxx . . $ `<file>/src/intl.h`/
21
22 #include <string.h>
23 #include "seqlib.h"cxx . . $ `<file>/src/seqlib.h`/
24 #include "seqpriv.h"cxx . . $ `<file>/src/seqpriv.h`/
25
26 /*
27 * Initialize a midi event from the context. The source and
28 * destination addresses will be set from the information
29 * stored in the context, which depends on the previous
30 * connection calls. In addition the time and channel are set.
31 * This should be called first before any of the following
32 * functions.
33 *
34 * Arguments:
35 * ctxp - Client application
36 * ep - Event to init
37 * time - Midi time
38 * devchan - Midi channel
39 */
40 void
41 seq_midi_event_initcxx . . $ seq_midi_event_init(1825f7fe94d84599).(seq_context_tcxx . . $ seq_context_t# *ctxp, snd_seq_event_tcxx . . $ snd_seq_event_t# *ep,
42 unsigned long time, int devchan)
43 {
44 int dev;
45
46 dev = devchan >> 4;
47
48 /*
49 * If insufficient output devices have been registered, then we
50 * just scale the device back to fit in the correct range. This
51 * is not necessarily what you want.
52 */
53 if (dev >= ctxp->ctxndestcxx . . $ `src/seqpriv.h:32:9`!)
54 dev = dev % ctxp->ctxndestcxx . . $ `src/seqpriv.h:32:9`!;
55
56 snd_seq_ev_clearcxx . . $ snd_seq_ev_clear(88c81eb0469c515c).(ep);
57 snd_seq_ev_schedule_tickcxx . . $ `<external>/4135540427972067373/seqmid.h:151:9`!(ep, ctxp->queue, 0, time);
58 ep->sourcecxx . . $ snd_seq_event#source. = ctxp->sourcecxx . . $ seq_context#source.;
59 if (ctxp->ctxndestcxx . . $ `src/seqpriv.h:32:9`! > 0)
60 ep->destcxx . . $ snd_seq_event#dest. = g_array_indexcxx . . $ `src/glib.h:1532:9`!(ctxp->destlist, snd_seq_addr_t, dev);
61 }
62
63 /*
64 * Send a note event.
65 * Arguments:
66 * ctxp - Client context
67 * ep - Event template
68 * note - Pitch of note
69 * vel - Velocity of note
70 * length - Length of note
71 */
72 void
73 seq_midi_notecxx . . $ seq_midi_note(115fea43cce26738).(seq_context_tcxx . . $ seq_context_t# *ctxp, snd_seq_event_tcxx . . $ snd_seq_event_t# *ep, int devchan, int note, int vel,
74 int length)
75 {
76 ep->typecxx . . $ snd_seq_event#type. = SND_SEQ_EVENT_NOTEcxx . . $ SND_SEQ_EVENT_NOTE.;
77
78 ep->datacxx . . $ snd_seq_event#data..notecxx . . $ snd_seq_event_data#note..channelcxx . . $ snd_seq_ev_note#channel. = devchan & 0xf;
79 ep->datacxx . . $ snd_seq_event#data..notecxx . . $ snd_seq_event_data#note..notecxx . . $ snd_seq_ev_note#note. = note;
80 ep->datacxx . . $ snd_seq_event#data..notecxx . . $ snd_seq_event_data#note..velocitycxx . . $ snd_seq_ev_note#velocity. = vel;
81 ep->datacxx . . $ snd_seq_event#data..notecxx . . $ snd_seq_event_data#note..durationcxx . . $ snd_seq_ev_note#duration. = length;
82
83 seq_writecxx . . $ seq_write(f9711ae91b75e353).(ctxp, ep);
84 }
85
86 /*
87 * Send a note on event.
88 * Arguments:
89 * ctxp - Client context
90 * ep - Event template
91 * note - Pitch of note
92 * vel - Velocity of note
93 * length - Length of note
94 */
95 void
96 seq_midi_note_oncxx . . $ seq_midi_note_on(115fea43cce26738).(seq_context_tcxx . . $ seq_context_t# *ctxp, snd_seq_event_tcxx . . $ snd_seq_event_t# *ep, int devchan, int note, int vel,
97 int length)
98 {
99 ep->typecxx . . $ snd_seq_event#type. = SND_SEQ_EVENT_NOTEONcxx . . $ SND_SEQ_EVENT_NOTEON.;
100
101 ep->datacxx . . $ snd_seq_event#data..notecxx . . $ snd_seq_event_data#note..channelcxx . . $ snd_seq_ev_note#channel. = devchan & 0xf;
102 ep->datacxx . . $ snd_seq_event#data..notecxx . . $ snd_seq_event_data#note..notecxx . . $ snd_seq_ev_note#note. = note;
103 ep->datacxx . . $ snd_seq_event#data..notecxx . . $ snd_seq_event_data#note..velocitycxx . . $ snd_seq_ev_note#velocity. = vel;
104 ep->datacxx . . $ snd_seq_event#data..notecxx . . $ snd_seq_event_data#note..durationcxx . . $ snd_seq_ev_note#duration. = length;
105
106 seq_writecxx . . $ seq_write(f9711ae91b75e353).(ctxp, ep);
107 }
108
109 /*
110 * Send a note off event.
111 * Arguments:
112 * ctxp - Client context
113 * ep - Event template
114 * note - Pitch of note
115 * vel - Velocity of note
116 * length - Length of note
117 */
118 void
119 seq_midi_note_offcxx . . $ seq_midi_note_off(115fea43cce26738).(seq_context_tcxx . . $ seq_context_t# *ctxp, snd_seq_event_tcxx . . $ snd_seq_event_t# *ep, int devchan, int note, int vel,
120 int length)
121 {
122 ep->typecxx . . $ snd_seq_event#type. = SND_SEQ_EVENT_NOTEOFFcxx . . $ SND_SEQ_EVENT_NOTEOFF.;
123
124 ep->datacxx . . $ snd_seq_event#data..notecxx . . $ snd_seq_event_data#note..channelcxx . . $ snd_seq_ev_note#channel. = devchan & 0xf;
125 ep->datacxx . . $ snd_seq_event#data..notecxx . . $ snd_seq_event_data#note..notecxx . . $ snd_seq_ev_note#note. = note;
126 ep->datacxx . . $ snd_seq_event#data..notecxx . . $ snd_seq_event_data#note..velocitycxx . . $ snd_seq_ev_note#velocity. = vel;
127 ep->datacxx . . $ snd_seq_event#data..notecxx . . $ snd_seq_event_data#note..durationcxx . . $ snd_seq_ev_note#duration. = length;
128
129 seq_writecxx . . $ seq_write(f9711ae91b75e353).(ctxp, ep);
130 }
131
132 /*
133 * Send a key pressure event.
134 * Arguments:
135 * ctxp - Application context
136 * ep - Event template
137 * note - Note to be altered
138 * value - Pressure value
139 */
140 void
141 seq_midi_keypresscxx . . $ seq_midi_keypress(d8303e21ad8a41d2).(seq_context_tcxx . . $ seq_context_t# *ctxp, snd_seq_event_tcxx . . $ snd_seq_event_t# *ep, int devchan, int note,
142 int value)
143 {
144 ep->typecxx . . $ snd_seq_event#type. = SND_SEQ_EVENT_KEYPRESScxx . . $ SND_SEQ_EVENT_KEYPRESS.;
145
146 ep->datacxx . . $ snd_seq_event#data..controlcxx . . $ snd_seq_event_data#control..channelcxx . . $ snd_seq_ev_ctrl#channel. = devchan & 0xf;
147 ep->datacxx . . $ snd_seq_event#data..controlcxx . . $ snd_seq_event_data#control..paramcxx . . $ snd_seq_ev_ctrl#param. = note;
148 ep->datacxx . . $ snd_seq_event#data..controlcxx . . $ snd_seq_event_data#control..valuecxx . . $ snd_seq_ev_ctrl#value. = value;
149 seq_writecxx . . $ seq_write(f9711ae91b75e353).(ctxp, ep);
150 }
151
152 /*
153 * Send a control event.
154 * Arguments:
155 * ctxp - Application context
156 * ep - Event template
157 * control - Controller to change
158 * value - Value to set it to
159 */
160 void
161 seq_midi_controlcxx . . $ seq_midi_control(d8303e21ad8a41d2).(seq_context_tcxx . . $ seq_context_t# *ctxp, snd_seq_event_tcxx . . $ snd_seq_event_t# *ep, int devchan, int control,
162 int value)
163 {
164 ep->typecxx . . $ snd_seq_event#type. = SND_SEQ_EVENT_CONTROLLERcxx . . $ SND_SEQ_EVENT_CONTROLLER.;
165
166 ep->datacxx . . $ snd_seq_event#data..controlcxx . . $ snd_seq_event_data#control..channelcxx . . $ snd_seq_ev_ctrl#channel. = devchan & 0xf;
167 ep->datacxx . . $ snd_seq_event#data..controlcxx . . $ snd_seq_event_data#control..paramcxx . . $ snd_seq_ev_ctrl#param. = control;
168 ep->datacxx . . $ snd_seq_event#data..controlcxx . . $ snd_seq_event_data#control..valuecxx . . $ snd_seq_ev_ctrl#value. = value;
169 seq_writecxx . . $ seq_write(f9711ae91b75e353).(ctxp, ep);
170 }
171
172 /*
173 * Send a program change event.
174 * Arguments:
175 * ctxp - Application context
176 * ep - Event template
177 * program - Program to set
178 */
179 void
180 seq_midi_programcxx . . $ seq_midi_program(d76d217fb6600c83).(seq_context_tcxx . . $ seq_context_t# *ctxp, snd_seq_event_tcxx . . $ snd_seq_event_t# *ep, int devchan, int program)
181 {
182 ep->typecxx . . $ snd_seq_event#type. = SND_SEQ_EVENT_PGMCHANGEcxx . . $ SND_SEQ_EVENT_PGMCHANGE.;
183
184 ep->datacxx . . $ snd_seq_event#data..controlcxx . . $ snd_seq_event_data#control..channelcxx . . $ snd_seq_ev_ctrl#channel. = devchan & 0xf;
185 ep->datacxx . . $ snd_seq_event#data..controlcxx . . $ snd_seq_event_data#control..valuecxx . . $ snd_seq_ev_ctrl#value. = program;
186 seq_writecxx . . $ seq_write(f9711ae91b75e353).(ctxp, ep);
187 }
188
189 /*
190 * Send a channel pressure event.
191 * Arguments:
192 * ctxp - Application context
193 * ep - Event template
194 * pressure - Pressure value
195 */
196 void
197 seq_midi_chanpresscxx . . $ seq_midi_chanpress(d76d217fb6600c83).(seq_context_tcxx . . $ seq_context_t# *ctxp, snd_seq_event_tcxx . . $ snd_seq_event_t# *ep, int devchan, int pressure)
198 {
199 ep->typecxx . . $ snd_seq_event#type. = SND_SEQ_EVENT_CHANPRESScxx . . $ SND_SEQ_EVENT_CHANPRESS.;
200
201 ep->datacxx . . $ snd_seq_event#data..controlcxx . . $ snd_seq_event_data#control..channelcxx . . $ snd_seq_ev_ctrl#channel. = devchan & 0xf;
202 ep->datacxx . . $ snd_seq_event#data..controlcxx . . $ snd_seq_event_data#control..valuecxx . . $ snd_seq_ev_ctrl#value. = pressure;
203 seq_writecxx . . $ seq_write(f9711ae91b75e353).(ctxp, ep);
204 }
205
206 /*
207 * Send a pitchbend message. The bend parameter is centered on
208 * zero, negative values mean a lower pitch.
209 * Arguments:
210 * ctxp - Application context
211 * ep - Event template
212 * bend - Bend value, centered on zero.
213 */
214 void
215 seq_midi_pitchbendcxx . . $ seq_midi_pitchbend(d76d217fb6600c83).(seq_context_tcxx . . $ seq_context_t# *ctxp, snd_seq_event_tcxx . . $ snd_seq_event_t# *ep, int devchan, int bend)
216 {
217 ep->typecxx . . $ snd_seq_event#type. = SND_SEQ_EVENT_PITCHBENDcxx . . $ SND_SEQ_EVENT_PITCHBEND.;
218
219 ep->datacxx . . $ snd_seq_event#data..controlcxx . . $ snd_seq_event_data#control..channelcxx . . $ snd_seq_ev_ctrl#channel. = devchan & 0xf;
220 ep->datacxx . . $ snd_seq_event#data..controlcxx . . $ snd_seq_event_data#control..valuecxx . . $ snd_seq_ev_ctrl#value. = bend;
221 seq_writecxx . . $ seq_write(f9711ae91b75e353).(ctxp, ep);
222 }
223
224 /*
225 * Send a tempo event. The tempo parameter is in microseconds
226 * per beat.
227 * Arguments:
228 * ctxp - Application context
229 * ep - Event template
230 * tempo - New tempo in usec per beat
231 */
232 void
233 seq_midi_tempocxx . . $ seq_midi_tempo(602bf0815d67e961).(seq_context_tcxx . . $ seq_context_t# *ctxp, snd_seq_event_tcxx . . $ snd_seq_event_t# *ep, int tempo)
234 {
235 ep->typecxx . . $ snd_seq_event#type. = SND_SEQ_EVENT_TEMPOcxx . . $ SND_SEQ_EVENT_TEMPO.;
236
237 ep->datacxx . . $ snd_seq_event#data..queuecxx . . $ snd_seq_event_data#queue..queuecxx . . $ snd_seq_ev_queue_control#queue. = ctxp->queuecxx . . $ seq_context#queue.;
238 ep->datacxx . . $ snd_seq_event#data..queuecxx . . $ snd_seq_event_data#queue..paramcxx . . $ snd_seq_ev_queue_control#param..valuecxx . . $ snd_seq_ev_queue_control#$anonymous_type_0#value. = tempo;
239 ep->destcxx . . $ snd_seq_event#dest..clientcxx . . $ snd_seq_addr#client. = SND_SEQ_CLIENT_SYSTEMcxx . . $ `<external>/4963296836554771614/seq.h:80:9`!;
240 ep->destcxx . . $ snd_seq_event#dest..portcxx . . $ snd_seq_addr#port. = SND_SEQ_PORT_SYSTEM_TIMERcxx . . $ `<external>/4963296836554771614/seq.h:239:9`!;
241 seq_writecxx . . $ seq_write(f9711ae91b75e353).(ctxp, ep);
242 }
243
244 /*
245 * Send a sysex event. The status byte is to distiguish
246 * continuation sysex messages.
247 * Arguments:
248 * ctxp - Application context
249 * ep - Event template
250 * status - Status byte for sysex
251 * data - Data to send
252 * length - Length of data
253 */
254 void
255 seq_midi_sysexcxx . . $ seq_midi_sysex(445d99f52c9088c3).(seq_context_tcxx . . $ seq_context_t# *ctxp, snd_seq_event_tcxx . . $ snd_seq_event_t# *ep, int status,
256 unsigned char *data, int length)
257 {
258 unsigned char *ndata;
259 int nlen;
260
261 ep->typecxx . . $ snd_seq_event#type. = SND_SEQ_EVENT_SYSEXcxx . . $ SND_SEQ_EVENT_SYSEX.;
262
263 ndata = g_malloccxx . . $ `src/glib.h:1299:9`!(length + 1);
264 nlen = length +1;
265
266 ndata[0] = status;
267 memcpycxx . . $ memcpy(cc817cb175f282d).(ndata+1, data, length);
268
269 snd_seq_ev_set_variablecxx . . $ `<external>/4135540427972067373/seqmid.h:208:9`!(ep, nlen, ndata);
270
271 seq_writecxx . . $ seq_write(f9711ae91b75e353).(ctxp, ep);
272
273 g_freecxx . . $ `src/glib.h:1302:9`!(ndata);
274 }
275
276 /*
277 * Send an echo event back to the source client at the specified
278 * time.
279 *
280 * Arguments:
281 * ctxp - Application context
282 * time - Time of event
283 */
284 void
285 seq_midi_echocxx . . $ seq_midi_echo(57fef5ba8926da1a).(seq_context_tcxx . . $ seq_context_t# *ctxp, unsigned long time)
286 {
287 snd_seq_event_tcxx . . $ snd_seq_event_t# ev;
288
289 seq_midi_event_initcxx . . $ seq_midi_event_init(1825f7fe94d84599).(ctxp, &ev, time, 0);
290 /* Loop back */
291 ev.destcxx . . $ snd_seq_event#dest. = ctxp->sourcecxx . . $ seq_context#source.;
292 seq_writecxx . . $ seq_write(f9711ae91b75e353).(ctxp, &ev);
293 }
294