source: buchla-68k/ram/asgvce.c@ b28a12e

Last change on this file since b28a12e was b28a12e, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Zero redundant declarations.

  • Property mode set to 100644
File size: 7.5 KB
Line 
1/*
2 =============================================================================
3 asgvce.c -- MIDAS-VII -- assign voice / enter notes into score
4 Version 12 -- 1988-10-03 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#undef DEBUGGER /* define to enable debug trace */
9
10#define DEBUGIT 0
11
12#include "ram.h"
13
14/*
15
16*/
17
18/*
19 =============================================================================
20 clrnl() -- clear note list
21 =============================================================================
22*/
23
24void clrnl(void)
25{
26 register int16_t i;
27
28 DB_ENTR("clrnl");
29
30 for (i = 0; i < NNEVTS - 1; i++) {
31
32 nevents[i].nxt = &nevents[i + 1];
33 nevents[i].note = 0;
34 nevents[i].group = 0;
35 }
36
37 nevents[NNEVTS - 1].nxt = (struct nevent *)0L;
38
39 nelist = (struct nevent *)0L;
40 nefree = &nevents[0];
41 nkdown = 0;
42
43 DB_EXIT("clrnl");
44}
45
46/*
47
48*/
49
50/*
51 =============================================================================
52 ne_end() -- enter a note end event
53 =============================================================================
54*/
55
56void ne_end(int16_t trg, int16_t grp)
57{
58 register int16_t nn;
59 register int32_t fcend;
60 register struct nevent *nx;
61 register struct n_entry *ep;
62
63 DB_ENTR("ne_end");
64
65 /* must be recording into a voice in record mode ... */
66
67 if ((recsw EQ 0) OR (grpmode[grp] NE 2)) {
68
69 DB_EXIT("ne_end");
70 return; /* ... or, we're done */
71 }
72
73 DB_CMNT("ne_end - recording");
74
75 /* make pointers point in the forward direction */
76
77 if (sd EQ D_BAK)
78 chgsdf();
79
80 if (se EQ D_BAK)
81 chgsef();
82/*
83
84*/
85 nn = trg & 0x007F; /* note number */
86
87 if (clksrc NE CK_STEP) { /* not in step mode */
88
89 DB_CMNT("ne_end - non-step");
90
91 if (E_NULL NE (ep = (struct n_entry *)e_alc(E_SIZE1))) {
92
93 DB_CMNT("ne_end - enter note end");
94 ep->e_time = t_cur;
95 ep->e_type = EV_NEND | 0x80;
96 ep->e_note = nn;
97 ep->e_group = grp;
98 ep->e_vel = SM_SCALE(64);
99
100 p_cur = e_ins((struct s_entry *)ep,
101 ep_adj(p_cur, 0, t_cur))->e_fwd;
102
103 if (t_cur EQ t_ctr)
104 newflag = TRUE;
105
106 se_disp(ep, D_FWD, gdstbc, 1);
107
108 } else {
109
110 DB_CMNT("ne_end - no space");
111 }
112
113 DB_EXIT("ne_end");
114 return;
115/*
116
117*/
118 } else if (nkdown GE 1) { /* process note entry in step mode */
119
120 DB_CMNT("ne_end - log key up");
121
122 if (0 EQ --nkdown) { /* if all keys are up ... */
123
124 if (stepenb) {
125
126 /* advance by the note weight */
127
128 DB_CMNT("ne_end - advance weight");
129 fcend = fc_val + stepfrm[3][stepint];
130 fc_val += stepfrm[stepwgt][stepint];
131 sc_trek(fc_val);
132 sc_trak(fc_val);
133 DB_CMNT("ne_end - doing note ends");
134 }
135
136 while (nelist) {
137
138 nn = nelist->note; /* get note */
139 grp = nelist->group; /* get group */
140
141 if (E_NULL NE (ep = (struct n_entry *)e_alc(E_SIZE1))) {
142
143 DB_CMNT("ne_end - enter note end");
144 ep->e_time = t_cur;
145 ep->e_type = EV_NEND | 0x80;
146 ep->e_note = nn;
147 ep->e_group = grp;
148 ep->e_vel = SM_SCALE(64);
149
150 p_cur = e_ins((struct s_entry *)ep,
151 ep_adj(p_cur, 0, t_cur))->e_fwd;
152
153 se_disp(ep, D_FWD, gdstbc, 1);
154
155 if (lstendc < NLSTENTS)
156 lstends[lstendc++] = ep;
157
158 } else {
159
160 DB_CMNT("ne_end - no space");
161 }
162/*
163
164*/
165 DB_CMNT("ne_end - freeing nevent");
166 nx = nelist->nxt; /* get next nelist ptr */
167 nelist->nxt = nefree; /* free nelist entry */
168 nefree = nelist; /* ... */
169 nelist = nx; /* update nelist */
170 }
171
172 lstflag = TRUE; /* indicate end of list */
173
174 DB_CMNT("ne_end - note ends done");
175
176 if (stepenb) {
177
178 if (fc_val LT fcend) { /* advance to the interval */
179
180 DB_CMNT("ne_end - advance interval");
181 fc_val = fcend;
182 sc_trek(fc_val);
183 sc_trak(fc_val);
184 }
185 }
186 }
187
188 } else {
189
190 nkdown = 0; /* no keys down */
191
192 lstendc = 0; /* no step entries to delete */
193 lstbgnc = 0;
194 lstflag = FALSE;
195 }
196
197 DB_EXIT("ne_end");
198}
199
200/*
201
202*/
203
204/*
205 =============================================================================
206 ne_bgn() -- enter a note begin event
207 =============================================================================
208*/
209
210void ne_bgn(int16_t grp, int16_t key, int16_t vel)
211{
212 register struct n_entry *ep;
213 register struct nevent *np;
214
215 DB_ENTR("ne_bgn");
216
217 /* must be recording into a group in record mode ... */
218
219 if ((recsw NE 0) AND (grpmode[grp] EQ 2)) {
220
221 DB_CMNT("ne_bgn - recording");
222
223 /* make pointers point in the forward direction */
224
225 if (sd EQ D_BAK)
226 chgsdf();
227
228 if (se EQ D_BAK)
229 chgsef();
230
231 if (lstflag) { /* cancel old list of notes */
232
233 lstbgnc = 0;
234 lstendc = 0;
235 lstflag = FALSE;
236 }
237
238 if (clksrc EQ CK_STEP) { /* step mode */
239
240 DB_CMNT("ne_bgn - step");
241 ++nkdown; /* count keys down */
242
243 if (nefree) { /* log a key closure */
244
245 np = nefree;
246 nefree = np->nxt;
247 np->note = key;
248 np->group = grp;
249 np->nxt = nelist;
250 nelist = np;
251 DB_CMNT("ne_bgn - key logged");
252
253 } else {
254
255 DB_CMNT("ne_bgn - nefree empty");
256 }
257 }
258/*
259
260*/
261 if (E_NULL NE (ep = (struct n_entry *)e_alc(E_SIZE1))) {
262
263 DB_CMNT("ne_bgn - enter note begin");
264 ep->e_time = t_cur;
265 ep->e_type = EV_NBEG | 0x80;
266 ep->e_note = key;
267 ep->e_group = grp;
268 ep->e_vel = (clksrc EQ CK_STEP) ? SM_SCALE(64) : vel;
269
270 p_cur = e_ins((struct s_entry *)ep,
271 ep_adj(p_cur, 0, t_cur))->e_fwd;
272
273 se_disp(ep, D_FWD, gdstbc, 1);
274
275 if (t_cur EQ t_ctr)
276 newflag = TRUE;
277
278 if ((clksrc EQ CK_STEP) AND (lstbgnc < NLSTENTS))
279 lstbgns[lstbgnc++] = ep;
280
281 } else {
282
283 DB_CMNT("ne_bgn - no space");
284 }
285 }
286
287 DB_EXIT("ne_bgn");
288}
289
290/*
291
292*/
293
294/*
295 =============================================================================
296 showvel() -- display velocity for a group
297 =============================================================================
298*/
299
300void showvel(int16_t g, int16_t v)
301{
302 int8_t buf[6];
303
304 if (v_regs[5] & 0x0180)
305 vbank(0);
306
307 lastvel[g] = v;
308
309 sprintf(buf, "%03d", (v / 252));
310
311 vputs(obj8, 5, (g * 5) + 6, buf, SDW11ATR);
312}
313
314/*
315
316*/
317
318/*
319 =============================================================================
320 asgvce() -- assign a voice
321 =============================================================================
322*/
323
324void asgvce(int16_t grp, int16_t port, int16_t chan, int16_t key, int16_t vel)
325{
326 register int16_t i;
327 register int16_t tv;
328 register int16_t vp;
329 register int16_t trg;
330 register int16_t aflag;
331 register struct nevent *np;
332 register struct n_entry *ep;
333
334 DB_ENTR("asgvce");
335
336 trg = (port << 11) + (chan << 7) + key; /* trigger number */
337 vp = lastvce[grp] + 1; /* voice to start with */
338 vp = (vp > 11) ? 0 : vp; /* ... (adjust into range) */
339
340/*
341
342*/
343
344 DB_CMNT("asgvce - search unassgined");
345
346 for (i = 12; i--; ) { /* search for unassigned voice */
347
348 if ((vce2trg[vp] EQ -1) AND (vce2grp[vp] EQ (grp + 1))) {
349
350 if ((ndisp EQ 2) AND velflag AND (NOT recsw))
351 showvel(grp, vel);
352
353 lastvce[grp] = vp;
354 execkey(trg, tuntab[key], vp, 0);
355 DB_EXIT("asgvce - free voice");
356 return;
357 }
358
359 if (++vp > 11)
360 vp = 0;
361 }
362
363 DB_CMNT("asgvce - seach non-held");
364
365 for (i = 12; i--; ) { /* search for non-held voice */
366
367 tv = vce2trg[vp];
368
369 if (tv EQ -1)
370 aflag = TRUE; /* OK - unassigned */
371 else if (0 EQ (tv & (MKEYHELD << 8)))
372 aflag = TRUE; /* OK - not held */
373 else
374 aflag = FALSE; /* NO - held */
375
376 if (aflag AND (vce2grp[vp] EQ (grp + 1))) {
377
378 if ((ins2grp[grp] & GTAG1) AND
379 (tv NE trg) AND (tv NE -1))
380 legato = 1;
381
382 if ((ndisp EQ 2) AND velflag AND (NOT recsw))
383 showvel(grp, vel);
384
385 lastvce[grp] = vp;
386 execkey(trg, tuntab[key], vp, 0);
387 DB_EXIT("asgvce - stolen voice");
388 return;
389 }
390
391 if (++vp > 11)
392 vp = 0;
393 }
394
395 DB_EXIT("asgvce - no voice");
396}
397
Note: See TracBrowser for help on using the repository browser.