]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/input-file-results.cc (do_one_file): Remove Paper_book hack.
authorJan Nieuwenhuizen <janneke@gnu.org>
Sat, 10 Apr 2004 01:17:30 +0000 (01:17 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Sat, 10 Apr 2004 01:17:30 +0000 (01:17 +0000)
* lily/score.cc (book_rendering): New method.
(default_rendering): Create Paper_book helper locally, dump
output.

* lily/my-lily-lexer.cc (the_key_tab): Add book.

* lily/parser.yy: Handle \book.

* lily/include/book.hh:
* lily/book.cc: New file.

14 files changed:
ChangeLog
lily/book.cc [new file with mode: 0644]
lily/include/book.hh [new file with mode: 0644]
lily/include/context-def.hh
lily/include/input-file-results.hh
lily/include/lily-proto.hh
lily/include/main.hh
lily/include/music-output-def.hh
lily/include/score.hh
lily/input-file-results.cc
lily/my-lily-lexer.cc
lily/paper-book.cc
lily/parser.yy
lily/score.cc

index da67305e4264dde935c2f77f011c740d036560a1..862940022cf4946da5b761246febdafce690500f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2004-04-10  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+       * lily/input-file-results.cc (do_one_file): Remove Paper_book hack.
+
+       * lily/score.cc (book_rendering): New method.
+       (default_rendering): Create Paper_book helper locally, dump
+       output.
+
+       * lily/my-lily-lexer.cc (the_key_tab): Add book.
+
+       * lily/parser.yy: Handle \book.
+
+       * lily/include/book.hh: 
+       * lily/book.cc: New file.
+
 2004-04-10  Han-Wen Nienhuys   <hanwen@xs4all.nl>
 
        * lily/text-item.cc (interpret_string): new file, select font with
diff --git a/lily/book.cc b/lily/book.cc
new file mode 100644 (file)
index 0000000..f539374
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+  book.cc -- implement Book
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
+#include <stdio.h>
+
+#include "ly-smobs.icc"
+
+#include "book.hh"
+#include "global-context.hh"
+#include "ly-module.hh"
+#include "input-file-results.hh"
+#include "main.hh"
+#include "music-iterator.hh"
+#include "music-output-def.hh"
+#include "music-output.hh"
+#include "music.hh"
+#include "paper-book.hh"
+#include "paper-def.hh"
+#include "score.hh"
+#include "warn.hh"
+
+Book::Book ()
+  : Input ()
+{
+  header_ = SCM_EOL;
+  smobify_self ();
+}
+
+#if 0
+Book::Book (Book const &src)
+  : Input (src)
+{
+  header_ = SCM_EOL;
+  smobify_self ();
+
+  int score_count = src.scores_.size ();
+  for (int i = 0; i < score_count; i++)
+    scores_.push (src.scores_[i]->clone ());
+
+#if 0
+  header_ = ly_make_anonymous_module ();
+  if (is_module (src.header_))
+    ly_import_module (header_, src.header_);
+#endif
+}
+#endif
+
+Book::~Book ()
+{
+}
+
+IMPLEMENT_SMOBS (Book);
+IMPLEMENT_DEFAULT_EQUAL_P (Book);
+
+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 ());
+  return book->header_;
+}
+
+int
+Book::print_smob (SCM, SCM p, scm_print_state*)
+{
+  scm_puts ("#<Book>", p);
+  return 1;
+}
+
+void
+Book::process (String outname, Music_output_def *default_def, SCM header)
+{
+  Paper_book *paper_book = new Paper_book ();
+  int score_count = scores_.size ();
+  for (int i = 0; i < score_count; i++)
+    {
+      Paper_def *paper = 0;
+      SCM systems = scores_[i]->book_rendering (outname, default_def, &paper);
+      if (systems != SCM_UNDEFINED)
+       {
+         if (paper)
+           paper_book->papers_.push (paper);
+         paper_book->scores_.push (systems);
+         paper_book->global_headers_.push (global_input_file->header_);
+         paper_book->headers_.push (scores_[i]->header_);
+       }
+    }
+  paper_book->output (outname);
+  scm_gc_unprotect_object (paper_book->self_scm ());
+}
diff --git a/lily/include/book.hh b/lily/include/book.hh
new file mode 100644 (file)
index 0000000..7ffeec5
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+  book.hh -- declare Book
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
+#ifndef BOOK_HH
+#define BOOK_HH
+
+#include "input.hh"
+#include "lily-proto.hh"
+
+#include "parray.hh"
+#include "smobs.hh"
+
+class Book : public Input
+{
+  DECLARE_SMOBS (Book, foo);
+
+public:
+  SCM header_;
+  Link_array<Score> scores_;
+    
+  Book ();
+  Book (Book const&);
+  void process (String outname, Music_output_def*, SCM header);
+};
+DECLARE_UNSMOB (Book,book); 
+
+#endif /* BOOK_HH */
index 3760c044a62468043b9b83c36ea7c2f95909a6aa..01484666a6d797744cba2bb0faac913b03c45524 100644 (file)
@@ -7,8 +7,8 @@
   
  */
 
