]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/book.cc (process): return Paper_book
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 29 May 2004 10:38:53 +0000 (10:38 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 29 May 2004 10:38:53 +0000 (10:38 +0000)
(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.

12 files changed:
ChangeLog
lily/book.cc
lily/include/book.hh
lily/include/my-lily-lexer.hh
lily/include/my-lily-parser.hh
lily/include/paper-book.hh
lily/my-lily-lexer.cc
lily/my-lily-parser.cc
lily/paper-book.cc
lily/parser.yy
lily/score.cc
scm/lily.scm

index 440a0742ce4c40901699a71503f74600a1c786b4..9bddbebc1f465f1e576b8c65ec84680d045f4b51 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
+2004-05-29  Han-Wen Nienhuys   <hanwen@xs4all.nl>
+
+       * 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   <hanwen@xs4all.nl>
 
+       * input/test/fill-a4.ly: removed.
+
        * lily/parser.yy (output_def): push scope of parent_ Output_def
        too.
 
index 50fee8f48e038ac054105ec147c97bd036940314..267b5a6fac4464a53d6c84ad98a28c652df7da19 100644 (file)
@@ -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 ("<markup>",
-                                               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 ("<markup>", 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'...", "<markup>"));
index f3255ed8f67ad415561fd776d19b3ed4f29d113e..899fbb4d9d1caf32f5f10982a5dbcae4f25f45b2 100644 (file)
@@ -25,8 +25,8 @@ public:
   Link_array<Score> 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);
 
index 44f3966fc01a14e48ad42a6462528dd7e74cdd84..bdc95f7465f49cdd5e43eb3c4ca785944b81f8b3 100644 (file)
@@ -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 ();
index 1d98879da91c14791a1988564741a92119fee4c7..7c7c92aafc55881fdd25eb068be0f2d8fb61f882 100644 (file)
@@ -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_;
index 4733dc2ef493a75c73ad072f21b705a0b9131b5d..7975a5aa9a3f9eb7e5ec07cea68f21257eb05d36 100644 (file)
@@ -29,8 +29,8 @@ class Paper_book
   Real height_;
   SCM copyright_;
   SCM tagline_;
-  SCM global_header_;
 public:
+  SCM header_;
   Array<Score_lines> score_lines_;
   Output_def *bookpaper_;
   
index 8d9fcb93deeebc4ac12fbdf60771c6a1add66bfd..68300b00f70197828d4f32a172e93002be2bca72 100644 (file)
@@ -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 ()
 {
index bca0f455928f07cf33a9812e0840f085cd656c5e..365e64694cb406d16e62f9dbee895b265acd0a76 100644 (file)
 #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;
 }
index 0667ed1583d1201393cd816174868bff96e84343..b304ee447280747136393762b8ee4e12718379bc 100644 (file)
@@ -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);
index b9439c3e211cdcf5591135075fddbb199029ef0c..a5d77bd4da6698f1f6589081d0881c263a14e916 100644 (file)
@@ -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<Output_def*> (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);
index fad7635d4fbd1b37679ba19814f71a84cd3bfc15..d3bc525fc167edcc53a45cf16bdfe04f5f7c8a74 100644 (file)
@@ -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 ();
 }
index 0c29b3b5a526c564e019f83d17f788e2a6c2a405..3f82992e04fbf6cf4084ef3f9f29719adc69c0cb 100644 (file)
 
 (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)))