]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-score.cc
* lily/system.cc (spanner_count): new function
[lilypond.git] / lily / paper-score.cc
1 /*
2   paper-score.cc -- implement Paper_score
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "score.hh"
10 #include "main.hh"
11 #include "warn.hh"
12 #include "font-metric.hh"
13 #include "spanner.hh"
14 #include "paper-def.hh"
15 #include "system.hh"
16 #include "paper-column.hh"
17 #include "paper-score.hh"
18 #include "paper-column.hh"
19 #include "scm-hash.hh"
20 #include "gourlay-breaking.hh"
21 #include "paper-outputter.hh"
22 #include "input-file-results.hh"
23 #include "misc.hh"
24 #include "all-font-metrics.hh"
25
26 Paper_score::Paper_score ()
27 {
28   paper_ =0;
29   outputter_ =0;
30   system_ = 0;
31   main_smob_ = SCM_EOL;
32 }
33
34 void
35 Paper_score::typeset_line (System *l)
36 {
37   if (!system_)
38     {
39       system_ = l;              // ugh.
40     }
41   main_smob_ = gh_cons (l->self_scm (), main_smob_);
42   l->pscore_ = this;
43
44   /*
45     We don't unprotect l->self_scm (), we haven't got any place else to
46     protect it from collection.  */
47
48 }
49
50 Paper_score::Paper_score (Paper_score const &s)
51   : Music_output (s)
52 {
53   assert (false);
54 }
55
56 Array<Column_x_positions>
57 Paper_score::calc_breaking ()
58 {
59   Break_algorithm *algorithm=0;
60   Array<Column_x_positions> sol;
61
62   algorithm = new Gourlay_breaking ;
63   algorithm->set_pscore (this);
64   sol = algorithm->solve ();
65   delete algorithm;
66
67   return sol;
68 }
69
70 /*
71   urg. clean me
72  */
73 void
74 Paper_score::process ()
75 {
76   if (verbose_global_b)
77     progress_indication (_f ("Element count %d (spanners %d) ",
78                              system_->element_count (),
79                              system_->spanner_count ()));
80
81   
82   progress_indication (_ ("Preprocessing elements...") + " ");
83
84   /*
85     Be sure to set breakability on first & last column.
86    */
87   Link_array<Grob> pc (system_->columns ());
88   
89   pc[0]->set_grob_property ("breakable", SCM_BOOL_T);
90   pc.top ()->set_grob_property ("breakable", SCM_BOOL_T);
91
92   system_->pre_processing ();
93  
94   Array<Column_x_positions> breaking = calc_breaking ();
95   system_->break_into_pieces (breaking);
96   
97   outputter_ = paper_->get_paper_outputter ();
98   outputter_->output_header ();
99   outputter_->output_version ();
100
101   progress_indication ("\n");
102
103   if (global_input_file->header_)
104     {
105       outputter_->output_scope (global_input_file->header_, "lilypond");
106       outputter_->write_header_fields_to_file (global_input_file->header_);
107     }
108   
109   if (header_)
110     {
111       outputter_->output_scope (header_, "lilypond");
112       outputter_->write_header_fields_to_file (header_);
113     }
114   
115   outputter_->output_comment (_ ("Outputting Score, defined at: "));
116   outputter_->output_comment (origin_string_);
117
118   if (paper_->variable_tab_)
119     outputter_->output_scope (paper_->variable_tab_, "lilypondpaper");
120
121   SCM scm = scm_list_n (ly_symbol2scm ("header-end"), SCM_UNDEFINED);
122   outputter_->output_scheme (scm);
123
124   system_->output_lines ();
125
126   scm = scm_list_n (ly_symbol2scm ("end-output"), SCM_UNDEFINED);
127   outputter_->output_scheme (scm);
128
129   progress_indication ("\n");
130
131   // huh?
132   delete outputter_;
133   outputter_ = 0;
134   
135   if (verbose_global_b)
136     {
137       scm_write (scm_gc_stats (), scm_current_error_port ());
138       scm_flush (scm_current_error_port ());
139     }
140 }