Closed uliska closed 5 years ago
Added functions in music-tools
:
music-name
music-is?
(associated with a Pull Request in lilpond-export:
Am 05.11.18 um 15:40 schrieb Urs Liska:
@uliska commented on this pull request.
In scheme/oll-core/internal/grob-tools.scm https://github.com/openlilylib/oll-core/pull/41#discussion_r230772892:
+(use-modules (lily)) + +(define-public (grob-name grob)
- "Returns the name/type of a grob."
- (assq-ref (ly:grob-property grob 'meta) 'name))
+(define-public (filter-grobs-by-name name grob-list)
- "Filters a list of grobs by a grob name/type"
- (filter
- (lambda (grob)
- (eq? (grob-name grob) name))
- grob-list))
+(define-public (stem-direction grob)
- "Returns the stem-direction in the current note-column,
- assuming there's a single Stem present in any column
One question: Is this a safe assumption? In fact this is only based on some tests, but I have no idea if a) a grob's "X" grob-parent is always the NoteColumn (at least for any grob where one might want to check for a stem direction) and b) if it is ensured that a NoteColumn has exactly one Stem objet. a) I don't know if it is save to assume NoteColumn the direct parent. The NoteColumn might be searched with a recursive function upwards. If it is not found return #f - this is already happening. b) I assume that a NoteColumn has no more than one Stem-object, but I can say for sure.
If either no NoteColumn is found or it has n!=1 Stem-objects the function will fail. So failures should be catched gracefully in those cases, but a comment should be enough for now so that one has a chance to find the needle if an error occurs.
This is intended to become a larger collection of tools to (simplify the) work with grobs, in engravers and callbacks.
grob-name
is just a convenience function for a regularly used patternfilter-grobs-by-name
can for example be used to find elements in a current grob's parent NoteColumn (I used it to find a TextScript attached to a Slur's beginning)stem-direction
can be used to to determine the actual direction of a note, to force a grob to the stem or the notehead side.