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

Last change on this file was b28c09e, checked in by Thomas Lopatic <thomas@…>, 6 years ago

Avoid shadowing.

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