openlilylib / oll-core

Library Infrastructure for LilyPond add-ons
17 stars 13 forks source link

New Scheme modules (oll-core internal grob-tools) and ... music-tools #41

Closed uliska closed 5 years ago

uliska commented 6 years ago

This is intended to become a larger collection of tools to (simplify the) work with grobs, in engravers and callbacks.

uliska commented 5 years ago

Added functions in music-tools:

(associated with a Pull Request in lilpond-export:

jpvoigt commented 5 years ago

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.