From: Han-Wen Nienhuys Date: Mon, 31 May 2004 22:31:35 +0000 (+0000) Subject: * lily/lexer.ll: lex \score separately. X-Git-Tag: release/2.3.4~41 X-Git-Url: https://git.donarmstrong.com/lilypond.git?a=commitdiff_plain;h=c2d7bd9507fb36d3f7da86653e3fb0b905ec2bc1;p=lilypond.git * lily/lexer.ll: lex \score separately. * 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. --- diff --git a/lily/align-interface.cc b/lily/align-interface.cc index 6c08f13de4..b3bbf6a07c 100644 --- a/lily/align-interface.cc +++ b/lily/align-interface.cc @@ -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 dims; diff --git a/lily/include/paper-line.hh b/lily/include/paper-line.hh index 8c9bee071d..61e11807df 100644 --- a/lily/include/paper-line.hh +++ b/lily/include/paper-line.hh @@ -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; diff --git a/lily/include/stencil.hh b/lily/include/stencil.hh index f31cc7b897..a01c891a81 100644 --- a/lily/include/stencil.hh +++ b/lily/include/stencil.hh @@ -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 diff --git a/lily/lexer.ll b/lily/lexer.ll index b8a502edc1..70d6a8ba57 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -494,6 +494,9 @@ HYPHEN -- \> { return '>'; } + \\score { + return SCORE; + } {MARKUPCOMMAND} { String str (YYText () + 1); SCM s = lookup_markup_command (str); diff --git a/lily/paper-book.cc b/lily/paper-book.cc index 21abd2737d..9683445fff 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -24,22 +24,6 @@ */ -// 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. diff --git a/lily/paper-line.cc b/lily/paper-line.cc index a38c2a8241..eda36f62eb 100644 --- a/lily/paper-line.cc +++ b/lily/paper-line.cc @@ -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 () diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index f7533b6c65..83f37e3b54 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -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}.") { diff --git a/lily/parser.yy b/lily/parser.yy index 593f7acca5..e2b7bda88b 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -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); } ; diff --git a/lily/score.cc b/lily/score.cc index aaa6663616..8f0b5d98f2 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -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 ("")); + + scm_remember_upto_here_1 (prot); + return lines; +} diff --git a/lily/stencil.cc b/lily/stencil.cc index bbca94953e..18b73bfb1e 100644 --- a/lily/stencil.cc +++ b/lily/stencil.cc @@ -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 { diff --git a/lily/system.cc b/lily/system.cc index d8485232ab..9b8499810f 100644 --- a/lily/system.cc +++ b/lily/system.cc @@ -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 (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 ()); } diff --git a/lily/vertical-align-engraver.cc b/lily/vertical-align-engraver.cc index 625b96391f..7ad89b9b34 100644 --- a/lily/vertical-align-engraver.cc +++ b/lily/vertical-align-engraver.cc @@ -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; } }