From: Han-Wen Nienhuys Date: Fri, 7 May 2004 23:43:22 +0000 (+0000) Subject: * lily/paper-line.cc (Paper_line): don't store list of stencils, X-Git-Tag: release/2.3.1~11 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=60ca75ba7056c0a829991df19a1c89d7ceec55f0;p=lilypond.git * 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. --- diff --git a/ChangeLog b/ChangeLog index d66a9cc1e4..4e4708f8d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-05-08 Han-Wen Nienhuys + + * 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 * scm/output-sodipodi.scm: Resurrect sodipodi output. diff --git a/lily/include/book.hh b/lily/include/book.hh index c9191e63f9..7e65d51b21 100644 --- a/lily/include/book.hh +++ b/lily/include/book.hh @@ -11,7 +11,6 @@ #include "input.hh" #include "lily-proto.hh" - #include "parray.hh" #include "smobs.hh" diff --git a/lily/include/my-lily-parser.hh b/lily/include/my-lily-parser.hh index 2742ec7530..7c1ae9279e 100644 --- a/lily/include/my-lily-parser.hh +++ b/lily/include/my-lily-parser.hh @@ -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 */ diff --git a/lily/include/paper-book.hh b/lily/include/paper-book.hh index cdba4e4247..1e2c516377 100644 --- a/lily/include/paper-book.hh +++ b/lily/include/paper-book.hh @@ -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); diff --git a/lily/include/paper-line.hh b/lily/include/paper-line.hh index d336296ab4..771c77efc6 100644 --- a/lily/include/paper-line.hh +++ b/lily/include/paper-line.hh @@ -11,12 +11,12 @@ #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_; diff --git a/lily/include/stencil.hh b/lily/include/stencil.hh index 58d8e566ed..311b6eff18 100644 --- a/lily/include/stencil.hh +++ b/lily/include/stencil.hh @@ -28,15 +28,18 @@ 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 { diff --git a/lily/ly-module.cc b/lily/ly-module.cc index e536e9503a..f93eeb2922 100644 --- a/lily/ly-module.cc +++ b/lily/ly-module.cc @@ -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) { diff --git a/lily/paper-book.cc b/lily/paper-book.cc index d04112b9ec..c986136fc1 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -19,14 +19,14 @@ // 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]))); } diff --git a/lily/paper-line.cc b/lily/paper-line.cc index ee25815447..56c97c7ea1 100644 --- a/lily/paper-line.cc +++ b/lily/paper-line.cc @@ -15,11 +15,24 @@ 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", diff --git a/lily/parser.yy b/lily/parser.yy index 33d9e0e4a6..d785497338 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -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 ()); diff --git a/lily/score.cc b/lily/score.cc index c5c284b1f1..e194241fd2 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -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; diff --git a/lily/system.cc b/lily/system.cc index 177756601f..72937087f8 100644 --- a/lily/system.cc +++ b/lily/system.cc @@ -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