From ce593af7561f08610bb21e0c9e00bfba2807fe25 Mon Sep 17 00:00:00 2001 From: Neil Puttock Date: Tue, 23 Nov 2010 22:12:46 +0000 Subject: [PATCH] Add ly:grob-array->list; use in live-elements-list for InstrumentName. * lily/grob-array-scheme.cc (ly_grob_array_2_list): new exported function * lily/grob-array.cc (grob_array_to_list): new function: convert Grob_array to Scheme list * scm/output-lib.scm (system-start-text::calc-y-offset): simplify live-elements-list using filter! and ly:grob-array->list --- lily/grob-array-scheme.cc | 10 ++++++++++ lily/grob-array.cc | 13 +++++++++++++ lily/include/grob-array.hh | 1 + scm/output-lib.scm | 16 ++++------------ 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lily/grob-array-scheme.cc b/lily/grob-array-scheme.cc index d99cb58a90..7518d2e2f5 100644 --- a/lily/grob-array-scheme.cc +++ b/lily/grob-array-scheme.cc @@ -49,3 +49,13 @@ LY_DEFINE (ly_grob_array_ref, "ly:grob-array-ref", return me->grob (i)->self_scm (); } +LY_DEFINE (ly_grob_array_2_list, "ly:grob-array->list", + 1, 0, 0, + (SCM grob_arr), + "Return the elements of @var{grob-arr} as a Scheme list.") +{ + Grob_array *me = unsmob_grob_array (grob_arr); + LY_ASSERT_SMOB (Grob_array, grob_arr, 1); + + return grob_array_to_list (me); +} diff --git a/lily/grob-array.cc b/lily/grob-array.cc index 1cebe0e458..4084e0fa75 100644 --- a/lily/grob-array.cc +++ b/lily/grob-array.cc @@ -129,3 +129,16 @@ grob_list_to_grob_array (SCM lst) return arr_scm; } +SCM +grob_array_to_list (Grob_array *array) +{ + SCM list = SCM_EOL; + SCM *tail = &list; + + for (vsize i = 0; i < array->size (); i++) + { + *tail = scm_cons (array->grob (i)->self_scm (), SCM_EOL); + tail = SCM_CDRLOC (*tail); + } + return list; +} diff --git a/lily/include/grob-array.hh b/lily/include/grob-array.hh index cb2d2f56c1..6e49dabb56 100644 --- a/lily/include/grob-array.hh +++ b/lily/include/grob-array.hh @@ -53,6 +53,7 @@ DECLARE_UNSMOB (Grob_array, grob_array); vector const &ly_scm2link_array (SCM x); SCM grob_list_to_grob_array (SCM lst); +SCM grob_array_to_list (Grob_array *array); #endif /* GROB_ARRAY_HH */ diff --git a/scm/output-lib.scm b/scm/output-lib.scm index 716f36a735..6c10913d38 100644 --- a/scm/output-lib.scm +++ b/scm/output-lib.scm @@ -859,18 +859,10 @@ between the two text elements." (define-public (system-start-text::calc-y-offset grob) (define (live-elements-list me) - (let* ((elements (ly:grob-object me 'elements)) - (elts-length (ly:grob-array-length elements)) - (live-elements '())) - - (let get-live ((len elts-length)) - (if (> len 0) - (let ((elt (ly:grob-array-ref elements (1- len)))) - - (if (grob::is-live? elt) - (set! live-elements (cons elt live-elements))) - (get-live (1- len))))) - live-elements)) + (let ((elements (ly:grob-object me 'elements))) + + (filter! grob::is-live? + (ly:grob-array->list elements)))) (let* ((left-bound (ly:spanner-bound grob LEFT)) (live-elts (live-elements-list grob)) -- 2.39.2