From 2e77ecfa2052f244e0285ccaa5138690a3e1558c Mon Sep 17 00:00:00 2001 From: Nicolas Sceaux Date: Fri, 18 May 2007 16:16:48 +0200 Subject: [PATCH] Use book-(score|text|music)-handlers in book_body elements, after the fashion of the toplevel-(score|text|music)-handlers used for toplevel_expressions. Allow composite_music (and thus \pageBreak) in \book blocks. --- lily/book-scheme.cc | 9 +++++++++ lily/parser.yy | 15 +++++++++++---- ly/declarations-init.ly | 3 +++ scm/lily-library.scm | 23 ++++++++++++++++++----- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/lily/book-scheme.cc b/lily/book-scheme.cc index 7bb9ba0c6b..567504cf07 100644 --- a/lily/book-scheme.cc +++ b/lily/book-scheme.cc @@ -89,3 +89,12 @@ LY_DEFINE (ly_book_process_to_systems, "ly:book-process-to-systems", return SCM_UNSPECIFIED; } +LY_DEFINE (ly_book_add_score_x, "ly:book-add-score!", + 2, 0, 0, (SCM book_smob, SCM score), + "Add @var{score} to @var{book_smob} score list.") +{ + LY_ASSERT_SMOB (Book, book_smob, 1); + Book *book = unsmob_book (book_smob); + book->add_score (score); + return SCM_UNSPECIFIED; +} diff --git a/lily/parser.yy b/lily/parser.yy index 9df1034d16..9d209b9462 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -651,12 +651,19 @@ book_body: $2->unprotect (); } | book_body score_block { - SCM s = $2->self_scm (); - $$->add_score (s); - $2->unprotect(); + Score *score = $2; + SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler"); + scm_call_2 (proc, $$->self_scm (), score->self_scm ()); + score->unprotect (); + } + | book_body composite_music { + Music *music = unsmob_music ($2); + SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler"); + scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ()); } | book_body full_markup { - $$->add_score ($2); + SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler"); + scm_call_2 (proc, $$->self_scm (), $2); } | book_body lilypond_header { $$->header_ = $2; diff --git a/ly/declarations-init.ly b/ly/declarations-init.ly index 015e6dc754..364068c043 100644 --- a/ly/declarations-init.ly +++ b/ly/declarations-init.ly @@ -113,3 +113,6 @@ setDefaultDurationToQuarter = { c4 } #(define toplevel-score-handler collect-scores-for-book) #(define toplevel-text-handler collect-scores-for-book) +#(define book-music-handler collect-book-music-for-book) +#(define book-score-handler ly:book-add-score!) +#(define book-text-handler ly:book-add-score!) diff --git a/scm/lily-library.scm b/scm/lily-library.scm index 2758825016..7a1141d8f4 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -63,7 +63,7 @@ parser 'toplevel-scores (cons score (ly:parser-lookup parser 'toplevel-scores)))) -(define-public (collect-music-for-book parser music) +(define (collect-music-aux score-handler parser music) (define (music-property symbol) (let ((value (ly:music-property music symbol))) (if (not (null? value)) @@ -74,18 +74,31 @@ (for-each (lambda (symbol) (let ((permission (music-property symbol))) (if (symbol? permission) - (collect-scores-for-book - parser + (score-handler (ly:make-page-marker symbol (if (eqv? 'forbid permission) '() permission)))))) (list 'line-break-permission 'page-break-permission - 'page-turn-permission))) + 'page-turn-permission))) ((not (music-property 'void)) ;; a regular music expression: make a score with this music ;; void music is discarded - (collect-scores-for-book parser (scorify-music music parser))))) + (score-handler (scorify-music music parser))))) + +(define-public (collect-music-for-book parser music) + "Top-level music handler" + (collect-music-aux (lambda (score) + (collect-scores-for-book parser score)) + parser + music)) + +(define-public (collect-book-music-for-book parser book music) + "Book music handler" + (collect-music-aux (lambda (score) + (ly:book-add-score! book score)) + parser + music)) (define-public (scorify-music music parser) "Preprocess MUSIC." -- 2.39.5