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