-#ifndef TRANSLATOR_DEF_HH
-#define TRANSLATOR_DEF_HH
+#ifndef CONTEXT_DEF_HH
+#define CONTEXT_DEF_HH
 
 #include "lily-proto.hh"
 #include "smobs.hh"
@@ -36,27 +36,28 @@ public:
   void add_context_mod (SCM);
   SCM default_child_context_name ();
   SCM get_context_name () const;
-  SCM get_accepted (SCM)  const;
-  SCM get_property_ops ()  const { return property_ops_; }
+  SCM get_accepted (SCM) const;
+  SCM get_property_ops () const { return property_ops_; }
   SCM get_translator_names (SCM) const;
   void set_acceptor (SCM accepts, bool add);
 
-  Link_array<Context_def> path_to_acceptable_context (SCM type_string, Music_output_def* odef) const;
+  Link_array<Context_def> path_to_acceptable_context (SCM type_string,
+                                                     Music_output_def*) const;
   Context * instantiate (SCM extra_ops);
 
   SCM to_alist () const;
-  static SCM make_scm () ;
+  static SCM make_scm ();
+
+  SCM clone_scm () const;
+  void apply_default_property_operations (Context*);
 
-  SCM clone_scm ()const;
-  void apply_default_property_operations (Context *);
 private:
-  DECLARE_SMOBS (Context_def,foo);
+  DECLARE_SMOBS (Context_def, foo);
   Context_def ();
   Context_def (Context_def const&);
 };
 
-DECLARE_UNSMOB(Context_def,context_def);
-
+DECLARE_UNSMOB (Context_def, context_def);
 
-#endif /* TRANSLATOR_DEF_HH */
+#endif /* CONTEXT_DEF_HH */
 
index 08d7192417ae6bf24cf902425cede48e96b90c9c..610ff422a6300dc9e029e2a38dc60f12dd055320 100644 (file)
@@ -23,6 +23,7 @@ public:
   Array<String> target_strings_;
   Protected_scm header_;
 
+  int book_count_;
   int score_count_;
   
   void do_deps (String);
index b8181cdf5855266b4ddaf9dc184e06ea9fb4116c..0e1dc356c147e1a9652919f0521a695b54028e90 100644 (file)
@@ -36,6 +36,7 @@ class Bar_req_collect_engraver;
 class Beaming_info_list;
 class Bezier;
 class Bezier_bow;
+class Book;
 class Break_algorithm;
 class Change_iterator;
 class Change_translator;
index b923465bd171066b1fa9cf950adee0c94f766b84..5465c3cfd972320d5446f3d357674f9ebbdb1d44 100644 (file)
@@ -45,6 +45,4 @@ extern int exit_status_global;
 extern File_path global_path;
 extern int score_count_global;
 
-extern Paper_book *paper_book;
-
 #endif /* MAIN_HH */
index fd327454526507662986671947bea4bcde502876..4bde0d6e8d32ee1aaa56067b4b275d3744e07063 100644 (file)
@@ -6,9 +6,8 @@
   (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
-
-#ifndef Music_output_DEF_HH
-#define Music_output_DEF_HH
+#ifndef MUSIC_OUTPUT_DEF_HH
+#define MUSIC_OUTPUT_DEF_HH
 
 #include "string.hh"
 #include "lily-proto.hh"
@@ -44,5 +43,6 @@ public:
   DECLARE_SMOBS (Music_output_def,);
 };
 
