]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/paper-line.cc (Paper_line): don't store list of stencils,
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 7 May 2004 23:43:22 +0000 (23:43 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 7 May 2004 23:43:22 +0000 (23:43 +0000)
but convert to single Stencil immediately.

* lily/paper-book.cc (title): don't return Stencil* but Stencil.

12 files changed:
ChangeLog
lily/include/book.hh
lily/include/my-lily-parser.hh
lily/include/paper-book.hh
lily/include/paper-line.hh
lily/include/stencil.hh
lily/ly-module.cc
lily/paper-book.cc
lily/paper-line.cc
lily/parser.yy
lily/score.cc
lily/system.cc

index d66a9cc1e4fe537db4fbbcf5603a37e851516f35..4e4708f8d0238742e85cfe16c6ec327914089d08 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2004-05-08  Han-Wen Nienhuys   <hanwen@xs4all.nl>
+
+       * lily/paper-line.cc (Paper_line): don't store list of stencils,
+       but convert to single Stencil immediately.
+
+       * lily/paper-book.cc (title): don't return Stencil* but Stencil.
+
 2004-05-07  Jan Nieuwenhuizen  <janneke@gnu.org>
 
        * scm/output-sodipodi.scm: Resurrect sodipodi output.
index c9191e63f9d0bb61c9e253f9418bf8cef91cb24f..7e65d51b217a78ea9105c2a0732e03810c867c6e 100644 (file)
@@ -11,7 +11,6 @@
 
 #include "input.hh"
 #include "lily-proto.hh"
-
 #include "parray.hh"
 #include "smobs.hh"
 
index 2742ec7530e8752a69c48f90ba0b0a1ecb224a03..7c1ae9279eb84e243286719112009aaa85af896c 100644 (file)
@@ -56,7 +56,7 @@ public:
   My_lily_parser (My_lily_parser const&);
 
   DECLARE_SCHEME_CALLBACK (paper_description, ());
-  
+
   Input here_input () const;
   Input pop_spot ();
   void beam_check (SCM); 
@@ -79,4 +79,6 @@ SCM ly_parser_print_score (SCM, SCM);
 SCM ly_parser_bookify (SCM, SCM);
 SCM ly_parser_scorify (SCM, SCM);
 
+Music_output_def *get_paper (My_lily_parser *parser);
+
 #endif /* MY_LILY_PARSER_HH */
index cdba4e42479e0950983711139c6bf7de6ed8d1b8..1e2c516377e3b428ff0984229a8fb4da052dc163 100644 (file)
@@ -32,7 +32,7 @@ public:
   SCM lines ();
   SCM pages ();
   SCM scopes (int);
-  Stencil *title (int);
+  Stencil title (int);
   void classic_output (String);
   void init ();
   void output (String);
index d336296ab40041573b828583f25d20635110f6bf..771c77efc6874e906085582f2434cc7441ab3083 100644 (file)
 #include "lily-proto.hh"
 #include "smobs.hh"
 #include "offset.hh"
+#include "stencil.hh"
 
 class Paper_line
 {
   DECLARE_SMOBS (Paper_line, );
-  SCM stencils_;
-  Offset dim_;
+  Stencil stencil_;
   bool is_title_;
   int penalty_;
   
index 58d8e566ed27ec4c33ac8627601dbce43f0d2426..311b6eff188b0f45c268c91f011da91aae5269b7 100644 (file)
     SCHEME is a Scheme expression that --when eval'd-- produces the
     desired output.  
 
-
-    Because of the way that Stencil is implemented, it is the most
-    efficient to add "fresh" stencils to what you're going to build.
+    Notes:
     
-    Dimension behavior:
+    * Because of the way that Stencil is implemented, it is the most
+    efficient to add "fresh" stencils to what you're going to build.
 
-    Empty stencils have empty dimensions.  If add_at_edge is used to
+    * Do not create Stencil objects on the heap. That includes passing
+    around Stencil* which are produced by unsmob_stencil().
+    
+    * Empty stencils have empty dimensions.  If add_at_edge is used to
     init the stencil, we assume that
-    DIMENSIONS = (Interval (0,0),Interval (0,0)
+
+      DIMENSIONS = (Interval (0,0),Interval (0,0)
 */
 class Stencil
 {
index e536e9503a8aff2c3813013a59167fc32f09dd7e..f93eeb2922ca7ffa2832cb5faac052e83b37b606 100644 (file)
@@ -100,6 +100,10 @@ ly_module_lookup (SCM module, SCM sym)
 #undef FUNC_NAME
 }
 
+/*
+  Lookup SYM in a list of modules, which do not have to be related.
+  Return the first instance.
+ */
 SCM
 ly_modules_lookup (SCM modules, SCM sym)
 {
index d04112b9ec9b129ecaf4bc9946e3d5d0bec3c482..c986136fc103f86fc9e52c4c8f0fabb9b209932c 100644 (file)
 
 // JUNKME
 SCM
-stencil2line (Stencil *stil, bool is_title = false)
+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 (),
+  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);
 
@@ -135,28 +135,31 @@ Paper_book::scopes (int i)
   return scopes;
 }
 
-Stencil*
+Stencil
 Paper_book::title (int i)
 {
+  /*
+    TODO: get from book-paper definition.
+   */
   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 field = (i == 0 ? ly_symbol2scm ("bookTitle")
               : ly_symbol2scm ("scoreTitle"));
 
-  Stencil *title = 0;
+  Stencil title;
   SCM scopes = this->scopes (i);
   SCM s = ly_modules_lookup (scopes, field);
   if (s != SCM_UNDEFINED && scm_variable_bound_p (s) == SCM_BOOL_T)
-    title = unsmob_stencil (scm_call_2 (user_title,
+    title = *unsmob_stencil (scm_call_2 (user_title,
                                        papers_[0]->self_scm (),
                                        scm_variable_ref (s)));
   else
-    title = unsmob_stencil (scm_call_2 (i == 0 ? book_title : score_title,
+    title = *unsmob_stencil (scm_call_2 (i == 0 ? book_title : score_title,
                                        papers_[0]->self_scm (),
                                        scopes));
-  if (title)
-    title->align_to (Y_AXIS, UP);
+  if (!title.is_empty ())
+    title.align_to (Y_AXIS, UP);
   
   return title;
 }
@@ -202,9 +205,9 @@ Paper_book::init ()
   height_ = 0;
   for (int i = 0; i < score_count; i++)
     {
-      Stencil *title = this->title (i);
-      if (title)
-       height_ += title->extent (Y_AXIS).length ();
+      Stencil title = this->title (i);
+      if (!title.is_empty ())
+       height_ += title.extent (Y_AXIS).length ();
 
       int line_count = SCM_VECTOR_LENGTH ((SCM) scores_[i]);
       for (int j = 0; j < line_count; j++)
@@ -239,7 +242,8 @@ Paper_book::lines ()
   SCM lines = SCM_EOL;
   for (int i = 0; i < score_count; i++)
     {
-      if (Stencil *title = this->title (i))
+      Stencil title = this->title (i);      
+      if (!title.is_empty ())
        lines = ly_snoc (stencil2line (title, true), lines);
       lines = scm_append (scm_list_2 (lines, scm_vector_to_list (scores_[i])));
     }
index ee258154475cf8ee27b58463187a5f8ded1e309b..56c97c7ea1168f3368e7cf6df7e928599675acda 100644 (file)
 
 Paper_line::Paper_line (Offset o, SCM stencils, int penalty, bool is_title)
 {
-  dim_ = o;
-  stencils_ = stencils;
   is_title_ = is_title;
   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 ());
 }
 
 Paper_line::~Paper_line ()
@@ -35,7 +48,7 @@ SCM
 Paper_line::mark_smob (SCM smob)
 {
   Paper_line *line = (Paper_line*) ly_cdr (smob);
-  return line->stencils_;
+  return line-> stencil_.expr ();
 }
 
 int
@@ -51,12 +64,6 @@ Paper_line::print_smob (SCM smob, SCM port, scm_print_state*)
   return 1;
 }
 
-Offset
-Paper_line::dim () const
-{
-  return dim_;
-}
-
 bool
 Paper_line::is_title () const
 {
@@ -69,22 +76,17 @@ Paper_line::penalty () const
   return penalty_;
 }
 
-SCM
-Paper_line::stencils () const
+Offset
+Paper_line::dim () const
 {
-  return stencils_;
+  return Offset (stencil_.extent (X_AXIS).length (),
+                stencil_.extent (Y_AXIS).length ());
 }
 
 SCM
 Paper_line::to_stencil () const
 {
-  Stencil stencil;
-  for (SCM s = stencils_; ly_c_pair_p (s); s = ly_cdr (s))
-    stencil.add_stencil (*unsmob_stencil (ly_car (s)));
-  Offset o = dim ();
-  Box x (Interval (0, o[X_AXIS]), Interval (0, o[Y_AXIS]));
-  stencil = Stencil (x, stencil.expr ());
-  return stencil.smobbed_copy ();
+  return stencil_.smobbed_copy ();
 }
 
 LY_DEFINE (ly_paper_line_height, "ly:paper-line-height",
index 33d9e0e4a647b6eb24cd98ef6ec03623d3bef0aa..d785497338c80b009070b2870d14eb63c2033c36 100644 (file)
@@ -2528,7 +2528,7 @@ markup:
                Score *score = $1;
                Book *book = new Book;
                book->scores_.push (score);
-               extern Music_output_def* get_paper (My_lily_parser *parser);
+
                Music_output_def *paper = get_paper (THIS);
                SCM s = book->to_stencil (paper, THIS->header_);
                scm_gc_unprotect_object (score->self_scm ());
index c5c284b1f1e3fadbcd404bb7a986a63281cd7dd3..e194241fd28e382700e4803f58f181ac92b094a4 100644 (file)
@@ -215,10 +215,7 @@ LY_DEFINE (ly_score_bookify, "ly:score-bookify",
           (SCM score_smob),
           "Return SCORE encapsulated in a BOOK.")
 {
-#if 0
-  SCM_ASSERT_TYPE (ly_c_parser_p (parser_smob), parser_smobd, SCM_ARG1, __FUNCTION__, "parser_smob");
-  SCM_ASSERT_TYPE (ly_c_score_p (score_smob), score_smob, SCM_ARG1, __FUNCTION__, "score_smob");
-#endif
+  SCM_ASSERT_TYPE (unsmob_score (score_smob), score_smob, SCM_ARG1, __FUNCTION__, "score_smob");
   
   Score *score = unsmob_score (score_smob);
   Book *book = new Book;
index 177756601f91555a3f0d5f10210ae958b8789b39..72937087f82c2104cfe7a09a2685a2833b08d8f4 100644 (file)
@@ -379,8 +379,7 @@ System::get_line ()
   Paper_line *pl = new Paper_line (Offset (x.length (), y.length ()),
                                   stencils, penalty);
 
-  scm_gc_unprotect_object (pl->self_scm ());
-  return pl->self_scm ();
+  return scm_gc_unprotect_object (pl->self_scm ());
 }
 
 Link_array<Item>