]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lily-parser.cc
(bezier-sandwich): New function.
[lilypond.git] / lily / lily-parser.cc
index 8ad9b9c47e4224e9b6aac15e4ca2fc4565230ba0..d83528ccc59e863c27cb138c97c3c1f3c9784e3d 100644 (file)
@@ -7,7 +7,11 @@
        Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
+
 #include "book.hh"
+#include "lilypond-key.hh"
+#include "context-selector.hh"
+#include "grob-selector.hh"
 #include "file-name.hh"
 #include "file-path.hh"
 #include "lily-version.hh"
@@ -66,7 +70,7 @@ IMPLEMENT_DEFAULT_EQUAL_P (Lily_parser);
 SCM
 Lily_parser::mark_smob (SCM s)
 {
-  Lily_parser *parser = (Lily_parser*) ly_cdr (s);
+  Lily_parser *parser = (Lily_parser*) SCM_CELL_WORD_1 (s);
   return (parser->lexer_) ? parser->lexer_->self_scm () : SCM_EOL;
 }
 
@@ -74,7 +78,7 @@ int
 Lily_parser::print_smob (SCM s, SCM port, scm_print_state*)
 {
   scm_puts ("#<my_lily_parser ", port);
-  Lily_parser *parser = (Lily_parser*) ly_cdr (s);
+  Lily_parser *parser = (Lily_parser*) SCM_CELL_WORD_1 (s);
   (void) parser;
   scm_puts (" >", port);
   return 1;
@@ -100,11 +104,24 @@ Lily_parser::parse_file (String init, String name, String out_name)
   set_yydebug (0);
 
   lexer_->new_input (init, sources_);
+#ifdef TWEAK
+  File_name f (name);
+  String s = global_path.find (f.base_ + ".twy");
+  if (s == "")
+    Grob_selector::set_tweaks (SCM_EOL);
+  else
+    {
+      s = gulp_file_to_string (s, false);
+      SCM tweaks = scm_eval_string (scm_makfrom0str (s.to_str0 ()));
+      Grob_selector::set_tweaks (tweaks);
+    }
+  Context_selector::set_tweaks (SCM_EOL);
+#endif  
 
   /* Read .ly IN_FILE, lex, parse, write \score blocks from IN_FILE to
      OUT_FILE (unless IN_FILE redefines output file name).  */
   do_yyparse ();
-  
+
   if (!define_spots_.is_empty ())
     {
       define_spots_.top ().warning (_ ("Braces don't match"));
@@ -125,7 +142,7 @@ Lily_parser::parse_string (String ly_code)
 
 
   SCM oldmod = scm_current_module ();
-  scm_set_current_module (ly_car (lexer_->scopes_));
+  scm_set_current_module (scm_car (lexer_->scopes_));
   
   // TODO: use $parser 
   lexer_->set_identifier (ly_symbol2scm ("parser"),
@@ -281,7 +298,7 @@ LY_DEFINE (ly_parse_file, "ly:parse-file",
       Sources sources;
       sources.set_path (&global_path);
   
-      progress_indication (_f ("Now processing `%s'", file_name.to_str0 ()));
+      progress_indication (_f ("Processing `%s'", file_name.to_str0 ()));
       progress_indication ("\n");
 
       Lily_parser *parser = new Lily_parser (&sources);
@@ -374,15 +391,14 @@ LY_DEFINE (ly_parser_parse_string, "ly:parser-parse-string",
 }
 
 Output_def*
-get_paper (Lily_parser *parser)
+get_layout (Lily_parser *parser)
 {
-  SCM id = parser->lexer_->lookup_identifier ("$defaultpaper");
-  Output_def *paper = unsmob_output_def (id);
-  paper = paper ? paper->clone () : new Output_def;
-  paper->set_variable (ly_symbol2scm ("is-paper"), SCM_BOOL_T);
+  SCM id = parser->lexer_->lookup_identifier ("$defaultlayout");
+  Output_def *layout = unsmob_output_def (id);
+  layout = layout ? layout->clone () : new Output_def;
+  layout->set_variable (ly_symbol2scm ("is-layout"), SCM_BOOL_T);
 
-  paper->parent_ = unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultbookpaper"));
-  return paper;
+  return layout;
 }
 
 
@@ -390,22 +406,22 @@ Output_def*
 get_midi (Lily_parser *parser)
 {
   SCM id = parser->lexer_->lookup_identifier ("$defaultmidi");
-  Output_def *paper = unsmob_output_def (id);
-  paper = paper ? paper->clone () : new Output_def;
-  paper->set_variable (ly_symbol2scm ("is-midi"), SCM_BOOL_T);
-  return paper;
+  Output_def *layout = unsmob_output_def (id);
+  layout = layout ? layout->clone () : new Output_def;
+  layout->set_variable (ly_symbol2scm ("is-midi"), SCM_BOOL_T);
+  return layout;
 }
 
 
 Output_def*
-get_bookpaper (Lily_parser *parser)
+get_paper (Lily_parser *parser)
 {
-  SCM id = parser->lexer_->lookup_identifier ("$defaultbookpaper");
-  Output_def *paper = unsmob_output_def (id);
+  SCM id = parser->lexer_->lookup_identifier ("$defaultpaper");
+  Output_def *layout = unsmob_output_def (id);
 
-  paper = paper ? dynamic_cast<Output_def*> (paper->clone ()) : new Output_def;
-  paper->set_variable (ly_symbol2scm ("is-bookpaper"), SCM_BOOL_T);
-  return paper;
+  layout = layout ? dynamic_cast<Output_def*> (layout->clone ()) : new Output_def;
+  layout->set_variable (ly_symbol2scm ("is-paper"), SCM_BOOL_T);
+  return layout;
 }
 
 
@@ -419,6 +435,11 @@ LY_DEFINE (ly_parser_print_score, "ly:parser-print-score",
   Lily_parser *parser = unsmob_my_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");
 
@@ -432,20 +453,23 @@ LY_DEFINE (ly_parser_print_score, "ly:parser-print-score",
   (*c)++;
 
   SCM os = scm_makfrom0str (outname.to_string ().to_str0 ());
-  SCM bookpaper = get_bookpaper (parser)->self_scm ();
+  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 (),
-                      bookpaper,
-                      header, os);
+                      paper,
+                      header, os,
+                      key->self_scm ());
 
   if (score->defs_.is_empty ())
     {
-      Output_def *paper = get_paper (parser);
-      default_rendering (score->get_music(), paper->self_scm (),
-                        get_bookpaper (parser)->self_scm (),
-                        header, os);
-      scm_gc_unprotect_object (paper->self_scm ());
+      Output_def *layout = get_layout (parser);
+      default_rendering (score->get_music(), layout->self_scm (),
+                        get_paper (parser)->self_scm (),
+                        header, os, key->self_scm ());
+      scm_gc_unprotect_object (layout->self_scm ());
     }
+
+  scm_gc_unprotect_object (key->self_scm ());
   return SCM_UNSPECIFIED;
 }
 
@@ -474,13 +498,13 @@ LY_DEFINE (ly_parser_print_book, "ly:parser-print-book",
 {
   Lily_parser *parser = unsmob_my_lily_parser (parser_smob);
   Book *book = unsmob_book (book_smob);
-  Output_def *bp = unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultbookpaper"));
+  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->bookpaper_ = bp;
+  book->paper_ = bp;
   
   File_name outname (parser->output_basename_);
   int *c = &parser->book_count_;
@@ -488,15 +512,16 @@ LY_DEFINE (ly_parser_print_book, "ly:parser-print-book",
     outname.base_ += "-" + to_string (*c);
   (*c)++;
 
-  Output_def *paper = get_paper (parser);
-
-  Paper_book* pb = book->process (outname.to_string (), paper);
-
-  pb->output (outname.to_string ());
+  Output_def *layout = get_layout (parser);
+  Paper_book* pb = book->process (outname.to_string (), layout);
   
-  scm_gc_unprotect_object (paper->self_scm ());
-  scm_gc_unprotect_object (pb->self_scm ());
+  if (pb)
+    {
+      pb->output (outname.to_string ());
+      scm_gc_unprotect_object (pb->self_scm ());
+    }
 
+  scm_gc_unprotect_object (layout->self_scm ());
   return SCM_UNSPECIFIED;
 }