[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
API for getting various kinds of grobs
From: |
Janek Warchoł |
Subject: |
API for getting various kinds of grobs |
Date: |
Mon, 11 Mar 2013 01:23:07 +0100 |
Hi,
since Mike is very busy i decided to post some of my questions to the list.
I'm working on simplifying self_alignment_interface - i hope to unify
different methods that are used now into one versatile and more
powerful method.
Currently virtually all grobs are aligned relative to their parents.
For example, let's consider LyricTexts:
{ c'' } \addlyrics { la }
If i do
\override LyricText #'self-alignment-X = #LEFT
it will result in "la" being left-aligned to its parent, namely the NoteHead.
What if i wanted to center the LyricText on the stem? Currently
there's no straightforward way to do this.
There are many grobs that might be used as references for aligning
other grobs, for example:
- respective NoteColumns,
- NoteHeads,
- Stems,
- StaffSymbol (for vertical alignment)
- (obviously) XYparents
- and probably more.
What i could do (but don't want to) is write truckloads of callbacks
similar to the ones that are already present in
self-alignment-interface.cc:
MAKE_SCHEME_CALLBACK (Self_alignment_interface, aligned_on_y_parent, 1);
SCM
Self_alignment_interface::aligned_on_y_parent (SCM smob)
{
return aligned_on_object (unsmob_grob (smob), unsmob_grob
(smob)->get_parent (Y_AXIS), Y_AXIS);
}
MAKE_SCHEME_CALLBACK (Self_alignment_interface, y_aligned_on_note_columns, 1);
SCM
Self_alignment_interface::y_aligned_on_note_columns (SCM smob)
{
return aligned_on_object (unsmob_grob (smob), unsmob_grob
(smob)->get_column (), Y_AXIS);
}
MAKE_SCHEME_CALLBACK (Self_alignment_interface, x_aligned_on_stem, 1);
SCM
Self_alignment_interface::x_aligned_on_stem (SCM smob)
{
return aligned_on_object (unsmob_grob (smob), unsmob_grob
(smob)->get_stem (), X_AXIS);
}
SCM
Self_alignment_interface::aligned_on_parent (Grob *me, Grob *him, Axis a)
{
(...)
}
and then use overrides like this to get grobs aligned on other grobs:
\override LyricText #'X-offset = #ly:self-alignment-interface::x_aligned_on_stem
But i don't like this approach.
What i would like: specify the reference grob in a property, for example
\override LyricText #'align-to = #'Stem
and then have one callback function that would be smart enough to find
appropriate grob to use and feed it to the method calculating
alignment. The callback would probably look like this:
MAKE_SCHEME_CALLBACK (Self_alignment_interface, x_aligned, 1)
SCM
Self_alignment_interface::x_aligned (SCM smob)
{
Grob *me = unsmob_grob (smob);
what_to_align_to = me->internal_get_property (ly_symbol2scm ("align-to"))
return general_alignment (me, me->get_grob (what_to_align_to), X_AXIS);
}
The magic lies in writing get_grob. I know that there is a function
called get_object, but i'll probably have to modify it.
What do you think about this? Is that feasible?
(is it at least clear what i want? :P)
best,
janek
- API for getting various kinds of grobs,
Janek Warchoł <=