From 26bb48ca73e9b8f4c0aeca0427eff8b7520b0731 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Wed, 9 Mar 2005 00:54:31 +0000 Subject: [PATCH] * lily/book.cc: * lily/paper-book.cc: Fold hearders, score and texts into scores_. * lily/parser.yy: Handle toplevel and book texts as score. * scm/page-layout.scm (default-page-make-stencil): Bugfix: (page-properties rename. --- ChangeLog | 12 ++++ input/regression/score-text.ly | 5 +- lily/book-scheme.cc | 11 +--- lily/book.cc | 76 +++++++++++------------- lily/include/accidental-interface.hh | 15 +++-- lily/include/book.hh | 9 +-- lily/include/music.hh | 1 - lily/include/paper-book.hh | 26 +++------ lily/include/score.hh | 12 ++-- lily/lily-parser-scheme.cc | 7 +-- lily/paper-book.cc | 86 ++++++++++++---------------- lily/parser.yy | 36 ++++-------- lily/score-scheme.cc | 11 +--- lily/score.cc | 15 ++--- ly/declarations-init.ly | 1 + ly/init.ly | 2 +- scm/lily-library.scm | 5 +- scm/page-layout.scm | 2 +- scripts/lilypond-book.py | 4 +- 19 files changed, 146 insertions(+), 190 deletions(-) diff --git a/ChangeLog b/ChangeLog index 01967b3883..96300d92fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2005-03-09 Jan Nieuwenhuizen + + * lily/book.cc: + * lily/paper-book.cc: Fold hearders, score and texts into scores_. + + * lily/parser.yy: Handle toplevel and book texts as score. + + * scm/page-layout.scm (default-page-make-stencil): + Bugfix: (page-properties rename. + + * scm/backend-library.scm (ly:system): Typo. + 2005-03-09 Han-Wen Nienhuys * lily/font-select.cc (get_font_by_design_size): revert diff --git a/input/regression/score-text.ly b/input/regression/score-text.ly index a86f06ef18..2cf43d5621 100644 --- a/input/regression/score-text.ly +++ b/input/regression/score-text.ly @@ -2,13 +2,16 @@ \header { - texidoc = "Markup texts are set beneath a score." + texidoc = "Markup texts are rendered above or below a score." } \paper { linewidth = #110 } +\markup { + \fill-line { "High up above" } +} << \relative { \clef bass diff --git a/lily/book-scheme.cc b/lily/book-scheme.cc index 32bcb0e158..058be63a9e 100644 --- a/lily/book-scheme.cc +++ b/lily/book-scheme.cc @@ -25,14 +25,9 @@ LY_DEFINE(ly_make_book, "ly:make-book", if (ly_c_module_p (header)) book->header_ = header; - - for (SCM s = scores; scm_is_pair (s); s = scm_cdr (s)) - { - Score *score = unsmob_score (scm_car (s)); - if (score) - book->scores_.push (score); - } - + + book->scores_ = scm_append (scm_list_2 (scores, book->scores_)); + SCM x = book->self_scm (); scm_gc_unprotect_object (x); return x; diff --git a/lily/book.cc b/lily/book.cc index d15233f70c..0ba3fdf7f8 100644 --- a/lily/book.cc +++ b/lily/book.cc @@ -6,10 +6,10 @@ (c) 1997--2005 Han-Wen Nienhuys */ +#include "book.hh" #include -#include "book.hh" #include "lilypond-key.hh" #include "global-context.hh" #include "main.hh" @@ -20,6 +20,7 @@ #include "paper-book.hh" #include "score.hh" #include "stencil.hh" +#include "text-item.hh" #include "warn.hh" #include "ly-smobs.icc" @@ -29,7 +30,7 @@ Book::Book () { paper_ = 0; header_ = SCM_EOL; - assert (!scores_.size ()); + scores_ = SCM_EOL; smobify_self (); } @@ -44,16 +45,16 @@ SCM Book::mark_smob (SCM s) { Book *book = (Book*) SCM_CELL_WORD_1 (s); - int score_count = book->scores_.size (); - for (int i = 0; i < score_count; i++) - scm_gc_mark (book->scores_[i]->self_scm ()); #if 0 if (book->key_) scm_gc_mark (book->key_->self_scm()); #endif + if (book->paper_) scm_gc_mark (book->paper_->self_scm ()); + scm_gc_mark (book->scores_); + return book->header_; } @@ -64,23 +65,26 @@ Book::print_smob (SCM, SCM p, scm_print_state*) return 1; } +void +Book::add_score (SCM s) +{ + scores_ = scm_cons (s, scores_); +} + /* This function does not dump the output; outname is required eg. for dumping header fields. */ Paper_book * Book::process (String outname, Output_def *default_def) { - bool error = false; - for (int i = 0; i < scores_.size(); i++) - error = error || scores_[i]->error_found_; - - if (error) - return 0; + for (SCM s = scores_; s != SCM_EOL; s = scm_cdr (s)) + if (Score *score = unsmob_score (scm_car (s))) + if (score->error_found_) + return 0; Paper_book *paper_book = new Paper_book (); Real scale = scm_to_double (paper_->c_variable ("outputscale")); Output_def * scaled_bookdef = scale_output_def (paper_, scale); - Object_key * key = new Lilypond_general_key (0, user_key_, 0); SCM scm_key = key->self_scm(); scm_gc_unprotect_object (scm_key); @@ -89,40 +93,30 @@ Book::process (String outname, Output_def *default_def) scm_gc_unprotect_object (scaled_bookdef->self_scm()); paper_book->header_ = header_; - int score_count = scores_.size (); - for (int i = 0; i < score_count; i++) + + /* Render in order of parsing. */ + for (SCM s = scm_reverse (scores_); s != SCM_EOL; s = scm_cdr (s)) { - SCM systems = scores_[i]->book_rendering (outname, - paper_book->paper_, - default_def, - key - ); - - /* - If the score is empty, generate no output. Should we - do titling? - */ - if (SCM_NFALSEP(scm_vector_p (systems))) + if (Score *score = unsmob_score (scm_car (s))) { - Score_systems sc; - sc.systems_ = systems; - sc.header_ = scores_[i]->header_; - sc.texts_ = scores_[i]->texts_; - paper_book->score_systems_.push (sc); + SCM systems = score + ->book_rendering (outname, paper_book->paper_, default_def, key); + + /* If the score is empty, generate no output. Should we do + titling? */ + if (scm_is_vector (systems)) + { + if (ly_c_module_p (header_)) + paper_book->add_score (header_); + paper_book->add_score (systems); + } } + else if (Text_interface::markup_p (scm_car (s))) + paper_book->add_score (scm_car (s)); + else + assert (0); } - scm_remember_upto_here_1 (scm_key); return paper_book; } - - - - -void -Book::add_score (Score *s) -{ - scores_.push (s); - scm_gc_unprotect_object (s->self_scm ()); -} diff --git a/lily/include/accidental-interface.hh b/lily/include/accidental-interface.hh index 236e177078..2b8aabfc12 100644 --- a/lily/include/accidental-interface.hh +++ b/lily/include/accidental-interface.hh @@ -1,11 +1,10 @@ -/* -accidental-interface.hh -- declare Accidental_interface - -source file of the GNU LilyPond music typesetter - -(c) 2002--2005 Han-Wen Nienhuys - - */ +/* + accidental-interface.hh -- declare Accidental_interface + + source file of the GNU LilyPond music typesetter + + (c) 2002--2005 Han-Wen Nienhuys +*/ #ifndef ACCIDENTAL_INTERFACE_HH #define ACCIDENTAL_INTERFACE_HH diff --git a/lily/include/book.hh b/lily/include/book.hh index 2be317d12f..0d4fa66147 100644 --- a/lily/include/book.hh +++ b/lily/include/book.hh @@ -18,18 +18,19 @@ class Book : public Input { DECLARE_SMOBS (Book, foo); + public: String user_key_; - SCM header_; Output_def *paper_; + SCM scores_; - void add_score (Score*); - Link_array scores_; Book (); - void set_keys (); + void add_score (SCM); Paper_book* process (String, Output_def*); + void set_keys (); }; + DECLARE_UNSMOB (Book, book); #endif /* BOOK_HH */ diff --git a/lily/include/music.hh b/lily/include/music.hh index 6a0794092f..973b65ac87 100644 --- a/lily/include/music.hh +++ b/lily/include/music.hh @@ -61,6 +61,5 @@ DECLARE_UNSMOB(Music, music); Music *make_music_by_name (SCM sym); SCM ly_music_deep_copy (SCM); -SCM ly_music_scorify (SCM, SCM, SCM); #endif /* MUSIC_HH */ diff --git a/lily/include/paper-book.hh b/lily/include/paper-book.hh index 4ee2911cee..a95ed8e3f6 100644 --- a/lily/include/paper-book.hh +++ b/lily/include/paper-book.hh @@ -15,40 +15,29 @@ class Output_def; class Stencil; -struct Score_systems -{ - SCM systems_; - SCM header_; - SCM texts_; +/** Paper_book collects headers, systems (Paper_system) and texts, and + exports them to the output backend, either as systems or as + completely formatted pages. */ - Score_systems () ; - void gc_mark (); -}; - -/* - -This class is rather empty. It collects systems (Paper_system), and -exports them to the output backend, either as systems or as completely -formatted pages. - -*/ class Paper_book { DECLARE_SMOBS (Paper_book, ); SCM systems_; SCM pages_; + public: SCM header_; - Array score_systems_; + SCM scores_; Output_def *paper_; Paper_book (); + void add_score (SCM); SCM systems (); SCM pages (); Stencil book_title (); - Stencil score_title (int); + Stencil score_title (SCM); void classic_output (String); void output (String); void post_processing (SCM, SCM); @@ -57,4 +46,3 @@ public: DECLARE_UNSMOB (Paper_book, paper_book) #endif /* PAPER_BOOK_HH */ - diff --git a/lily/include/score.hh b/lily/include/score.hh index fac59eee38..bb879e9841 100644 --- a/lily/include/score.hh +++ b/lily/include/score.hh @@ -22,6 +22,7 @@ class Score : public Input DECLARE_SMOBS (Score, foo); SCM music_; + public: String user_key_; Link_array defs_; @@ -29,18 +30,19 @@ public: SCM texts_; bool error_found_; - SCM get_music () const; - void set_music (SCM music, SCM parser); Score (); Score (Score const&); - + + SCM get_music () const; + void set_music (SCM music, SCM parser); SCM book_rendering (String, Output_def*, Output_def*, Object_key*); }; DECLARE_UNSMOB (Score, score); -SCM ly_run_translator (SCM, SCM, SCM); +void default_rendering (SCM, SCM, SCM, SCM, SCM, SCM); +SCM ly_music_scorify (SCM, SCM); SCM ly_render_output (SCM, SCM); -void default_rendering (SCM, SCM, SCM, SCM, SCM, SCM, SCM); +SCM ly_run_translator (SCM, SCM, SCM); #endif /* SCORE_HH */ diff --git a/lily/lily-parser-scheme.cc b/lily/lily-parser-scheme.cc index 1e10b870c3..69c90478b1 100644 --- a/lily/lily-parser-scheme.cc +++ b/lily/lily-parser-scheme.cc @@ -26,6 +26,7 @@ LY_DEFINE (ly_set_point_and_click, "ly:set-point-and-click", 1, 0, 0, (SCM what), "Deprecated.") { + (void) what; warning ("ly:set-point-and-click called"); return SCM_UNSPECIFIED; } @@ -205,16 +206,14 @@ LY_DEFINE (ly_parser_print_score, "ly:parser-print-score", SCM paper = get_paper (parser)->self_scm (); for (int i = 0; i < score->defs_.size (); i++) default_rendering (score->get_music (), score->defs_[i]->self_scm (), - paper, header, score->texts_, - os, key->self_scm ()); + paper, header, os, key->self_scm ()); if (score->defs_.is_empty ()) { Output_def *layout = get_layout (parser); default_rendering (score->get_music(), layout->self_scm (), get_paper (parser)->self_scm (), - header, score->texts_, - os, key->self_scm ()); + header, os, key->self_scm ()); scm_gc_unprotect_object (layout->self_scm ()); } diff --git a/lily/paper-book.cc b/lily/paper-book.cc index b9e94803db..d3a7e8512f 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -19,9 +19,10 @@ Paper_book::Paper_book () { + header_ = SCM_EOL; pages_ = SCM_BOOL_F; + scores_ = SCM_EOL; systems_ = SCM_BOOL_F; - header_ = SCM_EOL; paper_ = 0; smobify_self (); @@ -39,13 +40,11 @@ SCM Paper_book::mark_smob (SCM smob) { Paper_book *b = (Paper_book*) SCM_CELL_WORD_1 (smob); - for (int i = 0; i < b->score_systems_.size (); i++) - b->score_systems_[i].gc_mark (); - if (b->paper_) scm_gc_mark (b->paper_->self_scm ()); scm_gc_mark (b->header_); scm_gc_mark (b->pages_); + scm_gc_mark (b->scores_); return b->systems_; } @@ -72,10 +71,16 @@ dump_fields () return fields; } +void +Paper_book::add_score (SCM s) +{ + scores_ = scm_cons (s, scores_); +} + void Paper_book::output (String outname) { - if (!score_systems_.size ()) + if (scores_ == SCM_EOL) return; /* Generate all stencils to trigger font loads. */ @@ -124,8 +129,10 @@ Paper_book::classic_output (String outname) if (ly_c_module_p (header_)) scopes = scm_cons (header_, scopes); - if (ly_c_module_p (score_systems_[0].header_)) - scopes = scm_cons (score_systems_[0].header_, scopes); +#if 0 + if (ly_c_module_p (scores_[0].header_)) + scopes = scm_cons (scores_[0].header_, scopes); +#endif //end ugh String format = output_backend_global; @@ -174,20 +181,18 @@ Paper_book::book_title () } Stencil -Paper_book::score_title (int i) +Paper_book::score_title (SCM header) { SCM title_func = paper_->lookup_variable (ly_symbol2scm ("score-title")); Stencil title; - // ugh code dup SCM scopes = SCM_EOL; if (ly_c_module_p (header_)) scopes = scm_cons (header_, scopes); - if (ly_c_module_p (score_systems_[i].header_)) - scopes = scm_cons (score_systems_[i].header_, scopes); - //end ugh + if (ly_c_module_p (header)) + scopes = scm_cons (header, scopes); SCM tit = SCM_EOL; if (ly_c_procedure_p (title_func)) @@ -242,30 +247,28 @@ Paper_book::systems () = scm_call_1 (ly_lily_module_constant ("layout-extract-page-properties"), paper_->self_scm ()); - int score_count = score_systems_.size (); - for (int i = 0; i < score_count; i++) + SCM header = SCM_EOL; + for (SCM s = scm_reverse (scores_); s != SCM_EOL; s = scm_cdr (s)) { - Stencil title = score_title (i); - if (!title.is_empty ()) + if (ly_c_module_p (scm_car (s))) + header = scm_car (s); + else if (scm_is_vector (scm_car (s))) { - Paper_system *ps = new Paper_system (title, true); - systems_ = scm_cons (ps->self_scm (), systems_); - scm_gc_unprotect_object (ps->self_scm ()); - - set_system_penalty (ps, score_systems_[i].header_); - - } + Stencil title = score_title (header); + if (!title.is_empty ()) + { + Paper_system *ps = new Paper_system (title, true); + systems_ = scm_cons (ps->self_scm (), systems_); + scm_gc_unprotect_object (ps->self_scm ()); + set_system_penalty (ps, header); + } + header = SCM_EOL; - if (scm_vector_p (score_systems_[i].systems_) == SCM_BOOL_T) - { - // guh. - SCM system_list = scm_vector_to_list (score_systems_[i].systems_); - + SCM system_list = scm_vector_to_list (scm_car (s)); system_list = scm_reverse (system_list); systems_ = scm_append (scm_list_2 (system_list, systems_)); } - - for (SCM s = score_systems_[i].texts_; s != SCM_EOL; s = scm_cdr (s)) + else if (Text_interface::markup_p (scm_car (s))) { SCM t = Text_interface::interpret_markup (paper_->self_scm (), page_properties, @@ -275,8 +278,10 @@ Paper_book::systems () systems_ = scm_cons (ps->self_scm (), systems_); scm_gc_unprotect_object (ps->self_scm ()); // FIXME: figure out penalty. - //set_system_penalty (ps, score_systems_[i].header_); + //set_system_penalty (ps, scores_[i].header_); } + else + assert (0); } systems_ = scm_reverse (systems_); @@ -309,22 +314,3 @@ Paper_book::pages () pages_ = scm_apply_0 (proc, scm_list_2 (systems (), self_scm ())); return pages_; } - - -/****************************************************************/ - -Score_systems::Score_systems () -{ - systems_ = SCM_EOL; - header_ = SCM_EOL; - texts_ = SCM_EOL; -} - -void -Score_systems::gc_mark () -{ - scm_gc_mark (systems_); - scm_gc_mark (header_); - scm_gc_mark (texts_); -} - diff --git a/lily/parser.yy b/lily/parser.yy index fe8dbee582..064323bcf5 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -436,7 +436,6 @@ or %type Alternative_music %type full_markup lyric_markup %type markup_list markup_composed_list markup_braced_list markup_braced_list_body -%type optional_text %type markup_head_1_item markup_head_1_list markup simple_markup markup_top %type mode_changing_head %type mode_changing_head_with_context @@ -492,12 +491,16 @@ toplevel_expression: scm_call_2 (proc, THIS->self_scm (), score->self_scm ()); scm_gc_unprotect_object (score->self_scm ()); } - | toplevel_music optional_text { + | toplevel_music { Music *music = $1; SCM proc = THIS->lexer_->lookup_identifier ("toplevel-music-handler"); - scm_call_3 (proc, THIS->self_scm (), music->self_scm (), $2); + scm_call_2 (proc, THIS->self_scm (), music->self_scm ()); scm_gc_unprotect_object (music->self_scm ()); } + | full_markup { + SCM proc = THIS->lexer_->lookup_identifier ("toplevel-text-handler"); + scm_call_2 (proc, THIS->self_scm (), $1); + } | output_def { SCM id = SCM_EOL; Output_def * od = $1; @@ -541,15 +544,6 @@ lilypond_header: } ; -optional_text: - /* empty */ { - $$ = SCM_EOL - } - | optional_text full_markup { - $$ = ly_snoc ($2, $1); - } - ; - /* DECLARATIONS */ @@ -671,25 +665,17 @@ book_body: $$->paper_ = $2; scm_gc_unprotect_object ($2->self_scm ()); } - | book_body score_block optional_text { - Score *score = $2; - score->texts_ = $3; - $$->add_score (score); - } - /* let's do optional - | book_body full_markup { - if (!$$->scores_.size ()) - THIS->parser_error (@2, _("\\markup cannot be used before \\score.")); - Score *score = $$->scores_.top (); - score->texts_ = ly_snoc ($2, score->texts_); + | book_body score_block { + SCM s = $2->self_scm (); + $$->add_score (s); + scm_gc_unprotect_object (s); } - */ | book_body lilypond_header { $$->header_ = $2; } | book_body error { $$->paper_ = 0; - $$->scores_.clear(); + $$->scores_ = SCM_EOL; } | book_body object_id_setting { $$->user_key_ = ly_scm2string ($2); diff --git a/lily/score-scheme.cc b/lily/score-scheme.cc index 7da2b20b46..d8470132c1 100644 --- a/lily/score-scheme.cc +++ b/lily/score-scheme.cc @@ -14,18 +14,15 @@ #include "global-context.hh" LY_DEFINE (ly_music_scorify, "ly:music-scorify", - 3, 0, 0, - (SCM music, SCM texts, SCM parser), + 2, 0, 0, + (SCM music, SCM parser), "Return MUSIC with TEXTS encapsulated in SCORE.") { #if 0 SCM_ASSERT_TYPE (ly_c_music_p (music), music, SCM_ARG1, __FUNCTION__, "music"); #endif Score *score = new Score; - score->set_music (music, parser); - score->texts_ = texts; - scm_gc_unprotect_object (score->self_scm ()); return score->self_scm (); } @@ -42,9 +39,7 @@ LY_DEFINE (ly_score_embedded_format, "ly:score-embedded-format", Output_def *od = unsmob_output_def (layout); if (sc->error_found_) - { - return SCM_EOL; - } + return SCM_EOL; SCM_ASSERT_TYPE (sc, score, SCM_ARG1, __FUNCTION__, "Score"); SCM_ASSERT_TYPE (od, layout, SCM_ARG2, __FUNCTION__, "Output_def"); diff --git a/lily/score.cc b/lily/score.cc index e072eaaaf1..f8747dd660 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -91,7 +91,7 @@ Score::Score (Score const &s) void default_rendering (SCM music, SCM outdef, SCM book_outputdef, - SCM header, SCM texts, + SCM header, SCM outname, SCM key) { @@ -128,14 +128,11 @@ default_rendering (SCM music, SCM outdef, Paper_book *paper_book = new Paper_book (); paper_book->header_ = header; paper_book->paper_ = unsmob_output_def (scaled_bookdef); - - Score_systems sc; - sc.systems_ = systems; - sc.header_ = header; - sc.texts_ = texts; - - paper_book->score_systems_.push (sc); - + + if (ly_c_module_p (header)) + paper_book->add_score (header); + paper_book->add_score (systems); + paper_book->classic_output (ly_scm2string (outname)); scm_gc_unprotect_object (paper_book->self_scm ()); } diff --git a/ly/declarations-init.ly b/ly/declarations-init.ly index 052bd6edb0..eecf711186 100644 --- a/ly/declarations-init.ly +++ b/ly/declarations-init.ly @@ -116,3 +116,4 @@ setDefaultDurationToQuarter = { c4 } #(define toplevel-book-handler ly:parser-print-book) #(define toplevel-music-handler collect-music-for-book) #(define toplevel-score-handler collect-scores-for-book) +#(define toplevel-text-handler collect-scores-for-book) diff --git a/ly/init.ly b/ly/init.ly index 5e3305072a..3e36bd347b 100644 --- a/ly/init.ly +++ b/ly/init.ly @@ -33,5 +33,5 @@ #(if (pair? toplevel-scores) (ly:parser-print-book parser - (apply ly:make-book $defaultpaper $globalheader (reverse toplevel-scores)))) + (apply ly:make-book $defaultpaper $globalheader toplevel-scores))) diff --git a/scm/lily-library.scm b/scm/lily-library.scm index 786545cfad..18fb45ff5c 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -65,9 +65,8 @@ parser 'toplevel-scores (cons score (ly:parser-lookup parser 'toplevel-scores)))) -(define-public (collect-music-for-book parser music texts) - (collect-scores-for-book parser (ly:music-scorify music texts parser))) - +(define-public (collect-music-for-book parser music) + (collect-scores-for-book parser (ly:music-scorify music parser))) ;;;;;;;;;;;;;;;; diff --git a/scm/page-layout.scm b/scm/page-layout.scm index c2f554bb84..fb32fb6eeb 100644 --- a/scm/page-layout.scm +++ b/scm/page-layout.scm @@ -87,7 +87,7 @@ create offsets. (system-separator-markup (ly:output-def-lookup layout 'systemSeparatorMarkup)) (system-separator-stencil (if (markup? system-separator-markup) (interpret-markup layout - (page-properties layout) + (layout-extract-page-properties layout) system-separator-markup) #f)) (lmargin (ly:output-def-lookup layout 'leftmargin)) diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 495577ead1..559a08012e 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -532,9 +532,9 @@ PREAMBLE_LY = r'''%%%% Generated by %(program_name)s %%%% Options: [%(option_string)s] #(set! toplevel-score-handler ly:parser-print-score) -#(set! toplevel-music-handler (lambda (p m t) +#(set! toplevel-music-handler (lambda (p m) (ly:parser-print-score - p (ly:music-scorify m t p)))) + p (ly:music-scorify m p)))) #(define version-seen? #t) %(preamble_string)s -- 2.39.2