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 |
|
---|
20 | void 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 |
|
---|
48 | void 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 (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 = EV_NEND | 0x80;
|
---|
86 | ep->e_note = nn;
|
---|
87 | ep->e_group = 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(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 |
|
---|
112 | if (stepenb) {
|
---|
113 |
|
---|
114 | /* advance by the note weight */
|
---|
115 |
|
---|
116 | DB_CMNT("ne_end - advance weight");
|
---|
117 | fcend = fc_val + stepfrm[3][stepint];
|
---|
118 | fc_val += stepfrm[stepwgt][stepint];
|
---|
119 | sc_trek(fc_val);
|
---|
120 | sc_trak(fc_val);
|
---|
121 | DB_CMNT("ne_end - doing note ends");
|
---|
122 | }
|
---|
123 |
|
---|
124 | while (nelist) {
|
---|
125 |
|
---|
126 | nn = nelist->note; /* get note */
|
---|
127 | grp = nelist->group; /* get group */
|
---|
128 |
|
---|
129 | if (E_NULL NE (ep = (struct n_entry *)e_alc(E_SIZE1))) {
|
---|
130 |
|
---|
131 | DB_CMNT("ne_end - enter note end");
|
---|
132 | ep->e_time = t_cur;
|
---|
133 | ep->e_type = EV_NEND | 0x80;
|
---|
134 | ep->e_note = nn;
|
---|
135 | ep->e_group = grp;
|
---|
136 | ep->e_vel = SM_SCALE(64);
|
---|
137 |
|
---|
138 | p_cur = e_ins((struct s_entry *)ep,
|
---|
139 | ep_adj(p_cur, 0, t_cur))->e_fwd;
|
---|
140 |
|
---|
141 | se_disp(ep, D_FWD, gdstbc, 1);
|
---|
142 |
|
---|
143 | if (lstendc < NLSTENTS)
|
---|
144 | lstends[lstendc++] = ep;
|
---|
145 |
|
---|
146 | } else {
|
---|
147 |
|
---|
148 | DB_CMNT("ne_end - no space");
|
---|
149 | }
|
---|
150 |
|
---|
151 | DB_CMNT("ne_end - freeing nevent");
|
---|
152 | nx = nelist->nxt; /* get next nelist ptr */
|
---|
153 | nelist->nxt = nefree; /* free nelist entry */
|
---|
154 | nefree = nelist; /* ... */
|
---|
155 | nelist = nx; /* update nelist */
|
---|
156 | }
|
---|
157 |
|
---|
158 | lstflag = TRUE; /* indicate end of list */
|
---|
159 |
|
---|
160 | DB_CMNT("ne_end - note ends done");
|
---|
161 |
|
---|
162 | if (stepenb) {
|
---|
163 |
|
---|
164 | if (fc_val LT fcend) { /* advance to the interval */
|
---|
165 |
|
---|
166 | DB_CMNT("ne_end - advance interval");
|
---|
167 | fc_val = fcend;
|
---|
168 | sc_trek(fc_val);
|
---|
169 | sc_trak(fc_val);
|
---|
170 | }
|
---|
171 | }
|
---|
172 | }
|
---|
173 |
|
---|
174 | } else {
|
---|
175 |
|
---|
176 | nkdown = 0; /* no keys down */
|
---|
177 |
|
---|
178 | lstendc = 0; /* no step entries to delete */
|
---|
179 | lstbgnc = 0;
|
---|
180 | lstflag = FALSE;
|
---|
181 | }
|
---|
182 |
|
---|
183 | DB_EXIT("ne_end");
|
---|
184 | }
|
---|
185 |
|
---|
186 | /*
|
---|
187 | =============================================================================
|
---|
188 | ne_bgn() -- enter a note begin event
|
---|
189 | =============================================================================
|
---|
190 | */
|
---|
191 |
|
---|
192 | void ne_bgn(int16_t grp, int16_t key, int16_t vel)
|
---|
193 | {
|
---|
194 | register struct n_entry *ep;
|
---|
195 | register struct nevent *np;
|
---|
196 |
|
---|
197 | DB_ENTR("ne_bgn");
|
---|
198 |
|
---|
199 | /* must be recording into a group in record mode ... */
|
---|
200 |
|
---|
201 | if ((recsw NE 0) AND (grpmode[grp] EQ 2)) {
|
---|
202 |
|
---|
203 | DB_CMNT("ne_bgn - recording");
|
---|
204 |
|
---|
205 | /* make pointers point in the forward direction */
|
---|
206 |
|
---|
207 | if (sd EQ D_BAK)
|
---|
208 | chgsdf();
|
---|
209 |
|
---|
210 | if (se EQ D_BAK)
|
---|
211 | chgsef();
|
---|
212 |
|
---|
213 | if (lstflag) { /* cancel old list of notes */
|
---|
214 |
|
---|
215 | lstbgnc = 0;
|
---|
216 | lstendc = 0;
|
---|
217 | lstflag = FALSE;
|
---|
218 | }
|
---|
219 |
|
---|
220 | if (clksrc EQ CK_STEP) { /* step mode */
|
---|
221 |
|
---|
222 | DB_CMNT("ne_bgn - step");
|
---|
223 | ++nkdown; /* count keys down */
|
---|
224 |
|
---|
225 | if (nefree) { /* log a key closure */
|
---|
226 |
|
---|
227 | np = nefree;
|
---|
228 | nefree = np->nxt;
|
---|
229 | np->note = key;
|
---|
230 | np->group = grp;
|
---|
231 | np->nxt = nelist;
|
---|
232 | nelist = np;
|
---|
233 | DB_CMNT("ne_bgn - key logged");
|
---|
234 |
|
---|
235 | } else {
|
---|
236 |
|
---|
237 | DB_CMNT("ne_bgn - nefree empty");
|
---|
238 | }
|
---|
239 | }
|
---|
240 |
|
---|
241 | if (E_NULL NE (ep = (struct n_entry *)e_alc(E_SIZE1))) {
|
---|
242 |
|
---|
243 | DB_CMNT("ne_bgn - enter note begin");
|
---|
244 | ep->e_time = t_cur;
|
---|
245 | ep->e_type = EV_NBEG | 0x80;
|
---|
246 | ep->e_note = key;
|
---|
247 | ep->e_group = grp;
|
---|
248 | ep->e_vel = (clksrc EQ CK_STEP) ? SM_SCALE(64) : vel;
|
---|
249 |
|
---|
250 | p_cur = e_ins((struct s_entry *)ep,
|
---|
251 | ep_adj(p_cur, 0, t_cur))->e_fwd;
|
---|
252 |
|
---|
253 | se_disp(ep, D_FWD, gdstbc, 1);
|
---|
254 |
|
---|
255 | if (t_cur EQ t_ctr)
|
---|
256 | newflag = TRUE;
|
---|
257 |
|
---|
258 | if ((clksrc EQ CK_STEP) AND (lstbgnc < NLSTENTS))
|
---|
259 | lstbgns[lstbgnc++] = ep;
|
---|
260 |
|
---|
261 | } else {
|
---|
262 |
|
---|
263 | DB_CMNT("ne_bgn - no space");
|
---|
264 | }
|
---|
265 | }
|
---|
266 |
|
---|
267 | DB_EXIT("ne_bgn");
|
---|
268 | }
|
---|
269 |
|
---|
270 | /*
|
---|
271 | =============================================================================
|
---|
272 | showvel() -- display velocity for a group
|
---|
273 | =============================================================================
|
---|
274 | */
|
---|
275 |
|
---|
276 | void showvel(int16_t g, int16_t v)
|
---|
277 | {
|
---|
278 | int8_t buf[6];
|
---|
279 |
|
---|
280 | if (v_regs[5] & 0x0180)
|
---|
281 | vbank(0);
|
---|
282 |
|
---|
283 | lastvel[g] = v;
|
---|
284 |
|
---|
285 | sprintf(buf, "%03d", (v / 252));
|
---|
286 |
|
---|
287 | vputs(obj8, 5, (g * 5) + 6, buf, SDW11ATR);
|
---|
288 | }
|
---|
289 |
|
---|
290 | /*
|
---|
291 | =============================================================================
|
---|
292 | asgvce() -- assign a voice
|
---|
293 | =============================================================================
|
---|
294 | */
|
---|
295 |
|
---|
296 | void asgvce(int16_t grp, int16_t port, int16_t chan, int16_t key, int16_t vel)
|
---|
297 | {
|
---|
298 | register int16_t i;
|
---|
299 | register int16_t tv;
|
---|
300 | register int16_t vp;
|
---|
301 | register int16_t trg;
|
---|
302 | register int16_t aflag;
|
---|
303 |
|
---|
304 | DB_ENTR("asgvce");
|
---|
305 |
|
---|
306 | trg = (port << 11) + (chan << 7) + key; /* trigger number */
|
---|
307 | vp = lastvce[grp] + 1; /* voice to start with */
|
---|
308 | vp = (vp > 11) ? 0 : vp; /* ... (adjust into range) */
|
---|
309 |
|
---|
310 | DB_CMNT("asgvce - search unassgined");
|
---|
311 |
|
---|
312 | for (i = 12; i--; ) { /* search for unassigned voice */
|
---|
313 |
|
---|
314 | if ((vce2trg[vp] EQ -1) AND (vce2grp[vp] EQ (grp + 1))) {
|
---|
315 |
|
---|
316 | if ((ndisp EQ 2) AND velflag AND (NOT recsw))
|
---|
317 | showvel(grp, vel);
|
---|
318 |
|
---|
319 | lastvce[grp] = vp;
|
---|
320 | execkey(trg, tuntab[key], vp, 0);
|
---|
321 | DB_EXIT("asgvce - free voice");
|
---|
322 | return;
|
---|
323 | }
|
---|
324 |
|
---|
325 | if (++vp > 11)
|
---|
326 | vp = 0;
|
---|
327 | }
|
---|
328 |
|
---|
329 | DB_CMNT("asgvce - seach non-held");
|
---|
330 |
|
---|
331 | for (i = 12; i--; ) { /* search for non-held voice */
|
---|
332 |
|
---|
333 | tv = vce2trg[vp];
|
---|
334 |
|
---|
335 | if (tv EQ -1)
|
---|
336 | aflag = TRUE; /* OK - unassigned */
|
---|
337 | else if (0 EQ (tv & (MKEYHELD << 8)))
|
---|
338 | aflag = TRUE; /* OK - not held */
|
---|
339 | else
|
---|
340 | aflag = FALSE; /* NO - held */
|
---|
341 |
|
---|
342 | if (aflag AND (vce2grp[vp] EQ (grp + 1))) {
|
---|
343 |
|
---|
344 | if ((ins2grp[grp] & GTAG1) AND
|
---|
345 | (tv NE trg) AND (tv NE -1))
|
---|
346 | legato = 1;
|
---|
347 |
|
---|
348 | if ((ndisp EQ 2) AND velflag AND (NOT recsw))
|
---|
349 | showvel(grp, vel);
|
---|
350 |
|
---|
351 | lastvce[grp] = vp;
|
---|
352 | execkey(trg, tuntab[key], vp, 0);
|
---|
353 | DB_EXIT("asgvce - stolen voice");
|
---|
354 | return;
|
---|
355 | }
|
---|
356 |
|
---|
357 | if (++vp > 11)
|
---|
358 | vp = 0;
|
---|
359 | }
|
---|
360 |
|
---|
361 | DB_EXIT("asgvce - no voice");
|
---|
362 | }
|
---|
363 |
|
---|