]> git.donarmstrong.com Git - lilypond.git/commitdiff
(LY_DEFINE): ly:parser-output-name:
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 11 Jul 2005 12:51:13 +0000 (12:51 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 11 Jul 2005 12:51:13 +0000 (12:51 +0000)
new function.
(LY_DEFINE): change name ly:parser-define -> ly:parser-define!

19 files changed:
ChangeLog
lily/book-scheme.cc
lily/book.cc
lily/default-actions.cc
lily/include/book.hh
lily/include/ly-module.hh
lily/lily-parser-scheme.cc
lily/output-def.cc
lily/paper-book-scheme.cc
lily/paper-book.cc
lily/score-scheme.cc
lily/score.cc
ly/declarations-init.ly
ly/init.ly
python/convertrules.py
scm/framework-eps.scm
scm/lily-library.scm
scm/safe-lily.scm
scripts/lilypond-book.py

index 6e730da368226f190356d67f91ca3db36e139120..8ccf916294ba072255848a7d0b32d35696e11408 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2005-07-11  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
+       * lily/lily-parser-scheme.cc (LY_DEFINE): ly:parser-output-name:
+       new function.
+       (LY_DEFINE): change name ly:parser-define -> ly:parser-define!
+
        * scm/framework-*.scm: use port arguments throughout.
 
        * lily/include/lily-guile.hh: rename ly_c_X_p -> ly_is_X
index 5c86770e3f69648ccd88af4be95b2e3012f74122..c3b30bd8e7031319c17fb9f7a0b60e0da298ce6b 100644 (file)
@@ -7,8 +7,10 @@
 */
 
 #include "book.hh"
+
 #include "output-def.hh"
 #include "score.hh"
+#include "paper-book.hh"
 #include "ly-module.hh"
 
 LY_DEFINE (ly_make_book, "ly:make-book",
@@ -23,7 +25,7 @@ LY_DEFINE (ly_make_book, "ly:make-book",
   Book *book = new Book;
   book->paper_ = odef;
 
-  if (ly_c_module_p (header))
+  if (ly_is_module (header))
     book->header_ = header;
 
   book->scores_ = scm_append (scm_list_2 (scores, book->scores_));
@@ -32,3 +34,34 @@ LY_DEFINE (ly_make_book, "ly:make-book",
   scm_gc_unprotect_object (x);
   return x;
 }
+
+LY_DEFINE (ly_parser_print_book, "ly:book-process",
+          3, 0, 0, (SCM book_smob,
+                    SCM default_paper,
+                    SCM default_layout,
+                    SCM basename),
+          "Print book.")
+{
+  Book *book = unsmob_book (book_smob);
+
+  SCM_ASSERT_TYPE (book, book_smob, SCM_ARG1, __FUNCTION__, "Book");
+  SCM_ASSERT_TYPE (unsmob_output_def (default_paper),
+                  default_layout, SCM_ARG2, __FUNCTION__, "\\paper block");
+  SCM_ASSERT_TYPE (unsmob_output_def (default_layout),
+                  default_layout, SCM_ARG3, __FUNCTION__, "\\layout block");
+  SCM_ASSERT_TYPE (scm_is_string (basename), basename, SCM_ARG4, __FUNCTION__, "string");
+
+  String base = ly_scm2string (basename);
+  Paper_book *pb = book->process (base,
+                                 unsmob_output_def (default_paper),
+                                 unsmob_output_def (default_layout)
+                                 );
+  if (pb)
+    {
+      pb->output (base);
+      scm_gc_unprotect_object (pb->self_scm ());
+    }
+
+  return SCM_UNSPECIFIED;
+}
+
index 724ab9cc13ad14ded6c74f5872cc7918df64b5c0..59c9c206afb1b91478641f17f2463b2a02a9ece9 100644 (file)
@@ -77,16 +77,20 @@ Book::add_score (SCM s)
 /* 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)
+Book::process (String outname,
+              Output_def *default_paper,
+              Output_def *default_layout)
 {
   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;
 
+  Output_def *paper = paper_ ? default_paper : paper_;
+  
   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);
+  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 ();
@@ -104,7 +108,7 @@ Book::process (String outname, Output_def *default_def)
       if (Score *score = unsmob_score (scm_car (s)))
        {
          SCM outputs = score
-           ->book_rendering (paper_book->paper_, default_def, key);
+           ->book_rendering (paper_book->paper_, default_layout, key);
 
          while (scm_is_pair (outputs))
            {
@@ -122,7 +126,7 @@ Book::process (String outname, Output_def *default_def)
              else if (Paper_score *pscore = dynamic_cast<Paper_score *> (output)) 
                {
                  SCM systems = pscore->get_paper_systems ();
-                 if (ly_c_module_p (score->header_))
+                 if (ly_is_module (score->header_))
                    paper_book->add_score (score->header_);
                  paper_book->add_score (systems);
                }
index 34f7c62224d6ec970a73c7bb371c635269c9ba42..ef7f931191a080be0082d67b5c8357d077eddb58 100644 (file)
@@ -8,99 +8,3 @@
 
 */
 
-#include "lily-parser.hh"
-#include "lily-lexer.hh"
-#include "lilypond-key.hh"
-#include "book.hh"
-#include "paper-book.hh"
-#include "score.hh"
-#include "file-name.hh"
-#include "output-def.hh"
-
-
-
-
-/* TODO: move this to Scheme?  Why take the parser arg, and all the back
-   & forth between scm and c++? */
-LY_DEFINE (ly_parser_print_score, "ly:parser-print-score",
-          2, 0, 0,
-          (SCM parser_smob, SCM score_smob),
-          "Print score, i.e., the classic way.")
-{
-  Lily_parser *parser = unsmob_lily_parser (parser_smob);
-  Score *score = unsmob_score (score_smob);
-
-  Object_key *key = new Lilypond_general_key (0, score->user_key_, 0);
-
-  if (score->error_found_)
-    return SCM_UNSPECIFIED;
-
-  SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "parser");
-  SCM_ASSERT_TYPE (score, score_smob, SCM_ARG2, __FUNCTION__, "score");
-
-  SCM header = ly_c_module_p (score->header_)
-    ? score->header_
-    : parser->lexer_->lookup_identifier ("$globalheader");
-
-  File_name outname (parser->output_basename_);
-  int *c = &parser->book_count_;
-  if (*c)
-    outname.base_ += "-" + to_string (*c);
-  (*c)++;
-
-  SCM os = scm_makfrom0str (outname.to_string ().to_str0 ());
-  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, os, key->self_scm ());
-
-  if (score->defs_.is_empty ())
-    {
-      Output_def *layout = get_layout (parser);
-      default_rendering (score->get_music (),
-                        layout->self_scm (),
-                        paper,
-                        header, os, key->self_scm ());
-      
-      scm_gc_unprotect_object (layout->self_scm ());
-    }
-
-  scm_gc_unprotect_object (paper);
-  scm_gc_unprotect_object (key->self_scm ());
-  return SCM_UNSPECIFIED;
-}
-
-
-LY_DEFINE (ly_parser_print_book, "ly:parser-print-book",
-          2, 0, 0, (SCM parser_smob, SCM book_smob),
-          "Print book.")
-{
-  Lily_parser *parser = unsmob_lily_parser (parser_smob);
-  Book *book = unsmob_book (book_smob);
-  Output_def *bp = unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"));
-
-  SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "Lilypond parser");
-  SCM_ASSERT_TYPE (book, book_smob, SCM_ARG2, __FUNCTION__, "Book");
-
-  /*  ugh. changing argument.*/
-  book->paper_ = bp;
-
-  File_name outname (parser->output_basename_);
-  int *c = &parser->book_count_;
-  if (*c)
-    outname.base_ += "-" + to_string (*c);
-  (*c)++;
-
-  Output_def *layout = get_layout (parser);
-  Paper_book *pb = book->process (outname.to_string (), layout);
-
-  if (pb)
-    {
-      pb->output (outname.to_string ());
-      scm_gc_unprotect_object (pb->self_scm ());
-    }
-
-  scm_gc_unprotect_object (layout->self_scm ());
-  return SCM_UNSPECIFIED;
-}
-
index 88b9207c3e23730005826f23e7365979bcad9f7f..44c764703d664e25167cea8589d7dc86d85fe21b 100644 (file)
@@ -27,7 +27,9 @@ public:
 
   Book ();
   void add_score (SCM);
