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

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

Point of no return.

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