2 /* Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by Arkkra Enterprises */
3 /* All rights reserved */
5 /* functions for building up lists of GRPSYL structs,
6 * error checking them, etc. These functions are called at parse
15 /* 1-line staff allows for default pitch on first chord of measure. However,
16 * at the time we are gathering note information, it may not be known whether
17 * we are on a 1-line staff or not, so it is temporarily set to PP_NO_PITCH,
18 * then later if we have a 1-line staff, it gets converted to default of C4 */
19 #define DFLT_PITCH 'c'
22 /* how many NOTE structs to allocate at a time. We don't know in advance
23 * how many we'll need, so get a bunch and realloc as necessary. */
24 #define NOTE_CHUNK (4)
26 static int Tuplet_state
= NOITEM
; /* current tuplet state */
27 static struct GRPSYL
*Tuplet_list_p
; /* first GRPSYL in a tuplet group */
28 static short Slur_begin
; /* slurtolist index at which <> began */
30 /* static functions */
31 static void clone_notelist
P((struct GRPSYL
*new_p
, struct GRPSYL
*old_p
,
33 static void finish_bar
P((void));
34 static void restart_bar
P((void));
35 static void fix_grpsyl_list
P((struct MAINLL
*mainll_item_p
));
36 static void fix_a_group_list
P((struct GRPSYL
*grpsyllist_p
, int staffno
,
37 int vno
, char *fname
, int lineno
, int mrptnum
,
38 struct TIMEDSSV
* tssv_p
));
39 static void chk_a_syl_list
P((struct GRPSYL
*grpsyl_p
, char *fname
,
42 /* change relative octaves to absolute */
43 static void resolve_octaves
P((struct GRPSYL
*grpsyl_item_p
,
45 static void fix_frets
P((struct GRPSYL
*grpsyl_item_p
));
46 static int string_number
P((struct STRINGINFO
*stringinfo_p
, int nstrings
,
47 int letter
, int accidental
, int nticks
));
49 static void check_grace
P((struct GRPSYL
*grpsyl_item_p
, char *fname
,
51 static void fix_strlist
P((struct GRPSYL
*gs_p
, int font
, int size
,
52 char *fname
, int lineno
));
53 static void check4missing_voices
P((struct MAINLL
*list_p
));
54 static void fix_mrpt
P((struct MAINLL
*mll_p
));
55 static int chk_mrpt_ssv_interactions
P((struct SSV
*ssv_p
, struct GRPSYL
*gs_p
,
57 static int is_ms
P((struct GRPSYL
*gs_p
));
58 static int voices_override
P((int staff
, int field
));
59 static void sort_notes
P((struct GRPSYL
*grpsyl_p
, char *fname
, int lineno
));
60 static int parse_bend_string
P((char *bendstring
));
61 static void check_bends
P((struct GRPSYL
*gs_p
, struct MAINLL
*mll_p
));
64 /* allocate a new GRPSYL struct and return a pointer to it */
69 int grp_or_syl
; /* GS_GROUP or GS_SYLLABLE */
75 /* allocate a new structure */
76 CALLOC(GRPSYL
, new_p
, 1);
78 /* fill in default values */
79 new_p
->grpsize
= GS_NORMAL
;
80 new_p
->grpvalue
= GV_NORMAL
;
81 new_p
->grpcont
= GC_NOTES
;
82 new_p
->beamloc
= NOITEM
;
83 new_p
->breakbeam
= NO
;
84 new_p
->tuploc
= NOITEM
;
85 new_p
->grpsyl
= (short) grp_or_syl
;
87 new_p
->inputfile
= Curr_filename
;
88 new_p
->inputlineno
= (short) yylineno
;
89 new_p
->normwith
= YES
;
90 new_p
->stemdir
= (short) UNKNOWN
;
91 new_p
->beamto
= CS_SAME
;
92 new_p
->stemto
= CS_SAME
;
93 /* default to no user-specified stem length */
94 new_p
->stemlen
= STEMLEN_UNKNOWN
;
95 /* default to no user-specified rest dist */
96 new_p
->restdist
= NORESTDIST
;
97 /* default to no user-specified syllable position */
98 new_p
->sylposition
= NOSYLPOSITION
;
99 /* no clef change before this group */
100 new_p
->clef
= NOCLEF
;
101 /* by default, placement will figure out the note head shape */
102 new_p
->headshape
= HS_UNKNOWN
;
103 /* let Mup figure out angle for beams */
104 new_p
->beamslope
= NOBEAMANGLE
;
105 /* everything else zero-ed is proper default */
111 /* Copy group attributes (grpsize, grpvalue, "with" list, etc)
112 * from one GRPSYL to another */
115 copy_attributes(newgrp_p
, oldgrp_p
)
117 struct GRPSYL
*newgrp_p
; /* copy info into this one */
118 struct GRPSYL
*oldgrp_p
; /* copy from this one */
122 yyerror("empty [] not allowed on the first chord of a measure");
126 newgrp_p
->grpvalue
= oldgrp_p
->grpvalue
;
127 newgrp_p
->grpsize
= oldgrp_p
->grpsize
;
128 newgrp_p
->headshape
= oldgrp_p
->headshape
;
129 newgrp_p
->stemdir
= oldgrp_p
->stemdir
;
130 newgrp_p
->stemlen
= oldgrp_p
->stemlen
;
131 newgrp_p
->ho_usage
= oldgrp_p
->ho_usage
;
132 newgrp_p
->ho_value
= oldgrp_p
->ho_value
;
134 clone_withlist(newgrp_p
, oldgrp_p
);
136 if (oldgrp_p
->slash_alt
> 0) {
137 newgrp_p
->slash_alt
= oldgrp_p
->slash_alt
;
139 newgrp_p
->padding
= oldgrp_p
->padding
;
140 /* restdist is only used for rests, but easiest to just always copy,
141 * since grpcont hasn't been set yet. */
142 newgrp_p
->restdist
= oldgrp_p
->restdist
;
146 /* make a copy of withlist */
149 clone_withlist(newgrp_p
, oldgrp_p
)
151 struct GRPSYL
*newgrp_p
;
152 struct GRPSYL
*oldgrp_p
;
155 register int n
; /* index through with list */
158 newgrp_p
->nwith
= oldgrp_p
->nwith
;
159 if (oldgrp_p
->nwith
> 0) {
160 MALLOCA(char *, newgrp_p
->withlist
, oldgrp_p
->nwith
);
161 for (n
= 0; n
< oldgrp_p
->nwith
; n
++) {
162 newgrp_p
->withlist
[n
] =
163 copy_string(oldgrp_p
->withlist
[n
] + 2,
164 Curr_font
, Curr_size
);
170 /* Copy timeunit info from one GRPSYL to another,
171 * or use default if source is NULL. If needed to use default timeunit,
172 * and that included additive times, returns pointer to the list of those
173 * times, else return NULL. */
176 copy_timeunit(newgrp_p
, oldgrp_p
, timelist_p
)
178 struct GRPSYL
*newgrp_p
; /* copy info into here */
179 struct GRPSYL
*oldgrp_p
; /* copy from here. If NULL, use default value */
180 struct TIMELIST
*timelist_p
; /* If non-null use this instead of oldgrp_p */
187 if (oldgrp_p
== (struct GRPSYL
*) 0) {
189 /* use default timeunit. Have to figure out differently for
190 * lyrics than notes, because for lyrics the voice depends
191 * on the lyrics place. */
192 if (newgrp_p
->grpsyl
== GS_GROUP
) {
193 ssv_p
= get_dflt_timeunit_ssv();
196 ssv_p
= get_lyr_dflt_timeunit_ssv();
198 newgrp_p
->fulltime
= ssv_p
->timeunit
;
200 newgrp_p
->basictime
= reconstruct_basictime(newgrp_p
->fulltime
);
201 newgrp_p
->dots
= recalc_dots(newgrp_p
->fulltime
,
202 newgrp_p
->basictime
);
203 return(ssv_p
->timelist_p
);
209 newgrp_p
->basictime
= oldgrp_p
->basictime
;
210 newgrp_p
->dots
= oldgrp_p
->dots
;
212 /* actual time value is (2 * basictime)
213 * - (basic_time x 1/2 to the (dots) power) */
214 /* can't just copy the fulltime from oldgrp, because that
215 * may have been altered if it was a tuplet */
216 if (newgrp_p
->basictime
== 0) {
217 /* strange case of double whole, stored as zero */
221 else if (newgrp_p
->basictime
== -1) {
222 /* strange case of quad whole, stored as -1 */
228 basictime
.d
= newgrp_p
->basictime
;
231 newgrp_p
->fulltime
= calcfulltime(basictime
, newgrp_p
->dots
);
234 /* note that tuplet values are dealt with in end_tuplet(). Once we
235 * collect an entire tuplet, we can go through and multiply
236 * the fulltimes by the appropriate amount */
241 /* copy notes (list of NOTE structs) from one GRPSYL to another, along with
242 * a few group attributes that should be copied when a GRPSYL is copied. */
245 copy_notes(newgrp_p
, oldgrp_p
)
247 struct GRPSYL
*newgrp_p
; /* copy into here */
248 struct GRPSYL
*oldgrp_p
; /* copy from here */
251 /* first GRPSYL in bar must have notes specified */
252 if (oldgrp_p
== (struct GRPSYL
*) 0) {
253 add_note(newgrp_p
, PP_NO_PITCH
, '\0', DFLT_OCT
, 0, NO
, (char *) 0);
254 newgrp_p
->notelist
[ newgrp_p
->nnotes
].tie
= NO
;
255 newgrp_p
->notelist
[ newgrp_p
->nnotes
].notesize
= GS_NORMAL
;
259 /* there was a previous GRPSYL -- use it for defaults */
260 newgrp_p
->grpcont
= oldgrp_p
->grpcont
;
261 clone_notelist(newgrp_p
, oldgrp_p
, NO
);
262 newgrp_p
->is_meas
= oldgrp_p
->is_meas
;
263 newgrp_p
->uncompressible
= oldgrp_p
->uncompressible
;
268 /* once the info about a group has been gathered,
269 * add it to list of GRPSYL structs */
272 link_notegroup(newgrp_p
, last_grp_p
)
274 struct GRPSYL
*newgrp_p
; /* one to add on */
275 struct GRPSYL
*last_grp_p
; /* one to add it onto */
280 debug(4, "link_notegroup file=%s line=%d", newgrp_p
->inputfile
,
281 newgrp_p
->inputlineno
);
283 if (last_grp_p
== (struct GRPSYL
*) 0) {
284 /* first one: we need to keep a pointer to this one to
285 * link onto one or more STAFF structs later */
286 Curr_gs_list_p
= newgrp_p
;
291 last_grp_p
->next
= newgrp_p
;
293 newgrp_p
->prev
= last_grp_p
;
295 /* fill in tuplet information, based on current state. Adjust tuplet
296 * state if necessary for use with later groups */
297 newgrp_p
->tuploc
= (short) Tuplet_state
;
298 if (Tuplet_state
== STARTITEM
) {
299 Tuplet_list_p
= newgrp_p
;
300 Tuplet_state
= INITEM
;
303 /* We don't have a quad whole note character,
304 * so don't allow 1/4 on notes */
305 if (EQ(newgrp_p
->fulltime
, Four
)) {
306 for (n
= 0; n
< newgrp_p
->nnotes
; n
++) {
307 if (newgrp_p
->notelist
[n
].letter
>= 'a' &&
308 newgrp_p
->notelist
[n
].letter
<= 'g') {
309 yyerror("1/4 not allowed on notes");
315 /* dist is only allowed on rests */
316 if (newgrp_p
->restdist
!= NORESTDIST
) {
317 for (n
= 0; n
< newgrp_p
->nnotes
; n
++) {
318 if (newgrp_p
->notelist
[n
].letter
!= PP_REST
) {
319 yyerror("dist only allowed on rests");
326 /* make a copy of a linked list of GRPSYL structs and return a pointer to it */
327 /* Note that while this function is called for both groups and syllables,
328 * lyric syllables are not copied by this function. Lyrics syllables are
329 * handled in lyrics.c */
332 clone_gs_list(list_p
, copy_noteinfo
)
334 struct GRPSYL
*list_p
; /* the list to be cloned */
335 int copy_noteinfo
; /* if YES, copy notes and with lists */
338 struct GRPSYL
*new_p
, *newlist_p
;
339 struct GRPSYL
*prev_p
= (struct GRPSYL
*) 0; /* to remember last one,
340 to know where to link on current one */
344 /* walk down the existing list */
345 for (newlist_p
= (struct GRPSYL
*) 0; list_p
!= (struct GRPSYL
*) 0;
346 list_p
= list_p
->next
) {
348 /* allocate space for copy of list element and fill it in */
349 MALLOC(GRPSYL
, new_p
, 1);
351 (void) memcpy(new_p
, list_p
, sizeof(struct GRPSYL
) );
353 /* we can't just copy the links--they have to be recalculated */
354 if (newlist_p
== (struct GRPSYL
*) 0) {
356 /* first in new list: keep track of where list begins,
357 * since we need to return this value, and keep track
358 * of where we are, so we can link the next element
359 * onto this one, which will be its prev element */
365 prev_p
->next
= new_p
;
366 new_p
->prev
= prev_p
;
370 if (copy_noteinfo
== YES
) {
371 /* also need to make copies of the notelist, since
372 * they contain COORDS that are unique
373 * for each instance */
374 clone_notelist(new_p
, list_p
, YES
);
376 /* with lists cannot be shared,
377 * because otherwise fix_string
378 * could get called on an already fixed string. */
379 clone_withlist(new_p
, list_p
);
387 /* make a copy of the notelist in one GRPSYL struct into another */
390 clone_notelist(new_p
, old_p
, copy_acc_etc
)
392 struct GRPSYL
*new_p
; /* copy into here */
393 struct GRPSYL
*old_p
; /* from here */
394 int copy_acc_etc
; /* if YES, copy accidentals. If just reusing a
395 * group on the same staff, we don't want to
396 * copy these things */
399 register int n
; /* index through note list */
402 /* mark the number of notes in the new list */
403 new_p
->nnotes
= old_p
->nnotes
;
405 /* copy cross-staff stem info */
406 new_p
->stemto
= old_p
->stemto
;
407 new_p
->stemto_idx
= old_p
->stemto_idx
;
409 if (old_p
->nnotes
> 0) {
411 /* allocate new memory and copy from old to new */
412 MALLOC(NOTE
, new_p
->notelist
, old_p
->nnotes
);
414 (void)memcpy((char *) new_p
->notelist
, (char *) old_p
->notelist
,
415 (unsigned) (old_p
->nnotes
* sizeof(struct NOTE
)));
419 else if ((new_p
->grpsyl
== GS_GROUP
) && (new_p
->grpcont
== GC_NOTES
) &&
420 is_mrpt(new_p
) == NO
) {
421 yyerror("tried to use previous chord for defaults, but it had no notes");
425 for (n
= 0; n
< old_p
->nnotes
; n
++) {
427 if (copy_acc_etc
== YES
) {
428 new_p
->notelist
[n
].nslurto
= old_p
->notelist
[n
].nslurto
;
429 /* It isn't necessarily safe to share slurto lists.
430 * In particular, if multiple staffs are specified,
431 * and they have different clefs, the default octave
432 * will be different. So make a copy to be safe. */
433 if (new_p
->notelist
[n
].nslurto
> 0) {
434 MALLOC(SLURTO
, new_p
->notelist
[n
].slurtolist
,
435 new_p
->notelist
[n
].nslurto
);
436 memcpy(new_p
->notelist
[n
].slurtolist
,
437 old_p
->notelist
[n
].slurtolist
,
438 sizeof(struct SLURTO
) *
439 old_p
->notelist
[n
].nslurto
);
442 new_p
->notelist
[n
].slurtolist
= (struct SLURTO
*) 0;
446 new_p
->notelist
[n
].nslurto
= 0;
447 new_p
->notelist
[n
].slurtolist
= (struct SLURTO
*) 0;
448 new_p
->notelist
[n
].is_bend
= NO
;
449 new_p
->notelist
[n
].smallbend
= NO
;
452 /* alloc space for coordinates */
453 MALLOCA(float, new_p
->notelist
[n
].c
, NUMCTYPE
);
456 /* if a note that was cloned had an accidental on it,
457 * the clone doesn't need the accidental since we are in
458 * the same measure. Ties also do not get copied. But on tab staff,
459 * the accidental does need to get copied since it's part of the
460 * name of the string. */
461 for (n
= 0; n
< old_p
->nnotes
; n
++) {
462 if(copy_acc_etc
== NO
) {
463 if (Doing_tab_staff
== NO
) {
464 new_p
->notelist
[n
].accidental
= '\0';
465 new_p
->notelist
[n
].acc_has_paren
= NO
;
467 new_p
->notelist
[n
].tie
= NO
;
473 /* add a NOTE to a list of notes off a GRPSYL */
476 add_note(grpsyl_p
, pitch
, accidental
, octave
, nticks
, has_paren
, bendstring
)
478 struct GRPSYL
*grpsyl_p
; /* what group to associate note with */
479 int pitch
; /* 'a' to 'g' */
480 /* can also be pseudo-pitches for rest, space and rpt */
481 int accidental
; /* '\0', '#', '&', 'n', 'x', or 'B' */
482 int octave
; /* octave for normal staffs,
483 * fret for tab staffs, uncompressibility
484 * for space pseudo-notes */
485 int nticks
; /* number of tick marks, for tab staffs */
486 int has_paren
; /* YES if accidental has parentheses (for
487 * non-tab staffs) or if fret has parentheses
488 * (for tab staffs) */
489 char *bendstring
; /* bend specification, or null if no bend */
492 register int index
; /* into notelist */
495 if (grpsyl_p
->nnotes
== 0) {
496 /* first time--need to allocate */
497 CALLOC(NOTE
, grpsyl_p
->notelist
, NOTE_CHUNK
);
500 /* see if overflowed and thus need to re-allocate more space */
501 else if ((grpsyl_p
->nnotes
% NOTE_CHUNK
) == 0) {
502 REALLOC(NOTE
, grpsyl_p
->notelist
, grpsyl_p
->nnotes
+ NOTE_CHUNK
);
503 memset((void *) (& grpsyl_p
->notelist
[grpsyl_p
->nnotes
]),
504 0, NOTE_CHUNK
* sizeof(struct NOTE
));
507 /* find index into notelist where we put this note */
508 index
= grpsyl_p
->nnotes
;
510 /* allocate space for coordinates. The coordinates must be in a
511 * malloc-ed array and not a static array. At one point, we thought
512 * we could save a few bytes by changing back to array, but that
513 * would be a lot of work. The reason is that the
514 * coordinates are pointed to whenever there is a location tag on a
515 * note. The array must not move or else the location tag reference
516 * would be wrong. Since we qsort the notes later on, the coords would
517 * move if they were a static array rather than a malloc-ed array.
518 * In order to allow moving them, we'd have to keep track of all note
519 * location tags for much longer than we currently do, and then go
520 * back and change their values when notes are sorted. It would require
521 * finding entries in a hash table by other than their key (i.e,
522 * require a linear search or another whole indexing scheme), and
523 * also require either going back to patch up any lines, curves, and
524 * prints that used the coords, or delaying their definition by saving
525 * lots of information around. */
526 MALLOCA(float, grpsyl_p
->notelist
[index
].c
, NUMCTYPE
);
528 grpsyl_p
->notelist
[ index
].letter
= (short) pitch
;
529 grpsyl_p
->notelist
[ index
].accidental
= (char) accidental
;
530 grpsyl_p
->notelist
[ index
].acc_has_paren
= has_paren
;
531 if (Doing_tab_staff
== YES
&& pitch
>= 'a' && pitch
<= 'g') {
536 /* do error checks */
537 if (accidental
!= '\0' && accidental
!= '#' && accidental
!= '&') {
538 yyerror("accidental on tab staff can only be # or &");
541 if (fret
== NOFRET
&& bendstring
== (char *) 0) {
542 yyerror("a fret number and/or bend must be specified");
543 /* put in something valid so later functions won't
547 else if ((fret
< MINFRET
|| fret
> MAXFRET
) && fret
!= NOFRET
) {
548 l_yyerror(grpsyl_p
->inputfile
, grpsyl_p
->inputlineno
,
549 "invalid fret number %d, must be %d-%d or have a bend",
550 fret
, MINFRET
, MAXFRET
);
554 /* Cram fret and nticks in stepsup field for now. Later
555 * we will put fret in its proper place, but right now that
556 * is used for something else */
557 TMP_SAVE( (&(grpsyl_p
->notelist
[index
])), nticks
, fret
);
559 /* cram the bend info into octave field */
560 grpsyl_p
->notelist
[ index
].octave
561 = parse_bend_string(bendstring
);
565 yyerror("' not allowed on non-tablature staff");
567 grpsyl_p
->notelist
[ index
].octave
= (short) octave
;
569 grpsyl_p
->notelist
[ index
].nslurto
= 0;
570 grpsyl_p
->notelist
[ index
].tie
= NO
;
571 grpsyl_p
->notelist
[ index
].tiestyle
= L_NORMAL
;
572 grpsyl_p
->notelist
[ index
].tiedir
= UNKNOWN
;
573 grpsyl_p
->notelist
[ index
].slurtolist
= (struct SLURTO
*)0;
574 grpsyl_p
->notelist
[ index
].notesize
= GS_NORMAL
;
576 /* don't need to initialize anything else in NOTE */
578 (grpsyl_p
->nnotes
)++;
582 /* once an entire chord is gathered, release any extra space gotten for
586 resize_notelist(gs_p
)
591 int extra
; /* how many extra NOTE structs there are */
594 extra
= NOTE_CHUNK
- (gs_p
->nnotes
% NOTE_CHUNK
);
596 if (extra
> 0 && extra
< NOTE_CHUNK
) {
597 /* release extra NOTE space */
598 REALLOC(NOTE
, gs_p
->notelist
, gs_p
->nnotes
);
603 /* when we get to a bar line, we have to go back and rearrange things and
604 * do some error checks that couldn't be done until we had everything
605 * collected. All the non-STAFF structures have to be put after the STAFFs.
614 struct MAINLL
*mll_p
; /* to walk through list */
615 static short firstbar
= YES
; /* if first time this func was called */
616 short v
; /* voice number */
617 short found_above_for
[MAXSTAFFS
+1]; /* how many times this staff
618 * was succesfully matched up with a
619 * "bm with staff below" */
620 int i
; /* index though above array */
621 int other_staff
; /* other staff for cross-staff beam */
622 int with_above
; /* how many "bm with staff above"
623 * found on current staff */
628 /* The "restart" is a strange thing only vaguely like a regular bar,
629 * so handle it separately */
630 if (bartype
== RESTART
) {
635 if (List_of_staffs_p
== (struct MAINLL
*) 0) {
636 yyerror("empty measure");
640 /* Make sure all voices are present; fill in measure space for
641 * any that are missing */
642 check4missing_voices(List_of_staffs_p
);
644 /* attach all the lyrics to the right places */
645 attach_lyrics2staffs(List_of_staffs_p
);
647 /* set up all the cross-staff beams */
648 for (i
= 1; i
<= MAXSTAFFS
; i
++) {
649 found_above_for
[i
] = 0;
651 for (mll_p
= List_of_staffs_p
; mll_p
!= (struct MAINLL
*) 0;
652 mll_p
= mll_p
->next
) {
654 if (mll_p
->str
!= S_STAFF
) {
659 /* check every group of every voice */
660 for (v
= 0; v
< MAXVOICES
; v
++) {
663 /* Only check visible voices */
664 if (vvpath(mll_p
->u
.staff_p
->staffno
, v
+1, VISIBLE
)->visible
== NO
) {
668 for (gs_p
= mll_p
->u
.staff_p
->groups_p
[v
];
669 gs_p
!= (struct GRPSYL
*) 0;
672 /* if this is the first group in a cross-staff
673 * beam, take care to that */
674 if (gs_p
->beamloc
== STARTITEM
&&
675 gs_p
->beamto
== CS_BELOW
) {
676 /* before calling chk_crossbeams, make
677 * sure the gs_p we are passing has its
678 * vno set properly, since normally
679 * that doesn't happen till later.
680 * Maybe this cross-staff stuff should
681 * be done later, but I don't want to
682 * move it without a lot of thought to
683 * make sure that wouldn't break
684 * something, so this will work for now.
687 other_staff
= chk_crossbeam(gs_p
, mll_p
);
688 if (other_staff
> 0) {
689 (found_above_for
[other_staff
])++;
692 else if (gs_p
->beamloc
== STARTITEM
&&
693 gs_p
->beamto
== CS_ABOVE
) {
698 if (found_above_for
[mll_p
->u
.staff_p
->staffno
] < with_above
) {
699 l_yyerror(mll_p
->inputfile
, mll_p
->inputlineno
,
700 "'bm with staff above' has no visible matching 'bm with staff below' (may be missing, invisible, or on wrong voice)");
704 /* if first measure, check if "pickup" measure. If so, it doesn't
705 * count toward measure number */
706 if (firstbar
== YES
&& bartype
!= INVISBAR
) {
707 if (has_pickup() == YES
) {
708 /* don't count pickup measure */
711 /* set flag so we won't check again */
715 /* increment measure number for rehearsal numbers */
716 if (bartype
!= INVISBAR
&& Got_multirest
== 0) {
724 /* Returns YES if piece begins with a pickup measure. */
729 int v
; /* voice index */
730 struct MAINLL
*mll_p
; /* to step through main list */
732 /* go through each voice of each staff looking for non-space */
733 for (mll_p
= Mainllhc_p
; mll_p
!= (struct MAINLL
*) 0;
734 mll_p
= mll_p
->next
) {
736 /* Measures where the entire measure is compressible space
737 * and which end with an invisbar were probably just for the
738 * purpose of kludging in a funny time signature or something
739 * like that, so we ignore those measures while checking for a
742 if (mll_p
->str
== S_BAR
&& mll_p
->u
.bar_p
->bartype
!= INVISBAR
) {
743 /* got through entire first measure */
746 if (mll_p
->str
!= S_STAFF
) {
750 for (v
= 0; v
< MAXVOICES
; v
++) {
751 if (mll_p
->u
.staff_p
->groups_p
[v
] != 0 &&
752 (mll_p
->u
.staff_p
->groups_p
[v
]
753 ->grpcont
!= GC_SPACE
||
754 mll_p
->u
.staff_p
->groups_p
[v
]
755 ->uncompressible
== YES
) ) {
756 /* Found a voice that exists,
757 * but begins with a non-space or an
758 * uncompressible space. So it's not a pickup */
767 /* Do final cleanup in preparation for next bar of input */
773 struct MAINLL
*mll_p
;
775 /* Walk thru the list, fixing everything that is left to fix */
776 for (mll_p
= List_of_staffs_p
; mll_p
!= (struct MAINLL
*) 0;
777 mll_p
= mll_p
->next
) {
779 if (mll_p
->str
== S_BAR
) {
783 if (mll_p
->str
== S_STAFF
) {
784 /* Walk down each GRPSYL list and
785 * look for various errors and fix up things that
786 * couldn't be determined before */
787 fix_grpsyl_list(mll_p
);
789 /* Set the visibility attribute for staff */
790 mll_p
->u
.staff_p
->visible
=
791 (svpath(mll_p
->u
.staff_p
->staffno
,
797 /* add padding etc for any rolls in the measure */
798 do_rolls(Mainlltc_p
);
800 /* in case things are screwed up because of user input errors,
801 * reset tuplet state. */
802 Tuplet_state
= NOITEM
;
804 /* do measure level checks on "stuff" */
807 /* get ready for next measure */
808 List_of_staffs_p
= (struct MAINLL
*) 0;
816 /* A "restart" is a funny sort of bar.
817 * We create a measure of space before it. */
823 struct MAINLL
*mll_p
;
824 struct MAINLL
*mainbar_p
; /* the restart */
826 if (List_of_staffs_p
!= 0) {
827 yyerror("restart cannot be preceeded by music data");
830 if (Got_some_data
== NO
) {
831 yyerror("restart cannot be used at the beginning");
835 /* It doesn't make sense to begin a repeat right before a restart,
837 for (mll_p
= Mainlltc_p
->prev
; mll_p
!= (struct MAINLL
*) 0;
838 mll_p
= mll_p
->prev
) {
839 if (mll_p
->str
== S_BAR
) {
840 if (mll_p
->u
.bar_p
->bartype
== REPEATSTART
) {
841 yyerror("repeatstart not allowed immediately before restart");
843 else if (mll_p
->u
.bar_p
->bartype
== REPEATBOTH
) {
844 yyerror("repeatboth not allowed immediately before restart");
850 /* save the bar so we can move after the staffs */
851 mainbar_p
= Mainlltc_p
;
852 /* create a "measure" of all space */
854 check4missing_voices(List_of_staffs_p
);
855 /* move the restart BAR after the empty measure */
856 unlinkMAINLL(mainbar_p
);
857 insertMAINLL(mainbar_p
, Mainlltc_p
);
862 /* walk down the linked lists of GRPSYLs and fix everything that is left to
863 * fix: font/size, octaves, default timeunits, etc */
866 fix_grpsyl_list(mainll_item_p
)
868 struct MAINLL
*mainll_item_p
;
872 struct STAFF
*staff_p
;
873 struct MAINLL
*mll_p
; /* for finding timed SSVs */
874 struct TIMEDSSV
*tssv_p
;
879 if (mainll_item_p
->str
!= S_STAFF
) {
880 pfatal("wrong struct type passed to fix_grpsyl_list()");
882 staff_p
= mainll_item_p
->u
.staff_p
;
885 /* verify voice is valid for current vscheme */
886 numvoices
= vscheme_voices(svpath(staff_p
->staffno
,VSCHEME
)->vscheme
);
887 if (staff_p
->groups_p
[1] != (struct GRPSYL
*) 0 && numvoices
== 1) {
888 l_yyerror(staff_p
->groups_p
[1]->inputfile
,
889 staff_p
->groups_p
[1]->inputlineno
,
890 "can't have voice 2 when vscheme=1");
892 if (staff_p
->groups_p
[2] != (struct GRPSYL
*) 0 && numvoices
< 3) {
893 l_yyerror(staff_p
->groups_p
[2]->inputfile
,
894 staff_p
->groups_p
[2]->inputlineno
,
895 "can't have voice 3 unless vscheme is 3o or 3f");
898 /* Determine if there are timed SSVs to deal with */
900 for (mll_p
= mainll_item_p
; mll_p
!= 0; mll_p
= mll_p
->next
) {
901 if (mll_p
->str
== S_BAR
) {
902 tssv_p
= mll_p
->u
.bar_p
->timedssv_p
;
908 for (v
= 0; v
< MAXVOICES
; v
++) {
909 if (staff_p
->groups_p
[v
] != (struct GRPSYL
*) 0) {
911 setssvstate(mainll_item_p
);
913 fix_a_group_list(staff_p
->groups_p
[v
],
914 staff_p
->staffno
, v
+ 1,
915 staff_p
->groups_p
[v
]->inputfile
,
916 staff_p
->groups_p
[v
]->inputlineno
,
920 /* on tablature staffs, must deal with bends */
921 if (is_tab_staff(staff_p
->staffno
) == YES
) {
922 check_bends(staff_p
->groups_p
[v
], mainll_item_p
);
927 /* make sure timed SSVs are all up to date at end of measure */
928 for ( ; tssv_p
!= 0; tssv_p
= tssv_p
->next
) {
929 asgnssv(&tssv_p
->ssv
);
932 /* then check syllables */
933 for (v
= 0; v
< staff_p
->nsyllists
; v
++) {
934 chk_a_syl_list(staff_p
->syls_p
[v
],
935 staff_p
->syls_p
[v
]->inputfile
,
936 staff_p
->syls_p
[v
]->inputlineno
);
941 /* walk through a list of GRPSYLs (GROUPs, not SYLLABLESs), and fix up things
942 * like octaves, etc */
946 fix_a_group_list(grpsyllist_p
, staffno
, vno
, fname
, lineno
, mrptnum
, tssv_p
)
948 struct GRPSYL
*grpsyllist_p
;
950 int vno
; /* voice number */
951 char *fname
; /* file name for error messages */
952 int lineno
; /* input line number, for error messages */
953 int mrptnum
; /* to decide whether to run fix_string or not */
954 struct TIMEDSSV
*tssv_p
; /* points to any timed SSVs in this measure */
958 int n
; /* index through notelist */
959 RATIONAL total_time
; /* to add up all fulltimes in current voice/verse */
960 short default_octave
;
961 struct GRPSYL
*grpsyl_p
;
962 struct GRPSYL
*gs_p
; /* for walking through grace runs */
967 if (grpsyllist_p
== (struct GRPSYL
*) 0) {
968 /* this is un undefined voice, so nothing to do */
972 debug(4, "fix_a_group_list file=%s lineno=%d staffno=%d vno=%d",
973 grpsyllist_p
->inputfile
, grpsyllist_p
->inputlineno
,
976 /* will need to fix up the font and size of strings in the
977 * "with" lists, so figure out
978 * which font and size to use for that */
979 font
= (svpath(staffno
, FONT
))->font
980 + (svpath(staffno
, FONTFAMILY
))->fontfamily
;
981 size
= (svpath(staffno
, SIZE
))->size
;
983 /* initialize total time for this voice in this meas */
986 /* find default octave for this staff/voice */
987 default_octave
= (vvpath(staffno
, vno
, DEFOCT
))->defoct
;
989 grpsyl_p
= grpsyllist_p
;
991 Doing_tab_staff
= is_tab_staff(staffno
);
994 for ( ; grpsyl_p
!= (struct GRPSYL
*) 0; grpsyl_p
= grpsyl_p
->next
) {
996 /* fill in staffno and vno */
997 grpsyl_p
->staffno
= (short) staffno
;
998 grpsyl_p
->vno
= (short) vno
;
1000 /* Apply any timed SSVs */
1001 while (tssv_p
!= 0 && LE(tssv_p
->time_off
, total_time
)) {
1002 asgnssv(&tssv_p
->ssv
);
1003 tssv_p
= tssv_p
->next
;
1004 /* the default octave might have changed,
1005 * so look it up again.
1007 default_octave
= (vvpath(staffno
, vno
, DEFOCT
))->defoct
;
1009 /* if no pitch given on first group of measure, use default
1010 * pitch if 1-line staff, otherwise error */
1011 if (grpsyl_p
->nnotes
== 1 && grpsyl_p
->notelist
[0].letter
1013 if (svpath(staffno
, STAFFLINES
)->stafflines
== 1 &&
1014 Doing_tab_staff
== NO
) {
1015 grpsyl_p
->notelist
[0].letter
= DFLT_PITCH
;
1018 l_yyerror(fname
, lineno
,
1019 "must have note(s) specified for first group in bar");
1023 /* make sure "with" lists are in right size/font */
1024 /* When groups are copied to expand measure repeats for
1025 * MIDI purposes, any 'with' lists would already be in
1026 * internal format, so we don't want to try to fix them,
1027 * but otherwise strings need to be put in internal format */
1029 fix_strlist(grpsyl_p
, font
, size
, fname
, lineno
);
1033 if (Doing_tab_staff
== YES
) {
1034 /* determine proper STRINGNO and FRETNO information */
1035 fix_frets(grpsyl_p
);
1038 /* take care of relative octaves */
1039 resolve_octaves(grpsyl_p
, default_octave
);
1043 if (svpath(staffno
, STAFFLINES
)->stafflines
== 1
1044 && grpsyl_p
->nnotes
> 1) {
1045 l_warning(fname
, lineno
,
1046 "more than one note in chord on 1-line staff");
1049 /* put notes in order top to bottom */
1050 sort_notes(grpsyl_p
, fname
, lineno
);
1052 /* if group is small notes, mark each note as small */
1053 if (grpsyl_p
->grpsize
!= GS_NORMAL
) {
1055 for (n
= 0; n
< grpsyl_p
->nnotes
; n
++) {
1057 grpsyl_p
->notelist
[n
].notesize
1058 = grpsyl_p
->grpsize
;
1063 /* at first we thought we should mark the whole group small if all
1064 * notes were small, but later decided not, so this is ifdef-ed out */
1065 /* on the other hand, if all notes are explicitly marked
1066 * small, make the whole group small. This is handy in case,
1067 * for example, the user uses ? instead of [cue] on a
1068 * single-note group */
1069 else if (grpsyl_p
->grpcont
== GC_NOTES
) {
1070 int numsmall
; /* how many small notes */
1072 for (numsmall
= n
= 0; n
< grpsyl_p
->nnotes
; n
++) {
1073 if (grpsyl_p
->notelist
[n
].notesize
1078 if (grpsyl_p
->nnotes
> 0 &&
1079 numsmall
== grpsyl_p
->nnotes
) {
1080 grpsyl_p
->grpsize
= GS_SMALL
;
1085 /* error check rests */
1086 if (grpsyl_p
->grpcont
== GC_REST
) {
1087 if ( (grpsyl_p
->prev
!= (struct GRPSYL
*) 0)
1088 && (grpsyl_p
->prev
->grpcont
1090 && (grpsyl_p
->prev
->grpvalue
1092 l_yyerror(fname
, lineno
,
1093 "can't have grace notes before rest");
1096 /* We used to disallow stemdir on rests, but it could
1097 * come from an earlier []... and doesn't really hurt;
1098 * it doesn't matter which direction the non-existent
1099 * stem is, so we silently ignore.
1101 if (IS_STEMLEN_KNOWN(grpsyl_p
->stemlen
)) {
1102 /* Might be just from a [ ]... on an earlier
1103 * group, and doesn't really hurt anything,
1104 * so silently ignore.
1106 grpsyl_p
->stemlen
= 0.0;
1110 /* error check space */
1111 else if (grpsyl_p
->grpcont
== GC_SPACE
) {
1112 if (IS_STEMLEN_KNOWN(grpsyl_p
->stemlen
)) {
1113 grpsyl_p
->stemlen
= 0.0;
1117 /* error check measure repeats */
1118 if (is_mrpt(grpsyl_p
) == YES
) {
1119 if (grpsyl_p
->nwith
!= 0
1120 || grpsyl_p
->grpvalue
!= GV_NORMAL
1121 || grpsyl_p
->headshape
!= HS_UNKNOWN
1122 || grpsyl_p
->grpsize
!= GS_NORMAL
1123 || IS_STEMLEN_KNOWN(grpsyl_p
->stemlen
)
1124 || grpsyl_p
->stemdir
!= UNKNOWN
1125 || grpsyl_p
->slash_alt
> 0) {
1126 l_yyerror(fname
, lineno
,
1127 "can't specify items in [ ] with measure repeat (except padding and tag)");
1129 if (grpsyl_p
->slash_alt
< 0) {
1130 l_yyerror(fname
, lineno
,
1131 "can't specify alt with measure repeat");
1133 if (grpsyl_p
->tie
== YES
) {
1134 l_yyerror(fname
, lineno
,
1135 "can't specify tie with measure repeat");
1138 /* grace notes need special handling */
1139 if (grpsyl_p
->grpvalue
== GV_ZERO
&& is_mrpt(grpsyl_p
) == NO
) {
1141 /* grace notes really take no time */
1142 grpsyl_p
->fulltime
= Zero
;
1144 /* do some error checks */
1145 check_grace(grpsyl_p
, fname
, lineno
);
1147 /* if more than one grace note in a row, beam them */
1148 if (grpsyl_p
->beamloc
== NOITEM
1149 && grpsyl_p
->basictime
> 4) {
1151 /* if there is another grace following, will
1152 * need to beam them */
1153 if ((grpsyl_p
->next
!= (struct GRPSYL
*)0) &&
1154 (grpsyl_p
->next
->grpvalue
1156 (grpsyl_p
->next
->basictime
1159 /* mark the first one as STARTITEM */
1160 grpsyl_p
->beamloc
= STARTITEM
;
1162 /* mark intermediates, if any,
1163 * as INITEM, and last in run
1164 * of grace as ENDITEM */
1165 for (gs_p
= grpsyl_p
->next
;
1167 != (struct GRPSYL
*) 0;
1168 gs_p
= gs_p
->next
) {
1169 if (gs_p
->next
->grpvalue
1171 gs_p
->next
->basictime
1173 gs_p
->beamloc
= INITEM
;
1176 gs_p
->beamloc
= ENDITEM
;
1180 if (gs_p
->next
== (struct GRPSYL
*) 0){
1181 /* grace at end of measure is
1182 * illegal, but we catch that
1183 * in check_grace(). So just
1184 * mark the beam as ended */
1185 gs_p
->beamloc
= ENDITEM
;
1191 /* if this group is alternating with the next, need to
1192 * adjust fulltimes to be 1/2 of their current values. */
1193 if (grpsyl_p
->slash_alt
< 0 && is_mrpt(grpsyl_p
) == NO
) {
1194 /* need to error check first. First, there must
1195 * be another group in this measure. Moreover, it
1196 * must have the same fulltime value, and both
1197 * must be either NORMAL or SMALL size. Also, the
1198 * next group can't have an alt. */
1199 if (grpsyl_p
->next
== (struct GRPSYL
*) 0) {
1200 l_yyerror(fname
, lineno
,
1201 "cannot specify 'alt' on last group in measure");
1205 else if (grpsyl_p
->next
->grpvalue
== GV_ZERO
||
1206 grpsyl_p
->grpvalue
== GV_ZERO
) {
1207 l_yyerror(fname
, lineno
,
1208 "can't use 'alt' on grace notes");
1211 else if ( ! EQ(grpsyl_p
->fulltime
,
1212 grpsyl_p
->next
->fulltime
) ) {
1213 l_yyerror(fname
, lineno
,
1214 "groups in 'alt' pair must have identical time values");
1217 else if (grpsyl_p
->next
->grpsize
1218 != grpsyl_p
->grpsize
) {
1219 l_yyerror(fname
, lineno
,
1220 "can't mix normal and cue notes for 'alt'");
1223 else if (grpsyl_p
->next
->slash_alt
< 0) {
1224 l_yyerror(fname
, lineno
,
1225 "can't have 'alt' on consecutive chords");
1229 else if (grpsyl_p
->next
->slash_alt
> 0) {
1230 l_yyerror(fname
, lineno
,
1231 "can't have 'slash' on second chord of 'alt' pair");
1234 else if (grpsyl_p
->grpcont
!= GC_NOTES
||
1235 grpsyl_p
->next
->grpcont
!= GC_NOTES
) {
1236 l_yyerror(fname
, lineno
,
1237 "'alt' must be preceeded and followed by notes, not rest or space");
1241 grpsyl_p
->fulltime
=
1242 rdiv(grpsyl_p
->fulltime
, Two
);
1243 grpsyl_p
->next
->fulltime
=
1244 rdiv(grpsyl_p
->next
->fulltime
, Two
);
1247 if (grpsyl_p
->stemdir
!= grpsyl_p
->next
->stemdir
) {
1248 l_yyerror(fname
, lineno
,
1249 "'alt' pair chords must have identical stem directions");
1252 if (grpsyl_p
->beamto
!= CS_SAME
) {
1253 l_yyerror(fname
, lineno
,
1254 "'alt' not allowed on cross-staff beams");
1257 else if (grpsyl_p
->grpvalue
!= GV_ZERO
&&
1258 grpsyl_p
->slash_alt
> 0 &&
1259 is_mrpt(grpsyl_p
) == NO
) {
1261 /* need to make sure number of slashes is valid */
1262 /* figure out how many actual chords are represented
1263 * by the slashed chord */
1264 switch (grpsyl_p
->basictime
) {
1278 /* multiply by two for each additional slash beyond
1279 * the first. We shouldn't really need this IF, since
1280 * if should be okay to shift by 0, but for some reason,
1281 * on my system, if slash_alt is 1 and the optimizer
1282 * is run on this code, the following "if (n == 0)"
1283 * statement doesn't work right. It works fine if
1284 * the optimizer isn't run! (YIKES!!!!) */
1285 if (grpsyl_p
->slash_alt
> 1) {
1286 nn
= nn
<< (grpsyl_p
->slash_alt
- 1);
1290 /* shifted left into oblivion */
1291 yyerror("too many slashes");
1293 /* We are okay as long as the number of dots is no
1294 * more than the number of zero bits on the right end
1295 * of the number. If there are more, user is trying
1296 * to subdivide too much, so disallow */
1297 else if (drmo(nn
) < grpsyl_p
->dots
) {
1298 yyerror("illegal number of slashes");
1301 if (grpsyl_p
->beamto
!= CS_SAME
) {
1302 l_yyerror(fname
, lineno
,
1303 "'slash' not allowed on cross-staff beams");
1307 /* check for unclosed custom beams */
1308 if (grpsyl_p
->next
== (struct GRPSYL
*) 0 &&
1309 (grpsyl_p
->beamloc
== STARTITEM
||
1310 grpsyl_p
->beamloc
== INITEM
) ) {
1311 yyerror("missing ebm");
1314 if (grpsyl_p
->is_meas
== YES
&& (grpsyl_p
->prev
!= 0 ||
1315 grpsyl_p
->next
!= 0) ) {
1316 yyerror("measure duration item must be the only thing in the measure");
1319 /* add up the total time in the measure */
1320 total_time
= radd(total_time
, grpsyl_p
->fulltime
);
1323 /* check for not equal to time signature. */
1324 if ( NE(total_time
, Score
.time
) && (grpsyllist_p
->is_meas
== NO
1325 || grpsyllist_p
->next
!= 0) ) {
1326 l_yyerror(fname
, lineno
,
1327 "time in measure (%ld/%ld) does not add up to time signature",
1328 total_time
.n
, total_time
.d
);
1331 /* set up any beaming */
1332 if (has_cust_beaming(grpsyllist_p
) == NO
) {
1333 do_beaming(grpsyllist_p
, GS_NORMAL
, staffno
, vno
);
1334 do_beaming(grpsyllist_p
, GS_SMALL
, staffno
, vno
);
1336 set_alt_beams(grpsyllist_p
);
1338 for (grpsyl_p
= grpsyllist_p
; grpsyl_p
!= (struct GRPSYL
*) 0;
1339 grpsyl_p
= grpsyl_p
->next
) {
1340 /* We only allow specifying slope for beam on first group
1341 * of a beam. To be very certain of avoiding any possiblity
1342 * of floating point roundoff errors,
1343 * we compare for being close to NOBEAMANGLE.
1345 if (fabs(grpsyl_p
->beamslope
- NOBEAMANGLE
) > 0.01) {
1346 if (grpsyl_p
->beamloc
!= STARTITEM
) {
1347 l_yyerror(fname
, lineno
,
1348 "slope can only be specified on the first chord of a beam");
1350 else if (grpsyl_p
->grpcont
== GC_SPACE
) {
1351 if (grpsyl_p
->beamto
!= CS_SAME
) {
1352 l_yyerror(fname
, lineno
,
1353 "on cross-staff beam, specify slope on staff with notes, not with space");
1356 /* Don't think it should really be
1357 * possible to get here... */
1358 l_yyerror(fname
, lineno
,
1359 "slope can't be specified on space");
1367 /* make sure all the syllable times add up to time signature */
1370 chk_a_syl_list(grpsyl_p
, fname
, lineno
)
1372 struct GRPSYL
*grpsyl_p
; /* list to check */
1373 char *fname
; /* file name for error messages */
1374 int lineno
; /* input line for error messages */
1377 RATIONAL total_time
;
1382 for ( ; grpsyl_p
!= (struct GRPSYL
*) 0; grpsyl_p
= grpsyl_p
->next
) {
1383 total_time
= radd(total_time
, grpsyl_p
->fulltime
);
1386 /* check for not equal to time signature. */
1387 if ( NE(total_time
, Score
.time
) ) {
1388 l_yyerror(fname
, lineno
,
1389 "time in measure (%ld/%ld) does not add up to time signature",
1390 total_time
.n
, total_time
.d
);
1395 /* resolve all the relative octaves to absolute octaves.
1396 * Here's the deal: if the relative octave is negative,
1397 * add (the negative value) to the default to get the
1398 * real octave. If the relative is >= USE_DFLT_OCTAVE,
1399 * add (octave - USE_DFLT_OCT) to the default to get the real
1400 * value. Otherwise the relative is the absolute. */
1403 resolve_octaves(grpsyl_item_p
, default_octave
)
1405 struct GRPSYL
*grpsyl_item_p
; /* GRPSYL containing notes to resolve */
1406 int default_octave
; /* default octave to use */
1409 register int n
; /* walk through note list */
1410 register int sl
; /* walk through slurtolist */
1412 struct NOTE
*note_p
; /* current note */
1415 for (n
= 0; n
< grpsyl_item_p
->nnotes
; n
++) {
1417 note_p
= &(grpsyl_item_p
->notelist
[n
]);
1418 octave
= note_p
->octave
;
1421 /* add (the negative value) to default octave */
1422 note_p
->octave
= (short)(default_octave
+ octave
);
1424 else if (octave
>= USE_DFLT_OCTAVE
) {
1425 /* this means 0 or more to add to default octave */
1426 note_p
->octave
= (short)(default_octave
+ octave
1429 else if (octave
> MAXOCTAVE
) {
1430 l_yyerror(grpsyl_item_p
->inputfile
,
1431 grpsyl_item_p
->inputlineno
,
1432 "octave %d out of range (%d-%d)",
1433 octave
, MINOCTAVE
, MAXOCTAVE
);
1436 /* also adjust any slurto */
1437 if (note_p
->nslurto
> 0) {
1438 for (sl
= note_p
->nslurto
- 1; sl
>= 0; sl
--) {
1439 octave
= note_p
->slurtolist
[sl
].octave
;
1441 note_p
->slurtolist
[sl
].octave
=
1442 default_octave
+ octave
;
1444 else if (octave
>= USE_DFLT_OCTAVE
) {
1445 note_p
->slurtolist
[sl
].octave
=
1446 default_octave
+ octave
1455 /* given a fulltime value, figure out what its basictime value was.
1456 * Here's the deal: First we find the power of 2 that is less than or
1457 * equal to the numerator of fulltime. Then we take that number over the
1458 * denominator of fulltime and reduce to lowest terms. The new denominator
1459 * is the basictime. Note that this won't work for tuplets, but we don't
1460 * call this for tuplets, so we're safe... */
1463 reconstruct_basictime(fulltime
)
1465 RATIONAL fulltime
; /* find the basic time of this */
1468 RATIONAL newtime
; /* RATIONAL of basictime */
1471 if (fulltime
.n
< 0) {
1472 pfatal("negative fulltime numerator");
1475 /* guess MAXBASICTIME and work down by powers of 2
1476 * till we get <= fulltime numerator */
1477 for (newtime
.n
= MAXBASICTIME
; newtime
.n
> fulltime
.n
; newtime
.n
>>= 1) {
1480 newtime
.d
= fulltime
.d
;
1483 /* special case -- double whole basictime is 0 */
1484 if (EQ(newtime
, Two
)) {
1487 /* special case -- quad whole basictime is -1 */
1488 else if (EQ(newtime
, Four
)) {
1492 return ( (int) newtime
.d
);
1497 /* Given a fulltime and basictime,
1498 * figure out how many dots there must have been.
1499 * Start with basictime as a RATIONAL. If equal to fulltime, fine, we are
1500 * done. Otherwise, keep adding 50% of previous value until it is equal.
1501 * The number of times we have to do this is the number of dots */
1504 recalc_dots(fulltime
, basictime
)
1510 RATIONAL rat_basictime
;
1511 RATIONAL halftime
; /* half of previous note or dot */
1514 if (basictime
== 0) {
1515 /* special case of double whole */
1516 rat_basictime
.n
= 2;
1517 rat_basictime
.d
= 1;
1519 else if (basictime
== -1) {
1520 /* special case of quad whole */
1521 rat_basictime
.n
= 4;
1522 rat_basictime
.d
= 1;
1525 rat_basictime
.n
= 1;
1526 rat_basictime
.d
= basictime
;
1529 halftime
= rmul(rat_basictime
, One_half
);
1530 for (dots
= 0; LT(rat_basictime
, fulltime
); dots
++) {
1531 rat_basictime
= radd(rat_basictime
, halftime
);
1532 halftime
= rmul(halftime
, One_half
);
1538 /* make sure all the GRPSYL fields for a grace group are valid */
1541 check_grace(grpsyl_item_p
, fname
, lineno
)
1543 struct GRPSYL
*grpsyl_item_p
; /* which grace group to check */
1544 char *fname
; /* file name for error messages */
1545 int lineno
; /* in input, for error messages */
1548 int n
; /* index through notelist */
1550 if (grpsyl_item_p
->dots
!= 0) {
1551 l_yyerror(fname
, lineno
, "can't have dots on grace notes");
1554 else if (grpsyl_item_p
->slash_alt
== 1) {
1555 if ( (grpsyl_item_p
->prev
!= (struct GRPSYL
*) 0
1556 && grpsyl_item_p
->prev
->grpvalue
== GV_ZERO
)
1557 || (grpsyl_item_p
->next
!= (struct GRPSYL
*) 0
1558 && grpsyl_item_p
->next
->grpvalue
== GV_ZERO
)) {
1559 l_yyerror(fname
, lineno
,
1560 "slash only allowed on single grace note");
1564 else if (grpsyl_item_p
->slash_alt
> 1) {
1565 l_yyerror(fname
, lineno
, "only 1 slash allowed on grace note");
1568 if (grpsyl_item_p
->basictime
< 4) {
1569 l_yyerror(fname
, lineno
,
1570 "grace note must be quarter note or shorter");
1573 /* can't mix quarter grace notes (which don't have stems) with
1574 * shorter grace notes (that do have stems and get beamed) */
1575 if (grpsyl_item_p
->basictime
== 4 &&
1576 ((grpsyl_item_p
->prev
!= (struct GRPSYL
*) 0
1577 && grpsyl_item_p
->prev
->grpvalue
== GV_ZERO
1578 && grpsyl_item_p
->prev
->basictime
> 4) ||
1579 (grpsyl_item_p
->next
!= (struct GRPSYL
*) 0
1580 && grpsyl_item_p
->next
->grpvalue
== GV_ZERO
1581 && grpsyl_item_p
->next
->basictime
> 4))) {
1582 l_yyerror(fname
, lineno
,
1583 "can't mix quarter and shorter grace notes");
1584 /* set to shorter to avoid any future error messages */
1585 grpsyl_item_p
->basictime
= 8;
1588 if (is_tab_staff(grpsyl_item_p
->staffno
) == YES
) {
1589 for (n
= 0; n
< grpsyl_item_p
->nnotes
; n
++) {
1590 if (HASBEND(grpsyl_item_p
->notelist
[n
])) {
1591 l_yyerror(fname
, lineno
,
1592 "can't have bend on grace note");
1597 else if (grpsyl_item_p
->prev
!= (struct GRPSYL
*) 0) {
1599 for (n
= 0; n
< grpsyl_item_p
->prev
->nnotes
; n
++) {
1600 if (grpsyl_item_p
->prev
->notelist
[n
].is_bend
) {
1601 l_yyerror(fname
, lineno
,
1602 "can't have bend on grace note");
1609 if (grpsyl_item_p
->next
== (struct GRPSYL
*) 0) {
1610 l_yyerror(fname
, lineno
,
1611 "grace note cannot be last thing in measure");
1614 if (grpsyl_item_p
->beamloc
== STARTITEM
) {
1615 l_yyerror(fname
, lineno
,
1616 "custom beaming not allowed on grace notes");
1619 if (grpsyl_item_p
->stemdir
!= UNKNOWN
) {
1620 l_warning(fname
, lineno
,
1621 "stem direction not allowed on grace notes");
1624 /* Only first and last in a series of grace are allowed
1625 * to have stem length specified, and then both have to be.
1626 * If this one is first of a series, do the check.
1628 if ( (grpsyl_item_p
->prev
== 0
1629 || grpsyl_item_p
->prev
->grpvalue
!= GV_ZERO
)
1630 && grpsyl_item_p
->next
!= 0
1631 && grpsyl_item_p
->next
->grpvalue
== GV_ZERO
) {
1632 struct GRPSYL
*gs_p
;
1633 for (gs_p
= grpsyl_item_p
->next
;
1635 gs_p
->next
->grpvalue
== GV_ZERO
;
1636 gs_p
= gs_p
->next
) {
1637 if (gs_p
->stemlen
!= STEMLEN_UNKNOWN
) {
1638 l_warning(fname
, lineno
,
1639 "stem length cannot be specified in the middle of a series of grace notes");
1640 gs_p
->stemlen
= STEMLEN_UNKNOWN
;
1643 if ( (gs_p
->stemlen
== STEMLEN_UNKNOWN
) !=
1644 (grpsyl_item_p
->stemlen
== STEMLEN_UNKNOWN
) ) {
1645 l_warning(fname
, lineno
,
1646 "stem length must be specified on both first and last grace or on neither");
1647 gs_p
->stemlen
= STEMLEN_UNKNOWN
;
1648 grpsyl_item_p
->stemlen
= STEMLEN_UNKNOWN
;
1654 /* given a GRPSYL struct, fill in the font and size for all the
1655 * strings in the with list */
1658 fix_strlist(gs_p
, font
, size
, fname
, lineno
)
1660 struct GRPSYL
*gs_p
; /* fix all with lists in this list of GRPSYLS */
1661 int font
; /* set their default font to this */
1662 int size
; /* set their default size to this */
1663 char *fname
; /* file name for error messages */
1664 int lineno
; /* input line number for error messages */
1670 if (gs_p
->grpcont
!= GC_NOTES
&& gs_p
->nwith
> 0) {
1671 l_warning(fname
, lineno
,
1672 " 'with' items on rest or space ignored");
1677 for (n
= 0; n
< gs_p
->nwith
; n
++) {
1678 (void) fix_string(gs_p
->withlist
[n
], font
, size
,
1684 /* when a tuplet begins, mark tuplet state accordingly, and keep track to
1685 * mark subsequent notes till the end of the tuplet. */
1691 if ((Tuplet_state
== INITEM
) || (Tuplet_state
== STARTITEM
)) {
1692 yyerror("nested tuplets not allowed");
1696 /* just remember we are starting a tuplet. When we actual get
1697 * a note, we will mark it appropriately (in link_notegroup() ) */
1698 Tuplet_state
= STARTITEM
;
1702 /* once we reach the end of a tuplet, adjust all the time values */
1705 end_tuplet(tupcont
, tuptime
, printtup
, tupside
)
1707 int tupcont
; /* number to print on top of tuplet */
1708 RATIONAL tuptime
; /* what time value to stuff tuplet into. If 0,
1709 * then use the next lower power of 2 of tupcont */
1710 int printtup
; /* one of the PT_* values, specifying whether to print
1711 * number and bracket */
1712 int tupside
; /* side at which to print number/bracket */
1715 RATIONAL mult_factor
; /* how much to adjust due to tuplet */
1716 int num_non_grace
= 0; /* how many non-grace notes in tuplet */
1717 int factor
; /* numerator of mult_factor */
1718 RATIONAL tot_time
; /* total time taken by tuplet by adding up
1719 * the un-adjusted times. */
1720 struct GRPSYL
*gs_p
; /* walk through tuplet list */
1724 /* future notes that come in are not in this tuplet */
1725 Tuplet_state
= NOITEM
;
1728 yyerror("tuplet number must be greater than 1");
1732 if ( (printtup
== PT_NEITHER
) && (tupside
!= PL_UNKNOWN
) ) {
1733 l_warning(Curr_filename
, yylineno
,
1734 "when tuplet number is not printed, tuplet side is ignored");
1737 if (EQ(tuptime
, Zero
)) {
1738 /* this means user didn't specify, so we have to use
1739 * the next lower power of two */
1740 if ( (tupcont
& (tupcont
- 1)) == 0) {
1741 yyerror("if tuplet number is a power of 2, tuplet time must be given as well");
1745 /* guess MAXBASICTIME, then keep taking the next
1746 * lower power of 2 until we get under the tupcont:
1747 * that's the right value to use */
1748 for (factor
= MAXBASICTIME
; factor
> tupcont
; factor
>>= 1) {
1751 /* determine what to multiple each fulltime by */
1752 mult_factor
.n
= factor
;
1753 mult_factor
.d
= tupcont
;
1757 /* figure out adjustment based on user-specified amount of
1758 * time the tuplet is supposed to take */
1760 for (gs_p
= Tuplet_list_p
; gs_p
!= (struct GRPSYL
*) 0;
1761 gs_p
= gs_p
->next
) {
1762 if (gs_p
->grpvalue
!= GV_ZERO
) {
1763 tot_time
= radd(tot_time
, gs_p
->fulltime
);
1768 mult_factor
= rdiv(tuptime
, tot_time
);
1771 /* if factor is <= 1/2 or >= 2, the user must have specified
1772 * the wrong note lengths */
1773 if (LE(mult_factor
, One_half
) || GE(mult_factor
, Two
)) {
1774 yyerror("illegal tuplet: values couldn't add up to specified tuplet time value");
1778 /* go through the list, filling in tupcont, tuptime, and adjusting
1779 * fulltime of each note */
1780 for ( ; Tuplet_list_p
!= (struct GRPSYL
*) 0;
1781 Tuplet_list_p
= Tuplet_list_p
->next
) {
1783 Tuplet_list_p
->tupcont
= (short) tupcont
;
1784 Tuplet_list_p
->printtup
= printtup
;
1785 Tuplet_list_p
->tupside
= tupside
;
1787 if (Tuplet_list_p
->grpvalue
!= GV_ZERO
) {
1789 if (Tuplet_list_p
->next
!= (struct GRPSYL
*) 0 ||
1790 num_non_grace
>= 1) {
1791 /* adjust fulltime */
1792 Tuplet_list_p
->fulltime
=
1793 rmul(Tuplet_list_p
->fulltime
,
1797 else if (num_non_grace
== 0) {
1798 /* don't include leading grace notes in tuplet */
1799 Tuplet_list_p
->tuploc
= NOITEM
;
1800 Tuplet_list_p
->next
->tuploc
= STARTITEM
;
1803 /* if this is the end of the list, mark end of tuplet */
1804 if (Tuplet_list_p
->next
== (struct GRPSYL
*) 0) {
1806 if (Tuplet_list_p
->grpvalue
== GV_ZERO
) {
1807 yyerror("can't end tuplet with grace note");
1810 if(num_non_grace
== 1) {
1811 Tuplet_list_p
->tuploc
= LONEITEM
;
1815 Tuplet_list_p
->tuploc
= ENDITEM
;
1822 /* check that all voices are actually present in a measure, add a measure
1823 * space for any that are missing. Also make sure any measure repeats
1824 * are correct: if more than one voice and one is a measure repeat,
1825 * either all must be measure repeats, or those that aren't must be
1826 * measure spaces, in which case the spaces are turned into measure repeats.
1827 * Also fill in the mrptnum field of measure repeat STAFF
1828 * to be the count of repeated measures.
1832 check4missing_voices(list_p
)
1834 struct MAINLL
*list_p
; /* list of STAFFs */
1837 register int s
; /* walk through staff list */
1838 int v
; /* index through voices */
1839 int numvoices
; /* how many voices on current staff */
1842 debug(4, "check4missing_voices");
1844 if (list_p
== (struct MAINLL
*) 0) {
1845 pfatal("null list passed to check4missing_voices()");
1848 /* check each staff */
1849 for ( s
= 1; s
<= Score
.staffs
; s
++) {
1851 if (list_p
->str
!= S_STAFF
|| list_p
->u
.staff_p
->staffno
!= s
) {
1852 if (Errorcount
> 0) {
1853 /* if the input is garbage, we might get called
1854 * with strange things in the main list. We
1855 * would have already exclaimed about
1856 * the errors, so don't bother to try to
1857 * deal with the mess, just return */
1861 /* if input was good, we shouldn't get here */
1862 pfatal("info about staff %d not in list", s
);
1866 /* insert space for any missing voices */
1867 numvoices
= vscheme_voices(svpath(s
, VSCHEME
)->vscheme
);
1868 for (v
= 0; v
< numvoices
; v
++) {
1869 if (list_p
->u
.staff_p
->groups_p
[v
]
1870 == (struct GRPSYL
*) 0) {
1871 add_meas_space( &(list_p
->u
.staff_p
->groups_p
[v
]),
1876 /* fix up any measure repeats */
1879 if (list_p
->next
!= (struct MAINLL
*) 0) {
1880 list_p
= list_p
->next
;
1886 /* fill in measure space for empty voice */
1889 add_meas_space(gs_p_p
, staff
, voice
)
1891 struct GRPSYL
**gs_p_p
; /* where to put space */
1896 struct GRPSYL
*grpsyl_p
;
1899 grpsyl_p
= newGRPSYL(GS_GROUP
);
1902 grpsyl_p
->staffno
= (short) staff
;
1903 grpsyl_p
->vno
= (short) voice
;
1904 grpsyl_p
->basictime
= -1;
1905 grpsyl_p
->is_meas
= YES
;
1907 /* We are creating a line that doesn't appear in the user's input.
1908 * However, if we make it an anonymous line, if this grpsyl ever
1909 * gets referenced to print an error message (which it might--
1910 * like if user tries to tie something into this generated measure
1911 * space) the user will have no clue as to where the problem is in
1912 * their input. So put in the current file/line which will point to
1913 * the bar line at the end of the measure, which will at least point
1914 * the user to the right general area. */
1915 grpsyl_p
->inputfile
= Curr_filename
;
1916 grpsyl_p
->inputlineno
= (short) yylineno
;
1917 grpsyl_p
->grpcont
= GC_SPACE
;
1919 /* in another place, one compiler didn't fill in properly
1920 * when I assigned Score.time directly in one step, so to
1921 * take no chances, do numerator and denominator separately */
1922 grpsyl_p
->fulltime
.n
= Score
.time
.n
;
1923 grpsyl_p
->fulltime
.d
= Score
.time
.d
;
1926 /* given a MAINLL that points to a STAFF, check if that staff is a measure
1927 * repeat, and if so, validate and normalize it
1933 struct MAINLL
*mll_p
; /* points to a STAFF */
1936 struct GRPSYL
*gs_voice_p
[MAXVOICES
]; /* groups for each voice */
1937 struct GRPSYL
*prevgrp_p
;
1938 struct STAFF
*staff_p
;
1939 struct MAINLL
*prevmll_p
; /* measure being repeated */
1940 int voice_is_mrpt
[MAXVOICES
]; /* boolean for each voice */
1942 int found_non_mrpt
; /* something other than mrpt or ms */
1947 /* find out if any voice is a measure repeat */
1949 found_non_mrpt
= NO
;
1950 for (v
= 0; v
< MAXVOICES
; v
++) {
1951 gs_voice_p
[v
] = mll_p
->u
.staff_p
->groups_p
[v
];
1952 voice_is_mrpt
[v
] = is_mrpt(gs_voice_p
[v
]);
1953 if (voice_is_mrpt
[v
] == YES
) {
1956 else if (is_ms(gs_voice_p
[v
]) == NO
) {
1957 found_non_mrpt
= YES
;
1961 /* if none are a measure repeat, we are done */
1962 if (found_mrpt
== NO
) {
1966 /* At least one must be a meas repeat. If the others aren't
1967 * either also a measure repeat or a measure space, user error. */
1968 if (found_non_mrpt
== YES
) {
1969 l_yyerror(gs_voice_p
[0]->inputfile
, gs_voice_p
[0]->inputlineno
,
1970 "if one voice is mrpt, other voices cannot contain notes or rests");
1974 staff_p
= mll_p
->u
.staff_p
;
1975 staff
= staff_p
->staffno
;
1977 /* At this point, we have at least one voice that is mrpt, and
1978 * any other voices that exist are either mrpt or ms.
1979 * Find the previous measure to find out how many measures of
1980 * mrpt we have in a row, to fill in the mrptnum field.
1981 * But before calling prevgrpsyl(), need to make sure the staffno and
1982 * vno are filled in on the GRSPYL we pass to it, since we're so early
1983 * in parsing that hasn't happened yet, but prevgrpsyl() needs them.
1984 * We use the GRPSYL for voice 1, since we know that always exists.
1986 gs_voice_p
[0]->staffno
= staff
;
1987 gs_voice_p
[0]->vno
= 1;
1989 if ((prevgrp_p
= prevgrpsyl(gs_voice_p
[0], &prevmll_p
)) == (struct GRPSYL
*) 0) {
1990 /* We fell off the top of the main list */
1991 l_yyerror(gs_voice_p
[0]->inputfile
, gs_voice_p
[0]->inputlineno
,
1992 "mrpt cannot be used on the first measure");
1994 /* Force to measure space, so that if there are subsequent
1995 * mrpt measures, they don't give more errors; no reason
1996 * to complain more than once */
1997 for (v
= 0; v
< MAXVOICES
; v
++) {
1998 if (gs_voice_p
[v
] != (struct GRPSYL
*) 0) {
1999 gs_voice_p
[v
]->grpcont
= GC_SPACE
;
2005 /* Having a mrpt after a multirest doesn't make sense. At best,
2006 * it is ambiguous: should we repeat the multirest or the last
2007 * measure of rest? If the former, we have big problems if one
2008 * staff has a mrpt and another doesn't. If it's the latter, why
2009 * doesn't the user just use mr? That would be smaller and clearer. */
2010 if (prevgrp_p
->basictime
< -1) {
2011 l_yyerror(gs_voice_p
[0]->inputfile
, gs_voice_p
[0]->inputlineno
,
2012 "mrpt cannot be used in measure after multirest");
2013 for (v
= 0; v
< MAXVOICES
; v
++) {
2014 if (gs_voice_p
[v
] != (struct GRPSYL
*) 0) {
2015 gs_voice_p
[v
]->grpcont
= GC_SPACE
;
2021 if (is_mrpt(prevgrp_p
) == YES
) {
2022 /* Our current one must be numbered
2023 * one more than the previous one */
2024 staff_p
->mrptnum
= prevmll_p
->u
.staff_p
->mrptnum
+ 1;
2027 /* if this happens to be the first mrpt, it is numbered "2" */
2028 staff_p
->mrptnum
= 2;
2031 /* Certain parameter changes are not allowed in the middle of
2032 * runs of measure repeats because they cause the contents of
2033 * the measure to be too different to make sense. These
2034 * include changes in time signature, defoct, transpose.
2035 * So back up from the mrpt measure to its preceeding measure,
2036 * checking for any SSVs that might have something illegal in them.
2038 for (mll_p
= mll_p
->prev
; mll_p
!= prevmll_p
; mll_p
= mll_p
->prev
) {
2040 if (mll_p
->str
== S_SSV
) {
2041 if (chk_mrpt_ssv_interactions(mll_p
->u
.ssv_p
,
2042 gs_voice_p
[0], staff
) == NO
) {
2043 /* Force to measure space, so that if
2044 * there are subsequent mrpt measures,
2045 * they don't give more errors; no reason
2046 * to complain more than once */
2047 for (v
= 0; v
< MAXVOICES
; v
++) {
2048 if (gs_voice_p
[v
] != (struct GRPSYL
*) 0) {
2049 gs_voice_p
[v
]->grpcont
= GC_SPACE
;
2057 /* If doing MIDI, expand the measure repeat to what it is repeating */
2058 if (Doing_MIDI
== YES
) {
2059 for (v
= 0; v
< MAXVOICES
; v
++) {
2062 free_grpsyls(staff_p
->groups_p
[v
]);
2063 /* Note that the notelist does need to be copied,
2064 * (arg 2 == YES) because even though coords
2065 * are not used in MIDI, vcombine code may delete
2066 * the list, so it cannot be shared across groups.
2068 staff_p
->groups_p
[v
] = clone_gs_list(
2069 prevmll_p
->u
.staff_p
->groups_p
[v
], YES
);
2070 /* The cloned list may already have breakbeam set,
2071 * which will confuse has_cust_beaming(). For MIDI
2072 * purposes, we don't care about beams anyway,
2073 * much less subbeams, and breakbeam will get set
2074 * properly later anyway on these groups,
2075 * so just set to NO here. */
2076 for (g_p
= staff_p
->groups_p
[v
]; g_p
!= 0; g_p
= g_p
->next
) {
2077 g_p
->breakbeam
= NO
;
2082 /* We force all to GC_NOTES to make sure they are all mrpt,
2083 * even if some were originally ms. */
2084 for (v
= 0; v
< MAXVOICES
; v
++) {
2085 if (gs_voice_p
[v
] != (struct GRPSYL
*) 0) {
2086 gs_voice_p
[v
]->grpcont
= GC_NOTES
;
2093 /* given an SSV found while searching up the main list for a measure repeat
2094 * defining measure, figure out whether having a measure repeat is valid or
2095 * not. Some SSV changes alter things so much that a measure repeat no longer
2096 * makes sense, so we block it. Return YES if all seems well, NO if not.
2099 /* Here is the list of things we do NOT allow user to change between a
2100 * mrpt and the (earlier) measure that defines it */
2101 static struct Disallowed_ssv_fields
{
2102 int field
; /* index of the field in SSV "used" array */
2103 char * name
; /* to use in error message */
2104 } mrpt_ssv_list
[] = {
2106 { DEFOCT
, "defoct" },
2108 { TRANSPOSITION
, "transpose" },
2109 { ADDTRANSPOSITION
, "addtranspose" },
2110 { NUMSTAFF
, "staffs" },
2111 { 0, (char *) 0 } /* end the list */
2115 chk_mrpt_ssv_interactions(ssv_p
, gs_p
, staffno
)
2118 struct GRPSYL
*gs_p
;
2122 int ret
= YES
; /* return value after all checks */
2123 int err
= NO
; /* did we find error this time through loop? */
2124 int field
; /* index into used array in SSV */
2125 int i
; /* loop through list of disallowed things */
2128 /* check all possible thing that we don't allow. Complain about
2129 * as many errors as we find. Some of these things only occur in
2130 * score or score/staff context, but it's easier to just make
2131 * the code very general; if the field isn't used, things will still
2134 for (i
= 0; mrpt_ssv_list
[i
].name
!= (char *) 0; i
++) {
2135 field
= mrpt_ssv_list
[i
].field
;
2138 switch (ssv_p
->context
) {
2141 /* for things that can be overriden on staff
2142 * and/or voice, the score one will only apply
2143 * if there isn't an override in effect */
2144 if (ssv_p
->used
[field
] == YES
) {
2145 if (Staff
[staffno
-1].used
[field
] == YES
) {
2146 /* overridden by staff, so ignore */
2149 if (voices_override(staffno
, field
) == YES
) {
2150 /* overridden by all voices; ignore */
2159 if (ssv_p
->staffno
!= staffno
) {
2160 /* This applies to some other staff. Since this
2161 * SSV is totally irrrelevant, we can return,
2162 * rather than loop through checking for other
2163 * possible errors. */
2166 if (ssv_p
->used
[field
] == YES
) {
2167 if (ssv_p
->context
== C_STAFF
&&
2168 voices_override(staffno
, field
) == YES
) {
2169 /* overridden on all voices, so ignore */
2177 pfatal("bad context in mrpt/ssv check");
2182 /* this field change not allowed */
2183 l_yyerror(gs_p
->inputfile
, gs_p
->inputlineno
,
2184 "can't use mrpt after %s change",
2185 mrpt_ssv_list
[i
].name
);
2194 /* Returns YES if the given SSV field is overriden by all voices
2195 * on the given staff, NO if not. */
2198 voices_override(staff
, field
)
2200 int staff
; /* check this staff */
2201 int field
; /* check this field */
2207 numvoices
= vscheme_voices(svpath(staff
, VSCHEME
)->vscheme
);
2208 for (v
= 0; v
< numvoices
; v
++) {
2209 if (Voice
[staff
- 1][v
].used
[field
] == NO
) {
2210 /* this voice does not override */
2218 /* return YES if given GRPSYL represents a measure repeat */
2223 struct GRPSYL
*gs_p
;
2226 return (gs_p
!= (struct GRPSYL
*) 0 && gs_p
->is_meas
== YES
2227 && gs_p
->grpcont
== GC_NOTES
&& gs_p
->nnotes
== 0) ? YES
: NO
;
2230 /* return YES if given GRPSYL represents a measure space */
2234 struct GRPSYL
*gs_p
;
2237 /* non-existent is like measure space */
2238 if (gs_p
== (struct GRPSYL
*) 0) {
2241 return (gs_p
->is_meas
== YES
&& gs_p
->grpcont
== GC_SPACE
) ? YES
: NO
;
2245 /* sort the notes to be top to bottom */
2248 sort_notes(grpsyl_p
, fname
, lineno
)
2250 struct GRPSYL
*grpsyl_p
; /* sort the notes off this GRPSYL */
2251 char *fname
; /* file name for error messages */
2252 int lineno
; /* input line number */
2256 struct NOTE
*highest_p
; /* note with highest pitch on a staff */
2257 struct NOTE
*lowest_p
; /* note with lowest pitch on a staff */
2258 int othervis
= -1; /* staff number of adjacent visible staff */
2261 if (grpsyl_p
->nnotes
< 2) {
2262 /* nothing to sort! */
2266 /* If have cross-staff stemming, do extra error checks */
2267 if (grpsyl_p
->stemto
!= CS_SAME
) {
2269 if (Doing_tab_staff
== YES
) {
2270 l_yyerror(grpsyl_p
->inputfile
, grpsyl_p
->inputlineno
,
2271 "stemming with another staff is not allowed on a tablature staff");
2273 else if (svpath(grpsyl_p
->staffno
, STAFFLINES
)->stafflines
!= 5) {
2274 l_yyerror(grpsyl_p
->inputfile
, grpsyl_p
->inputlineno
,
2275 "stemming to another staff only allowed from a 5-line staff");
2277 if (input_style(grpsyl_p
->staffno
, grpsyl_p
->vno
)
2278 == IS_CHORD_INPUT
) {
2279 l_yyerror(grpsyl_p
->inputfile
, grpsyl_p
->inputlineno
,
2280 "stemming to another staff not allowed on chord-at-a-time input");
2283 if (grpsyl_p
->stemto
== CS_ABOVE
) {
2284 for (othervis
= grpsyl_p
->staffno
- 1; othervis
> 0; othervis
--) {
2285 if (svpath(othervis
, VISIBLE
)->visible
== YES
) {
2286 if (svpath(grpsyl_p
->staffno
, STAFFLINES
)->stafflines
!= 5
2287 || is_tab_staff(othervis
)) {
2288 l_yyerror(grpsyl_p
->inputfile
, grpsyl_p
->inputlineno
,
2289 "for stem with staff above, preceeding visible staff must be a normal 5-line staff");
2294 if (othervis
<= 0) {
2295 l_yyerror(grpsyl_p
->inputfile
, grpsyl_p
->inputlineno
,
2296 "can't stem with above from top visible staff");
2299 else if (grpsyl_p
->stemto
== CS_BELOW
) {
2300 for (othervis
= grpsyl_p
->staffno
+ 1; othervis
<= Score
.staffs
; othervis
++) {
2301 if (svpath(othervis
, VISIBLE
)->visible
== YES
) {
2302 if (svpath(grpsyl_p
->staffno
, STAFFLINES
)->stafflines
!= 5
2303 || is_tab_staff(othervis
)) {
2304 l_yyerror(grpsyl_p
->inputfile
, grpsyl_p
->inputlineno
,
2305 "for stem with staff below, following visible staff must be a normal 5-line staff");
2310 if (othervis
>= Score
.staffs
+ 1) {
2311 l_yyerror(grpsyl_p
->inputfile
, grpsyl_p
->inputlineno
,
2312 "can't stem with below from bottom visible staff");
2316 /* The two staffs must have the same staffscale.
2317 * Use floating point comparision for "close enough" */
2318 if (othervis
> 0 && othervis
<= Score
.staffs
) {
2319 if (fabs(svpath(othervis
,STAFFSCALE
)->staffscale
-
2320 svpath(grpsyl_p
->staffno
, STAFFSCALE
)->staffscale
) > 0.001) {
2321 l_yyerror(grpsyl_p
->inputfile
, grpsyl_p
->inputlineno
,
2322 "staff being stemed to must have same staffscale");
2327 /* If this group is stemmed to another staff,
2328 * we have to make sure the notes on the two staffs don't overlap,
2329 * since we can't handle duplicate notes,
2330 * and it's kind of silly anyway.
2331 * At this point, the stemto_idx will be at the first
2332 * "other staff" note. In the case of stem with above,
2333 * we need to adjust that to be at the last normal staff group,
2334 * because that is the convention we use. In any case, once
2335 * we verify there is no overlap, we can go ahead and sort the
2336 * group as usual, since we know that will end up sorting each
2337 * staff's notes properly.
2339 if (grpsyl_p
->stemto
== CS_ABOVE
) {
2340 /* Find highest note on normal staff */
2341 if (grpsyl_p
->stemto_idx
== 0) {
2342 /* no notes at all on normal staff */
2347 highest_p
= &(grpsyl_p
->notelist
[0]);
2348 for (n
= 1; n
< grpsyl_p
->stemto_idx
; n
++) {
2349 if (notecomp(&(grpsyl_p
->notelist
[n
]), highest_p
) > 0) {
2350 highest_p
= &(grpsyl_p
->notelist
[n
]);
2354 /* Find lowest note on above staff */
2355 if (grpsyl_p
->stemto_idx
== grpsyl_p
->nnotes
) {
2356 /* Actually, we don't currently allow this case
2357 * (blocked in parsing code),
2358 * but if we ever do, this code should handle it...
2363 lowest_p
= &(grpsyl_p
->notelist
[n
]);
2364 for ( ; n
< grpsyl_p
->nnotes
; n
++) {
2365 if (notecomp(&(grpsyl_p
->notelist
[n
]), lowest_p
) < 0) {
2366 lowest_p
= &(grpsyl_p
->notelist
[n
]);
2370 /* Make sure there is no overlap */
2371 if (highest_p
!= 0 && lowest_p
!= 0 &&
2372 notecomp(highest_p
, lowest_p
) <= 0) {
2373 l_yyerror(grpsyl_p
->inputfile
, grpsyl_p
->inputlineno
,
2374 "the 'with above' notes are not allowed to overlap with notes on the normal staff");
2377 /* With CS_ABOVE, the index is supposed to point to the last on
2378 * the normal, so adjust to do that. */
2379 grpsyl_p
->stemto_idx
= grpsyl_p
->nnotes
- grpsyl_p
->stemto_idx
- 1;
2381 else if (grpsyl_p
->stemto
== CS_BELOW
) {
2382 /* Do analogous for below */
2383 /* Find lowest note on normal staff */
2384 if (grpsyl_p
->stemto_idx
== 0) {
2385 /* no notes at all on normal staff */
2390 lowest_p
= &(grpsyl_p
->notelist
[0]);
2391 for (n
= 1; n
< grpsyl_p
->stemto_idx
; n
++) {
2392 if (notecomp(&(grpsyl_p
->notelist
[n
]), lowest_p
) < 0) {
2393 lowest_p
= &(grpsyl_p
->notelist
[n
]);
2397 /* Find highest note on below staff */
2398 if (grpsyl_p
->stemto_idx
== grpsyl_p
->nnotes
) {
2403 highest_p
= &(grpsyl_p
->notelist
[n
]);
2404 for (n
++ ; n
< grpsyl_p
->nnotes
; n
++) {
2405 if (notecomp(&(grpsyl_p
->notelist
[n
]), highest_p
) > 0) {
2406 highest_p
= &(grpsyl_p
->notelist
[n
]);
2410 /* Make sure there is no overlap */
2411 if (highest_p
!= 0 && lowest_p
!= 0 &&
2412 notecomp(highest_p
, lowest_p
) <= 0) {
2413 l_yyerror(grpsyl_p
->inputfile
, grpsyl_p
->inputlineno
,
2414 "the 'with below' notes are not allowed to overlap with notes on the normal staff");
2418 /* sort top to bottom */
2419 qsort( (char *) grpsyl_p
->notelist
, (unsigned int) grpsyl_p
->nnotes
,
2420 sizeof (struct NOTE
), notecomp
);
2422 /* now that they are sorted, check for duplicates. */
2423 for (n
= 0; n
< grpsyl_p
->nnotes
- 1; n
++) {
2424 if (notecomp(&(grpsyl_p
->notelist
[n
]),
2425 &(grpsyl_p
->notelist
[n
+1])) == 0) {
2426 /* For voice-at-a-time, duplicate is an error.
2427 * For chord-at-a-time, we merge them, except that
2428 * for tablature, if the frets don't match we
2429 * can't merge them. */
2430 if (input_style(grpsyl_p
->staffno
, grpsyl_p
->vno
)
2431 == IS_VOICE_INPUT
||
2432 (Doing_tab_staff
== YES
&&
2433 grpsyl_p
->notelist
[n
].FRETNO
!=
2434 grpsyl_p
->notelist
[n
+1].FRETNO
)
2436 if (Doing_tab_staff
== YES
) {
2437 struct STRINGINFO
*strinfo_p
;
2439 strinfo_p
= &(svpath(grpsyl_p
->staffno
,
2440 STAFFLINES
)->strinfo
[ (int)
2441 grpsyl_p
->notelist
[n
].STRINGNO
]);
2442 l_yyerror(fname
, lineno
,
2443 "string %s occurred more than once in a single chord",
2446 strinfo_p
->accidental
,
2447 strinfo_p
->nticks
));
2450 l_yyerror(fname
, lineno
,
2451 "pitch %c%d occurred more than once in a single chord",
2452 grpsyl_p
->notelist
[n
].letter
,
2453 grpsyl_p
->notelist
[n
].octave
);
2457 merge_dup_notes(grpsyl_p
, n
);
2458 /* in case there was more than one duplicate,
2459 * arrange to check this same one again,
2460 * against the group that has taken the place
2461 * of the removed group (if any) */
2469 /* Compare notes. Return 1 if first is lower, -1 if higher, 0 if same.
2470 * For tablature, this just compares the strings; for non-tablature,
2471 * it just compares pitch and octave, not counting accidentals. */
2474 notecomp(item1_p
, item2_p
)
2477 const void *item1_p
; /* the notes to compare */
2478 const void *item2_p
;
2480 char *item1_p
; /* the notes to compare */
2485 struct NOTE
*note1_p
;
2486 struct NOTE
*note2_p
;
2488 /* cast to proper type */
2489 note1_p
= (struct NOTE
*) item1_p
;
2490 note2_p
= (struct NOTE
*) item2_p
;
2492 if (Doing_tab_staff
== YES
) {
2493 /* for tablature, just need to compare the string numbers. */
2494 if (note1_p
->STRINGNO
< note2_p
->STRINGNO
) {
2497 else if (note1_p
->STRINGNO
> note2_p
->STRINGNO
) {
2505 /* first compare octaves */
2506 if ( note1_p
->octave
< note2_p
->octave
) {
2510 if (note1_p
->octave
> note2_p
->octave
) {
2514 /* if same octaves, compare pitches */
2515 if (Letshift
[note1_p
->letter
- 'a'] < Letshift
[note2_p
->letter
- 'a']) {
2519 if (Letshift
[note1_p
->letter
- 'a'] > Letshift
[note2_p
->letter
- 'a']) {
2527 /* Make sure data ends with some kind of bar line (which can optionally
2528 * be followed by blocks). Start at end of main list and go backwards.
2529 * If we hit a S_BAR, then all is well.
2530 * If we hit a S_STAFF first or beginning of list, we have a problem.
2531 * Also does error checks on any FEED at the end of the piece.
2532 * It does a similar check on any FEED at the beginning. (It doesn't
2533 * really fit the name of the function, but keeps the checks together.)
2537 check4barline_at_end()
2540 struct MAINLL
*list_p
; /* walk through main list */
2541 int saw_block
= NO
; /* if saw an S_BLOCKHEAD */
2544 /* first check for FEED at the beginning */
2545 for (list_p
= Mainllhc_p
; list_p
!= (struct MAINLL
*) NULL
;
2546 list_p
= list_p
->next
) {
2547 if (list_p
->str
== S_STAFF
) {
2548 /* no user-supplied feed at beginning */
2551 else if (list_p
->str
== S_FEED
) {
2552 /* rightmargin applies to previous feed,
2553 * but there is no previous feed to the first score */
2554 if (list_p
->u
.feed_p
->rightmargin
>= 0.0) {
2555 l_warning(list_p
->inputfile
, list_p
->inputlineno
,
2556 "rightmargin on newscore at beginning of piece is ignored");
2558 /* Note: we probably ought to give a
2559 * warning for pagefeed here and ignore it,
2560 * to be like at the end of a piece.
2561 * But this was inadvertently allowed in the past
2562 * (it produces a blank page),
2563 * so we leave it that way
2564 * for backward compatibility.
2569 for (list_p
= Mainlltc_p
; list_p
!= (struct MAINLL
*) NULL
;
2570 list_p
= list_p
->prev
) {
2572 if (list_p
->str
== S_BAR
) {
2573 /* found BAR before STAFF. Good. */
2574 /* if user forgot to end an ending, do it for them */
2575 if (list_p
->u
.bar_p
->endingloc
== INITEM
) {
2576 list_p
->u
.bar_p
->endingloc
= ENDITEM
;
2578 else if (list_p
->u
.bar_p
->endingloc
== STARTITEM
) {
2579 l_yyerror(list_p
->inputfile
, list_p
->inputlineno
,
2580 "can't begin ending on final bar line");
2583 if (list_p
->u
.bar_p
->bartype
== RESTART
) {
2584 l_yyerror(list_p
->inputfile
, list_p
->inputlineno
,
2585 "final bar line cannot be a restart");
2590 else if (list_p
->str
== S_STAFF
) {
2591 /* Oh-oh. No ending bar line */
2592 yyerror("ending bar line missing");
2596 else if (list_p
->str
== S_BLOCKHEAD
) {
2599 else if (list_p
->str
== S_FEED
) {
2600 if (list_p
->u
.feed_p
->leftmargin
>= 0.0) {
2601 l_warning(list_p
->inputfile
, list_p
->inputlineno
,
2602 "leftmargin on newscore at end of piece is ignored");
2607 /* if we are here, we went all through the list */
2608 if (saw_block
== NO
) {
2609 yyerror("no music data or blocks found in input");
2614 /* when user wants a multi-rest, create a STAFF for each staff. Then for
2615 * each of them, fill in a GRPSYL with basictime as the negative of the
2616 * number of measure, and fulltime as the length of a measure. Attach this
2617 * GRPSYL as the only item off of voice 1, and to other voices as well,
2618 * if there are other voice and we are doing MIDI. */
2621 add_multirest(nummeas
)
2623 int nummeas
; /* how many measures in the multi-rest */
2626 register int s
; /*staff index */
2627 struct GRPSYL
*new_p
; /* newly allocated GRPSYL for multirest */
2628 int v
; /* voice index */
2632 /* if already have notes in this measure, user goofed */
2633 if (Got_group
== YES
) {
2638 if (Got_multirest
== 1) {
2639 yyerror("can't have consecutive multirests (maybe missing bar?)");
2643 /* we could allow up to 32767 and still fit in a short, but huge
2644 * numbers can lead to rational overflow in midi, and who in their
2645 * right mind would want that many measures of multirest anyway? */
2646 if (rangecheck(nummeas
, 2, MAXMULTINUM
, "multirest measures") == NO
) {
2650 /* create all the staffs and fill them in */
2652 for (s
= 1; s
<= Score
.staffs
; s
++) {
2653 numvoices
= vscheme_voices(svpath(s
, VSCHEME
)->vscheme
);
2654 for (v
= 0; v
< numvoices
; v
++) {
2655 if (v
== 0 || Doing_MIDI
== YES
) {
2656 Staffmap_p
[s
]->u
.staff_p
->groups_p
[v
] = new_p
2657 = newGRPSYL(GS_GROUP
);
2658 new_p
->grpcont
= GC_REST
;
2659 new_p
->basictime
= -nummeas
;
2660 new_p
->fulltime
= Score
.time
;
2666 Got_some_data
= YES
;
2668 /* update measure numbers for rehearsal mark and stuff use */
2669 Meas_num
+= nummeas
;
2670 multi_stuff(nummeas
);
2674 /* this function gets called when we discover user has mixed multi-rest and
2675 * music data in a single measure. If we've already reported this on the
2676 * current measure, Got_multirest will be 2, so we just return,
2677 * otherwise report it and set Got_multirest to 2 */
2683 if (Got_multirest
!= 2) {
2684 yyerror( "can't mix music data and multi-rest in same measure");
2690 /* Recursively free a list of GRPSYLs. If this is a GS_GROUP,
2691 * also free the withlist and notelist if they exist,
2692 * and anything hanging off the notelist. If this is a GS_SYLLABLE, anything
2693 * that is hanging of the grpsyl will NOT be freed.
2699 struct GRPSYL
*gs_p
; /* what to free */
2702 int n
; /* to index through lists */
2704 if (gs_p
== (struct GRPSYL
*) 0) {
2705 /* end of recursion */
2709 if (gs_p
->grpsyl
== GS_GROUP
) {
2710 free_notelist(gs_p
);
2712 /* free the withlist */
2713 for (n
= 0; n
< gs_p
->nwith
; n
++) {
2714 if (gs_p
->withlist
[n
] != (char *) 0) {
2715 FREE(gs_p
->withlist
[n
]);
2718 if (gs_p
->withlist
!= (char **) 0 && gs_p
->nwith
> 0) {
2719 FREE(gs_p
->withlist
);
2723 free_grpsyls(gs_p
->next
);
2728 /* Free things off of NOTEs in the notelist, if any, plus the list itself */
2733 struct GRPSYL
*gs_p
;
2738 for (n
= 0; n
< gs_p
->nnotes
; n
++) {
2739 /* free coordinate array, if any */
2740 if (gs_p
->notelist
[n
].c
!= (float *) 0) {
2741 FREE(gs_p
->notelist
[n
].c
);
2744 /* free any slurto lists */
2745 if (gs_p
->notelist
[n
].slurtolist
!= (struct SLURTO
*) 0) {
2746 FREE(gs_p
->notelist
[n
].slurtolist
);
2750 /* free the notelist itself, if any */
2751 if (gs_p
->notelist
!= (struct NOTE
*) 0 && gs_p
->nnotes
> 0) {
2752 FREE(gs_p
->notelist
);
2757 /* add a slurto note to list */
2760 add_slurto(grpsyl_p
, pitch
, octave
, note_index
, slurstyle
)
2762 struct GRPSYL
*grpsyl_p
; /* what group to associate slurto with */
2763 int pitch
; /* 'a' to 'g' */
2765 int note_index
; /* which note in the chord to slur from */
2766 int slurstyle
; /* L_NORMAL, L_DOTTED, or L_DASHED */
2769 struct NOTE
*note_p
; /* note to attach to */
2772 if (note_index
< 0) {
2773 /* user tried to slur from a rest or something like that */
2774 yyerror("no note to slur from");
2778 note_p
= &(grpsyl_p
->notelist
[ note_index
]);
2779 if (note_p
->nslurto
== 0) {
2780 /* first time--need to allocate */
2781 MALLOC(SLURTO
, note_p
->slurtolist
, 1);
2784 /* else re-allocate more space */
2786 REALLOC(SLURTO
, note_p
->slurtolist
, note_p
->nslurto
+ 1);
2789 note_p
->slurtolist
[ note_p
->nslurto
].letter
= (char) pitch
;
2790 note_p
->slurtolist
[ note_p
->nslurto
].octave
= (short) octave
;
2791 note_p
->slurtolist
[ note_p
->nslurto
].slurstyle
= (short) slurstyle
;
2792 /* we'll fix up this value later when we know the right one */
2793 note_p
->slurtolist
[ note_p
->nslurto
].slurdir
= (short) UNKNOWN
;
2795 (note_p
->nslurto
)++;
2799 /* At the beginning of a <> which indicates slurs,
2800 * save which slurtolist index we are are on.
2801 * When at the end of the slur, we will discover if the user specified a
2802 * bend direction for the slurs, and if so, have to go back and fill in
2803 * that direction for all the slurtolist items from the saved index to
2804 * the end of the list. This is needed since user may have several <>
2805 * items with different directions, e.g.,
2810 begin_slur(grpsyl_p
, note_index
)
2812 struct GRPSYL
*grpsyl_p
;
2816 if (grpsyl_p
== 0 || note_index
< 0 || note_index
>= grpsyl_p
->nnotes
) {
2817 /* must have been bad input */
2820 Slur_begin
= grpsyl_p
->notelist
[note_index
].nslurto
;
2823 /* At the end of a slur, either <> style or "slur" keyword style,
2824 * go back and fill in the bulge direction. If note_index is -1,
2825 * this is a "slur" that applies to all notes of the group, and
2826 * there should be one slurto item on each note.
2830 set_slurdir(grpsyl_p
, note_index
, dir
)
2832 struct GRPSYL
*grpsyl_p
;
2833 int note_index
; /* which note's slurtolist to use */
2834 int dir
; /* UP, DOWN, UNKNOWN */
2840 if (note_index
== -1) {
2841 for (n
= 0; n
< grpsyl_p
->nnotes
; n
++) {
2842 if (grpsyl_p
->notelist
[n
].nslurto
>= 1) {
2843 grpsyl_p
->notelist
[n
]
2844 .slurtolist
[grpsyl_p
->notelist
[n
].nslurto
-1]
2847 /* If no slurto, should already have
2848 * error generated elsewhere */
2852 for (i
= Slur_begin
; i
< grpsyl_p
->notelist
[note_index
].nslurto
; i
++) {
2853 grpsyl_p
->notelist
[note_index
].slurtolist
[i
].slurdir
= dir
;
2859 /* given a bend string, return what should be crammed into the
2860 * octave field to save this info, using the TABOCT macro. If the string
2861 * is incomprehensible, print error, and do what we can. */
2863 /* define states for the simple parser */
2864 #define DOING_INTEGER 1
2865 #define DOING_NUMERATOR 2
2866 #define DOING_DENOMINATOR 3
2870 parse_bend_string(bendstring
)
2875 int intpart
= 0; /* integer part of bend */
2876 int num
= 0, den
= 1; /* numerator and denominator
2877 * of fractional part of bend */
2880 /* if null string, easy to parse */
2881 if (bendstring
== (char *) 0) {
2882 return (TABOCT(0, 0, 0));
2885 /* string is in internal format, so skip first 2 bytes, plus any
2886 * leading white space */
2887 for (bendstring
+= 2; *bendstring
!= '\0'; bendstring
++) {
2888 if (isgraph(*bendstring
)) {
2893 /* the text "full" is a special case */
2894 if (strcmp(bendstring
, "full") == 0) {
2898 /* the text better be a number and/or fractional part,
2900 int state
; /* DOING_INTEGER, DOING_NUMERATOR,
2901 * DOING_DENOMINATOR, or GOT_ERROR */
2903 for (state
= DOING_INTEGER
;
2904 *bendstring
!= '\0' && state
< GOT_ERROR
;
2907 if (isdigit(*bendstring
)) {
2908 /* add to the correct item */
2911 intpart
= (intpart
* 10) + (*bendstring
- '0');
2913 case DOING_NUMERATOR
:
2914 num
= (num
* 10) + (*bendstring
- '0');
2916 case DOING_DENOMINATOR
:
2917 den
= (den
* 10) + (*bendstring
- '0');
2920 pfatal("bad state in parse_bend_string");
2925 /* handle white space */
2926 else if (*bendstring
== ' ' || *bendstring
== '\t') {
2927 if (state
== DOING_INTEGER
) {
2928 /* end of integer part */
2929 state
= DOING_NUMERATOR
;
2931 /* ignore any other white space */
2934 else if (*bendstring
== '/') {
2935 /* starting parsing of denominator */
2941 /* oops. what we thought was the integer
2942 * part was really the numerator of the
2943 * fractional part. Adjust accordingly. */
2946 state
= DOING_DENOMINATOR
;
2949 case DOING_NUMERATOR
:
2950 state
= DOING_DENOMINATOR
;
2953 case DOING_DENOMINATOR
:
2954 yyerror("more than one / in bend string");
2959 pfatal("bad state in parse_bend_string");
2965 yyerror("invalid character in bend string");
2971 /* make sure we can fit them in our cramped space */
2972 (void) rangecheck(intpart
, MINBENDINT
, MAXBENDINT
,
2973 "integer part of bend");
2974 (void) rangecheck(num
, MINBENDNUM
, MAXBENDNUM
,
2975 "numerator of bend fraction");
2976 (void) rangecheck(den
, MINBENDDEN
, MAXBENDDEN
,
2977 "denominator of bend fraction");
2979 return (TABOCT(intpart
, num
, den
));
2983 /* given a tablature GRPSYL, look up the proper string number based on the
2984 * letter/accidental that is currently there, and fill in the STRINGNO and
2985 * FRETNO fields with their correct values. The slurto items also get
2986 * their string letter/accidental values translated to string number. */
2989 fix_frets(grpsyl_item_p
)
2991 struct GRPSYL
*grpsyl_item_p
;
2994 int n
; /* index through note list */
2995 int s
; /* index through slurto */
2996 struct NOTE
*note_p
; /* current note */
2997 struct STRINGINFO
*string_info_p
; /* string translation table,
2998 * to map between pitch/accidental and
3000 int nstrings
; /* how many strings there are */
3003 /* find appropriate string mapping table and its size */
3004 string_info_p
= Staff
[grpsyl_item_p
->staffno
- 1].strinfo
;
3005 nstrings
= Staff
[grpsyl_item_p
->staffno
- 1].stafflines
;
3007 /* for each note, translate to string number, and put fret in its
3009 for (n
= 0; n
< grpsyl_item_p
->nnotes
; n
++) {
3010 /* get pointer to the current note in the group */
3011 note_p
= &(grpsyl_item_p
->notelist
[n
]);
3013 /* doing mapping from pitch/accidental to string number */
3014 note_p
->STRINGNO
= string_number(string_info_p
, nstrings
,
3015 note_p
->letter
, note_p
->accidental
, TMP_NTICKS(note_p
));
3017 /* fill in the correct fret number, now that its space is
3019 note_p
->FRETNO
= TMP_FRET(note_p
);
3020 note_p
->stepsup
= 0; /* no longer need this temp space */
3022 /* also fix up any slurto items */
3023 for (s
= 0; s
< note_p
->nslurto
; s
++) {
3024 if (note_p
->slurtolist
[s
].octave
== USE_DFLT_OCTAVE
) {
3025 note_p
->slurtolist
[s
].STRINGNO
3033 /* look up a letter/acc/nticks combination in the string_info_p table of
3034 * size nstrings, and return the index of the string that matched. If none
3035 * match, print an error and return 0. However, if the pitch is PP_NO_PITCH,
3036 * don't print the error, because an error would already have been printed
3037 * earlier, and it just adds confusion to print another one.
3038 * Also don't complain about rest and space, because they are legal.
3042 string_number(string_info_p
, nstrings
, letter
, accidental
, nticks
)
3044 struct STRINGINFO
*string_info_p
; /* string translation table */
3045 int nstrings
; /* number of entries in table */
3048 int nticks
; /* number of ' marks */
3053 if (string_info_p
== (struct STRINGINFO
*) 0) {
3054 pfatal("null stringinfo");
3057 /* look through string_info list for a matching string */
3058 for (i
= 0; i
< nstrings
; i
++) {
3059 if (string_info_p
[i
].letter
== letter
&&
3060 string_info_p
[i
].accidental
== accidental
&&
3061 string_info_p
[i
].nticks
== nticks
) {
3062 /* found it. return its index */
3067 /* If letter is PP_NO_PITCH, that means user failed to put a letter
3068 * for the first group in the measure. We would have already
3069 * exclaimed about that in fix_a_grpsyl_list(), so rather than
3070 * generate lots more messages due to the same error,
3071 * just silently return the default string of 0.
3072 * Rests, spaces, and rpts are also fine--they will get converted to
3073 * groups later. Otherwise the error message is needed. */
3074 if (letter
>= 'a' && letter
<= 'g') {
3075 /* no match found */
3076 l_yyerror(Curr_filename
, yylineno
, "no '%s' string",
3077 format_string_name(letter
, accidental
, nticks
));
3080 /* use string 0 as default, to have something to return */
3085 /* given a string number and staff number, return the text representation
3086 * of that string. Returns pointer to static area. */
3089 stringname(stringno
, staffno
)
3095 struct STRINGINFO
*stringinfo_p
;
3098 /* make sure we have a valid string number */
3099 if (stringno
< 0 || stringno
>= Staff
[staffno
- 1].stafflines
) {
3100 pfatal("string number %d out of range", stringno
);
3103 /* get pointer to proper table entry for this string */
3104 stringinfo_p
= & (Staff
[staffno
- 1].strinfo
[stringno
] );
3106 /* return text representation */
3107 return(format_string_name(stringinfo_p
->letter
,
3108 stringinfo_p
->accidental
,
3109 stringinfo_p
->nticks
));
3113 /* to print some ticks, print as much of this string as necessary */
3114 static char tickstring
[MAXTICKS
+ 1];
3116 /* given string letter, accidental, and number of tick marks, return
3117 * pointer to static area that contains the text representation of the
3121 format_string_name(letter
, accidental
, nticks
)
3128 static char name
[MAXTICKS
+ 3]; /* this is what will get returned */
3129 int tickoffset
= 1; /* where in name that ticks begin */
3132 /* fill in string letter plus accidental if any */
3133 name
[0] = (char) letter
;
3134 if (accidental
!= 0) {
3135 name
[1] = (char) accidental
;
3139 /* first time through, fill in maximum number of ticks. This makes
3140 * it possible to have the right number, even if MAXTICKS changes
3142 if (tickstring
[0] == '\0') {
3143 for (i
= 0; i
< MAXTICKS
; i
++) {
3144 tickstring
[i
] = '\'';
3148 /* add appropriate number of ticks to name */
3149 (void) sprintf(name
+ tickoffset
, tickstring
+ strlen(tickstring
) - nticks
);
3155 /* given a list of grpsyls, check that every non-prebend bend has a previous
3156 * groups which contains the same string as the bend is on. Also disallow
3157 * slashes on groups that just have a bend. */
3160 check_bends(gs_p
, mll_p
)
3162 struct GRPSYL
*gs_p
;
3163 struct MAINLL
*mll_p
;
3166 int n
; /* notelist index */
3167 int ns
; /* slurto index */
3168 struct GRPSYL
*prevgrp_p
; /* previous group in same staff/voice */
3169 struct NOTE
*prevnote_p
; /* note in previous group */
3170 int has_bend
, has_prebend
; /* YES or NO */
3171 struct MAINLL
*nmll_p
;
3174 /* check each group in the list */
3175 for ( ; gs_p
!= (struct GRPSYL
*) 0; gs_p
= gs_p
->next
) {
3177 /* check each note in the group */
3178 has_bend
= has_prebend
= NO
;
3179 for (n
= 0; n
< gs_p
->nnotes
; n
++) {
3181 if (HASBEND(gs_p
->notelist
[n
])
3182 && gs_p
->notelist
[n
].FRETNO
== NOFRET
) {
3184 /* this is a non-prebend bend, so it needs to
3185 * be checked. Find the previous group */
3188 if ((prevgrp_p
= prevgrpsyl(gs_p
, &nmll_p
))
3189 != (struct GRPSYL
*) 0) {
3191 /* find the matching note (string),
3192 * If not found, the function will
3193 * print an error. */
3195 find_matching_note(prevgrp_p
,
3196 gs_p
->notelist
[n
].letter
,
3197 gs_p
->notelist
[n
].octave
,
3200 if (prevnote_p
== (struct NOTE
*) 0) {
3204 /* previous group not allowed to have
3205 * slide other than inward nowhere */
3206 for (ns
= 0; ns
< prevnote_p
->nslurto
;
3208 switch (prevnote_p
->slurtolist
3212 /* these are okay */
3215 l_yyerror(gs_p
->inputfile
,
3217 "can't have bend on note following a slide");
3223 yyerror("can't do bend--no previous group");
3227 /* slashes are not allowed on bend groups */
3228 if (gs_p
->slash_alt
!= 0) {
3229 yyerror("slash not allowed with bend");
3230 gs_p
->slash_alt
= 0;
3233 else if (HASBEND(gs_p
->notelist
[n
])
3234 && gs_p
->notelist
[n
].FRETNO
!= NOFRET
) {
3239 if (has_bend
== YES
&& has_prebend
== YES
) {
3240 yyerror("mixture of prebend and bend not allowed on the same chord");
3247 * When the input includes additive time values like 2+8 or 2.+32
3248 * on groups, we need to create a group for each extra time value.
3249 * For notes, the groups are all tied together to make them effectively
3250 * a single group. If there are any subtractions in the list of time values,
3251 * we have no way to determine what time values the user really wants,
3252 * so we keep using as big as possible (including dots) until we get enough.
3253 * Should be called with the group currently last in the GRPSYL list.
3254 * Returns the (possibly new) last group.
3258 expandgrp(grpsyl_p
, timelist_p
)
3260 struct GRPSYL
*grpsyl_p
; /* the first group; pattern to clone */
3261 struct TIMELIST
*timelist_p
; /* the list of additional time values */
3264 struct GRPSYL
*gs_p
; /* group being processed */
3265 struct TIMELIST
*tl_p
; /* index through list to check for subtracts */
3266 int had_neg
; /* YES if there was at least one subtraction */
3267 RATIONAL totaltime
; /* all times added together */
3268 int n
; /* index through notelist */
3271 if (timelist_p
== 0) {
3272 /* nothing to expand */
3276 /* disallow on grace */
3277 if (grpsyl_p
->grpvalue
== GV_ZERO
) {
3278 yyerror("can't use additive time values on grace notes");
3281 /* disallow if alt on group */
3282 if (grpsyl_p
->slash_alt
< 0) {
3283 yyerror("can't use additive time values and alt on same chord");
3287 /* If there were any subtraction, need to do that differently
3288 * than if all are additions. Check if any subtractions, and
3289 * add up total time in case we need it. */
3290 for (had_neg
= NO
, totaltime
= grpsyl_p
->fulltime
, tl_p
= timelist_p
;
3291 tl_p
!= 0; tl_p
= tl_p
->next
) {
3292 if (MI(tl_p
->fulltime
)) {
3295 totaltime
= radd(totaltime
, tl_p
->fulltime
);
3297 if (had_neg
== YES
) {
3298 /* It's impossible to know what time values the user
3299 * really wants us to use, so we keep using the largest
3300 * possible values until we get enough, using as many
3301 * dots as possible along the way.
3303 RATIONAL
try; /* The time value we're currently attempting
3304 * to use; will be used if remaining time
3305 * is at least this long, else take half
3307 int needgrp
; /* YES if need to alloc a new group.
3308 * (Have one group to start with,
3309 * so first time through loop don't need
3312 /* We start with double whole, and keep using smaller times
3313 * from there until we get enough, using dots if possible.
3314 * I suppose for rests we really *should* start with quad
3315 * whole rather than double whole, but since we don't know
3316 * what the user really wants anyway, and the cases where
3317 * this would make a difference are so rare, and since the
3318 * user can always specify exactly what they do want,
3319 * don't bother. (They'll just get two double whole rests.) */
3321 for (needgrp
= NO
, try = Two
; PL(totaltime
); ) {
3322 if (GE(totaltime
, try)) {
3323 /* We can use this trial time value */
3324 if (needgrp
== YES
) {
3325 gs_p
->next
= clone_gs_list(gs_p
, YES
);
3326 gs_p
->next
->prev
= gs_p
;
3328 /* If the original group started a beam,
3329 * added groups must be inside */
3330 if (gs_p
->beamloc
== STARTITEM
) {
3331 gs_p
->beamloc
= INITEM
;
3334 gs_p
->fulltime
= try;
3336 gs_p
->basictime
= reconstruct_basictime(gs_p
->fulltime
);
3337 totaltime
= rsub(totaltime
, try);
3338 if (GE(totaltime
, try)) {
3339 /* Total time is so long we can use
3340 * another one of this time value. */
3346 /* Trial time is too long. Try half as much. */
3347 try = rdiv(try, Two
);
3351 /* If still some time left, see if we can add one
3352 * or more dots to use up more time. */
3353 for (try = rdiv(try, Two
); GE(totaltime
, try);
3354 try = rdiv(try, Two
)) {
3356 gs_p
->fulltime
= radd(gs_p
->fulltime
,
3358 totaltime
= rsub(totaltime
, try);
3364 else { /* (No subtractions) */
3365 /* We will add a group for each added time value */
3366 for (gs_p
= grpsyl_p
; timelist_p
!= 0;
3367 timelist_p
= timelist_p
->next
) {
3368 /* Make a copy the GRPSYL. This function is to be called
3369 * with the group currently at the end of a list,
3370 * so the "list" being cloned is only a single group,
3371 * but might as well use the existing function... */
3372 gs_p
->next
= clone_gs_list(gs_p
, YES
);
3373 gs_p
->next
->prev
= gs_p
;
3375 /* Now fix up the time values in the cloned group */
3376 gs_p
->fulltime
= timelist_p
->fulltime
;
3377 gs_p
->basictime
= reconstruct_basictime(gs_p
->fulltime
);
3378 gs_p
->dots
= recalc_dots(gs_p
->fulltime
,
3380 /* If the original group started a beam,
3381 * added groups must be inside */
3382 if (gs_p
->beamloc
== STARTITEM
) {
3383 gs_p
->beamloc
= INITEM
;
3388 /* We need to tie the note groups together. Rests are not yet in
3389 * final form, so have to look for PP_REST. */
3390 if (grpsyl_p
->grpcont
== GC_NOTES
&& (grpsyl_p
->nnotes
!= 1
3391 || grpsyl_p
->notelist
[0].letter
!= PP_REST
)) {
3392 for (gs_p
= grpsyl_p
; gs_p
->next
!= 0; gs_p
= gs_p
->next
) {
3394 for (n
= 0; n
< gs_p
->nnotes
; n
++) {
3395 gs_p
->notelist
[n
].tie
= YES
;
3398 /* tied-to notes accidentals must be implied, not explicit */
3399 for (n
= 0; n
< grpsyl_p
->nnotes
; n
++) {
3400 if (grpsyl_p
->notelist
[n
].accidental
!= '\0') {
3401 struct GRPSYL
*ngs_p
;
3402 for (ngs_p
= grpsyl_p
->next
; ngs_p
!= 0;
3403 ngs_p
= ngs_p
->next
) {
3404 ngs_p
->notelist
[n
].accidental
= '\0';
3414 * Given a RATIONAL basictime and number of dots,
3415 * return the corresponding fulltime. That is calculated by
3416 * (2 * basictime) - (basictime x 1/2 to the (dots) power)
3420 calcfulltime(basictime
, dots
)
3426 return( rsub (rmul(Two
, basictime
), rmul(basictime
, rrai(One_half
, dots
))) );