lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: setting the number of pages for a score


From: Joe Neeman
Subject: Re: setting the number of pages for a score
Date: Sun, 19 Feb 2006 17:07:00 +1100
User-agent: Mozilla Thunderbird 1.0.7 (X11/20051121)

And maybe I should attach the patch too...

Joe Neeman wrote:

I've cleaned up most (all?) of the issues that you brought up with my previous code. I've moved some things around to improve readability and I've addressed a few of the performance problems. Also, it is now possible to force (or prevent) starting on the right hand page by using "first-page-right = ##t" in the \paper block. It will still crash if line breaking doesn't satisfy constraints and it still requires manual addition of possible break points.

I'm not so sure about my changes to make-page, but it makes calling make-page from C++ easier and it doesn't adversely affect any current usage...


Index: lily/break-algorithm.cc
===================================================================
RCS file: /sources/lilypond/lilypond/lily/break-algorithm.cc,v
retrieving revision 1.54
diff -u -r1.54 break-algorithm.cc
--- lily/break-algorithm.cc     11 Feb 2006 11:35:18 -0000      1.54
+++ lily/break-algorithm.cc     19 Feb 2006 05:36:33 -0000
@@ -89,7 +89,7 @@
 }
 
 vector<Column_x_positions>
-Break_algorithm::solve () const
+Break_algorithm::solve ()
 {
   vector<Column_x_positions> h= do_solve ();
 
Index: lily/gourlay-breaking.cc
===================================================================
RCS file: /sources/lilypond/lilypond/lily/gourlay-breaking.cc,v
retrieving revision 1.93
diff -u -r1.93 gourlay-breaking.cc
--- lily/gourlay-breaking.cc    11 Feb 2006 11:35:18 -0000      1.93
+++ lily/gourlay-breaking.cc    19 Feb 2006 05:36:34 -0000
@@ -75,7 +75,7 @@
    inspiration.
 */
 vector<Column_x_positions>
-Gourlay_breaking::do_solve () const
+Gourlay_breaking::do_solve ()
 {
   vector<Break_node> optimal_paths;
   vector<Grob*> all
Index: lily/paper-book.cc
===================================================================
RCS file: /sources/lilypond/lilypond/lily/paper-book.cc,v
retrieving revision 1.132
diff -u -r1.132 paper-book.cc
--- lily/paper-book.cc  15 Feb 2006 13:02:17 -0000      1.132
+++ lily/paper-book.cc  19 Feb 2006 05:36:39 -0000
@@ -381,7 +381,7 @@
 
   pages_ = SCM_EOL;
   SCM proc = paper_->c_variable ("page-breaking");
-  pages_ = scm_apply_0 (proc, scm_list_2 (systems (), self_scm ()));
+  pages_ = scm_apply_0 (proc, scm_list_1(self_scm ()));
   return pages_;
 }
 
Index: lily/paper-score.cc
===================================================================
RCS file: /sources/lilypond/lilypond/lily/paper-score.cc,v
retrieving revision 1.97
diff -u -r1.97 paper-score.cc
--- lily/paper-score.cc 15 Feb 2006 02:06:30 -0000      1.97
+++ lily/paper-score.cc 19 Feb 2006 05:36:39 -0000
@@ -28,7 +28,7 @@
   layout_ = layout;
   system_ = 0;
   systems_ = SCM_EOL;
-  paper_systems_ = SCM_EOL;
+  paper_systems_ = SCM_BOOL_F;
 }
 
 Paper_score::Paper_score (Paper_score const &s)
@@ -91,11 +91,6 @@
   pc.back ()->set_property ("breakable", SCM_BOOL_T);
 
   system_->pre_processing ();
-
-  vector<Column_x_positions> breaking = calc_breaking ();
-  system_->break_into_pieces (breaking);
-
-  paper_systems_ = system_->get_paper_systems ();
 }
 
 System *
@@ -111,8 +106,14 @@
 }
 
 SCM
-Paper_score::get_paper_systems () const
+Paper_score::get_paper_systems ()
 {
+  if (paper_systems_ == SCM_BOOL_F)
+    {
+      vector<Column_x_positions> breaking = calc_breaking ();
+      system_->break_into_pieces (breaking);
+      paper_systems_ = system_->get_paper_systems ();
+    }
   return paper_systems_;
 }
 
