1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
/* contexts.c
* Context finders: functions that find the current clef, key, and time
* signature contexts for the measures being displayed
*
* These functions are also invoked when a staff is created
*
*
* for Denemo, a gtk+ frontend to GNU Lilypond
* (c) 1999, 2000, 2001 Matthew Hiller
*/
#include "datastructures.h"
#include "drawingprims.h"
#include "objops.h"
#include "staffops.h"
/* This function finds the first mudelaobject of type thetype before measure
* curmeasure. It returns NULL if it was unable to find such a mudelaobject */
static mudelaobject *
find_context (measurenode * curmeasure, gint thetype)
{
objnode *curobj;
curmeasure = curmeasure->prev;
if (!curmeasure)
return NULL;
curobj = lastobjnode (curmeasure);
while (1)
{
while (!curobj)
{ /* Cycle back to preceding measure */
if (!curmeasure->prev)
return NULL; /* That is, we've fallen off the beginnig */
curmeasure = curmeasure->prev;
curobj = lastobjnode (curmeasure);
}
if (((mudelaobject *) curobj->data)->type == thetype)
return curobj->data;
else
curobj = curobj->prev;
}
}
void
find_leftmost_staffcontext (staff * curstaffstruct, struct scoreinfo *si)
{
measurenode *leftmeasure = g_list_nth (curstaffstruct->measures,
si->leftmeasurenum - 1);
mudelaobject *obj;
if (obj = find_context (leftmeasure, CLEF))
curstaffstruct->leftmost_clefcontext = obj->u.clefval.type;
else
curstaffstruct->leftmost_clefcontext = curstaffstruct->sclef;
if (obj = find_context (leftmeasure, KEYSIG))
curstaffstruct->leftmost_keysigcontext = obj->u.keyval.number;
else
curstaffstruct->leftmost_keysigcontext = curstaffstruct->skey;
initkeyaccs (curstaffstruct->leftmost_keyaccs,
curstaffstruct->leftmost_keysigcontext);
curstaffstruct->leftmost_keywidth =
draw_key (NULL, NULL, 0, 0, curstaffstruct->leftmost_keysigcontext,
0, 0, FALSE);
if (obj = find_context (leftmeasure, TIMESIG))
{
curstaffstruct->leftmost_time1context = obj->u.timeval.time1;
curstaffstruct->leftmost_time2context = obj->u.timeval.time2;
}
else
{
curstaffstruct->leftmost_time1context = curstaffstruct->stime1;
curstaffstruct->leftmost_time2context = curstaffstruct->stime2;
}
if (obj = find_context (leftmeasure, STEMDIRECTIVE))
curstaffstruct->leftmost_stem_directive = obj->u.stemval.type;
else
curstaffstruct->leftmost_stem_directive = STEMBOTH;
}
void
find_leftmost_allcontexts (struct scoreinfo *si)
{
staffnode *curstaff = si->thescore;
si->maxkeywidth = G_MININT;
for (; curstaff; curstaff = curstaff->next)
{
find_leftmost_staffcontext (curstaff->data, si);
si->maxkeywidth = MAX (si->maxkeywidth,
((staff *) curstaff->data)->leftmost_keywidth);
}
}
|