]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/lexer.ll: lex \score separately.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 31 May 2004 22:31:35 +0000 (22:31 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 31 May 2004 22:31:35 +0000 (22:31 +0000)
* lily/paper-book.cc: junk stencil2line.

* lily/paper-line.cc (Paper_line): construct from Stencil
directly. No futzing with the dimensions.

* lily/include/paper-line.hh (class Paper_line):

* lily/stencil.cc (interpret_stencil_expression): combine-stencil
takes arbitrary number of arguments.

12 files changed:
lily/align-interface.cc
lily/include/paper-line.hh
lily/include/stencil.hh
lily/lexer.ll
lily/paper-book.cc
lily/paper-line.cc
lily/paper-outputter.cc
lily/parser.yy
lily/score.cc
lily/stencil.cc
lily/system.cc
lily/vertical-align-engraver.cc

index 6c08f13de4191dcfad017d2773fa3a24fae6f54a..b3bbf6a07c4f74ee25ec5fbaebadbb6477a0751c 100644 (file)
@@ -128,7 +128,7 @@ Align_interface::align_elements_to_extents (Grob * me, Axis a)
   if (!stacking_dir)
     stacking_dir = DOWN;
   
-  Interval threshold  = robust_scm2interval ( me->get_property ("threshold"), Interval (0, Interval::infinity ()));
+  Interval threshold = robust_scm2interval (me->get_property ("threshold"), Interval (0, Interval::infinity ()));
   
   Array<Interval> dims;
 
index 8c9bee071df02e46b6a92c28059918461cd64e86..61e11807df4101f15755c9e99b603c5b0ca422c9 100644 (file)
@@ -23,7 +23,7 @@ class Paper_line
 public:
   int number_;
 
-  Paper_line (Offset, SCM, int penalty = 0, bool = false);
+  Paper_line (Stencil, int penalty, bool);
 
   Offset dim () const;
   Stencil to_stencil () const;
index f31cc7b897d20bb34958c2ea4a9a3e9940c4bf20..a01c891a813cfc594828f291344a2de929864736 100644 (file)
@@ -20,7 +20,7 @@
 
     It is implemented as a "tree" of scheme expressions, as in
 
-     Expr = combine Expr Expr
+     Expr = combine Expr-list
             | translate Offset Expr
            | origin (ORIGIN) Expr
            | no-origin Expr
index b8a502edc127113667e558202797cd6ebd2ab10a..70d6a8ba573b6378e613a4405242f18c1ea6fbca 100644 (file)
@@ -494,6 +494,9 @@ HYPHEN              --
        \> {
                return '>';
        }
+       \\score {
+               return SCORE;
+       }
        {MARKUPCOMMAND} {
                String str (YYText () + 1);
                SCM s = lookup_markup_command (str);
index 21abd2737db8d0843a965657e6e636ab21855e73..9683445fffd2fb028581b4cfdef21d59eea16b69 100644 (file)
   
  */
 
-// JUNKME
-SCM
-stencil2line (Stencil stil, bool is_title = false)
-{
-  static SCM z;
-  if (!z)
-    z = scm_permanent_object (ly_offset2scm (Offset (0, 0)));
-  Offset dim = Offset (stil.extent (X_AXIS).length (),
-                      stil.extent (Y_AXIS).length ());
-  Paper_line *pl = new Paper_line (dim, scm_cons (stil.smobbed_copy (),
-                                                 SCM_EOL),
-                                  -10001 * is_title, is_title);
-
-  return scm_gc_unprotect_object (pl->self_scm ());
-}
-
 
 Paper_book::Paper_book ()
 {
@@ -319,15 +303,24 @@ Paper_book::lines ()
 
   Stencil title = book_title ();      
   if (!title.is_empty ())
-    lines_ = scm_cons (stencil2line (title, true), lines_);
+    {
+      Paper_line *pl = new Paper_line (title, -10001, true);
+      
+      lines_ = scm_cons (pl->self_scm (), lines_);
+      scm_gc_unprotect_object (pl->self_scm ());
+    }
   
   int score_count = score_lines_.size ();
   for (int i = 0; i < score_count; i++)
     {
       Stencil title = score_title (i);      
       if (!title.is_empty ())
-       lines_ = scm_cons (stencil2line (title, true), lines_);
-
+       {
+         Paper_line *pl = new Paper_line (title, -10001, true);
+         lines_ = scm_cons (pl->self_scm (), lines_);
+         scm_gc_unprotect_object (pl->self_scm ());
+       }
+      
       if (scm_vector_p (score_lines_[i].lines_) == SCM_BOOL_T)
        {
          SCM line_list = scm_vector_to_list (score_lines_[i].lines_); // guh.
index a38c2a82416f5bf0a08edf4aede708474b50a640..eda36f62ebe89eb6ffe17be8cc2eceb6ac2a9590 100644 (file)
@@ -21,27 +21,13 @@ IMPLEMENT_DEFAULT_EQUAL_P (Paper_line);
 #define TITLE_PENALTY -1
 
 
-Paper_line::Paper_line (Offset o, SCM stencils, int penalty, bool is_title)
+Paper_line::Paper_line (Stencil s, int penalty, bool is_title)
 {
   is_title_ = is_title;
   number_ = 0;
   penalty_ = penalty;
   smobify_self ();
-
-
-  /*
-    TODO: we should extend the definition of stencil to allow
-
-    stencil-expr:  LISTOF stencil-expr*
-
-    so that we don't use as much memory for combining the stencils, and
-    can do this conversion in constant time. 
-  */
-  for (SCM s = stencils; ly_c_pair_p (s); s = ly_cdr (s))
-    stencil_.add_stencil (*unsmob_stencil (ly_car (s)));
-
-  Box x (Interval (0, o[X_AXIS]), Interval (0, o[Y_AXIS]));
-  stencil_ = Stencil (x, stencil_.expr ());
+  stencil_ = s;
 }
 
 Paper_line::~Paper_line ()
index f7533b6c657e1f0d20a04a8b6cde7190fe2daa6c..83f37e3b547bb3a10df051f7f39150506f0446d7 100644 (file)
@@ -115,7 +115,7 @@ get_paper_outputter (String outname, String f)
 IMPLEMENT_SMOBS(Paper_outputter);
 IMPLEMENT_DEFAULT_EQUAL_P(Paper_outputter);
 
-LY_DEFINE(ly_outputter_dump_string, "ly:outputter-dump-stencil",
+LY_DEFINE(ly_outputter_dump_stencil, "ly:outputter-dump-stencil",
          2, 0,0, (SCM outputter, SCM stencil),
          "Dump stencil @var{expr} onto @var{outputter}."
          )
@@ -132,7 +132,7 @@ LY_DEFINE(ly_outputter_dump_string, "ly:outputter-dump-stencil",
 }
 
 
-LY_DEFINE(ly_outputter_dump_stencil, "ly:outputter-dump-string",
+LY_DEFINE(ly_outputter_dump_string, "ly:outputter-dump-string",
          2, 0, 0, (SCM outputter, SCM str),
          "Dump @var{str} onto @var{outputter}.")
 {
index 593f7acca5cf07ea8679cedc2627a0d1f0f54ca0..e2b7bda88b334556b415c67e7c6afac5bce72332 100644 (file)
@@ -2450,29 +2450,14 @@ markup:
        | STRING_IDENTIFIER {
                $$ = $1;
        }
-       | {
+       | SCORE {
                SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
                THIS->lexer_->push_note_state (alist_to_hashq (nn));
-       }
-       /* cont */ score_block {
-               /* WIP this is a bit arbitrary,
-                  we should also allow \book or Composite_music.
-                  However, you'd typically want to change paper
-                  settings, and need a \score block anyway.  */
-
+       } '{' score_body '}' {
+               Score * sc = $4;
+               $$ = scm_list_2 (ly_scheme_function ("score-markup"), sc->self_scm ());
+               scm_gc_unprotect_object (sc->self_scm ());
                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);
-               scm_gc_unprotect_object (score->self_scm ());
-               scm_gc_unprotect_object (book->self_scm ());
-               $$ = scm_list_2 (ly_scheme_function ("stencil-markup"), s);
        }
        ;
 
index aaa6663616390f980b9dea08067d0aa5c69b72af..8f0b5d98f29dd1fc111eb5b56859094cfdd6e505 100644 (file)
@@ -43,6 +43,7 @@ Score::~Score ()
 
 IMPLEMENT_SMOBS (Score);
 IMPLEMENT_DEFAULT_EQUAL_P (Score);
+IMPLEMENT_TYPE_P (Score, "ly:score?");
 
 SCM
 Score::mark_smob (SCM s)
@@ -69,7 +70,6 @@ Score::print_smob (SCM , SCM p, scm_print_state*)
   store point & click locations.
   Global to save some time. (Sue us!)
  */
-
 Score::Score (Score const &s)
   : Input (s)
 {
@@ -281,3 +281,46 @@ LY_DEFINE (ly_score_bookify, "ly:score-bookify",
   scm_gc_unprotect_object (book->self_scm ());
   return book->self_scm ();
 }
+
+
+LY_DEFINE (ly_score_embedded_format, "ly:score-embedded-format",
+          2, 0, 0, (SCM score, SCM paper),
+          "Run @var{score} through @var{paper}, a output definition, "
+          " scaled to correct outputscale already,  return a list of paper-lines. ")
+{
+  Score * sc = unsmob_score (score);
+  Output_def *od = unsmob_output_def (paper);
+
+  SCM_ASSERT_TYPE (sc, score, SCM_ARG1, __FUNCTION__, "Score");
+  SCM_ASSERT_TYPE (od, paper, SCM_ARG2, __FUNCTION__, "Output_def");
+
+  SCM lines = SCM_EOL;
+  Output_def * score_def  = 0;
+
+  /*
+    UGR, FIXME, these are default \paper blocks once again. They suck.
+   */
+  for (int i = 0; !score_def && i < sc->defs_.size (); i++)
+    {
+      if (sc->defs_[i]->c_variable ("is-paper") == SCM_BOOL_T)
+       {
+         score_def = sc->defs_[i];
+       }
+    }
+
+  if (!score_def)
+    return lines;
+  
+      
+  score_def = score_def->clone ();
+  SCM prot = score_def->self_scm ();
+  scm_gc_unprotect_object (prot);
+
+  score_def->parent_ = od;
+  
+  SCM context = ly_run_translator (sc->music_, score_def->self_scm ());
+  lines = ly_format_output (context, scm_makfrom0str ("<embedded>"));
+  
+  scm_remember_upto_here_1 (prot);
+  return lines;
+}
index bbca94953efb13023a8626d20e8b352102c7585f..18b73bfb1ed78d54c743fb18408fe703fff07090 100644 (file)
@@ -119,6 +119,8 @@ Stencil::add_stencil (Stencil const &s)
   dim_.unite (s.dim_);
 }
 
+
+
 void
 Stencil::set_empty (bool e)
 {
@@ -223,8 +225,11 @@ interpret_stencil_expression (SCM expr,
        }
       else if (head == ly_symbol2scm ("combine-stencil"))
        {
-         interpret_stencil_expression (ly_cadr (expr), func, func_arg, o);
-         expr = ly_caddr (expr);
+         for (SCM x = ly_cdr (expr); ly_c_pair_p (x); x = ly_cdr (x))
+           {
+             interpret_stencil_expression (ly_car (x), func, func_arg, o);
+           }
+         return ;
        }
       else
        {
index d8485232ab2b83f428705416122fc2a9df0233de..9b8499810f3d54a8a2fe81e0c472a6573d3defc3 100644 (file)
@@ -133,9 +133,9 @@ System::get_lines ()
     progress_indication (_f ("Element count %d.",  count + element_count ()));
 
   int line_count = broken_intos_.size ();
-  SCM lines = scm_c_make_vector (line_count, SCM_UNDEFINED);
+  SCM lines = scm_c_make_vector (line_count, SCM_EOL);
   
-   for (int i = 0; i < line_count; i++)
+  for (int i = 0; i < line_count; i++)
     {
       if (verbose_global_b)
        progress_indication ("[");
@@ -147,7 +147,7 @@ System::get_lines ()
       if (verbose_global_b)
        progress_indication (to_string (i) + "]");
     }
-   return lines;
+  return lines;
 }
 
 /* Find the loose columns in POSNS, and drape them around the columns
@@ -336,6 +336,9 @@ System::get_line ()
      Start with layer 3, since scm_cons prepends to list.  */
   SCM all = get_property ("all-elements");
 
+  SCM exprs = SCM_EOL;
+  SCM *tail = &exprs;
+
   Real penalty = 0;
   for (int i = LAYER_COUNT; i--;)
     for (SCM s = all; ly_c_pair_p (s); s = ly_cdr (s))
@@ -357,16 +360,25 @@ System::get_line ()
 
        /* Must copy the stencil, for we cannot change the stencil
           cached in G.  */
-       SCM my_stencil = stil->smobbed_copy ();
-       unsmob_stencil (my_stencil)->translate (o + extra);
-       stencils = scm_cons (my_stencil, stencils);
 
+       Stencil st = *stil;
+       st.translate (o + extra);
+       *tail = scm_cons (st.expr (), SCM_EOL);
+       tail = SCM_CDRLOC(*tail);
+       
+       /*
+         UGH. back-end should extract this info from the System? 
+        */
        if (g->original_)
          {
+           /*
+             Huh ? penalties from all columns are added ??!! --hwn
+            */
            if (Item *it = dynamic_cast <Item*> (g))
              {
                Grob *col = it->get_column ();
                SCM s = col->get_property ("page-penalty");
+               
                // FIXME; page breaking is not discrete at +-10000
                if (ly_c_number_p (s)) // && fabs (ly_scm2double (s)) < 10000)
                  penalty += ly_scm2double (s);
@@ -376,8 +388,11 @@ System::get_line ()
 
   Interval x (extent (this, X_AXIS));
   Interval y (extent (this, Y_AXIS));
-  Paper_line *pl = new Paper_line (Offset (x.length (), y.length ()),
-                                  stencils, (bool) penalty); // FIXME.
+  Stencil sys_stencil (Box (x,y),
+                      scm_cons (ly_symbol2scm ("combine-stencil"),
+                                exprs));
+  
+  Paper_line *pl = new Paper_line (sys_stencil, (int) penalty, false);
 
   return scm_gc_unprotect_object (pl->self_scm ());
 }
index 625b96391f9b7f42b33cc3d8fd063673f197106a..7ad89b9b345be5986f1accdbdf8cd957e0be878a 100644 (file)
@@ -35,9 +35,8 @@ Vertical_align_engraver::process_music ()
 {
   if (!valign_)
     {
-      valign_ =make_spanner ("VerticalAlignment", SCM_EOL);
+      valign_ = make_spanner ("VerticalAlignment", SCM_EOL);
       valign_->set_bound (LEFT,unsmob_grob (get_property ("currentCommandColumn")));
-      
     }
 }
 
@@ -47,7 +46,7 @@ Vertical_align_engraver::finalize ()
   if (valign_)
     {
       valign_->set_bound (RIGHT,unsmob_grob (get_property ("currentCommandColumn")));
-      valign_ =0;
+      valign_ = 0;
     }
 }