Index: lily/system.cc
===================================================================
RCS file: /sources/lilypond/lilypond/lily/system.cc,v
retrieving revision 1.138
diff -u -r1.138 system.cc
--- lily/system.cc      11 Feb 2006 11:35:17 -0000      1.138
+++ lily/system.cc      19 Feb 2006 05:36:39 -0000
@@ -205,7 +205,7 @@
   for (vsize i = 0; i < breaking.size (); i++)
     {
       System *system = dynamic_cast<System *> (clone (i));
-      system->rank_ = i;
+      system->rank_ = broken_intos_.size ();
 
       vector<Grob*> c (breaking[i].cols_);
       pscore_->typeset_system (system);
Index: lily/include/break-algorithm.hh
===================================================================
RCS file: /sources/lilypond/lilypond/lily/include/break-algorithm.hh,v
retrieving revision 1.31
diff -u -r1.31 break-algorithm.hh
--- lily/include/break-algorithm.hh     11 Feb 2006 11:35:17 -0000      1.31
+++ lily/include/break-algorithm.hh     19 Feb 2006 05:36:39 -0000
@@ -30,14 +30,14 @@
 
   Simple_spacer_wrapper *generate_spacing_problem (vector<Grob*> const &,
                                                   Interval) const;
-  virtual vector<Column_x_positions> do_solve () const = 0;
+  virtual vector<Column_x_positions> do_solve () = 0;
 
 public:
   virtual ~Break_algorithm ();
   Simple_spacer *(*get_line_spacer) ();
   Break_algorithm ();
   void set_pscore (Paper_score *);
-  vector<Column_x_positions> solve () const;
+  vector<Column_x_positions> solve ();
 };
 
 #endif // BREAK_HH
Index: lily/include/gourlay-breaking.hh
===================================================================
RCS file: /sources/lilypond/lilypond/lily/include/gourlay-breaking.hh,v
retrieving revision 1.21
diff -u -r1.21 gourlay-breaking.hh
--- lily/include/gourlay-breaking.hh    11 Feb 2006 11:35:16 -0000      1.21
+++ lily/include/gourlay-breaking.hh    19 Feb 2006 05:36:39 -0000
@@ -16,7 +16,7 @@
 */
 struct Gourlay_breaking : public Break_algorithm
 {
-  vector<Column_x_positions> do_solve () const;
+  vector<Column_x_positions> do_solve ();
   Gourlay_breaking ();
   Real combine_demerits (Column_x_positions const &, Column_x_positions const 
&) const;
 };
Index: lily/include/paper-score.hh
===================================================================
RCS file: /sources/lilypond/lilypond/lily/include/paper-score.hh,v
retrieving revision 1.39
diff -u -r1.39 paper-score.hh
--- lily/include/paper-score.hh 11 Feb 2006 11:35:16 -0000      1.39
+++ lily/include/paper-score.hh 19 Feb 2006 05:36:39 -0000
@@ -30,7 +30,7 @@
   void typeset_system (System *);
   vector<Column_x_positions> calc_breaking ();
 
-  SCM get_paper_systems () const;
+  SCM get_paper_systems ();
 protected:
   virtual void process ();
   virtual void derived_mark () const;
Index: ly/paper-defaults.ly
===================================================================
RCS file: /sources/lilypond/lilypond/ly/paper-defaults.ly,v
retrieving revision 1.22
diff -u -r1.22 paper-defaults.ly
--- ly/paper-defaults.ly        10 Feb 2006 12:27:42 -0000      1.22
+++ ly/paper-defaults.ly        19 Feb 2006 05:36:39 -0000
@@ -57,6 +57,12 @@
     %%
     between-system-padding = #(* 4 mm)
 
+    %%
+    %% the assumed system height that we use for page-breaking
+    system-height = #8
+    blank-page-force = 15
+    blank-last-page-force = 0
+
     after-title-space = 5 \mm
     before-title-space = 10 \mm
     between-title-space = 2 \mm
Index: scm/layout-page-layout.scm
===================================================================
RCS file: /sources/lilypond/lilypond/scm/layout-page-layout.scm,v
retrieving revision 1.15
diff -u -r1.15 layout-page-layout.scm
--- scm/layout-page-layout.scm  16 Feb 2006 02:17:51 -0000      1.15
+++ scm/layout-page-layout.scm  19 Feb 2006 05:36:41 -0000
@@ -136,6 +136,150 @@
   (if (ly:output-def-lookup layout 'write-page-layout #f)
       (write-page-breaks pages)))
 
