1 | /*
|
---|
2 | =============================================================================
|
---|
3 | delnote.c -- MIDAS-VII note deletion
|
---|
4 | Version 16 -- 1988-10-27 -- D.N. Lynx Crowe
|
---|
5 | =============================================================================
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "ram.h"
|
---|
9 |
|
---|
10 | #define TO_LFT (TO_BAK + 1)
|
---|
11 |
|
---|
12 | /*
|
---|
13 | =============================================================================
|
---|
14 | delnote() -- delete a note
|
---|
15 | =============================================================================
|
---|
16 | */
|
---|
17 |
|
---|
18 | int16_t delnote(void)
|
---|
19 | {
|
---|
20 | register struct n_entry *bp, *cp, *ep;
|
---|
21 | register int32_t t_left;
|
---|
22 | register int16_t tnote, grp;
|
---|
23 | register int16_t runtag, scantag;
|
---|
24 | int16_t disptag;
|
---|
25 |
|
---|
26 | disptag = FALSE; /* nothing changed yet */
|
---|
27 |
|
---|
28 | if (NOT recsw) /* must be in record mode */
|
---|
29 | return(FAILURE);
|
---|
30 |
|
---|
31 | /* convert cursor position to note number and time */
|
---|
32 |
|
---|
33 | if (pix2mid())
|
---|
34 | goto notnote;
|
---|
35 |
|
---|
36 | ++cflag;
|
---|
37 | tnote = cnote;
|
---|
38 | t_left = t_cur - TO_LFT;
|
---|
39 | cp = (struct n_entry *)frfind(ctime, 0);
|
---|
40 |
|
---|
41 |
|
---|
42 | while (cflag--) { /* handle both naturals and accidentals */
|
---|
43 |
|
---|
44 | for (grp = 0; grp < 12; grp++) { /* for each group ... */
|
---|
45 |
|
---|
46 | if ((grpstat[grp] EQ 0) OR /* ... enabled and ... */
|
---|
47 | (grpmode[grp] NE 2)) /* ... in record mode: */
|
---|
48 | continue;
|
---|
49 |
|
---|
50 | runtag = TRUE;
|
---|
51 | bp = cp; /* start at cursor */
|
---|
52 |
|
---|
53 | while (runtag) { /* scan left from cursor until: */
|
---|
54 |
|
---|
55 | if ((bp->e_time LT t_left) OR
|
---|
56 | (bp->e_type EQ EV_SCORE)) { /* left edge */
|
---|
57 |
|
---|
58 | /* done -- nothing to delete */
|
---|
59 |
|
---|
60 | runtag = FALSE;
|
---|
61 | continue;
|
---|
62 |
|
---|
63 | } else if ((bp->e_type EQ EV_NEND) AND
|
---|
64 | (bp->e_note EQ tnote) AND
|
---|
65 | (bp->e_group EQ grp)) { /* note end */
|
---|
66 |
|
---|
67 | /* done -- overlap */
|
---|
68 |
|
---|
69 | runtag = FALSE;
|
---|
70 | continue;
|
---|
71 |
|
---|
72 | } else if ((bp->e_type EQ EV_NBEG) AND
|
---|
73 | (bp->e_note EQ tnote) AND
|
---|
74 | (bp->e_group EQ grp)) { /* note begin */
|
---|
75 |
|
---|
76 | /* possible deletion */
|
---|
77 |
|
---|
78 | /* scan right from note begin until: */
|
---|
79 |
|
---|
80 | ep = bp->e_fwd;
|
---|
81 | scantag = TRUE;
|
---|
82 |
|
---|
83 | while (scantag) {
|
---|
84 |
|
---|
85 | /* note begin -- done -- overlap */
|
---|
86 |
|
---|
87 | if ((ep->e_type EQ EV_NBEG) AND
|
---|
88 | (ep->e_note EQ tnote) AND
|
---|
89 | (ep->e_group EQ grp)) {
|
---|
90 |
|
---|
91 | scantag = FALSE;
|
---|
92 | runtag = FALSE;
|
---|
93 | continue;
|
---|
94 |
|
---|
95 | } else if ((ep->e_type EQ EV_NEND) AND
|
---|
96 | (ep->e_note EQ tnote) AND
|
---|
97 | (ep->e_group EQ grp)) {
|
---|
98 |
|
---|
99 | /* note end */
|
---|
100 |
|
---|
101 | /* delete note end */
|
---|
102 |
|
---|
103 | if (cp EQ ep)
|
---|
104 | cp = cp->e_bak;
|
---|
105 |
|
---|
106 | if (p_ctr EQ ep)
|
---|
107 | p_ctr = p_ctr->e_bak;
|
---|
108 |
|
---|
109 | if (p_bak EQ ep)
|
---|
110 | p_bak = p_bak->e_bak;
|
---|
111 |
|
---|
112 | if (p_fwd EQ ep)
|
---|
113 | p_fwd = p_fwd->e_bak;
|
---|
114 |
|
---|
115 | if (p_cur EQ ep)
|
---|
116 | p_cur = p_cur->e_bak;
|
---|
117 |
|
---|
118 | e_del(e_rmv(ep));
|
---|
119 |
|
---|
120 | /* delete note begin */
|
---|
121 |
|
---|
122 | if (cp EQ bp)
|
---|
123 | cp = cp->e_bak;
|
---|
124 |
|
---|
125 | if (p_ctr EQ bp)
|
---|
126 | p_ctr = p_ctr->e_bak;
|
---|
127 |
|
---|
128 | if (p_bak EQ bp)
|
---|
129 | p_bak = p_bak->e_bak;
|
---|
130 |
|
---|
131 | if (p_fwd EQ bp)
|
---|
132 | p_fwd = p_fwd->e_bak;
|
---|
133 |
|
---|
134 | if (p_cur EQ bp)
|
---|
135 | p_cur = p_cur->e_bak;
|
---|
136 |
|
---|
137 | e_del(e_rmv(bp));
|
---|
138 |
|
---|
139 | disptag = TRUE;
|
---|
140 | runtag = FALSE;
|
---|
141 | scantag = FALSE;
|
---|
142 | continue;
|
---|
143 |
|
---|
144 | } else if (ep->e_type EQ EV_FINI) {
|
---|
145 |
|
---|
146 | /* score end */
|
---|
147 |
|
---|
148 | /* delete note begin */
|
---|
149 |
|
---|
150 | if (cp EQ bp)
|
---|
151 | cp = cp->e_bak;
|
---|
152 |
|
---|
153 | if (p_ctr EQ bp)
|
---|
154 | p_ctr = p_ctr->e_bak;
|
---|
155 |
|
---|
156 | if (p_bak EQ bp)
|
---|
157 | p_bak = p_bak->e_bak;
|
---|
158 |
|
---|
159 | if (p_fwd EQ bp)
|
---|
160 | p_fwd = p_fwd->e_bak;
|
---|
161 |
|
---|
162 | if (p_cur EQ bp)
|
---|
163 | p_cur = p_cur->e_bak;
|
---|
164 |
|
---|
165 | e_del(e_rmv(bp));
|
---|
166 |
|
---|
167 | disptag = TRUE;
|
---|
168 | runtag = FALSE;
|
---|
169 | scantag = FALSE;
|
---|
170 | continue;
|
---|
171 | }
|
---|
172 |
|
---|
173 | /* scan right */
|
---|
174 |
|
---|
175 | ep = ep->e_fwd;
|
---|
176 |
|
---|
177 | } /* end while (scantag) */
|
---|
178 |
|
---|
179 | } /* end if */
|
---|
180 |
|
---|
181 | /* scan left */
|
---|
182 |
|
---|
183 | bp = bp->e_bak;
|
---|
184 |
|
---|
185 | } /* end while (runtag) */
|
---|
186 |
|
---|
187 | } /* end for (grp) */
|
---|
188 |
|
---|
189 | /* handle accidentals */
|
---|
190 |
|
---|
191 | if (ac_code EQ N_SHARP)
|
---|
192 | ++tnote; /* treat accidentals as sharps */
|
---|
193 | else
|
---|
194 | --tnote; /* treat accidentals as flats */
|
---|
195 |
|
---|
196 | } /* end while (cflag) */
|
---|
197 |
|
---|
198 | notnote: /* jumped to if pix2mid() returned FAILURE (not on a note) */
|
---|
199 |
|
---|
200 | /* check for a bar marker delete operation */
|
---|
201 |
|
---|
202 | if (NOT disptag) { /* if no notes were deleted, try for a bar */
|
---|
203 |
|
---|
204 | if (ctime < 0L) /* time has to be good */
|
---|
205 | return(FAILURE);
|
---|
206 |
|
---|
207 | /* search current time for a bar marker - delete any found */
|
---|
208 |
|
---|
209 | ep = ep_adj(p_cur, 1, ctime);
|
---|
210 |
|
---|
211 | while (ctime EQ ep->e_time) {
|
---|
212 |
|
---|
213 | bp = ep->e_fwd;
|
---|
214 |
|
---|
215 | if (EV_BAR EQ ep->e_type) {
|
---|
216 |
|
---|
217 | if (ep EQ p_bak)
|
---|
218 | p_bak = p_bak->e_bak;
|
---|
219 |
|
---|
220 | if (ep EQ p_ctr)
|
---|
221 | p_ctr = p_ctr->e_bak;
|
---|
222 |
|
---|
223 | if (ep EQ p_cur)
|
---|
224 | p_cur = p_cur->e_bak;
|
---|
225 |
|
---|
226 | if (ep EQ p_fwd)
|
---|
227 | p_fwd = p_fwd->e_bak;
|
---|
228 |
|
---|
229 | e_del(e_rmv(ep));
|
---|
230 | disptag = TRUE;
|
---|
231 | }
|
---|
232 |
|
---|
233 | ep = bp;
|
---|
234 | }
|
---|
235 | }
|
---|
236 |
|
---|
237 | if (disptag)
|
---|
238 | sc_refr(t_cur);
|
---|
239 |
|
---|
240 | return(disptag ? SUCCESS : FAILURE);
|
---|
241 | }
|
---|
242 |
|
---|