-  Paper_book *process (String, Output_def *);
+  Paper_book *process (String,
+                      Output_def *def_paper,
+                      Output_def *def_layout);
   void set_keys ();
 };
 
index 52371605766c95e1908168c7dff1e5c7b362cf23..96d2e1fccfb583c5c372e58f9b39e0ed9e0387b7 100644 (file)
@@ -17,7 +17,7 @@ SCM ly_module_lookup (SCM module, SCM sym);
 SCM ly_modules_lookup (SCM modules, SCM sym, SCM);
 SCM ly_module_symbols (SCM mod);
 void ly_reexport_module (SCM mod);
-inline bool ly_c_module_p (SCM x) { return SCM_MODULEP (x); }
+inline bool ly_is_module (SCM x) { return SCM_MODULEP (x); }
 void ly_clear_anonymous_modules ();
 SCM ly_use_module (SCM mod, SCM used);
 
index 006e5560272fce6ac11b836df4cd8563f8513aaa..27cf5e5e5c69a3536b523e89f9c07a585e09a73e 100644 (file)
@@ -155,7 +155,7 @@ LY_DEFINE (ly_clone_parser, "ly:clone-parser",
   return scm_gc_unprotect_object (clone->self_scm ());
 }
 
-LY_DEFINE (ly_parser_define, "ly:parser-define",
+LY_DEFINE (ly_parser_define, "ly:parser-define!",
           3, 0, 0, (SCM parser_smob, SCM symbol, SCM val),
           "Bind SYMBOL to VAL in PARSER_SMOB's module.")
 {
@@ -216,3 +216,15 @@ LY_DEFINE (ly_parser_set_note_names, "ly:parser-set-note-names",
 
   return SCM_UNSPECIFIED;
 }
+
+
+LY_DEFINE (ly_parser_output_name, "ly:parser-output-name",
+          1, 0, 0, (SCM parser),
+          "Return the base name of the output file.")
+{
+  Lily_parser *p = unsmob_lily_parser (parser);
+  SCM_ASSERT_TYPE (p, parser, SCM_ARG1, __FUNCTION__, "Lilypond parser");
+
+  return scm_from_locale_string (p->output_basename_.to_str0 ());
+}
+
index e08816a7b80e6ab435b39fb481fba4949c7cd6b1..0010d69b4f41286751856619721c82b5dd288103 100644 (file)
@@ -40,7 +40,7 @@ Output_def::Output_def (Output_def const &s)
 
   input_origin_ = s.input_origin_;
   scope_ = ly_make_anonymous_module (false);
-  if (ly_c_module_p (s.scope_))
+  if (ly_is_module (s.scope_))
     ly_module_copy (scope_, s.scope_);
 }
 
index 8b5d6c866e0d30f99ec379d6ac881383f5146bac..69b7dc02eedac1595136db5fffbca72c8ee96703 100644 (file)
@@ -25,7 +25,7 @@ LY_DEFINE (ly_paper_book_scopes, "ly:paper-book-scopes",
   SCM_ASSERT_TYPE (pb, book, SCM_ARG1, __FUNCTION__, "Paper_book");
 
   SCM scopes = SCM_EOL;
-  if (ly_c_module_p (pb->header_))
+  if (ly_is_module (pb->header_))
     scopes = scm_cons (pb->header_, scopes);
 
   return scopes;
index 97be3c094a3fc315df90a598979b959bd2748b45..e1fadabd325b498e12e9859ae42a3b4d7fb0fac2 100644 (file)
@@ -89,7 +89,7 @@ Paper_book::output (String outname)
   pages ();
 
   SCM scopes = SCM_EOL;
-  if (ly_c_module_p (header_))
+  if (ly_is_module (header_))
     scopes = scm_cons (header_, scopes);
 
   String mod_nm = "scm framework-" + output_backend_global;
@@ -126,10 +126,10 @@ Paper_book::classic_output (String outname)
   systems ();
 
   SCM scopes = SCM_EOL;
-  if (ly_c_module_p (header_))
+  if (ly_is_module (header_))
     scopes = scm_cons (header_, scopes);
 
-  if (ly_c_module_p (header_0_))
+  if (ly_is_module (header_0_))
     scopes = scm_cons (header_0_, scopes);
 
   String format = output_backend_global;
@@ -156,7 +156,7 @@ Paper_book::book_title ()
   Stencil title;
 
   SCM scopes = SCM_EOL;
-  if (ly_c_module_p (header_))
+  if (ly_is_module (header_))
     scopes = scm_cons (header_, scopes);
 
   SCM tit = SCM_EOL;
@@ -182,10 +182,10 @@ Paper_book::score_title (SCM header)
   Stencil title;
 
   SCM scopes = SCM_EOL;
-  if (ly_c_module_p (header_))
+  if (ly_is_module (header_))
     scopes = scm_cons (header_, scopes);
 
-  if (ly_c_module_p (header))
+  if (ly_is_module (header))
     scopes = scm_cons (header, scopes);
 
   SCM tit = SCM_EOL;
@@ -206,7 +206,7 @@ Paper_book::score_title (SCM header)
 void
 set_system_penalty (Paper_system *ps, SCM header)
 {
-  if (ly_c_module_p (header))
+  if (ly_is_module (header))
     {
       SCM force = ly_module_lookup (header, ly_symbol2scm ("breakbefore"));
       if (SCM_VARIABLEP (force)
@@ -259,7 +259,7 @@ Paper_book::systems ()
   SCM header = SCM_EOL;
   for (SCM s = scm_reverse (scores_); s != SCM_EOL; s = scm_cdr (s))
     {
-      if (ly_c_module_p (scm_car (s)))
+      if (ly_is_module (scm_car (s)))
        {
          header = scm_car (s);
          if (header_0_ == SCM_EOL)
index 19bac6c48a7926d5b1078d530c20cd2e933331a2..ddd97e3a0dc8c58fba814ca8db2faf9c17ae9d72 100644 (file)
@@ -7,9 +7,12 @@
 */
 
 #include "score.hh"
+
 #include "music.hh"
 #include "output-def.hh"
 #include "global-context.hh"
+#include "lilypond-key.hh"
+
 
 LY_DEFINE (ly_make_score, "ly:make-score",
           1, 0, 0,
@@ -69,3 +72,52 @@ LY_DEFINE (ly_score_embedded_format, "ly:score-embedded-format",
   scm_remember_upto_here_1 (prot);
   return output;
 }
+
+LY_DEFINE (ly_score_process, "ly:score-process",
+          2, 0, 0,
+          (SCM score_smob,
+           SCM default_header,
+           SCM default_paper,
+           SCM default_layout,
+           SCM basename),
+          "Print score, i.e., the classic way.")
+{
+  Score *score = unsmob_score (score_smob);
+
+  SCM_ASSERT_TYPE (score, score_smob, SCM_ARG1, __FUNCTION__, "score");
+
+  SCM_ASSERT_TYPE (ly_is_module (default_header),
+                  default_header, SCM_ARG2, __FUNCTION__, "module");
+  SCM_ASSERT_TYPE (unsmob_output_def (default_paper),
+                  default_header, SCM_ARG3, __FUNCTION__, "\\paper block");
+  SCM_ASSERT_TYPE (unsmob_output_def (default_layout),
+                  default_header, SCM_ARG4, __FUNCTION__, "\\layout block");
+  SCM_ASSERT_TYPE (scm_is_string (basename),
+                  default_header, SCM_ARG5, __FUNCTION__, "basename");
+  
+  Object_key *key = new Lilypond_general_key (0, score->user_key_, 0);
+
+  if (score->error_found_)
+    return SCM_UNSPECIFIED;
+
+  SCM header = ly_is_module (score->header_)
+    ? score->header_
+    : default_header;
+  
+  for (int i = 0; i < score->defs_.size (); i++)
+    default_rendering (score->get_music (), score->defs_[i]->self_scm (),
+                      default_paper, header, basename, key->self_scm ());
+
+  if (score->defs_.is_empty ())
+    {
+      default_rendering (score->get_music (),
+                        default_layout,
+                        default_paper,
+                        header, basename, key->self_scm ());
+    }
+
+  scm_gc_unprotect_object (key->self_scm ());
+  return SCM_UNSPECIFIED;
+}
+
+
index 6d86607e68ce8f28812dea6aef370de495b38bb8..032c4be49630c6f0e4503163a5799a1df968cd81 100644 (file)
 #include "global-context.hh"
 #include "lily-parser.hh"
 #include "lilypond-key.hh"
-#include "ly-smobs.icc"
 #include "main.hh"
-#include "music-iterator.hh"
 #include "music.hh"
 #include "output-def.hh"
-#include "output-def.hh"
 #include "paper-book.hh"
 #include "paper-score.hh"
-#include "scm-hash.hh"
 #include "warn.hh"
 
+
+#include "music.hh"
+#include "ly-smobs.icc"
+
 Score::Score ()
   : Input ()
 {
@@ -84,7 +84,7 @@ Score::Score (Score const &s)
       scm_gc_unprotect_object (copy->self_scm ());
     }
   header_ = ly_make_anonymous_module (false);
-  if (ly_c_module_p (s.header_))
+  if (ly_is_module (s.header_))
     ly_module_copy (header_, s.header_);
 
   texts_ = s.texts_;
@@ -130,7 +130,7 @@ default_rendering (SCM music, SCM outdef,
       paper_book->header_ = header;
       paper_book->paper_ = unsmob_output_def (scaled_bookdef);
 
-      if (ly_c_module_p (header))
+      if (ly_is_module (header))
        paper_book->add_score (header);
 
       SCM systems = pscore->get_paper_systems ();
index 3c73227be1faed97b3104d34f4d8275be0aa85bd..9366ea74005093deaa0b497f7db03a3b7050c1e5 100644 (file)
@@ -116,7 +116,7 @@ setDefaultDurationToQuarter = { c4 }
 %% MAKE-HASH-TABLE in GUILE 1.6 takes mandatory size parameter.
 #(define musicQuotes (make-hash-table 29))
 
-#(define toplevel-book-handler ly:parser-print-book)
+#(define toplevel-book-handler print-book-with-defaults)
 #(define toplevel-music-handler collect-music-for-book)
 #(define toplevel-score-handler collect-scores-for-book)
 #(define toplevel-text-handler collect-scores-for-book)
index 6a7e513c7e8ab7a26d0bde403a17a8b371ae1cc8..29694bb3d8a3d6a63ca76f4815ea1de3938c12de 100644 (file)
@@ -34,6 +34,6 @@
   (version-not-seen-message input-file-name))
 
 #(if (pair? toplevel-scores)
-  (ly:parser-print-book parser
+  (toplevel-book-handler
+   parser
    (apply ly:make-book $defaultpaper $globalheader toplevel-scores)))
-
index 84f5fd3ea6e906ebe34b4fcb1f6411dc51f1877d..94dd62a7119a93c6c0be73778671b2b1fda137f9 100644 (file)
@@ -2504,12 +2504,18 @@ conversions.append (((2, 6, 0), conv,
                     'dummy rule for 2.6')) 
 
 
+
 def conv (str):
        return re.sub('ly:get-default-font', 'ly:grob-default-font', str) 
 
 conversions.append (((2, 7, 0), conv,
-                    
-                    'ly:get-default-font -> ly:grob-default-font')) 
+                    'ly:get-default-font -> ly:grob-default-font'))
+
+def conv (str):
+       return re.sub('ly:parser-define', 'ly:parser-define!', str)
+
+conversions.append (((2, 7, 0), conv,
+                    'ly:parser-define -> ly:parser-define!'))
 
 ################################################################
 
index b0212a8e69545a58b230ad9008b16060df70f16f..29d4df46b2e29c4270a60d17221a097b94905dc7 100644 (file)
@@ -60,7 +60,7 @@
                (display (format "@image{~a-~a}\n"
                                 basename (1+ c)) texi-system-port))
              (iota (length stencils)))
-    (display "@c eof - 'eof' is a Makefile marker; don not remove. " texi-system-port)
+    (display "@c eof - 'eof' is a Makefile marker; do not remove. " texi-system-port)
     (display "% eof - 'eof' is Makefile marker; do not remove. " tex-system-port)
     
     (dump-infinite-stack-EPS stencils))
index b9e326cae7167dd7de8ab359020c4d5c0f5a9070..f14f3d7b42f1937a94ce9c53c735940e933b9a48 100644 (file)
              (set! music (func music parser)))
            toplevel-music-functions)
 
-;  (display-scheme-music  music)
   (ly:make-score music))
 
