source: buchla-68k/orig/RAM/NEDACC.C@ 5f1d169

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

Imported original source code.

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