-DECLARE_UNSMOB(Music_output_def,music_output_def);
-#endif // Music_output_DEF_HH
+DECLARE_UNSMOB (Music_output_def, music_output_def);
+
+#endif /* MUSIC_OUTPUT_DEF_HH */
index 38e4b3aaf5db94eddb68ca8274011ec94f62c645..2c9858948ece57d82bbe644476d8a93b9d6f74a9 100644 (file)
@@ -9,14 +9,17 @@
 #ifndef SCORE_HH
 #define SCORE_HH
 
-#include "input.hh"
 #include "lily-proto.hh"
 
+#include "input.hh"
 #include "parray.hh"
 #include "smobs.hh"
+#include "virtual-methods.hh"
 
 class Score : public Input
 {
+  DECLARE_SMOBS (Score, foo);
+
 public:
   Link_array<Music_output_def> defs_;
   SCM music_;
@@ -24,13 +27,12 @@ public:
     
   Score ();
   Score (Score const&);
-  DECLARE_SMOBS (Score,foo);
+  SCM book_rendering (String, Music_output_def*, Paper_def**);
 };
-DECLARE_UNSMOB (Score,score); 
-
+DECLARE_UNSMOB (Score, score);
 
 SCM ly_run_translator (SCM, SCM);
 SCM ly_render_output (SCM, SCM);
-void default_rendering (SCM,SCM,SCM,SCM);
+void default_rendering (SCM, SCM, SCM, SCM);
 
 #endif /* SCORE_HH */
index bd45322c03e6ed37182befcc04188b4cecae7f26..d29420140fe53edfe8a4c1afd8b274c472b7c367 100644 (file)
@@ -32,8 +32,6 @@
 #include "scm-hash.hh"
 #include "ly-module.hh"
 
-#include "paper-book.hh"
-
 bool store_locations_global_b;
 
 /*
@@ -127,18 +125,17 @@ Input_file_results::~Input_file_results ()
   ly_clear_anonymous_modules ();
 }
 
-
-
 Input_file_results* global_input_file;
 
-Input_file_results::Input_file_results (String init, String in_file, String out_file)
+Input_file_results::Input_file_results (String init,
+                                       String in_file, String out_file)
 {
   header_ = ly_make_anonymous_module ();
   global_input_file = this;
+  book_count_ = 0;
   score_count_ = 0;
   sources_.set_path (&global_path);
   
-
   progress_indication (_f ("Now processing `%s'", in_file.to_str0 ()));
   progress_indication ("\n");
 
@@ -150,7 +147,6 @@ Input_file_results::Input_file_results (String init, String in_file, String out_
       exit_status_global  = 1;
       failed_files.push (in_file);
     }
-
   
   do_deps (out_file);
 }
@@ -225,11 +221,5 @@ do_one_file (char const *file)
       return;
     }
 
-  paper_book = new Paper_book ();;
   Input_file_results inp_file (init, in_file, out_file);
-  if (output_format_global == PAGE_LAYOUT)
-    paper_book->output (out_file);
-
-  scm_gc_unprotect_object (paper_book->self_scm ());
-  paper_book = 0;
 }
index 9cd0942a1ec06ee91a39310ddf4bb4c46d7bcb98..6a4016e35c950818578bd101abc246e69605cb87 100644 (file)
@@ -38,6 +38,7 @@ static Keyword_ent the_key_tab[] = {
   {"appoggiatura", APPOGGIATURA},
   {"autochange", AUTOCHANGE},
   {"bar", BAR},
+  {"book", BOOK},
   {"breathe", BREATHE},
   {"change", CHANGE},
   {"chords", CHORDS},
index c552f51d33783801c6650f7048a2a84a9b9fa280..1a844ab7e6df553daf89f45b9c62b774f1236b6c 100644 (file)
@@ -190,10 +190,6 @@ Page::text_height ()
 
 /****************************************************************/
 
