source: buchla-68k/ram/nedacc.c@ 46d8069

Last change on this file since 46d8069 was df097bf, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Code compiles, doesn't link.

  • Property mode set to 100644
File size: 16.5 KB
Line 
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;
218 register struct n_entry *np;
219 register short et;
220
221 DB_ENTR("nedesub");
222
223 ep = ep_adj(p_cur, 0, ctime);
224
225#if DEBUGIT
226 if (debugsw)
227 printf("nedesub(%d, %d): ctime=%ld, ep=$%08lX, t_cur=%ld, p_cur=$%08lX\n",
228 grp, note, ctime, ep, t_cur, p_cur);
229#endif
230
231/*
232
233*/
234 DB_CMNT("nedesub - left scan");
235
236 FOREVER { /* left scan */
237
238 et = 0x007F & ep->e_type;
239
240 switch (et) { /* dispatch off of event type */
241
242 case EV_NEND: /* note end */
243
244 if ((ep->e_data1 EQ note) AND
245 (ep->e_data2 EQ grp)) {
246
247 DB_EXIT("nedesub - note end hit");
248 return(1);
249 } else
250 break;
251
252 case EV_SCORE: /* score begin */
253
254 DB_EXIT("nedesub - score begin hit");
255 return(1);
256
257 case EV_NBEG: /* note begin */
258
259 if ((ep->e_data1 EQ note) AND
260 (ep->e_data2 EQ grp)) { /* group and note match */
261
262 ep = ep->e_fwd; /* setup for scan */
263 DB_CMNT("nedesub - NBEG nit - right scan");
264/*
265
266*/
267 FOREVER { /* right scan */
268
269 et = 0x007F & ep->e_type;
270
271 switch (et) {
272
273 case EV_NEND:
274
275 if ((ep->e_data1 EQ note) AND
276 (ep->e_data2 EQ grp)) {
277
278 DB_EXIT("nedesub - note end hit");
279 return(1);
280
281 } else
282 break;
283/*
284
285*/
286 case EV_NBEG:
287
288 if ((ep->e_data1 EQ note) AND
289 (ep->e_data2 EQ grp)) {
290
291 case EV_FINI:
292
293 DB_CMNT("nedesub - note begin / fini hit");
294
295 if (E_NULL NE (np = (struct n_entry *)e_alc(E_SIZE1))) {
296
297#if DEBUGIT
298 if (debugsw)
299 printf("nedesub(): note end entered - $%08lX t=%ld g=%d n=%d\n",
300 np, ctime, grp, note);
301#endif
302 DB_CMNT("nedesub - entering note end");
303 np->e_time = ctime;
304 np->e_type = EV_NEND;
305 np->e_note = note;
306 np->e_group = grp;
307 np->e_vel = SM_SCALE(64);
308 e_ins((struct s_entry *)np, ep_adj(p_cur, 0, ctime));
309 DB_EXIT("nedesub - note end entered");
310 return(0);
311
312 } else {
313
314 DB_EXIT("nedesub - no space for note end");
315 return(-1);
316 }
317
318 } /* end if */
319
320 } /* end switch */
321
322 ep = ep->e_fwd; /* point at next event */
323
324 } /* end FOREVER - right scan */
325
326 } /* end if */
327
328 } /* end switch */
329
330 ep = ep->e_bak; /* back up to previous event */
331
332 } /* end FOREVER - left scan */
333}
334
335/*
336
337*/
338
339/*
340 =============================================================================
341 ned_end() -- enter note end
342 =============================================================================
343*/
344
345short
346ned_end(grp)
347short grp;
348{
349 register short rc;
350
351 DB_ENTR("ned_end");
352
353#if DEBUGIT
354 if (debugsw)
355 printf("ned_end(): trying grp = %d, note = %d\n",
356 grp, cnote);
357#endif
358 DB_CMNT("ned_end - trying natural");
359
360 if (-1 EQ (rc = nedesub(grp, cnote))) { /* try for a natural */
361
362 noteop = NOP_NUL; /* clear pending operation code */
363 DB_EXIT("ned_end - nedesub returned -1 (no space)");
364 return(FAILURE);
365
366 } else if (0 EQ rc) {
367
368 noteop = NOP_NUL; /* clear pending operation code */
369 DB_EXIT("ned_end - natural note end entered");
370 return(SUCCESS);
371
372 } else if (1 NE rc) {
373
374#if DEBUGIT
375 if (debugsw)
376 printf("ned_end(): nedesub(%d, %d) returned %d\n",
377 grp, cnote + 1, rc);
378#endif
379
380 noteop = NOP_NUL; /* clear pending operation code */
381 DB_EXIT("ned_end - nedesub returned non-zero (unknown error)");
382 return(FAILURE);
383 }
384/*
385
386*/
387#if DEBUGIT
388 if (debugsw)
389 printf("ned_end(): trying grp = %d, note = %d\n",
390 grp, cnote + 1);
391#endif
392
393 DB_CMNT("ned_end - trying accidental");
394
395 if (-1 EQ (rc = nedesub(grp, cnote + 1))) { /* try for an accidental */
396
397 noteop = NOP_NUL; /* clear pending operation code */
398 DB_EXIT("ned_end - nedesub returned -1 (no space)");
399 return(FAILURE);
400
401 } else if (1 EQ rc) {
402
403 noteop = NOP_NUL; /* clear pending operation code */
404 DB_EXIT("ned_end - nedesub returned 1 (no match)");
405 return(FAILURE);
406
407 } else if (0 NE rc) {
408
409#if DEBUGIT
410 if (debugsw)
411 printf("ned_end(): nedesub(%d, %d) returned %d\n",
412 grp, cnote + 1, rc);
413#endif
414
415 noteop = NOP_NUL; /* clear pending operation code */
416 DB_EXIT("ned_end - nedesub returned non-zero (unknown error)");
417 return(FAILURE);
418 }
419
420 noteop = NOP_NUL; /* clear pending operation code */
421 DB_EXIT("ned_end - accidental note end entered");
422 return(SUCCESS);
423}
424
425/*
426
427*/
428
429/*
430 =============================================================================
431 ned_mvn() -- move entire note
432 =============================================================================
433*/
434
435short
436ned_mvn(grp)
437short grp;
438{
439 register struct n_entry *bp, *ep;
440 register short note;
441
442 DB_ENTR("ned_mvn");
443
444 if (notesel) { /* note selected -- now do the dirty work */
445
446 bp = p_nbeg; /* point at note begin event */
447 ep = p_nend; /* point at note end event */
448
449 /* clip out the note begin event */
450
451 DB_CMNT("ned_mvn - clipping out begin");
452
453 if (p_bak EQ bp)
454 p_bak = bp->e_fwd;
455
456 if (p_ctr EQ bp)
457 p_ctr = bp->e_fwd;
458
459 if (p_cur EQ bp)
460 p_cur = bp->e_fwd;
461
462 if (p_fwd EQ bp)
463 p_fwd = bp->e_fwd;
464
465 e_rmv((struct s_entry *)bp);
466/*
467
468*/
469 /* clip out the note end event */
470
471 DB_CMNT("ned_mvn - clipping out end");
472
473 if (p_bak EQ ep)
474 p_bak = ep->e_fwd;
475
476 if (p_ctr EQ ep)
477 p_ctr = ep->e_fwd;
478
479 if (p_cur EQ ep)
480 p_cur = ep->e_fwd;
481
482 if (p_fwd EQ ep)
483 p_fwd = ep->e_fwd;
484
485 e_rmv((struct s_entry *)ep);
486
487 bp->e_time = ctime; /* correct begin time */
488 ep->e_time = ctime + t_note; /* correct end time */
489
490 /* re-insert the note */
491
492 DB_CMNT("ned_mvn - re-inserting note");
493
494 e_ins((struct s_entry *)bp, ep_adj(p_cur, 0, ctime));
495 e_ins((struct s_entry *)ep, ep_adj(p_cur, 0, ctime + t_note));
496
497 notesel = FALSE; /* note not selected */
498 noteop = NOP_NUL; /* clear pending operation code */
499 DB_EXIT("ned_mvn - note moved");
500 return(SUCCESS);
501
502 } else {
503
504 if (E_NULL NE fcnote(grp, cnote)) {
505
506 notesel = TRUE; /* note selected */
507 DB_EXIT("ned_mvn - natural selected");
508 return(FAILURE);
509
510 } else if (-1 NE (note = accnote())) {
511
512 if (E_NULL NE (bp = fcnote(grp, note))) {
513
514 notesel = TRUE; /* note selected */
515 DB_EXIT("ned_mvn - accidental selected");
516 return(FAILURE);
517 }
518 }
519
520 notesel = FALSE; /* note not selected */
521 noteop = NOP_NUL; /* clear pending operation code */
522 DB_EXIT("ned_mvn - uanble to find note");
523 return(FAILURE);
524 }
525}
526
527/*
528
529*/
530
531/*
532 =============================================================================
533 ned_mvb() -- move beginning of note
534 =============================================================================
535*/
536
537short
538ned_mvb(grp)
539short grp;
540{
541 register struct n_entry *bp, *ep;
542 register short note;
543
544 DB_ENTR("ned_mvb");
545
546 if (notesel) { /* note selected -- now do the dirty work */
547
548 bp = p_nbeg; /* point at note begin event */
549 ep = p_nend; /* point at note end event */
550
551 if (ctime GE ep->e_time) { /* check move point */
552
553 noteop = NOP_NUL; /* clear pending operation */
554 notesel = FALSE; /* note not selected */
555 DB_EXIT("ned_mvb - move point after end");
556 return(FAILURE);
557 }
558
559 /* clip out the note begin event */
560
561 DB_CMNT("ned_mvb - clipping out begin");
562
563 if (p_bak EQ bp)
564 p_bak = bp->e_fwd;
565
566 if (p_ctr EQ bp)
567 p_ctr = bp->e_fwd;
568
569 if (p_cur EQ bp)
570 p_cur = bp->e_fwd;
571
572 if (p_fwd EQ bp)
573 p_fwd = bp->e_fwd;
574
575 e_rmv((struct s_entry *)bp);
576
577 bp->e_time = ctime; /* correct begin time */
578
579 /* re-insert begin event */
580
581 e_ins((struct s_entry *)bp, ep_adj(p_cur, 0, ctime));
582
583 noteop = NOP_NUL; /* clear pending operation */
584 notesel = FALSE; /* note not selected */
585 DB_EXIT("ned_mvb - begin moved");
586 return(SUCCESS);
587/*
588
589*/
590 } else {
591
592 if (E_NULL NE fcnote(grp, cnote)) { /* natural ? */
593
594 notesel = TRUE; /* note selected */
595 DB_EXIT("ned_mvb - natural selected");
596 return(FAILURE);
597
598 } else if (-1 NE (note = accnote())) { /* accidental ? */
599
600 if (E_NULL NE (bp = fcnote(grp, note))) {
601
602 notesel = TRUE; /* note selected */
603 DB_EXIT("ned_mvb - accidental selected");
604 return(FAILURE);
605 }
606 }
607
608 notesel = FALSE; /* note not selected */
609 noteop = NOP_NUL; /* clear pending operation code */
610 DB_EXIT("ned_mvb - unable to find note");
611 return(FAILURE);
612 }
613}
614
615/*
616
617*/
618
619/*
620 =============================================================================
621 ned_mve() -- move end of note
622 =============================================================================
623*/
624
625short
626ned_mve(grp)
627short grp;
628{
629 register struct n_entry *bp, *ep;
630 register short note;
631
632 DB_ENTR("ned_mve");
633
634 if (notesel) { /* note selected -- now do the dirty work */
635
636 bp = p_nbeg; /* point at note begin event */
637 ep = p_nend; /* point at note end event */
638
639 if (ctime LE bp->e_time) { /* check move point */
640
641 noteop = NOP_NUL; /* clear pending operation */
642 notesel = FALSE; /* note not selected */
643 DB_EXIT("ned_mve - move point before begin");
644 return(FAILURE);
645 }
646
647 /* clip out the note end event */
648
649 DB_CMNT("ned_mve - clipping out end");
650
651 if (p_bak EQ ep)
652 p_bak = ep->e_fwd;
653
654 if (p_ctr EQ ep)
655 p_ctr = ep->e_fwd;
656
657 if (p_cur EQ ep)
658 p_cur = ep->e_fwd;
659
660 if (p_fwd EQ ep)
661 p_fwd = ep->e_fwd;
662
663 e_rmv((struct s_entry *)ep);
664
665 ep->e_time = ctime; /* correct end time */
666
667 /* re-insert end event */
668
669 e_ins((struct s_entry *)ep, ep_adj(p_cur, 0, ctime));
670
671 noteop = NOP_NUL; /* clear pending operation */
672 notesel = FALSE; /* note not selected */
673 DB_EXIT("ned_mve - end moved");
674 return(SUCCESS);
675
676 } else {
677
678 if (E_NULL NE fcnote(grp, cnote)) { /* natural ? */
679
680 notesel = TRUE; /* note selected */
681 DB_EXIT("ned_mve - natural selected");
682 return(FAILURE);
683
684 } else if (-1 NE (note = accnote())) {
685
686 if (E_NULL NE (bp = fcnote(grp, note))) { /* accidental ? */
687
688 notesel = TRUE; /* note selected */
689 DB_EXIT("ned_mve - accidental selected");
690 return(FAILURE);
691 }
692 }
693
694 notesel = FALSE; /* note not selected */
695 noteop = NOP_NUL; /* clear pending operation code */
696 DB_EXIT("ned_mve - unable to find note");
697 return(FAILURE);
698 }
699}
700
701/*
702
703*/
704
705/*
706 =============================================================================
707 donote() -- do a note operation
708 =============================================================================
709*/
710
711donote()
712{
713 register short grp, i, gs;
714
715 DB_ENTR("donote");
716
717 if (scmctl NE -1) { /* area 1 menu must be down */
718
719 DB_EXIT("donote - scmctl NE -1");
720 return;
721 }
722
723 if (NOT recsw) { /* must be in record mode */
724
725 DB_EXIT("donote - not in record mode");
726 return;
727 }
728
729 /* determine which group we want to work with */
730
731 gs = 0;
732 grp = -1;
733
734 for (i = 0; i < 12; i++) { /* scan the groups */
735
736 if ((grpmode[i] EQ 2) AND grpstat[i]) {
737
738 grp = i; /* log the group */
739 ++gs; /* count enabled groups */
740#if DEBUGIT
741 if (debugsw)
742 printf("donote(): gs = %d, grp = %d\n", gs, grp);
743#endif
744 }
745 }
746
747#if DEBUGIT
748 if (debugsw)
749 printf("donote(): final gs = %d, grp = %d\n", gs, grp);
750#endif
751
752/*
753
754*/
755 if (gs NE 1) { /* must have a single group enabled */
756
757 DB_EXIT("donote - no single group enabled");
758 return;
759 }
760
761 if (pix2mid(cxval, cyval)) { /* must point at a note position */
762
763#if DEBUGIT
764 if (debugsw)
765 printf("donote(): no note at cxval = %d, cyval = %d\n",
766 cxval, cyval);
767#endif
768 DB_EXIT("donote - not at a note position");
769 return;
770 }
771/*
772
773*/
774#if DEBUGIT
775 if (debugsw)
776 printf("donote(): at (cxval=%d, cyval=%d): cnote=%d, cflag=%d, ctime=%ld\n",
777 cxval, cyval, cnote, cflag, ctime);
778#endif
779
780 DB_CMNT("donote - dispatching");
781
782 switch (noteop) { /* dispatch off of note operation code */
783
784 case NOP_ACC: /* Begin Acc */
785
786 if (ned_acc(grp))
787 break;
788
789 sc_refr(fc_val); /* refresh screen if successful */
790 break;
791
792 case NOP_NAT: /* Begin Nat */
793
794 if (ned_nat(grp))
795 break;
796
797 sc_refr(fc_val); /* refresh screen if successful */
798 break;
799
800 case NOP_END: /* End Note */
801
802 if (ned_end(grp))
803 break;
804
805 sc_refr(fc_val); /* refresh screen if successful */
806 break;
807/*
808
809*/
810 case NOP_MVN: /* Move Note */
811
812 if (ned_mvn(grp))
813 break;
814
815 sc_refr(fc_val); /* refresh screen if successful */
816 break;
817
818 case NOP_MVB: /* Move Begin */
819
820 if (ned_mvb(grp))
821 break;
822
823 sc_refr(fc_val); /* refresh screen if successful */
824 break;
825
826 case NOP_MVE: /* Move End */
827
828 if (ned_mve(grp))
829 break;
830
831 sc_refr(fc_val); /* refresh screen if successful */
832 break;
833
834 default:
835
836 DB_CMNT("donote - bad operation");
837 noteop = NOP_NUL; /* clear pending operation code */
838 }
839
840 dnedmod(); /* update note edit window */
841 DB_EXIT("donote");
842 return;
843}
Note: See TracBrowser for help on using the repository browser.