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