From 084f3d97cdb0dde6d31d09f291a7f46423d15ce8 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sat, 29 May 2004 10:38:53 +0000 Subject: [PATCH] * lily/book.cc (process): return Paper_book (to_stencil): use Book::process(). * lily/include/my-lily-parser.hh (class My_lily_parser): remove header_ field. Store in $globalheader * lily/parser.yy (book_body): book header is initted to $globalheader. --- ChangeLog | 14 ++++++++++ lily/book.cc | 51 +++++++++++----------------------- lily/include/book.hh | 4 +-- lily/include/my-lily-lexer.hh | 1 + lily/include/my-lily-parser.hh | 3 +- lily/include/paper-book.hh | 2 +- lily/my-lily-lexer.cc | 9 ++++-- lily/my-lily-parser.cc | 22 +++++++-------- lily/paper-book.cc | 20 ++++++------- lily/parser.yy | 8 ++++-- lily/score.cc | 11 ++++++-- scm/lily.scm | 3 +- 12 files changed, 77 insertions(+), 71 deletions(-) diff --git a/ChangeLog b/ChangeLog index 440a0742ce..9bddbebc1f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ +2004-05-29 Han-Wen Nienhuys + + * lily/book.cc (process): return Paper_book + (to_stencil): use Book::process(). + + * lily/include/my-lily-parser.hh (class My_lily_parser): remove + header_ field. Store in $globalheader + + * lily/parser.yy (book_body): book header is initted to + $globalheader. + + 2004-05-28 Han-Wen Nienhuys + * input/test/fill-a4.ly: removed. + * lily/parser.yy (output_def): push scope of parent_ Output_def too. diff --git a/lily/book.cc b/lily/book.cc index 50fee8f48e..267b5a6fac 100644 --- a/lily/book.cc +++ b/lily/book.cc @@ -61,17 +61,24 @@ Book::print_smob (SCM, SCM p, scm_print_state*) return 1; } -void -Book::process (String outname, Output_def *default_def, SCM header) +/* + 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) { Paper_book *paper_book = new Paper_book (); - Real scale = ly_scm2double (bookpaper_->c_variable ("outputscale")); Output_def * scaled_bookdef = scale_output_def (bookpaper_, scale); paper_book->bookpaper_ = scaled_bookdef; + 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++) { @@ -82,50 +89,24 @@ Book::process (String outname, Output_def *default_def, SCM header) { Score_lines sc; sc.lines_ = systems; - sc.header_ = header; + sc.header_ = header_; paper_book->score_lines_.push (sc); } } - paper_book->output (outname); - - scm_gc_unprotect_object (paper_book->bookpaper_->self_scm ()); - scm_gc_unprotect_object (paper_book->self_scm ()); + return paper_book; } /* FIXME: WIP, this is a hack. Return first page as stencil. */ SCM -Book::to_stencil (Output_def *default_def, SCM header) +Book::to_stencil (Output_def *default_def) { - Paper_book *paper_book = new Paper_book (); - Real scale = ly_scm2double (bookpaper_->c_variable ("outputscale")); - - Output_def * scaled_bookdef = scale_output_def (bookpaper_, scale); - - paper_book->bookpaper_ = scaled_bookdef; - - int score_count = scores_.size (); - for (int i = 0; i < score_count; i++) - { - SCM systems = scores_[i]->book_rendering ("", - bookpaper_, - default_def); - - if (systems != SCM_UNDEFINED) - { - Score_lines sc; - sc.lines_ = systems; - sc.header_ =header; - - paper_book->score_lines_.push (sc); - - // wtf: code dup. - } - } + Paper_book *paper_book = process ("", default_def); SCM pages = paper_book->pages (); - paper_book = 0; + scm_gc_unprotect_object (paper_book->self_scm ()); + if (pages != SCM_EOL) { progress_indication (_f ("paper output to `%s'...", "")); diff --git a/lily/include/book.hh b/lily/include/book.hh index f3255ed8f6..899fbb4d9d 100644 --- a/lily/include/book.hh +++ b/lily/include/book.hh @@ -25,8 +25,8 @@ public: Link_array scores_; Book (); - void process (String outname, Output_def*, SCM header); - SCM to_stencil (Output_def*, SCM header); + Paper_book* process (String, Output_def*); + SCM to_stencil (Output_def*); }; DECLARE_UNSMOB (Book, book); diff --git a/lily/include/my-lily-lexer.hh b/lily/include/my-lily-lexer.hh index 44f3966fc0..bdc95f7465 100644 --- a/lily/include/my-lily-lexer.hh +++ b/lily/include/my-lily-lexer.hh @@ -69,6 +69,7 @@ public: void start_main_input (); SCM lookup_identifier (String s); + SCM lookup_identifier_symbol (SCM s); void push_chord_state (SCM tab); void push_figuredbass_state (); void push_lyric_state (); diff --git a/lily/include/my-lily-parser.hh b/lily/include/my-lily-parser.hh index 1d98879da9..7c7c92aafc 100644 --- a/lily/include/my-lily-parser.hh +++ b/lily/include/my-lily-parser.hh @@ -14,7 +14,6 @@ #include "input.hh" #include "parray.hh" #include "pitch.hh" -#include "protected-scm.hh" #include "smobs.hh" #include "string.hh" @@ -44,7 +43,7 @@ public: Sources *sources_; Duration default_duration_; String output_basename_; - Protected_scm header_; + // Protected_scm header_; int score_count_; int book_count_; int fatal_error_; diff --git a/lily/include/paper-book.hh b/lily/include/paper-book.hh index 4733dc2ef4..7975a5aa9a 100644 --- a/lily/include/paper-book.hh +++ b/lily/include/paper-book.hh @@ -29,8 +29,8 @@ class Paper_book Real height_; SCM copyright_; SCM tagline_; - SCM global_header_; public: + SCM header_; Array score_lines_; Output_def *bookpaper_; diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index 8d9fcb93de..68300b00f7 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -149,9 +149,8 @@ My_lily_lexer::lookup_keyword (String s) } SCM -My_lily_lexer::lookup_identifier (String name) +My_lily_lexer::lookup_identifier_symbol (SCM sym) { - SCM sym = ly_symbol2scm (name.to_str0 ()); for (SCM s = scopes_; ly_c_pair_p (s); s = ly_cdr (s)) { SCM var = ly_module_lookup (ly_car (s), sym); @@ -162,6 +161,12 @@ My_lily_lexer::lookup_identifier (String name) return SCM_UNDEFINED; } +SCM +My_lily_lexer::lookup_identifier (String name) +{ + return lookup_identifier_symbol ( ly_symbol2scm (name.to_str0 ())); +} + void My_lily_lexer::start_main_input () { diff --git a/lily/my-lily-parser.cc b/lily/my-lily-parser.cc index bca0f45592..365e64694c 100644 --- a/lily/my-lily-parser.cc +++ b/lily/my-lily-parser.cc @@ -13,19 +13,19 @@ #include "file-path.hh" #include "lily-version.hh" #include "ly-module.hh" -#include "ly-smobs.icc" #include "main.hh" #include "my-lily-lexer.hh" #include "my-lily-parser.hh" #include "output-def.hh" -#include "parray.hh" +#include "paper-book.hh" #include "parser.hh" -#include "scm-hash.hh" #include "score.hh" #include "source.hh" -#include "string.hh" #include "warn.hh" +#include "ly-smobs.icc" + + My_lily_parser::My_lily_parser (Sources *sources) { book_count_ = 0; @@ -35,9 +35,7 @@ My_lily_parser::My_lily_parser (Sources *sources) default_duration_ = Duration (2,0); error_level_ = 0; last_beam_start_ = SCM_EOL; - header_ = SCM_EOL; - header_ = ly_make_anonymous_module (false); smobify_self (); } @@ -50,7 +48,6 @@ My_lily_parser::My_lily_parser (My_lily_parser const &src) default_duration_ = src.default_duration_; error_level_ = src.error_level_; last_beam_start_ = src.last_beam_start_; - header_ = src.header_; smobify_self (); lexer_ = new My_lily_lexer (*src.lexer_); @@ -69,7 +66,7 @@ SCM My_lily_parser::mark_smob (SCM s) { My_lily_parser *parser = (My_lily_parser*) ly_cdr (s); - return parser->header_; + return SCM_EOL; } int @@ -423,7 +420,7 @@ LY_DEFINE (ly_parser_print_score, "ly:parser-print-score", SCM_ASSERT_TYPE (score, score_smob, SCM_ARG2, __FUNCTION__, "score"); SCM header = ly_c_module_p (score->header_) ? score->header_ - : parser->header_.to_SCM (); + : parser->lexer_->lookup_identifier ("$globalheader"); File_name outname (parser->output_basename_); int *c = &parser->book_count_; @@ -464,7 +461,6 @@ LY_DEFINE (ly_parser_print_book, "ly:parser-print-book", /* ugh. changing argument.*/ book->bookpaper_ = bp; - SCM header = parser->header_; File_name outname (parser->output_basename_); int *c = &parser->book_count_; if (*c) @@ -473,8 +469,12 @@ LY_DEFINE (ly_parser_print_book, "ly:parser-print-book", Output_def *paper = get_paper (parser); - book->process (outname.to_string (), paper, header); + Paper_book* pb = book->process (outname.to_string (), paper); + pb->output (outname.to_string ()); + scm_gc_unprotect_object (paper->self_scm ()); + scm_gc_unprotect_object (pb->self_scm ()); + return SCM_UNDEFINED; } diff --git a/lily/paper-book.cc b/lily/paper-book.cc index 0667ed1583..b304ee4472 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -39,7 +39,7 @@ Paper_book::Paper_book () { copyright_ = SCM_EOL; tagline_ = SCM_EOL; - global_header_ = SCM_EOL; + header_ = SCM_EOL; bookpaper_ = 0; smobify_self (); @@ -65,7 +65,7 @@ Paper_book::mark_smob (SCM smob) scm_gc_mark (b->copyright_); if (b->bookpaper_) scm_gc_mark (b->bookpaper_->self_scm ()); - scm_gc_mark (b->global_header_); + scm_gc_mark (b->header_); return b->tagline_; } @@ -101,7 +101,7 @@ Paper_book::output (String outname) Paper_outputter *out = get_paper_outputter (outname); int page_count = scm_ilength (pages); - out->output_header (bookpaper_, global_header_, page_count, false); + out->output_header (bookpaper_, scm_list_1 (header_), page_count, false); for (SCM s = pages; s != SCM_EOL; s = ly_cdr (s)) { @@ -129,8 +129,8 @@ Paper_book::title (int i) // ugh code dup SCM scopes = SCM_EOL; - if (ly_c_module_p (global_header_)) - scopes = scm_cons (global_header_, scopes); + if (ly_c_module_p (header_)) + scopes = scm_cons (header_, scopes); if (ly_c_module_p (score_lines_[i].header_)) scopes = scm_cons (score_lines_[i].header_, scopes); @@ -162,14 +162,14 @@ Paper_book::classic_output (String outname) // ugh code dup SCM scopes = SCM_EOL; - if (ly_c_module_p (global_header_)) - scopes = scm_cons (global_header_, scopes); + if (ly_c_module_p (header_)) + scopes = scm_cons (header_, scopes); if (ly_c_module_p (score_lines_[0].header_)) scopes = scm_cons (score_lines_[0].header_, scopes); //end ugh - out->output_header (p, global_header_, 0, true); + out->output_header (p, header_, 0, true); SCM top_lines = score_lines_.top ().lines_; Paper_line *first = unsmob_paper_line (scm_vector_ref (top_lines, @@ -221,8 +221,8 @@ Paper_book::init () Output_def *paper = bookpaper_; SCM scopes = SCM_EOL; - if (ly_c_module_p (global_header_)) - scopes = scm_cons (global_header_, scopes); + if (ly_c_module_p (header_)) + scopes = scm_cons (header_, scopes); SCM make_tagline = paper->c_variable ("make-tagline"); tagline_ = scm_call_2 (make_tagline, paper->self_scm (), scopes); diff --git a/lily/parser.yy b/lily/parser.yy index b9439c3e21..a5d77bd4da 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -446,7 +446,7 @@ lilypond: /* empty */ toplevel_expression: lilypond_header { - THIS->header_ = $1; + THIS->lexer_->set_identifier (ly_symbol2scm ("$globalheader"), $1); } | add_quote { @@ -658,6 +658,7 @@ book_body: $$->set_spot (THIS->here_input ()); $$->bookpaper_ = dynamic_cast (unsmob_output_def (THIS->lexer_->lookup_identifier ("$defaultbookpaper"))->clone ()); scm_gc_unprotect_object ($$->bookpaper_->self_scm ()); + $$->header_ = THIS->lexer_->lookup_identifier ("$globalheader"); } | book_body book_paper_block { $$->bookpaper_ = $2; @@ -676,7 +677,7 @@ book_body: scm_gc_unprotect_object (music->self_scm ()); } | lilypond_header { - THIS->header_ = $1; + $$->header_ = $1; } | book_body error { @@ -2472,12 +2473,13 @@ markup: THIS->lexer_->pop_state (); Score *score = $2; Book *book = new Book; + book->header_ = THIS->lexer_->lookup_identifier ("$globalheader"); book->scores_.push (score); Output_def *paper = get_paper (THIS); book->bookpaper_ = get_bookpaper (THIS); - SCM s = book->to_stencil (paper, THIS->header_); + SCM s = book->to_stencil (paper); scm_gc_unprotect_object (score->self_scm ()); scm_gc_unprotect_object (book->self_scm ()); $$ = scm_list_2 (ly_scheme_function ("stencil-markup"), s); diff --git a/lily/score.cc b/lily/score.cc index fad7635d4f..d3bc525fc1 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -191,6 +191,9 @@ default_rendering (SCM music, SCM outdef, Music_output *output = g->get_output (); if (systems != SCM_UNDEFINED) { + /* + ugh, this is strange, Paper_book without a Book object. + */ Paper_book *paper_book = new Paper_book (); paper_book->bookpaper_ = unsmob_output_def (scaled_bookdef); @@ -263,15 +266,17 @@ Score::book_rendering (String outname, } LY_DEFINE (ly_score_bookify, "ly:score-bookify", - 1, 0, 0, - (SCM score_smob), - "Return SCORE encapsulated in a BOOK.") + 2, 0, 0, + (SCM score_smob, SCM header), + "Return @var{score_smob} encapsulated in a Book object. Set " + "@var{header} as book level header.") { SCM_ASSERT_TYPE (unsmob_score (score_smob), score_smob, SCM_ARG1, __FUNCTION__, "score_smob"); Score *score = unsmob_score (score_smob); Book *book = new Book; book->scores_.push (score); + book->header_ = header; scm_gc_unprotect_object (book->self_scm ()); return book->self_scm (); } diff --git a/scm/lily.scm b/scm/lily.scm index 0c29b3b5a5..3f82992e04 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -105,8 +105,7 @@ (define-public (print-score-as-book parser score) (let - ((book (ly:score-bookify score)) - ) + ((book (ly:score-bookify score (ly:parser-lookup parser '$globalheader)))) (ly:parser-print-book parser book))) -- 2.39.2