-
 (define-public (collect-music-for-book parser music)
   (collect-scores-for-book parser (scorify-music music parser)))
 
-  
+
+(define-public (print-book-with-defaults parser book)
+  (let*
+      ((paper (ly:parser-lookup parser '$defaultpaper))
+       (layout (ly:parser-lookup parser '$defaultlayout))
+       (count (ly:parser-lookup parser 'book-count))
+       (base (ly:parser-output-name parser)))
+
+    (if (not (integer? count))
+       (set! count 0))
+
+    (if (> count 0)
+       (set! (base (format #f "~a-~a" count))))
+
+    (ly:parser-define! book-count (1+ count))
+    
+
+    (ly:book-process book paper layout base)
+    ))
+
+(define-public (print-score-with-defaults parser score)
+  (let*
+      ((paper (ly:parser-lookup parser '$defaultpaper))
+       (layout (ly:parser-lookup parser '$defaultlayout))
+       (layout (ly:parser-lookup parser '$globalheader))
+       (count (ly:parser-lookup parser 'book-count))i
+       (base (ly:parser-output-name parser)))
+
+    (if (not (integer? count))
+       (set! count 0))
+
+    (if (> count 0)
+       (set! (base (format #f "~a-~a" count))))
+
+    (ly:parser-define! book-count (1+ count))
+    
+
+    (ly:score-process score header paper layout base)
+    ))
+
 ;;;;;;;;;;;;;;;;
-; alist
+;; alist
 (define-public assoc-get ly:assoc-get)
 
 (define-public (uniqued-alist alist acc)
index 0e0fb0d9cf4f70c515fbb19496658ac230ec50de..2f1e7dec539823171a3ddfcaaa249cfb99c37361 100644 (file)
    ly:output-def-lookup
    ly:parse-string
    ly:parser-parse-string
-   ly:parser-print-book
-   ly:parser-print-score
    ly:pitch-alteration
    ly:pitch-diff
    ly:pitch-notename
index 692790bf3c670d7000032194257580e1570c0f02..9ca2640b050f52fe155491afd07a0813ead7215d 100644 (file)
@@ -551,9 +551,9 @@ output = {
 PREAMBLE_LY = r'''%%%% Generated by %(program_name)s
 %%%% Options: [%(option_string)s]
 
-#(set! toplevel-score-handler ly:parser-print-score)
+#(set! toplevel-score-handler print-score-with-defaults)
 #(set! toplevel-music-handler (lambda (p m)
-                              (ly:parser-print-score
+                              (print-score-with-defaults
                                p (scorify-music m p))))
 
 #(ly:set-option (quote no-point-and-click))