]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/include/paper-line.hh (class Paper_line): New member
authorJan Nieuwenhuizen <janneke@gnu.org>
Sat, 10 Apr 2004 23:59:16 +0000 (23:59 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Sat, 10 Apr 2004 23:59:16 +0000 (23:59 +0000)
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.

13 files changed:
ChangeLog
lily/include/paper-book.hh
lily/include/paper-line.hh
lily/paper-book.cc
lily/paper-line.cc
lily/score-engraver.cc
lily/system.cc
ly/declarations-init.ly
ly/property-init.ly
scm/define-grob-properties.scm
scm/define-music-properties.scm
scm/define-music-types.scm
scm/music-functions.scm

index 9e4816fface82a9b3f7e6b25954309421f3a7c50..ffafbbf35fdd4469230e408b1a78dbe509d930d8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2004-04-11  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+       * 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   <hanwen@xs4all.nl>
 
        * ly/declarations-init.ly (melismaEnd): typo
index 91cb699028a7646ae50b7c804bd76242d0705e0c..ce9f7c3edac3d39512019a6fdadeb16ec839f6e0 100644 (file)
@@ -5,7 +5,6 @@
 
   (c) 2004  Jan Nieuwenhuizen <janneke@gnu.org>
 */
-
 #ifndef PAPER_BOOK_HH
 #define PAPER_BOOK_HH
 
index 1d383a7627b831538aecaa0c772122f786c0be16..4fa1d50f4a919def4c787c71fb8b4770e11d4052 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 2004  Jan Nieuwenhuizen <janneke@gnu.org>
 */
 #ifndef PAPER_LINE_HH
 #define PAPER_LINE_HH
 
 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);
index 3cea1e132716a49663f2595f28cf7f35a6fe34f8..7cfd6e10f6e0af4314ad719d083e09a3b943309d 100644 (file)
@@ -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 ());
 }
index 0b9b26ce65bfacbfabbeabc9c528f179bfd04fda..210dda7d69dfb160b899c29d9b533e9ddf736578 100644 (file)
 
 #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 ()));
 }
index 52e0e07842fc17e6648313c865954b076f96afec..52e6c63ba32f4ac075ba5813546d4c25d134f748 100644 (file)
@@ -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
index e727f1323fbf211e7afc355c5d27eafd4c38879c..12745084471d565273c278de025a2e32e14fdde7 100644 (file)
@@ -6,6 +6,8 @@
   (c) 1996--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
+#include <math.h>
+
 #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<Item*> (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<Item*> (unsmob_grob (ly_car (between)));
          Item *re = dynamic_cast<Item*> (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 ();
index 26d8cc733c21eaf82942364a388a89c85b330643..6107ef347e2bf0d657de1b98a8eed02b2bae359a 100644 (file)
@@ -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)
index 0c554b4b9ff45b9df9621ac8fa2cffcc74a28bf7..9adcb2bc9b3034059d92adb839bd48a14666ade0 100644 (file)
@@ -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)
index 61fe3911694a7185cd31d457fa615899b7e22d9d..c464392c665c84ab796203c1d10da2c306febd28 100644 (file)
@@ -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.")
 
index 52d28ed17c256cd1caa4d43b2e6e232ba52e3300..bf7545bba2af94138c4cc99501bf56bd6f93b6b2 100644 (file)
@@ -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.")
index 68f6357b588c431999c24d022b6ac4b0f8bc8434..bb6c47b3e7199b7cd32e5c00597cb034849f7a15 100644 (file)
@@ -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))
index a878dfde5f3231a863645f924d6e552d873e743d..6207329357acf94246067b5b2936139ae487f5fb 100644 (file)
@@ -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