source: buchla-68k/orig/RAM/SECCPY.C@ 4f508e6

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

Imported original source code.

  • Property mode set to 100755
File size: 15.5 KB
Line 
1/*
2 =============================================================================
3 seccpy.c -- section operation functions
4 Version 12 -- 1988-07-16 -- D.N. Lynx Crowe
5
6 This file contains the section operation functions for:
7
8 SOP_CPY copy sec_cpy()
9 SOP_MRG merge sec_mrg()
10 SOP_MOV move sec_mov()
11 SOP_RMV remove sec_rmv()
12 SOP_GRP regroup sec_grp()
13 SOP_DGR delete groups sec_dgr()
14 SOP_DEV delete events sec_dev()
15 =============================================================================
16*/
17
18#undef DEBUGGER /* define to enable debug trace */
19#define DEBUGIT 0
20
21#include "stddefs.h"
22#include "debug.h"
23#include "score.h"
24#include "scfns.h"
25#include "secops.h"
26#include "secdefs.h"
27
28#if DEBUGIT
29extern short debugsw;
30#endif
31
32extern short chksec(), oktocm(), oktode(), oktodg();
33
34extern long sizesec();
35
36extern struct s_entry *madjsec();
37
38extern short grptran;
39
40extern char cmgtags[];
41extern char cmgtype[];
42
43extern short ehdlist[];
44extern short grptmap[];
45
46/*
47
48*/
49
50/*
51 =============================================================================
52 sec_cpy() -- copy section 'ns' into the score at t_cur
53
54 ns section number to be copied
55
56 returns SUCCESS or FAILURE
57 =============================================================================
58*/
59
60short
61sec_cpy(ns)
62register short ns;
63{
64 register struct s_entry *cp, *lp, *rp;
65 register long newet;
66
67 DB_ENTR("sec_cpy");
68
69 secopok = TRUE;
70
71 if (chksec(ns)) { /* check that section is OK */
72
73 DB_EXIT("sec_cpy - FAILED chksec");
74 return(FAILURE);
75 }
76
77 /* see if we have enough free event space to make the copy */
78
79 if (sizesec() > evleft()) {
80
81 DB_EXIT("sec_cpy - FAILED sizesec");
82 return(FAILURE);
83 }
84
85 /* make sure we won't overflow the time range */
86
87 newet = t_sect + ((scp->e_bak)->e_bak)->e_time;
88
89 if ((newet < 0) OR (newet GE 0x00FFFFFFL)) {
90
91 DB_EXIT("sec_cpy - FAILED time check");
92 return(FAILURE);
93 }
94
95/*
96
97*/
98 /* make a time adjusted copy of the section */
99
100 if (E_NULL EQ (cp = madjsec(p_sbgn, t_cur))) {
101
102 DB_EXIT("sec_cpy - FAILED madjsec");
103 return(FAILURE);
104 }
105
106 /* point at the events in the score that will surround the copy */
107
108 lp = ep_adj(p_cur, 0, t_cur); /* events left of the copy */
109 rp = lp->e_fwd; /* events right of the copy */
110
111 /* adjust the times in the score past the copy */
112
113 edelta(lp, t_cur, t_sect);
114
115 /* insert the copy into the score */
116
117 lp->e_fwd = p_cbgn; /* link copy to left events */
118 p_cbgn->e_bak = lp;
119
120 rp->e_bak = p_cend; /* link copy to right events */
121 p_cend->e_fwd = rp;
122
123 /* fix-up the event headers in the copy */
124
125 ehfix(p_cbgn, p_cend);
126
127 DB_EXIT("sec_cpy - SUCCESS");
128 return(SUCCESS);
129}
130
131/*
132
133*/
134
135/*
136 =============================================================================
137 sec_mrg() -- merge section 'ns' into the score at t_cur
138
139 ns section number to be merged
140
141 returns SUCCESS or FAILURE
142 =============================================================================
143*/
144
145short
146sec_mrg(ns)
147register short ns;
148{
149 register struct s_entry *cp, *lp, *rp;
150 register long newet;
151 register short et;
152
153 DB_ENTR("sec_mrg");
154
155 secopok = TRUE;
156
157 if (chksec(ns)) { /* check that section is OK */
158
159 DB_EXIT("sec_mrg - FAILED chksec");
160 return(FAILURE);
161 }
162
163 /* see if we have enough free event space to make the copy */
164
165 if (sizesec() > evleft()) {
166
167 DB_EXIT("sec_mrg - FAILED sizesec");
168 return(FAILURE);
169 }
170
171 /* make sure we won't overflow the time range */
172
173 newet = t_sect + ((scp->e_bak)->e_bak)->e_time;
174
175 if ((newet < 0) OR (newet GE 0x00FFFFFFL)) {
176
177 DB_EXIT("sec_mrg - FAILED time check");
178 return(FAILURE);
179 }
180
181/*
182
183*/
184 /* make a time adjusted copy of the section */
185
186 if (E_NULL EQ (cp = madjsec(p_sbgn, t_cur))) {
187
188 DB_EXIT("sec_mrg - FAILED madjsec");
189 return(FAILURE);
190 }
191
192 DB_CMNT("sec_mrg - merging events");
193
194 lp = ep_adj(p_cur, 0, t_cur); /* get merge point */
195
196 while (cp) { /* merge events into score starting at p_cur */
197
198 rp = cp->e_fwd; /* point at next event */
199 lp = ep_adj(lp, 0, cp->e_time); /* update merge point */
200 lp = e_ins(cp, lp); /* insert the element */
201 et = cp->e_type & 0x007F; /* get event type */
202
203 if (-1 NE ehdlist[et]) /* see if it's a header */
204 eh_ins(cp, ehdlist[et]); /* update header list */
205
206 cp = rp; /* update copy pointer */
207 }
208
209 DB_EXIT("sec_mrg - SUCCESS");
210 return(SUCCESS);
211}
212
213/*
214
215*/
216
217/*
218 =============================================================================
219 sec_grp() -- regroup section 'ns'
220
221 ns section number to be re-grouped
222
223 returns SUCCESS or FAILURE
224 =============================================================================
225*/
226
227short
228sec_grp(ns)
229register short ns;
230{
231 register struct s_entry *cp, *rp;
232 register short et, nv, grp;
233
234 DB_ENTR("sec_grp");
235
236 secopok = TRUE;
237
238 if (chksec(ns)) { /* check that section is OK */
239
240 DB_EXIT("sec_grp - FAILED chksec");
241 return(FAILURE);
242 }
243
244 cp = p_sbgn; /* point at start of section */
245
246 while (cp NE p_send) { /* regroup events in section */
247
248 rp = cp->e_fwd; /* point at next event */
249 et = cp->e_type & 0x007F; /* get event type */
250
251 if (cmgtags[et]) { /* group sensitive ? */
252
253 grp = 0x000F & (cmgtype[et] ?
254 cp->e_data2 : cp->e_data1);
255
256 if ((et EQ EV_NBEG) OR (et EQ EV_NEND)) {
257
258 /* regroup */
259
260 cp->e_data2 = (cp->e_data2 & 0x00F0) |
261 grptmap[grp];
262
263 /* transpose */
264
265 nv = cp->e_data1 + grptran;
266
267 if (nv > 127)
268 nv = 127;
269 else if (nv < 0)
270 nv = 0;
271
272 cp->e_data1 = nv;
273
274 } else if ((et EQ EV_ANRS) OR (et EQ EV_ANVL)) {
275
276 /* regroup */
277
278 cp->e_data1 = (cp->e_data1 & 0x000F) |
279 (grptmap[grp] << 4);
280
281 } else {
282
283 /* regroup */
284
285 if (cmgtype[et])
286 cp->e_data2 = (cp->e_data2 & 0x00F0) |
287 grptmap[grp];
288 else
289 cp->e_data1 = (cp->e_data1 & 0x00F0) |
290 grptmap[grp];
291 }
292 }
293
294 cp = rp; /* update event pointer */
295 }
296
297 DB_EXIT("sec_grp - SUCCESS");
298 return(SUCCESS);
299}
300
301/*
302
303*/
304
305/*
306 =============================================================================
307 sec_mov() -- move section 'ns' to t_cur
308
309 ns section number to be moved
310
311 returns SUCCESS or FAILURE
312 =============================================================================
313*/
314
315short
316sec_mov(ns)
317register short ns;
318{
319 register struct s_entry *cp, *lp, *rp;
320 register long newet;
321 register short et, grp, nv;
322
323 DB_ENTR("sec_mov");
324
325 secopok = TRUE;
326
327 if (chksec(ns)) { /* check that section is OK */
328
329 DB_EXIT("sec_mov - FAILED chksec");
330 return(FAILURE);
331 }
332
333#if DEBUGIT
334 if (debugsw) {
335
336 printf("sec_mov: t_cur = %ld, t_sbgn = %ld, t_send = %ld, t_sect = %ld\n",
337 t_cur, t_sbgn, t_send, t_sect);
338
339 printf("sec_mov: p_cur = $%08lX, p_sbgn = $%08lX, p_send = $%08lX\n",
340 p_cur, p_sbgn, p_send);
341 }
342#endif
343
344 /* verify that section isn't being moved into itself */
345
346 if ((t_cur GE t_sbgn) AND (t_cur LE t_send)) {
347
348 DB_EXIT("sec_mov -- bad target");
349 return(FAILURE);
350 }
351
352/*
353
354*/
355 lp = ep_adj(p_cur, 0, t_cur); /* get left move point */
356 cp = p_send->e_fwd; /* get adjustment point */
357
358#if DEBUGIT
359 if (debugsw)
360 printf("sec_mov: lp = $%08lX, cp = $%08lX\n", lp, cp);
361#endif
362
363 /* clip out the section and close up the hole */
364
365 (p_sbgn->e_bak)->e_fwd = p_send->e_fwd;
366 (p_send->e_fwd)->e_bak = p_sbgn->e_bak;
367 p_sbgn->e_bak = E_NULL;
368 p_send->e_fwd = E_NULL;
369
370 /* adjust the times above the clip point to end of score */
371
372 if (t_cur GE t_send) /* adjust t_cur if above clip point */
373 t_cur -= t_sect;
374
375#if DEBUGIT
376 if (debugsw)
377 printf("sec_mov: adjusted t_cur = %ld\n", t_cur);
378#endif
379
380 while (EV_FINI NE (et = 0x007F & cp->e_type)) {
381
382 cp->e_time -= t_sect; /* adjust event time */
383 cp = cp->e_fwd; /* point at next event */
384 }
385
386/*
387
388*/
389#if DEBUGIT
390 if (debugsw)
391 printf("sec_mov: adjusted p_cur->e_time = %ld\n",
392 p_cur->e_time);
393#endif
394
395 /* relativize the section to 0 and unlink event headers from hplist */
396
397 rp = p_sbgn; /* start at the beginning */
398 newet = p_sbgn->e_time; /* relativize to begin time EQ 0 */
399
400 while (rp) {
401
402 rp->e_time -= newet; /* relativize the time */
403 et = 0x007F & rp->e_type; /* get event type */
404
405 if (cmgtags[et]) { /* group sensitive ? */
406
407 grp = 0x000F & (cmgtype[et] ?
408 rp->e_data2 : rp->e_data1);
409
410 if ((et EQ EV_NBEG) OR (et EQ EV_NEND)) {
411
412 /* regroup */
413
414 rp->e_data2 = (rp->e_data2 & 0x00F0) |
415 grptmap[grp];
416
417 /* transpose */
418
419 nv = rp->e_data1 + grptran;
420
421 if (nv > 127)
422 nv = 127;
423 else if (nv < 0)
424 nv = 0;
425
426 rp->e_data1 = nv;
427
428 } else if ((et EQ EV_ANRS) OR (et EQ EV_ANVL)) {
429
430 /* regroup */
431
432 rp->e_data1 = (rp->e_data1 & 0x000F) |
433 (grptmap[grp] << 4);
434
435 } else {
436
437 /* regroup */
438
439 if (cmgtype[et])
440 rp->e_data2 = (rp->e_data2 & 0x00F0) |
441 grptmap[grp];
442 else
443 rp->e_data1 = (rp->e_data1 & 0x00F0) |
444 grptmap[grp];
445 }
446 }
447
448 if (-1 NE ehdlist[et]) /* if it's a header ... */
449 eh_rmv(rp, ehdlist[et]); /* ... remove it from hplist */
450
451 rp = rp->e_fwd; /* point at the next event */
452 }
453
454 rp = lp->e_fwd; /* get right insert pointer */
455
456 /* insert the moved section */
457
458 p_sbgn->e_bak = lp;
459 p_send->e_fwd = rp;
460 lp->e_fwd = p_sbgn;
461 rp->e_bak = p_send;
462
463/*
464
465*/
466 /* derelativize the moved section and put headers back on hplist */
467
468 cp = p_sbgn;
469 newet = t_cur;
470
471#if DEBUGIT
472 if (debugsw)
473 printf("sec_mov: lp = $%08lX, cp = $%08lX, rp = $%08lX, newet = %ld\n",
474 lp, cp, rp, newet);
475#endif
476
477 while (cp NE rp) {
478
479 et = 0x007F & cp->e_type; /* get event type */
480 cp->e_time += newet; /* derelativize the time */
481
482 if (-1 NE ehdlist[et]) /* if event is a header ... */
483 eh_ins(cp, ehdlist[et]); /* ... put event on hplist */
484
485 cp = cp->e_fwd; /* point at next event */
486 }
487
488#if DEBUGIT
489 if (debugsw)
490 printf("sec_mov: adjusting times above $%08lx (%ld) by %ld\n",
491 cp, cp->e_time, t_sect);
492#endif
493
494 /* adjust times above move point */
495
496 while (EV_FINI NE (et = 0x007F & cp->e_type)) {
497
498 cp->e_time += t_sect; /* adjust the time */
499 cp = cp->e_fwd; /* point at next event */
500 }
501
502 DB_EXIT("sec_mov - SUCCESS");
503 return(SUCCESS);
504}
505
506/*
507
508*/
509
510/*
511 =============================================================================
512 sec_rmv() --remove section 'ns'
513
514 ns section number to be removed
515
516 returns SUCCESS or FAILURE
517 =============================================================================
518*/
519
520short
521sec_rmv(ns)
522register short ns;
523{
524 register struct s_entry *cp, *lp, *rp;
525 register short et;
526 struct s_entry *pp;
527
528 DB_ENTR("sec_rmv");
529
530 secopok = TRUE;
531
532 if (chksec(ns)) { /* check that section is OK */
533
534 DB_EXIT("sec_rmv - FAILED chksec");
535 return(FAILURE);
536 }
537
538 pp = cp = p_send->e_fwd; /* get adjustment point */
539
540#if DEBUGIT
541 if (debugsw) {
542
543 printf("sec_rmv: t_cur = %ld, t_sbgn = %ld, t_send = %ld, t_sect = %ld\n",
544 t_cur, t_sbgn, t_send, t_sect);
545
546 printf("sec_rmv: p_cur = $%08lX, p_sbgn = $%08lX, p_send = $%08lX\n",
547 p_cur, p_sbgn, p_send);
548
549 printf("sec_rmv: cp = $%08lX\n", cp);
550 }
551#endif
552
553/*
554
555*/
556 /* clip out the section and close up the hole */
557
558 (p_sbgn->e_bak)->e_fwd = p_send->e_fwd;
559 (p_send->e_fwd)->e_bak = p_sbgn->e_bak;
560 p_sbgn->e_bak = E_NULL;
561 p_send->e_fwd = E_NULL;
562
563 /* adjust the times above the clip point to end of score */
564
565 if (t_cur GE t_send) /* adjust t_cur if above clip point */
566 t_cur -= t_sect;
567
568#if DEBUGIT
569 if (debugsw)
570 printf("sec_rmv: adjusted t_cur = %ld\n", t_cur);
571#endif
572
573 while (EV_FINI NE (et = 0x007F & cp->e_type)) {
574
575 cp->e_time -= t_sect; /* adjust event time */
576 cp = cp->e_fwd; /* point at next event */
577 }
578
579#if DEBUGIT
580 if (debugsw)
581 printf("sec_rmv: adjusted p_cur->e_time = %ld\n",
582 p_cur->e_time);
583#endif
584
585 /* unlink event headers from hplist, fix pointers, and delete events */
586
587 rp = p_sbgn; /* start at the beginning */
588
589 while (rp) {
590
591 lp = rp->e_fwd; /* get next event pointer */
592 et = 0x007F & rp->e_type; /* get event type */
593
594 if (p_bak EQ rp) /* fix p_bak */
595 p_bak = pp;
596
597 if (p_cur EQ rp) /* fix p_cur */
598 p_cur = pp;
599
600 if (p_ctr EQ rp) /* fix p_ctr */
601 p_ctr = pp;
602
603 if (p_fwd EQ rp) /* fix p_fwd */
604 p_fwd = pp;
605
606 if (-1 NE ehdlist[et]) /* if it's a header ... */
607 eh_rmv(rp, ehdlist[et]); /* ... remove it from hplist */
608
609 e_del(e_rmv(rp)); /* delete the event */
610 rp = lp; /* point at next event */
611 }
612
613 seclist[curscor][ns] = E_NULL; /* delete section from seclist */
614 DB_EXIT("sec_rmv");
615 return(SUCCESS);
616}
617
618/*
619
620*/
621
622/*
623 =============================================================================
624 sec_dgr() --delete notes in enabled groups in section 'ns'
625
626 ns section number to be processed
627
628 returns SUCCESS or FAILURE
629 =============================================================================
630*/
631
632short
633sec_dgr(ns)
634register short ns;
635{
636 register struct s_entry *lp, *rp;
637
638 DB_ENTR("sec_dgr");
639
640 secopok = TRUE;
641
642 if (chksec(ns)) { /* check that section is OK */
643
644 DB_EXIT("sec_dgr - FAILED chksec");
645 return(FAILURE);
646 }
647
648#if DEBUGIT
649 if (debugsw) {
650
651 printf("sec_dgr: t_cur = %ld, t_sbgn = %ld, t_send = %ld, t_sect = %ld\n",
652 t_cur, t_sbgn, t_send, t_sect);
653
654 printf("sec_dgr: p_cur = $%08lX, p_sbgn = $%08lX, p_send = $%08lX\n",
655 p_cur, p_sbgn, p_send);
656 }
657#endif
658
659/*
660
661*/
662 /* delete note events for record enabled groups */
663
664 DB_CMNT("sec_dgr - deleting");
665
666 rp = p_sbgn->e_fwd; /* start at the beginning */
667
668 while (rp NE p_send) {
669
670 lp = rp->e_fwd; /* get next event pointer */
671
672 if (oktodg(rp)) { /* if it's one we want ... */
673
674 if (p_bak EQ rp) /* fix p_bak */
675 p_bak = lp;
676
677 if (p_cur EQ rp) /* fix p_cur */
678 p_cur = lp;
679
680 if (p_ctr EQ rp) /* fix p_ctr */
681 p_ctr = lp;
682
683 if (p_fwd EQ rp) /* fix p_fwd */
684 p_fwd = lp;
685
686 e_del(e_rmv(rp)); /* ... delete it */
687 }
688
689 rp = lp; /* point at next event */
690 }
691
692 DB_EXIT("sec_dgr");
693 return(SUCCESS);
694}
695
696/*
697
698*/
699
700/*
701 =============================================================================
702 sec_dev() --delete non-note events in enabled groups in section 'ns'
703
704 ns section number to be processed
705
706 returns SUCCESS or FAILURE
707 =============================================================================
708*/
709
710short
711sec_dev(ns)
712register short ns;
713{
714 register struct s_entry *lp, *rp;
715
716 DB_ENTR("sec_dev");
717
718 secopok = TRUE;
719
720 if (chksec(ns)) { /* check that section is OK */
721
722 DB_EXIT("sec_dev - FAILED chksec");
723 return(FAILURE);
724 }
725
726#if DEBUGIT
727 if (debugsw) {
728
729 printf("sec_dev: t_cur = %ld, t_sbgn = %ld, t_send = %ld, t_sect = %ld\n",
730 t_cur, t_sbgn, t_send, t_sect);
731
732 printf("sec_dev: p_cur = $%08lX, p_sbgn = $%08lX, p_send = $%08lX\n",
733 p_cur, p_sbgn, p_send);
734 }
735#endif
736
737/*
738
739*/
740 /* delete non-note events for record enabled groups */
741
742 DB_CMNT("sec_dev - deleting");
743
744 rp = p_sbgn->e_fwd; /* start at the beginning */
745
746 while (rp NE p_send) {
747
748 lp = rp->e_fwd; /* get next event pointer */
749
750 if (oktode(rp)) { /* if it's one we want ... */
751
752 if (p_bak EQ rp) /* fix p_bak */
753 p_bak = lp;
754
755 if (p_cur EQ rp) /* fix p_cur */
756 p_cur = lp;
757
758 if (p_ctr EQ rp) /* fix p_ctr */
759 p_ctr = lp;
760
761 if (p_fwd EQ rp) /* fix p_fwd */
762 p_fwd = lp;
763
764 e_del(e_rmv(rp)); /* ... delete it */
765 }
766
767 rp = lp; /* point at next event */
768 }
769
770 DB_EXIT("sec_dev");
771 return(SUCCESS);
772}
Note: See TracBrowser for help on using the repository browser.