+(define-public (space-systems paper-book page-height lines ragged?)
+  (define paper (ly:paper-book-paper paper-book))
+  (let* ((global-inter-system-space
+          (ly:output-def-lookup paper 'between-system-space))
+         (top-space
+          (ly:output-def-lookup paper 'page-top-space))
+         (global-fixed-dist (ly:output-def-lookup paper 
'between-system-padding))
+         
+         (system-vector (list->vector
+                         (append lines
+                                 (if (<= (length lines) 1)
+                                     '(#f)
+                                     '()))))
+         (staff-extents
+          (list->vector
+           (append (map paper-system-staff-extents lines)
+                   (if (<= (length lines) 1)
+                       '((0 . 0))
+                       '()))))
+
+         (real-extents
+          (list->vector
+           (append
+            (map
+             (lambda (sys) (paper-system-extent sys Y)) lines)
+            (if (<= (length lines) 1)
+                '((0 .  0))
+                '()))))
+         
+         (system-count (vector-length real-extents))
+         (topskip (max
+                   (+
+                    top-space
+                    (interval-end (vector-ref staff-extents 0)))
+                   (interval-end (vector-ref real-extents 0))
+                   ))
+         (last-system (vector-ref system-vector (1- system-count)))
+         (bottom-space (if (ly:prob? last-system)
+                           (ly:prob-property last-system 'bottom-space 0.0)
+                           0.0))
+         (space-left (- page-height
+                        bottom-space
+                        (apply + (map interval-length
+                                      (vector->list real-extents)))))
+
+         (space (- page-height
+                   topskip
+                   bottom-space
+                   (-  (interval-start
+                        (vector-ref real-extents (1- system-count))))))
+
+         (calc-spring
+          (lambda (idx)
+            (let* (
+                   (upper-system (vector-ref system-vector idx))
+                   (between-space (ly:prob-property upper-system 'next-space
+                                                            
global-inter-system-space))
+                   (fixed-dist (ly:prob-property upper-system 'next-padding
+                                                         global-fixed-dist))
+                   
+                   (this-system-ext (vector-ref staff-extents idx))
+                   (next-system-ext (vector-ref staff-extents (1+ idx)))
+                   (fixed (max 0 (- (+ (interval-end next-system-ext)
+                                       fixed-dist)
+                                    (interval-start this-system-ext))))
+                   (title1? (and (vector-ref system-vector idx)
+                                 (paper-system-title? (vector-ref 
system-vector idx)
+                                                           )))
+                   (title2? (and
+                             (vector-ref system-vector (1+ idx))
+                             (paper-system-title? (vector-ref system-vector 
(1+ idx)))))
+                   (ideal (+
+                           (cond
+                            ((and title2? title1?)
+                             (ly:output-def-lookup paper 'between-title-space))
+                            (title1?
+                             (ly:output-def-lookup paper 'after-title-space))
+                            (title2?
+                             (ly:output-def-lookup paper 'before-title-space))
+                            (else between-space))
+                           fixed))
+                   (hooke (/ 1 (- ideal fixed))))
+              (list ideal hooke))))
+
+         (springs (map calc-spring (iota (1- system-count))))
+         (calc-rod
+          (lambda (idx)
+            (let* (
+                   (upper-system (vector-ref system-vector idx))
+                   (fixed-dist (ly:prob-property upper-system 'next-padding
+                                                         global-fixed-dist))
+                   (this-system-ext (vector-ref real-extents idx))
+                   (next-system-ext (vector-ref real-extents (1+ idx)))
+                   
+                   (distance (max  (- (+ (interval-end next-system-ext)
+                                         fixed-dist)
+                                      (interval-start this-system-ext)
+                                      ) 0))
+                   (entry (list idx (1+ idx) distance)))
+              entry)))
+         (rods (map calc-rod (iota (1- system-count))))
+
+         ;; we don't set ragged based on amount space left.
+         ;; ragged-bottomlast = ##T is much more predictable
+         (result (ly:solve-spring-rod-problem
+                  springs rods space
+                  ragged?))
+
+         (force (car result))
+         (positions
+          (map (lambda (y)
+                 (+ y topskip))
+               (cdr  result))))
+
+    (if #f ;; debug.
+        (begin
+          (display (list "\n# systems: " system-count
+                         "\nreal-ext" real-extents "\nstaff-ext" staff-extents
+                         "\ninterscore" global-inter-system-space
+                         "\nspace-left" space-left
+                         "\nspring,rod" springs rods
+                         "\ntopskip " topskip
+                         " space " space
+                         "\npage-height" page-height
+                         "\nragged" ragged?
+                         "\nforce" force
+                         "\nres" (cdr result)
+                         "\npositions" positions "\n"))))
+
+    (cons force positions)))
+
+(define-public (make-page-from-systems p-book lines p-num prev ragged? last?)
+  (let*
+    ((page (make-page
+            p-book
+            'lines lines
+            'page-number p-num
+            'prev prev
+            'is-last last?))
+     (height (page-printable-height page))
+     (posns (cdr (space-systems p-book height lines ragged?))))
+    (page-set-property! page 'configuration posns)
+    page))
+
 ;; Optimal distribution of
 ;; lines over pages; line breaks are a given.
 
@@ -145,14 +289,14 @@
 ;; - separate function for word-wrap style breaking?
 ;; - ragged-bottom? ragged-last-bottom?
 
-(define-public (optimal-page-breaks lines paper-book)
+(define-public (optimal-page-breaks paper-book)
   "Return pages as a list starting with 1st page. Each page is a 'page Prob."
 
   (define MAXPENALTY 1e9)
   (define paper (ly:paper-book-paper paper-book))
+  (define lines (ly:paper-book-systems paper-book))
 
   ;; ugh.
-  (define page-alist (layout->page-init (ly:paper-book-paper paper-book))) 
   (define scopes (ly:paper-book-scopes paper-book))
   (define force-equalization-factor #f)
   (define (get-path node done)
@@ -181,136 +325,6 @@
                                         inter-system-space))
         user)))
 
-  (define (space-systems page-height lines ragged?)
-    (let* ((global-inter-system-space
-           (ly:output-def-lookup paper 'between-system-space))
-          (top-space
-           (ly:output-def-lookup paper 'page-top-space))
-          (global-fixed-dist (ly:output-def-lookup paper 
'between-system-padding))
-          
-          (system-vector (list->vector
-                          (append lines
-                                  (if (= (length lines) 1)
-                                      '(#f)
-                                      '()))))
-          (staff-extents
-           (list->vector
-            (append (map paper-system-staff-extents lines)
-                    (if (= (length lines) 1)
-                        '((0 . 0))
-                        '()))))
-
-          (real-extents
-           (list->vector
-            (append
-             (map
-              (lambda (sys) (paper-system-extent sys Y)) lines)
-             (if (= (length lines) 1)
-                 '((0 .  0))
-                 '()))))
-          
-          (system-count (vector-length real-extents))
-          (topskip (max
-                    (+
-                     top-space
-                     (interval-end (vector-ref staff-extents 0)))
-                    (interval-end (vector-ref real-extents 0))
-                    ))
-          (last-system (vector-ref system-vector (1- system-count)))
-          (bottom-space (if (ly:prob? last-system)
-                            (ly:prob-property last-system 'bottom-space 0.0)
-                            0.0))
-          (space-left (- page-height
-                         bottom-space
-                         (apply + (map interval-length
-                                       (vector->list real-extents)))))
-
-          (space (- page-height
-                    topskip
-                    bottom-space
-                    (-  (interval-start
-                         (vector-ref real-extents (1- system-count))))))
-
-          (calc-spring
-           (lambda (idx)
-             (let* (
-                    (upper-system (vector-ref system-vector idx))
-                    (between-space (ly:prob-property upper-system 'next-space
-                                                             
global-inter-system-space))
-                    (fixed-dist (ly:prob-property upper-system 'next-padding
-                                                          global-fixed-dist))
-                    
-                    (this-system-ext (vector-ref staff-extents idx))
-                    (next-system-ext (vector-ref staff-extents (1+ idx)))
-                    (fixed (max 0 (- (+ (interval-end next-system-ext)
-                                        fixed-dist)
-                                     (interval-start this-system-ext))))
-                    (title1? (and (vector-ref system-vector idx)
-                                  (paper-system-title? (vector-ref 
system-vector idx)
-                                                            )))
-                    (title2? (and
-                              (vector-ref system-vector (1+ idx))
-                              (paper-system-title? (vector-ref system-vector 
(1+ idx)))))
-                    (ideal (+
-                            (cond
-                             ((and title2? title1?)
-                              (ly:output-def-lookup paper 
'between-title-space))
-                             (title1?
-                              (ly:output-def-lookup paper 'after-title-space))
-                             (title2?
-                              (ly:output-def-lookup paper 'before-title-space))
-                             (else between-space))
-                            fixed))
-                    (hooke (/ 1 (- ideal fixed))))
-               (list ideal hooke))))
-
-          (springs (map calc-spring (iota (1- system-count))))
-          (calc-rod
-           (lambda (idx)
-             (let* (
-                    (upper-system (vector-ref system-vector idx))
-                    (fixed-dist (ly:prob-property upper-system 'next-padding
-                                                          global-fixed-dist))
-                    (this-system-ext (vector-ref real-extents idx))
-                    (next-system-ext (vector-ref real-extents (1+ idx)))
-                    
-                    (distance (max  (- (+ (interval-end next-system-ext)
-                                          fixed-dist)
-                                       (interval-start this-system-ext)
-                                       ) 0))
-                    (entry (list idx (1+ idx) distance)))
-               entry)))
-          (rods (map calc-rod (iota (1- system-count))))
-
-          ;; we don't set ragged based on amount space left.
-          ;; ragged-bottomlast = ##T is much more predictable
-          (result (ly:solve-spring-rod-problem
-                   springs rods space
-                   ragged?))
-
-          (force (car result))
-          (positions
-           (map (lambda (y)
-                  (+ y topskip))
-                (cdr  result))))
-
-      (if #f ;; debug.
-         (begin
-           (display (list "\n# systems: " system-count
-                          "\nreal-ext" real-extents "\nstaff-ext" staff-extents
-                          "\ninterscore" global-inter-system-space
-                          "\nspace-left" space-left
-                          "\nspring,rod" springs rods
-                          "\ntopskip " topskip
-                          " space " space
-                          "\npage-height" page-height
-                          "\nragged" ragged?
-                          "\nforce" force
-                          "\nres" (cdr result)
-                          "\npositions" positions "\n"))))
-
-      (cons force positions)))
-
   (define (walk-paths done-lines best-paths current-lines  last? current-best)
     "Return the best optimal-page-break-node that contains
 CURRENT-LINES.  DONE-LINES.reversed ++ CURRENT-LINES is a consecutive
@@ -324,8 +338,7 @@
                               (1+ (page-page-number (car best-paths)))))
 
           (this-page (make-page
-                      page-alist
-                      'paper-book paper-book
+                        paper-book
                       'is-last last?
                       'page-number this-page-num))
 
@@ -335,7 +348,7 @@
                        (and ragged-last?
                             last?)))
            (height (page-printable-height this-page))
-          (vertical-spacing (space-systems height current-lines ragged?))
+          (vertical-spacing (space-systems paper-book height current-lines 
ragged?))
           (satisfied-constraints (car vertical-spacing))
            (force (if satisfied-constraints
                      (if (and last? ragged-last?)
Index: scm/page.scm
===================================================================
RCS file: /sources/lilypond/lilypond/scm/page.scm,v
retrieving revision 1.8
diff -u -r1.8 page.scm
--- scm/page.scm        16 Feb 2006 02:17:51 -0000      1.8
+++ scm/page.scm        19 Feb 2006 05:36:41 -0000
@@ -37,10 +37,11 @@
 
 (define page-module (current-module))
 
-(define (make-page init  . args)
+(define (make-page p-book  . args)
   (let*
       ((p (apply ly:make-prob (append
-                              (list 'page init)
+                              (list 'page (layout->page-init 
(ly:paper-book-paper p-book))
+                         'paper-book p-book)
                               args))))
 
     (page-set-property! p 'head-stencil (page-header p))
@@ -196,7 +197,6 @@
       ((p-book (page-property page 'paper-book))
        (layout (ly:paper-book-paper p-book))
        (scopes (ly:paper-book-scopes p-book))
-       (lines (page-lines page))
        (number (page-page-number page))
        (last? (page-property page 'is-last))
        )
@@ -379,9 +379,6 @@
   (let*
       ((p-book (page-property page 'paper-book))
        (layout (ly:paper-book-paper p-book))
-       (scopes (ly:paper-book-scopes p-book))
-       (number (page-page-number page))
-       (last? (page-property page 'is-last))
        (h (- (ly:output-def-lookup layout 'paper-height)
               (ly:output-def-lookup layout 'top-margin)
               (ly:output-def-lookup layout 'bottom-margin)))
Index: scm/paper.scm
===================================================================
RCS file: /sources/lilypond/lilypond/scm/paper.scm,v
retrieving revision 1.65
diff -u -r1.65 paper.scm
--- scm/paper.scm       6 Feb 2006 01:13:59 -0000       1.65
+++ scm/paper.scm       19 Feb 2006 05:36:42 -0000
@@ -7,6 +7,7 @@
 (define-public (set-paper-dimension-variables mod)
   (module-define! mod 'dimension-variables
                  '(pt mm cm in staff-height staff-space
+           system-height
                       page-top-space
                       between-system-space between-system-padding
                       line-width indent paper-width paper-height 
horizontal-shift

reply via email to

[Prev in Thread] Current Thread [Next in Thread]