]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-score.cc
* lily/paper-outputter.cc (output_expr):
[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--2004 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 #include "stencil.hh"
27 #include "paper-book.hh"
28 #include "ly-module.hh"
29
30 Paper_score::Paper_score ()
31 {
32   paper_ = 0;
33   outputter_ = 0;
34   system_ = 0;
35   main_smob_ = SCM_EOL;
36   lines_ = SCM_EOL;
37   book_title_ = 0;
38   score_title_ = 0;
39 }
40
41 Paper_score::Paper_score (Paper_score const &s)
42   : Music_output (s)
43 {
44   assert (false);
45 }
46
47
48 void
49 Paper_score::typeset_line (System *line)
50 {
51   if (!system_)
52     /* ugh. */
53     system_ = line;
54
55   main_smob_ = gh_cons (line->self_scm (), main_smob_);
56   line->pscore_ = this;
57
58   scm_gc_unprotect_object (line->self_scm ());
59 }
60
61 Array<Column_x_positions>
62 Paper_score::calc_breaking ()
63 {
64   Break_algorithm *algorithm=0;
65   Array<Column_x_positions> sol;
66
67   algorithm = new Gourlay_breaking ;
68   algorithm->set_pscore (this);
69   sol = algorithm->solve ();
70   delete algorithm;
71
72   return sol;
73 }
74
75 void
76 Paper_score::process (String outname)
77 {
78   if (verbose_global_b)
79     progress_indication (_f ("Element count %d (spanners %d) ",
80                              system_->element_count (),
81                              system_->spanner_count ()));
82
83   progress_indication (_ ("Preprocessing graphical objects...") + " ");
84
85   /* FIXME: Check out why we need this - removing gives assertion failures
86      down the road.
87      
88      doubly, also done in Score_engraver */
89   Link_array<Grob> pc (system_->columns ());
90   pc[0]->set_property ("breakable", SCM_BOOL_T);
91   pc.top ()->set_property ("breakable", SCM_BOOL_T);
92     
93   system_->pre_processing ();
94  
95   Array<Column_x_positions> breaking = calc_breaking ();
96   system_->break_into_pieces (breaking);
97   lines_ = system_->get_lines ();
98
99   // FIXME: ...
100   outputter_ = paper_->get_paper_outputter (outname);
101
102   progress_indication ("\n");
103
104   SCM scopes = SCM_EOL;
105   if (header_)
106     scopes = scm_cons (header_, scopes);
107   if (global_input_file->header_ && global_input_file->header_ != header_)
108     scopes = scm_cons (global_input_file->header_, scopes);
109   
110   outputter_->output_metadata (scopes, paper_);
111
112 #ifdef PAGE_LAYOUT
113   SCM make_title = scm_primitive_eval (ly_symbol2scm ("make-title"));
114   SCM b = ly_modules_lookup (scopes, ly_symbol2scm ("bookTitle"));
115   if (b != SCM_UNDEFINED && scm_variable_bound_p (b) == SCM_BOOL_T)
116     book_title_
117       = unsmob_stencil (gh_call2 (make_title, paper_->self_scm (),
118                                   scm_variable_ref (b)));
119   
120   SCM s = ly_modules_lookup (scopes, ly_symbol2scm ("scoreTitle"));
121   if (s != SCM_UNDEFINED && scm_variable_bound_p (s) == SCM_BOOL_T)
122     score_title_
123       = unsmob_stencil (gh_call2 (make_title, paper_->self_scm (),
124                                   scm_variable_ref (s)));
125   
126 #if 0
127   // FIXME: 
128   delete system_;
129   system_ = 0;
130 #endif
131   
132   /* Ugh: caller (Score) should do this, but does not know our flavor
133      (paper or midi).  */
134   paper_book->paper_scores_.push (this);
135 #else
136   output ();
137 #endif  
138 }
139
140 void
141 Paper_score::output ()
142 {
143   outputter_->output_header (paper_);
144   
145   int line_count = SCM_VECTOR_LENGTH ((SCM) lines_);
146   for (int i = 0; i < line_count; i++)
147     outputter_->output_line (scm_vector_ref (lines_, scm_int2num (i)),
148                              i == line_count - 1);
149   
150   outputter_->output_scheme (scm_list_1 (ly_symbol2scm ("end-output")));
151   progress_indication ("\n");
152
153 #if 0  
154   // huh?
155   delete outputter_;
156   outputter_ = 0;
157 #endif  
158 }