source: buchla-68k/orig/RAM/ASGVCE.C@ 050d522

Last change on this file since 050d522 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 8 years ago

Imported original source code.

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