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

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

Fixed mixed-type pointer comparisons.

  • Property mode set to 100644
File size: 16.1 KB
RevLine 
[f40a309]1/*
2 =============================================================================
3 nedacc.c -- MIDAS-VII note edit functions
4 Version 11 -- 1988-08-16 -- D.N. Lynx Crowe
5
6 This file contains the note edit operations:
7
8 NOP_ACC Begin Acc ned_acc()
9 NOP_NAT Begin Nat ned_nat()
10 NOP_END End Note ned_end()
11 NOP_MVN Move Note ned_mvn()
12 NOP_MVB Move Begin ned_mvb()
13 NOP_MVE Move End ned_mve()
14
15 and some related support functions:
16
17 accnote()
18 donote()
19 nedesub()
20 =============================================================================
21*/
22
23#undef DEBUGGER /* define to enable debug trace */
24#define DEBUGIT 0
25
[b28a12e]26#include "ram.h"
[f40a309]27
28/*
29 =============================================================================
30 accnote() -- return accidental note number or -1 for errors
31 =============================================================================
32*/
33
[7258c6a]34int16_t accnote(void)
[f40a309]35{
[7258c6a]36 register int16_t rc;
[f40a309]37
38 DB_ENTR("accnote");
39
40 rc = -1;
41
42 if ((ac_code EQ N_SHARP) AND cflag) {
43
44 DB_CMNT("accnote - N_SHARP");
45 rc = cnote + 1;
46
47 } else if ((ac_code EQ N_FLAT) AND cflag) {
48
49 DB_CMNT("accnote - N_FLAT");
50 rc = cnote - 1;
51
52 } else {
53
54 DB_CMNT("accnote - no accidental possible");
55 }
56
57#if DEBUGIT
58 if (debugsw)
59 printf("accnote(): cnote = %d, ac_code = %d, cflag = %d, rc = %d\n",
60 cnote, ac_code, cflag, rc);
61#endif
62 DB_EXIT("accnote");
63 return(rc);
64}
65
66/*
67 =============================================================================
68 ned_acc() -- enter accidental note
69 =============================================================================
70*/
71
[7258c6a]72int16_t ned_acc(int16_t grp)
[f40a309]73{
[7258c6a]74 register int16_t nn;
[f40a309]75 register struct n_entry *ep;
76
77 DB_ENTR("ned_acc");
78
79 if (-1 EQ (nn = accnote())) {
80
81 DB_EXIT("ned_acc - accnote() failed");
82 return(FAILURE);
83 }
84
[8d0af8a]85 if ((struct n_entry *)E_NULL NE (ep = (struct n_entry *)e_alc(E_SIZE1))) {
[f40a309]86
87#if DEBUGIT
88 if (debugsw)
89 printf("ned_acc(): NBEG g=%d, n=%d, t=%ld, ep=$%08lX\n",
90 grp, nn, ctime, ep);
91#endif
92 DB_CMNT("ned_acc - entering note begin");
93 ep->e_time = ctime;
94 ep->e_type = EV_NBEG;
[81a59aa]95 ep->e_note = (int8_t)nn;
96 ep->e_group = (int8_t)grp;
[f40a309]97 ep->e_vel = SM_SCALE(64);
98 e_ins((struct s_entry *)ep, ep_adj(p_cur, 0, ctime));
99 noteop = NOP_END; /* setup for end of note */
100 DB_EXIT("ned_acc - note begin entered");
101 return(SUCCESS);
102 }
103
104 noteop = NOP_NUL; /* clear pending operation code */
105 DB_EXIT("ned_acc - no space for note begin");
106 return(FAILURE);
107}
108
109/*
110 =============================================================================
111 ned_nat() -- enter natural note
112 =============================================================================
113*/
114
[7258c6a]115int16_t ned_nat(int16_t grp)
[f40a309]116{
117 register struct n_entry *ep;
118
119 DB_ENTR("ned_nat");
120
[8d0af8a]121 if ((struct n_entry *)E_NULL NE (ep = (struct n_entry *)e_alc(E_SIZE1))) {
[f40a309]122
123#if DEBUGIT
124 if (debugsw)
125 printf("ned_nat(): NBEG g=%d, n=%d, t=%ld, ep=$%08lX\n",
126 grp, cnote, ctime, ep);
127#endif
128 DB_CMNT("ned_nat - entering note begin");
129 ep->e_time = ctime;
130 ep->e_type = EV_NBEG;
[81a59aa]131 ep->e_note = (int8_t)cnote;
132 ep->e_group = (int8_t)grp;
[f40a309]133 ep->e_vel = SM_SCALE(64);
134 e_ins((struct s_entry *)ep, ep_adj(p_cur, 0, ctime));
135 noteop = NOP_END; /* set up for end of note */
136 DB_EXIT("ned_nat - note begin entered");
137 return(SUCCESS);
138 }
139
140 noteop = NOP_NUL; /* clear pending operation code */
141 DB_EXIT("ned_nat - no space for note begin");
142 return(FAILURE);
143}
144
145/*
146 =============================================================================
147 nedesub() -- enter note end subroutine
148
149 Returns:
150
151 -1 note end not entered - out of space
152 0 note end entered OK
153 1 note end not entered - no matching begin
154 =============================================================================
155*/
156
[7258c6a]157int16_t nedesub(int16_t grp, int16_t note)
[f40a309]158{
[df097bf]159 register struct s_entry *ep;
160 register struct n_entry *np;
[7258c6a]161 register int16_t et;
[f40a309]162
163 DB_ENTR("nedesub");
164
165 ep = ep_adj(p_cur, 0, ctime);
166
167#if DEBUGIT
168 if (debugsw)
169 printf("nedesub(%d, %d): ctime=%ld, ep=$%08lX, t_cur=%ld, p_cur=$%08lX\n",
170 grp, note, ctime, ep, t_cur, p_cur);
171#endif
172
[fa38804]173
[f40a309]174 DB_CMNT("nedesub - left scan");
175
176 FOREVER { /* left scan */
177
178 et = 0x007F & ep->e_type;
179
180 switch (et) { /* dispatch off of event type */
181
182 case EV_NEND: /* note end */
183
184 if ((ep->e_data1 EQ note) AND
185 (ep->e_data2 EQ grp)) {
186
187 DB_EXIT("nedesub - note end hit");
188 return(1);
189 } else
190 break;
191
192 case EV_SCORE: /* score begin */
193
194 DB_EXIT("nedesub - score begin hit");
195 return(1);
196
197 case EV_NBEG: /* note begin */
198
199 if ((ep->e_data1 EQ note) AND
200 (ep->e_data2 EQ grp)) { /* group and note match */
201
202 ep = ep->e_fwd; /* setup for scan */
203 DB_CMNT("nedesub - NBEG nit - right scan");
[fa38804]204
[f40a309]205 FOREVER { /* right scan */
206
207 et = 0x007F & ep->e_type;
208
209 switch (et) {
210
211 case EV_NEND:
212
213 if ((ep->e_data1 EQ note) AND
214 (ep->e_data2 EQ grp)) {
215
216 DB_EXIT("nedesub - note end hit");
217 return(1);
218
219 } else
220 break;
[fa38804]221
[f40a309]222 case EV_NBEG:
223
224 if ((ep->e_data1 EQ note) AND
225 (ep->e_data2 EQ grp)) {
226
227 case EV_FINI:
228
229 DB_CMNT("nedesub - note begin / fini hit");
230
[8d0af8a]231 if ((struct n_entry *)E_NULL NE
232 (np = (struct n_entry *)e_alc(E_SIZE1))) {
[f40a309]233
234#if DEBUGIT
235 if (debugsw)
236 printf("nedesub(): note end entered - $%08lX t=%ld g=%d n=%d\n",
237 np, ctime, grp, note);
238#endif
239 DB_CMNT("nedesub - entering note end");
240 np->e_time = ctime;
241 np->e_type = EV_NEND;
[81a59aa]242 np->e_note = (int8_t)note;
243 np->e_group = (int8_t)grp;
[f40a309]244 np->e_vel = SM_SCALE(64);
245 e_ins((struct s_entry *)np, ep_adj(p_cur, 0, ctime));
246 DB_EXIT("nedesub - note end entered");
247 return(0);
248
249 } else {
250
251 DB_EXIT("nedesub - no space for note end");
252 return(-1);
253 }
254
255 } /* end if */
256
257 } /* end switch */
258
259 ep = ep->e_fwd; /* point at next event */
260
261 } /* end FOREVER - right scan */
262
263 } /* end if */
264
265 } /* end switch */
266
267 ep = ep->e_bak; /* back up to previous event */
268
269 } /* end FOREVER - left scan */
270}
271
272/*
273 =============================================================================
274 ned_end() -- enter note end
275 =============================================================================
276*/
277
[7258c6a]278int16_t ned_end(int16_t grp)
[f40a309]279{
[7258c6a]280 register int16_t rc;
[f40a309]281
282 DB_ENTR("ned_end");
283
284#if DEBUGIT
285 if (debugsw)
286 printf("ned_end(): trying grp = %d, note = %d\n",
287 grp, cnote);
288#endif
289 DB_CMNT("ned_end - trying natural");
290
291 if (-1 EQ (rc = nedesub(grp, cnote))) { /* try for a natural */
292
293 noteop = NOP_NUL; /* clear pending operation code */
294 DB_EXIT("ned_end - nedesub returned -1 (no space)");
295 return(FAILURE);
296
297 } else if (0 EQ rc) {
298
299 noteop = NOP_NUL; /* clear pending operation code */
300 DB_EXIT("ned_end - natural note end entered");
301 return(SUCCESS);
302
303 } else if (1 NE rc) {
304
305#if DEBUGIT
306 if (debugsw)
307 printf("ned_end(): nedesub(%d, %d) returned %d\n",
308 grp, cnote + 1, rc);
309#endif
310
311 noteop = NOP_NUL; /* clear pending operation code */
312 DB_EXIT("ned_end - nedesub returned non-zero (unknown error)");
313 return(FAILURE);
314 }
[fa38804]315
[f40a309]316#if DEBUGIT
317 if (debugsw)
318 printf("ned_end(): trying grp = %d, note = %d\n",
319 grp, cnote + 1);
320#endif
321
322 DB_CMNT("ned_end - trying accidental");
323
324 if (-1 EQ (rc = nedesub(grp, cnote + 1))) { /* try for an accidental */
325
326 noteop = NOP_NUL; /* clear pending operation code */
327 DB_EXIT("ned_end - nedesub returned -1 (no space)");
328 return(FAILURE);
329
330 } else if (1 EQ rc) {
331
332 noteop = NOP_NUL; /* clear pending operation code */
333 DB_EXIT("ned_end - nedesub returned 1 (no match)");
334 return(FAILURE);
335
336 } else if (0 NE rc) {
337
338#if DEBUGIT
339 if (debugsw)
340 printf("ned_end(): nedesub(%d, %d) returned %d\n",
341 grp, cnote + 1, rc);
342#endif
343
344 noteop = NOP_NUL; /* clear pending operation code */
345 DB_EXIT("ned_end - nedesub returned non-zero (unknown error)");
346 return(FAILURE);
347 }
348
349 noteop = NOP_NUL; /* clear pending operation code */
350 DB_EXIT("ned_end - accidental note end entered");
351 return(SUCCESS);
352}
353
354/*
355 =============================================================================
356 ned_mvn() -- move entire note
357 =============================================================================
358*/
359
[7258c6a]360int16_t ned_mvn(int16_t grp)
[f40a309]361{
362 register struct n_entry *bp, *ep;
[7258c6a]363 register int16_t note;
[f40a309]364
365 DB_ENTR("ned_mvn");
366
367 if (notesel) { /* note selected -- now do the dirty work */
368
369 bp = p_nbeg; /* point at note begin event */
370 ep = p_nend; /* point at note end event */
371
372 /* clip out the note begin event */
373
374 DB_CMNT("ned_mvn - clipping out begin");
375
[8d0af8a]376 if (p_bak EQ (struct s_entry *)bp)
[f40a309]377 p_bak = bp->e_fwd;
378
[8d0af8a]379 if (p_ctr EQ (struct s_entry *)bp)
[f40a309]380 p_ctr = bp->e_fwd;
381
[8d0af8a]382 if (p_cur EQ (struct s_entry *)bp)
[f40a309]383 p_cur = bp->e_fwd;
384
[8d0af8a]385 if (p_fwd EQ (struct s_entry *)bp)
[f40a309]386 p_fwd = bp->e_fwd;
387
388 e_rmv((struct s_entry *)bp);
[fa38804]389
[f40a309]390 /* clip out the note end event */
391
392 DB_CMNT("ned_mvn - clipping out end");
393
[8d0af8a]394 if (p_bak EQ (struct s_entry *)ep)
[f40a309]395 p_bak = ep->e_fwd;
396
[8d0af8a]397 if (p_ctr EQ (struct s_entry *)ep)
[f40a309]398 p_ctr = ep->e_fwd;
399
[8d0af8a]400 if (p_cur EQ (struct s_entry *)ep)
[f40a309]401 p_cur = ep->e_fwd;
402
[8d0af8a]403 if (p_fwd EQ (struct s_entry *)ep)
[f40a309]404 p_fwd = ep->e_fwd;
405
406 e_rmv((struct s_entry *)ep);
407
408 bp->e_time = ctime; /* correct begin time */
409 ep->e_time = ctime + t_note; /* correct end time */
410
411 /* re-insert the note */
412
413 DB_CMNT("ned_mvn - re-inserting note");
414
415 e_ins((struct s_entry *)bp, ep_adj(p_cur, 0, ctime));
416 e_ins((struct s_entry *)ep, ep_adj(p_cur, 0, ctime + t_note));
417
418 notesel = FALSE; /* note not selected */
419 noteop = NOP_NUL; /* clear pending operation code */
420 DB_EXIT("ned_mvn - note moved");
421 return(SUCCESS);
422
423 } else {
424
[8d0af8a]425 if ((struct n_entry *)E_NULL NE fcnote(grp, cnote)) {
[f40a309]426
427 notesel = TRUE; /* note selected */
428 DB_EXIT("ned_mvn - natural selected");
429 return(FAILURE);
430
431 } else if (-1 NE (note = accnote())) {
432
[8d0af8a]433 if ((struct n_entry *)E_NULL NE
434 (bp = fcnote(grp, note))) {
[f40a309]435
436 notesel = TRUE; /* note selected */
437 DB_EXIT("ned_mvn - accidental selected");
438 return(FAILURE);
439 }
440 }
441
442 notesel = FALSE; /* note not selected */
443 noteop = NOP_NUL; /* clear pending operation code */
444 DB_EXIT("ned_mvn - uanble to find note");
445 return(FAILURE);
446 }
447}
448
449/*
450 =============================================================================
451 ned_mvb() -- move beginning of note
452 =============================================================================
453*/
454
[7258c6a]455int16_t ned_mvb(int16_t grp)
[f40a309]456{
457 register struct n_entry *bp, *ep;
[7258c6a]458 register int16_t note;
[f40a309]459
460 DB_ENTR("ned_mvb");
461
462 if (notesel) { /* note selected -- now do the dirty work */
463
464 bp = p_nbeg; /* point at note begin event */
465 ep = p_nend; /* point at note end event */
466
467 if (ctime GE ep->e_time) { /* check move point */
468
469 noteop = NOP_NUL; /* clear pending operation */
470 notesel = FALSE; /* note not selected */
471 DB_EXIT("ned_mvb - move point after end");
472 return(FAILURE);
473 }
474
475 /* clip out the note begin event */
476
477 DB_CMNT("ned_mvb - clipping out begin");
478
[8d0af8a]479 if (p_bak EQ (struct s_entry *)bp)
[f40a309]480 p_bak = bp->e_fwd;
481
[8d0af8a]482 if (p_ctr EQ (struct s_entry *)bp)
[f40a309]483 p_ctr = bp->e_fwd;
484
[8d0af8a]485 if (p_cur EQ (struct s_entry *)bp)
[f40a309]486 p_cur = bp->e_fwd;
487
[8d0af8a]488 if (p_fwd EQ (struct s_entry *)bp)
[f40a309]489 p_fwd = bp->e_fwd;
490
491 e_rmv((struct s_entry *)bp);
492
493 bp->e_time = ctime; /* correct begin time */
494
495 /* re-insert begin event */
496
497 e_ins((struct s_entry *)bp, ep_adj(p_cur, 0, ctime));
498
499 noteop = NOP_NUL; /* clear pending operation */
500 notesel = FALSE; /* note not selected */
501 DB_EXIT("ned_mvb - begin moved");
502 return(SUCCESS);
[fa38804]503
[f40a309]504 } else {
505
[8d0af8a]506 if ((struct n_entry *)E_NULL NE fcnote(grp, cnote)) { /* natural ? */
[f40a309]507
508 notesel = TRUE; /* note selected */
509 DB_EXIT("ned_mvb - natural selected");
510 return(FAILURE);
511
512 } else if (-1 NE (note = accnote())) { /* accidental ? */
513
[8d0af8a]514 if ((struct n_entry *)E_NULL NE
515 (bp = fcnote(grp, note))) {
[f40a309]516
517 notesel = TRUE; /* note selected */
518 DB_EXIT("ned_mvb - accidental selected");
519 return(FAILURE);
520 }
521 }
522
523 notesel = FALSE; /* note not selected */
524 noteop = NOP_NUL; /* clear pending operation code */
525 DB_EXIT("ned_mvb - unable to find note");
526 return(FAILURE);
527 }
528}
529
530/*
531 =============================================================================
532 ned_mve() -- move end of note
533 =============================================================================
534*/
535
[7258c6a]536int16_t ned_mve(int16_t grp)
[f40a309]537{
538 register struct n_entry *bp, *ep;
[7258c6a]539 register int16_t note;
[f40a309]540
541 DB_ENTR("ned_mve");
542
543 if (notesel) { /* note selected -- now do the dirty work */
544
545 bp = p_nbeg; /* point at note begin event */
546 ep = p_nend; /* point at note end event */
547
548 if (ctime LE bp->e_time) { /* check move point */
549
550 noteop = NOP_NUL; /* clear pending operation */
551 notesel = FALSE; /* note not selected */
552 DB_EXIT("ned_mve - move point before begin");
553 return(FAILURE);
554 }
555
556 /* clip out the note end event */
557
558 DB_CMNT("ned_mve - clipping out end");
559
[8d0af8a]560 if (p_bak EQ (struct s_entry *)ep)
[f40a309]561 p_bak = ep->e_fwd;
562
[8d0af8a]563 if (p_ctr EQ (struct s_entry *)ep)
[f40a309]564 p_ctr = ep->e_fwd;
565
[8d0af8a]566 if (p_cur EQ (struct s_entry *)ep)
[f40a309]567 p_cur = ep->e_fwd;
568
[8d0af8a]569 if (p_fwd EQ (struct s_entry *)ep)
[f40a309]570 p_fwd = ep->e_fwd;
571
572 e_rmv((struct s_entry *)ep);
573
574 ep->e_time = ctime; /* correct end time */
575
576 /* re-insert end event */
577
578 e_ins((struct s_entry *)ep, ep_adj(p_cur, 0, ctime));
579
580 noteop = NOP_NUL; /* clear pending operation */
581 notesel = FALSE; /* note not selected */
582 DB_EXIT("ned_mve - end moved");
583 return(SUCCESS);
584
585 } else {
586
[8d0af8a]587 if ((struct n_entry *)E_NULL NE fcnote(grp, cnote)) { /* natural ? */
[f40a309]588
589 notesel = TRUE; /* note selected */
590 DB_EXIT("ned_mve - natural selected");
591 return(FAILURE);
592
593 } else if (-1 NE (note = accnote())) {
594
[8d0af8a]595 if ((struct n_entry *)E_NULL NE
596 (bp = fcnote(grp, note))) { /* accidental ? */
[f40a309]597
598 notesel = TRUE; /* note selected */
599 DB_EXIT("ned_mve - accidental selected");
600 return(FAILURE);
601 }
602 }
603
604 notesel = FALSE; /* note not selected */
605 noteop = NOP_NUL; /* clear pending operation code */
606 DB_EXIT("ned_mve - unable to find note");
607 return(FAILURE);
608 }
609}
610
611/*
612 =============================================================================
613 donote() -- do a note operation
614 =============================================================================
615*/
616
[0580615]617void donote(void)
[f40a309]618{
[7258c6a]619 register int16_t grp, i, gs;
[f40a309]620
621 DB_ENTR("donote");
622
623 if (scmctl NE -1) { /* area 1 menu must be down */
624
625 DB_EXIT("donote - scmctl NE -1");
626 return;
627 }
628
629 if (NOT recsw) { /* must be in record mode */
630
631 DB_EXIT("donote - not in record mode");
632 return;
633 }
634
635 /* determine which group we want to work with */
636
637 gs = 0;
638 grp = -1;
639
640 for (i = 0; i < 12; i++) { /* scan the groups */
641
642 if ((grpmode[i] EQ 2) AND grpstat[i]) {
643
644 grp = i; /* log the group */
645 ++gs; /* count enabled groups */
646#if DEBUGIT
647 if (debugsw)
648 printf("donote(): gs = %d, grp = %d\n", gs, grp);
649#endif
650 }
651 }
652
653#if DEBUGIT
654 if (debugsw)
655 printf("donote(): final gs = %d, grp = %d\n", gs, grp);
656#endif
657
[fa38804]658
[f40a309]659 if (gs NE 1) { /* must have a single group enabled */
660
661 DB_EXIT("donote - no single group enabled");
662 return;
663 }
664
[0c834c5]665 if (pix2mid()) { /* must point at a note position */
[f40a309]666
667#if DEBUGIT
668 if (debugsw)
669 printf("donote(): no note at cxval = %d, cyval = %d\n",
670 cxval, cyval);
671#endif
672 DB_EXIT("donote - not at a note position");
673 return;
674 }
[fa38804]675
[f40a309]676#if DEBUGIT
677 if (debugsw)
678 printf("donote(): at (cxval=%d, cyval=%d): cnote=%d, cflag=%d, ctime=%ld\n",
679 cxval, cyval, cnote, cflag, ctime);
680#endif
681
682 DB_CMNT("donote - dispatching");
683
684 switch (noteop) { /* dispatch off of note operation code */
685
686 case NOP_ACC: /* Begin Acc */
687
688 if (ned_acc(grp))
689 break;
690
691 sc_refr(fc_val); /* refresh screen if successful */
692 break;
693
694 case NOP_NAT: /* Begin Nat */
695
696 if (ned_nat(grp))
697 break;
698
699 sc_refr(fc_val); /* refresh screen if successful */
700 break;
701
702 case NOP_END: /* End Note */
703
704 if (ned_end(grp))
705 break;
706
707 sc_refr(fc_val); /* refresh screen if successful */
708 break;
[fa38804]709
[f40a309]710 case NOP_MVN: /* Move Note */
711
712 if (ned_mvn(grp))
713 break;
714
715 sc_refr(fc_val); /* refresh screen if successful */
716 break;
717
718 case NOP_MVB: /* Move Begin */
719
720 if (ned_mvb(grp))
721 break;
722
723 sc_refr(fc_val); /* refresh screen if successful */
724 break;
725
726 case NOP_MVE: /* Move End */
727
728 if (ned_mve(grp))
729 break;
730
731 sc_refr(fc_val); /* refresh screen if successful */
732 break;
733
734 default:
735
736 DB_CMNT("donote - bad operation");
737 noteop = NOP_NUL; /* clear pending operation code */
738 }
739
740 dnedmod(); /* update note edit window */
741 DB_EXIT("donote");
742 return;
743}
[6262b5c]744
Note: See TracBrowser for help on using the repository browser.