From: Jan Nieuwenhuizen Date: Sat, 10 Apr 2004 23:59:16 +0000 (+0000) Subject: * lily/include/paper-line.hh (class Paper_line): New member X-Git-Tag: release/2.3.0~23 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=6d1797ae3c657721dd49ba3bcf52ebd97842d33e;p=lilypond.git * lily/include/paper-line.hh (class Paper_line): New member var penalty_. * lily/system.cc (get_line): Initialise Paper_line with page-penalty's from original grobs. * scm/define-music-properties.scm (all-music-properties): Add page-penalty. * scm/define-grob-properties.scm (all-grob-descriptions): Idem. * lily/score-engraver.cc (try_music): Handle page-penalty. * ly/declarations-init.ly (pagebreak, noPagebreak): New command. --- diff --git a/ChangeLog b/ChangeLog index 9e4816ffac..ffafbbf35f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2004-04-11 Jan Nieuwenhuizen + + * lily/include/paper-line.hh (class Paper_line): New member + var penalty_. + + * lily/system.cc (get_line): Initialise Paper_line with + page-penalty's from original grobs. + + * scm/define-music-properties.scm (all-music-properties): Add + page-penalty. + + * scm/define-grob-properties.scm (all-grob-descriptions): Idem. + + * lily/score-engraver.cc (try_music): Handle page-penalty. + + * ly/declarations-init.ly (pagebreak, noPagebreak): New command. + 2004-04-11 Han-Wen Nienhuys * ly/declarations-init.ly (melismaEnd): typo diff --git a/lily/include/paper-book.hh b/lily/include/paper-book.hh index 91cb699028..ce9f7c3eda 100644 --- a/lily/include/paper-book.hh +++ b/lily/include/paper-book.hh @@ -5,7 +5,6 @@ (c) 2004 Jan Nieuwenhuizen */ - #ifndef PAPER_BOOK_HH #define PAPER_BOOK_HH diff --git a/lily/include/paper-line.hh b/lily/include/paper-line.hh index 1d383a7627..4fa1d50f4a 100644 --- a/lily/include/paper-line.hh +++ b/lily/include/paper-line.hh @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 1997--2004 Han-Wen Nienhuys + (c) 2004 Jan Nieuwenhuizen */ #ifndef PAPER_LINE_HH #define PAPER_LINE_HH @@ -14,18 +14,20 @@ class Paper_line { - DECLARE_SMOBS (Paper_line,) + DECLARE_SMOBS (Paper_line,); SCM stencils_; Offset dim_; bool is_title_; + int penalty_; public: - Paper_line (Offset, SCM, bool = false); + Paper_line (Offset, SCM, int penalty = 0, bool = false); int number_; Offset dim () const; SCM stencils () const; bool is_title () const; + int penalty () const; }; DECLARE_UNSMOB (Paper_line, paper_line); diff --git a/lily/paper-book.cc b/lily/paper-book.cc index 3cea1e1327..7cfd6e10f6 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -29,7 +29,8 @@ stencil2line (Stencil* stil, bool is_title = false) 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), is_title); + SCM_EOL), + -10001 * is_title, is_title); return scm_gc_unprotect_object (pl->self_scm ()); } diff --git a/lily/paper-line.cc b/lily/paper-line.cc index 0b9b26ce65..210dda7d69 100644 --- a/lily/paper-line.cc +++ b/lily/paper-line.cc @@ -12,11 +12,12 @@ #define TITLE_PENALTY -1 -Paper_line::Paper_line (Offset o, SCM stencils, bool is_title) +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 (); } @@ -59,6 +60,12 @@ Paper_line::is_title () const return is_title_; } +int +Paper_line::penalty () const +{ + return penalty_; +} + SCM Paper_line::stencils () const { @@ -85,9 +92,9 @@ LY_DEFINE (ly_paper_line_number, "ly:paper-line-number", LY_DEFINE (ly_paper_line_break_score, "ly:paper-line-break-score", 1, 0, 0, (SCM line), - "Return the score for breaking after @var{line}.") + "Return the score for page break after @var{line}.") { Paper_line *pl = unsmob_paper_line (line); SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line"); - return scm_int2num (int (pl->is_title ()) * TITLE_PENALTY); + return scm_int2num (int (pl->penalty ())); } diff --git a/lily/score-engraver.cc b/lily/score-engraver.cc index 52e0e07842..52e6c63ba3 100644 --- a/lily/score-engraver.cc +++ b/lily/score-engraver.cc @@ -259,30 +259,41 @@ Score_engraver::get_output () } bool -Score_engraver::try_music (Music*r) +Score_engraver::try_music (Music *m) { - bool gotcha = Engraver_group_engraver::try_music (r); + if (Engraver_group_engraver::try_music (m)) + return true; - if (!gotcha && r->is_mus_type ("break-event")) + if (m->is_mus_type ("break-event")) { - gotcha = true; - SCM pen = command_column_->get_property ("penalty"); - Real total_penalty = is_number (pen) - ? ly_scm2double (pen) - : 0.0; - - SCM rpen = r->get_property ("penalty"); - if (is_number (rpen)) - total_penalty += ly_scm2double (rpen); - - if (total_penalty > 10000.0) // ugh. arbitrary. + Real total_penalty = is_number (pen) ? ly_scm2double (pen) : 0.0; + + SCM mpen = m->get_property ("penalty"); + if (is_number (mpen)) + total_penalty += ly_scm2double (mpen); + + command_column_->set_property ("penalty", scm_make_real (total_penalty)); + + /* ugh. arbitrary, hardcoded */ + if (total_penalty > 10000.0) forbid_breaks (); - command_column_->set_property ("penalty", - scm_make_real (total_penalty)); + SCM page_pen = command_column_->get_property ("page-penalty"); + if (is_number (page_pen)) + { + Real total_pp = ly_scm2double (page_pen); + SCM mpage_pen = m->get_property ("page-penalty"); + if (is_number (mpen)) + total_pp += ly_scm2double (mpage_pen); + + // FIXME: this never reaches a grob that System::get_line sees. + command_column_->set_property ("page-penalty", + scm_make_real (total_pp)); + } + return true; } - return gotcha; + return false; } void diff --git a/lily/system.cc b/lily/system.cc index e727f1323f..1274508447 100644 --- a/lily/system.cc +++ b/lily/system.cc @@ -6,6 +6,8 @@ (c) 1996--2004 Han-Wen Nienhuys */ +#include + #include "axis-group-interface.hh" #include "warn.hh" #include "system.hh" @@ -154,7 +156,8 @@ System::get_lines () static void set_loose_columns (System* which, Column_x_positions const *posns) { - for (int i = 0; i < posns->loose_cols_.size (); i++) + int loose_col_count = posns->loose_cols_.size (); + for (int i = 0; i < loose_col_count; i++) { int divide_over = 1; Item *loose = dynamic_cast (posns->loose_cols_[i]); @@ -163,20 +166,19 @@ set_loose_columns (System* which, Column_x_positions const *posns) if (col->system_) continue; - Item * left = 0; - Item * right = 0; - do + Item *left = 0; + Item *right = 0; + while (1) { SCM between = loose->get_property ("between-cols"); if (!is_pair (between)) break; - Item *le = dynamic_cast (unsmob_grob (ly_car (between))); Item *re = dynamic_cast (unsmob_grob (ly_cdr (between))); if (!(le && re)) - break ; + break; if (!left && le) { @@ -185,10 +187,9 @@ set_loose_columns (System* which, Column_x_positions const *posns) left = left->find_prebroken_piece (RIGHT); } - divide_over ++; + divide_over++; loose = right = re->get_column (); } - while (1); if (!right->get_system ()) right = right->find_prebroken_piece (LEFT); @@ -331,14 +332,12 @@ System::get_line () if (Stencil *me = get_stencil ()) stencils = scm_cons (me->smobbed_copy (), stencils); - /* Output stencils in three layers: 0, 1, 2. The default layer is - 1. + /* Output stencils in three layers: 0, 1, 2. Default layer: 1. - Start with layer 3, since scm_cons prepends to list. - - */ + Start with layer 3, since scm_cons prepends to list. */ SCM all = get_property ("all-elements"); - + + Real penalty = 0; for (int i = LAYER_COUNT; i--;) for (SCM s = all; is_pair (s); s = ly_cdr (s)) { @@ -357,19 +356,27 @@ System::get_line () Offset (0, 0)) * Staff_symbol_referencer::staff_space (g); - /* - must copy the stencil, for we cannot change the stencil - cached in G. - */ + /* 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); + + // FIXME: never original + if (1 || g->original_) + { + SCM s = g->get_property ("page-penalty"); + // FIXME: 'page-penalty is never set + // FIXME; page breaking is not discrete at +-10000 + if (is_number (s)) // && fabs (ly_scm2double (s)) < 10000) + penalty += ly_scm2double (s); + } } Interval x (extent (this, X_AXIS)); Interval y (extent (this, Y_AXIS)); Paper_line *pl = new Paper_line (Offset (x.length (), y.length ()), - stencils); + stencils, penalty); scm_gc_unprotect_object (pl->self_scm ()); return pl->self_scm (); diff --git a/ly/declarations-init.ly b/ly/declarations-init.ly index 26d8cc733c..6107ef347e 100644 --- a/ly/declarations-init.ly +++ b/ly/declarations-init.ly @@ -27,8 +27,12 @@ should also set allowBeamBreak, but how to do it "portably"? (ie. also working with lyric sections) %} -break =#(make-event-chord (list (make-penalty-music -10001))) -noBreak = #(make-event-chord (list (make-penalty-music 10001))) + +%% rather name \newline, \newpage ? +break = #(make-event-chord (list (make-penalty-music -10001 0))) +noBreak = #(make-event-chord (list (make-penalty-music 10001 0))) +pagebreak = #(make-event-chord (list (make-penalty-music -10001 -10001))) +noPagebreak = #(make-event-chord (list (make-penalty-music 0 10001))) noBeam = #(make-music 'BeamForbidEvent) pipeSymbol = #(make-music 'BarCheck) diff --git a/ly/property-init.ly b/ly/property-init.ly index 0c554b4b9f..9adcb2bc9b 100644 --- a/ly/property-init.ly +++ b/ly/property-init.ly @@ -77,15 +77,6 @@ cadenzaOff = { \set Timing.measurePosition = #(ly:make-moment 0 1) } -newpage = \notes -{ - \break - %% FIXME: page break penalty should tickle into Paper_line - %% \context Score \applyoutput - %%#(outputproperty-compatibility (make-type-checker 'paper-column-interface) - %% 'between-system-string "\\newpage") -} - % dynamic ly:dir? text script, articulation script ly:dir? oneVoice = #(context-spec-music (make-voice-props-revert) 'Voice) voiceOne = #(context-spec-music (make-voice-props-set 0) 'Voice) diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index 61fe391169..c464392c66 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -349,11 +349,15 @@ pairs.}") (padding ,ly:dimension? "Add this much extra space between objects that are next to each other.") - (penalty ,number? "Penalty for breaking at -this column. 10000 or more means forbid linebreak, -10000 or less -means force linebreak. Other values influence linebreaking decisions + (page-penalty ,number? "Penalty for page break at +this column. 10000 or more means forbid linebreak, -10000 or less +means force page break. Other values influence page breaking decisions as a real penalty.") - + (penalty ,number? "Penalty for line break at +this column. 10000 or more means forbid line break, -10000 or less +means force line break. Other values influence line breaking decisions +as a real penalty.") + (pitch-max ,ly:pitch? "Top pitch for ambitus.") (pitch-min ,ly:pitch? "Bottom pitch for ambitus.") diff --git a/scm/define-music-properties.scm b/scm/define-music-properties.scm index 52d28ed17c..bf7545bba2 100644 --- a/scm/define-music-properties.scm +++ b/scm/define-music-properties.scm @@ -74,7 +74,8 @@ e.g. @code{\\tag #'part ...} could tag a piece of music as only being active in "This pitch was octavated by how many octaves? For chord inversions, this is negative.") (origin ,ly:input-location? "where was this piece of music defined?") - (penalty ,number? "Penalty for break hint.") + (page-penalty ,number? "Penalty for page break hint.") + (penalty ,number? "Penalty for line break hint.") (pitch ,ly:pitch? "the pitch of this note") (pitch-alist ,list? "list of pitches jointly forming the scale of a key signature") (pop-first ,boolean? "Do a revert before we try to do a override on some grob property.") diff --git a/scm/define-music-types.scm b/scm/define-music-types.scm index 68f6357b58..bb6c47b3e7 100644 --- a/scm/define-music-types.scm +++ b/scm/define-music-types.scm @@ -102,9 +102,7 @@ c8-[ c c-] c8") )) (BreakEvent . ( - (description . "Creates a line break. - -Syntax: \\break.") + (description . "Create a line break, Syntax: \\break or page break, Syntax: \\pagebreak.") (internal-class-name . "Event") (types . (general-music break-event event)) diff --git a/scm/music-functions.scm b/scm/music-functions.scm index a878dfde5f..6207329357 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -374,9 +374,10 @@ of beat groupings " (define-public (set-time-signature num den . rest) (ly:export (apply make-time-signature-set `(,num ,den . ,rest)))) -(define-public (make-penalty-music pen) +(define-public (make-penalty-music pen page-pen) (make-music 'BreakEvent - 'penalty pen)) + 'penalty pen + 'page-penalty page-pen)) (define-public (make-articulation name) (make-music 'ArticulationEvent