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

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

Added missing includes and declarations.

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