-/* Current global paper book.  Gives default_rendering access from
-   input-file-results.  */
-Paper_book *paper_book;
-
 Paper_book::Paper_book ()
 {
   copyright_ = SCM_EOL;
@@ -288,8 +284,8 @@ Stencil*
 Paper_book::title (int i)
 {
   SCM user_title = ly_scheme_function ("user-title");
-    SCM book_title = ly_scheme_function ("book-title");
-    SCM score_title = ly_scheme_function ("score-title");
+  SCM book_title = ly_scheme_function ("book-title");
+  SCM score_title = ly_scheme_function ("score-title");
   SCM field = (i == 0 ? ly_symbol2scm ("bookTitle")
               : ly_symbol2scm ("scoreTitle"));
 
index 528c4549fe2eff1cb8a385a1ab762adc7a2dd080..aaad718b357a43e6e74898bc5e0a8034197dada1 100644 (file)
@@ -25,30 +25,31 @@ TODO:
 #include <stdio.h>
 
 
-#include "scm-option.hh"
+#include "book.hh"
 #include "context-def.hh"
-#include "lily-guile.hh"
-#include "misc.hh"
-#include "my-lily-lexer.hh"
-#include "paper-def.hh"
-#include "midi-def.hh"
-#include "main.hh"
-#include "file-path.hh"
-#include "warn.hh"
 #include "dimensions.hh"
-#include "my-lily-parser.hh"
-#include "score.hh"
+#include "event.hh"
+#include "file-path.hh"
 #include "input-file-results.hh"
+#include "input-smob.hh"
 #include "input.hh"
+#include "lily-guile.hh"
 #include "lilypond-input-version.hh"
-#include "scm-hash.hh"
 #include "ly-module.hh"
-#include "music-sequence.hh"
-#include "input-smob.hh"
-#include "event.hh"
-#include "text-item.hh"
+#include "main.hh"
+#include "midi-def.hh"
+#include "misc.hh"
 #include "music-list.hh"
+#include "music-sequence.hh"
+#include "my-lily-lexer.hh"
+#include "my-lily-parser.hh"
 #include "paper-book.hh"
+#include "paper-def.hh"
+#include "scm-hash.hh"
+#include "scm-option.hh"
+#include "score.hh"
+#include "text-item.hh"
+#include "warn.hh"
 
 #define MY_MAKE_MUSIC(x)  make_music_by_name (ly_symbol2scm (x))
 
@@ -107,16 +108,11 @@ make_simple_markup (SCM encoding, SCM a)
 {
        SCM simple = ly_scheme_function ("simple-markup");
        if (is_symbol (encoding))
-       {
                return scm_list_3 (ly_scheme_function ("encoded-simple-markup"),
                           encoding, a);
-       } else
-               return scm_list_2 (simple, a);
-
-       return markup;
+       return scm_list_2 (simple, a);
 }
 
-
 bool
 is_duration (int t)
 {
@@ -177,12 +173,13 @@ of the parse stack onto the heap. */
 
 
 %union {
+       Book *book;
+       Music_output_def *outputdef;
+       SCM scm;
        String *string;
-    Music *music;
-    Score *score;
-    Music_output_def *outputdef;
-    SCM scm;
-    int i;
+       Music *music;
+       Score *score;
+       int i;
 }
 %{
 
@@ -248,6 +245,7 @@ or
 %token APPLYOUTPUT
 %token AUTOCHANGE
 %token BAR
+%token BOOK
 %token BREATHE
 %token CHANGE
 %token CHORDMODIFIERS
@@ -315,6 +313,7 @@ or
 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET  CHORD_SLASH
 %token FIGURE_SPACE
 
+%type <book>   book_block book_body
 %type <i>      exclamations questions dots optional_rest
 %type <i>       bass_mod
 %type <scm>    grace_head
@@ -427,23 +426,37 @@ toplevel_expression:
        }
        | add_quote {
        }
+       | book_block {
+               Book *book = $1;
+               SCM header = THIS->input_file_->header_.to_SCM ();
+               Path outname = split_path (THIS->output_basename_);
+               int *c = &THIS->input_file_->book_count_;
+               if (*c)
+                       outname.base += "-" + to_string (*c);
+               (*c)++;
+               Music_output_def *dp = unsmob_music_output_def
+                       (THIS->lexer_->lookup_identifier ("$defaultpaper"));
+               book->process (outname.to_string (),
+                       dp ? dp->clone () : new Paper_def, header);
+               scm_gc_unprotect_object (book->self_scm ());
+       }
        | score_block {
                Score *sc = $1;
-
-               SCM head = is_module (sc->header_) ? sc->header_ : THIS->input_file_->header_.to_SCM ();
+               SCM head = is_module (sc->header_) ? sc->header_
+                       : THIS->input_file_->header_.to_SCM ();
 
                Path p = split_path (THIS->output_basename_);
                int *c = &THIS->input_file_->score_count_;
                if (*c)
-                       {
                        p.base += "-" + to_string (*c);
-                       }
 
                (*c)++;
                SCM outname = scm_makfrom0str (p.to_string ().to_str0());
 
                for (int i = 0; i < sc->defs_.size (); i++)
-                       default_rendering (sc->music_, sc->defs_[i]->self_scm (), head, outname);
+                       default_rendering (sc->music_,
+                                          sc->defs_[i]->self_scm (), head,
+                                          outname);
 
                if (sc->defs_.is_empty ())
                {
@@ -592,9 +605,29 @@ context_def_spec_body:
        }
        ;
 
-/*
-       SCORE
-*/
+book_block:
+       BOOK {
+               THIS->push_spot ();
+       }
+       /*cont*/ '{' book_body '}'      {
+               THIS->pop_spot ();
+               $$ = $4;
+       }
+       ;
+
+book_body:
+       {
+               $$ = new Book;
+               $$->set_spot (THIS->here_input ());
+       }
+       | book_body score_block {
+               $$->scores_.push ($2);
+               scm_gc_unprotect_object ($2->self_scm ());
+       }
+       | book_body error {
+       }
+       ;
+
 score_block:
        SCORE {
                THIS->push_spot ();
@@ -602,7 +635,6 @@ score_block:
        /*cont*/ '{' score_body '}'     {
                THIS->pop_spot ();
                $$ = $4;
-
        }
        ;
 
index 81f8576f0b9464d2880a8e4f3263e90b34e06707..e81210c9961e7715247c4b7b10bf0d4b12e2244e 100644 (file)
@@ -35,32 +35,24 @@ Score::Score ()
 {
   header_ = SCM_EOL;
   music_ = SCM_EOL;
-
   smobify_self ();
 }
 
 Score::~Score ()
 {
-  
 }
 
-
-
-
 IMPLEMENT_SMOBS (Score);
 IMPLEMENT_DEFAULT_EQUAL_P (Score);
 
-
 SCM
 Score::mark_smob (SCM s)
 {
-  Score * sc = (Score*) SCM_CELL_WORD_1 (s);
-
+  Score *sc = (Score*) SCM_CELL_WORD_1 (s);
   if (sc->header_)
     scm_gc_mark (sc->header_);
   for (int i = sc->defs_.size (); i--;)
     scm_gc_mark (sc->defs_[i]->self_scm ());
-  
   return sc->music_;
 }
 
@@ -83,7 +75,10 @@ Score::Score (Score const &s)
   : Input (s)
 {
   music_ = SCM_EOL;
+
+  // FIXME: SCM_EOL?
   header_ = 0;
+
   smobify_self ();
 
   Music * m =unsmob_music (s.music_);
@@ -175,15 +170,43 @@ default_rendering (SCM music, SCM outdef, SCM header, SCM outname)
       Music_output *output = g->get_output ();
       if (systems != SCM_UNDEFINED)
        {
+         Paper_book *paper_book = new Paper_book ();
          Paper_score *ps = dynamic_cast<Paper_score*> (output);
-
          paper_book->papers_.push (ps->paper_);
          paper_book->scores_.push (systems);
          paper_book->global_headers_.push (global_input_file->header_);
          paper_book->headers_.push (header);
-         if (output_format_global != PAGE_LAYOUT)
-           paper_book->classic_output (ly_scm2string (outname));
+         paper_book->classic_output (ly_scm2string (outname));
+         scm_gc_unprotect_object (paper_book->self_scm ());
        }
       delete output;
     }
 }
+
+SCM
+Score::book_rendering (String outname, Music_output_def *default_def,
+                      Paper_def **paper)
+{
+  SCM out = scm_makfrom0str (outname.to_str0 ());
+  SCM systems = SCM_EOL;
+  int outdef_count = defs_.size ();
+  for (int i = 0; !i || i < outdef_count; i++)
+    {
+      Music_output_def *def = outdef_count ? defs_[i] : default_def;
+      SCM context = ly_run_translator (music_, def->self_scm ());
+      if (Global_context *g = dynamic_cast<Global_context*>
+         (unsmob_context (context)))
+       {
+         SCM s = ly_format_output (context, out);
+         if (s != SCM_UNDEFINED)
+           {
+             systems = s;
+             /* Ugh. */
+             Music_output *output = g->get_output ();
+             if (Paper_score *ps = dynamic_cast<Paper_score*> (output))
+               *paper = ps->paper_;
+           }
+       }
+    }
+  return systems;
+}