2 score.cc -- implement Score
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
16 #include "cpu-timer.hh"
17 #include "global-context.hh"
18 #include "international.hh"
19 #include "lily-parser.hh"
20 #include "lilypond-key.hh"
24 #include "output-def.hh"
25 #include "paper-book.hh"
26 #include "paper-score.hh"
29 #include "ly-smobs.icc"
32 Score::origin () const
34 return unsmob_input (input_location_
);
43 input_location_
= SCM_EOL
;
45 input_location_
= make_input (Input ());
52 IMPLEMENT_SMOBS (Score
);
53 IMPLEMENT_DEFAULT_EQUAL_P (Score
);
54 IMPLEMENT_TYPE_P (Score
, "ly:score?");
57 Score::mark_smob (SCM s
)
59 Score
*sc
= (Score
*) SCM_CELL_WORD_1 (s
);
61 scm_gc_mark (sc
->header_
);
62 for (vsize i
= sc
->defs_
.size (); i
--;)
63 scm_gc_mark (sc
->defs_
[i
]->self_scm ());
65 scm_gc_mark (sc
->input_location_
);
70 Score::print_smob (SCM
, SCM p
, scm_print_state
*)
72 scm_puts ("#<Score>", p
);
77 Score::Score (Score
const &s
)
81 error_found_
= s
.error_found_
;
82 input_location_
= SCM_EOL
;
84 input_location_
= make_input (*s
.origin ());
86 Music
*m
= unsmob_music (s
.music_
);
89 Music
*mclone
= m
->clone ();
90 music_
= mclone
->unprotect ();
95 for (vsize i
= 0, n
= s
.defs_
.size (); i
< n
; i
++)
97 Output_def
*copy
= s
.defs_
[i
]->clone ();
98 defs_
.push_back (copy
);
101 header_
= ly_make_anonymous_module (false);
102 if (ly_is_module (s
.header_
))
103 ly_module_copy (header_
, s
.header_
);
107 default_rendering (SCM music
, SCM outdef
,
113 SCM scaled_def
= outdef
;
114 SCM scaled_bookdef
= book_outputdef
;
116 Output_def
*bpd
= unsmob_output_def (book_outputdef
);
119 if (bpd
->c_variable ("is-paper") == SCM_BOOL_T
)
121 Real scale
= scm_to_double (bpd
->c_variable ("output-scale"));
123 Output_def
*def
= scale_output_def (unsmob_output_def (outdef
), scale
);
124 Output_def
*bdef
= scale_output_def (bpd
, scale
);
127 scaled_def
= def
->self_scm ();
128 scaled_bookdef
= bdef
->self_scm ();
134 SCM context
= ly_run_translator (music
, scaled_def
, key
);
136 SCM output_as_scm
= ly_format_output (context
);
137 Music_output
*output
= unsmob_music_output (output_as_scm
);
139 if (Paper_score
*pscore
= dynamic_cast<Paper_score
*> (output
))
141 /* ugh, this is strange, Paper_book without a Book object. */
142 Paper_book
*paper_book
= new Paper_book ();
143 paper_book
->header_
= header
;
144 paper_book
->paper_
= unsmob_output_def (scaled_bookdef
);
146 if (ly_is_module (header
))
147 paper_book
->add_score (header
);
149 paper_book
->add_score (pscore
->self_scm ());
150 paper_book
->classic_output (outname
);
151 paper_book
->unprotect ();
154 scm_remember_upto_here_1 (scaled_def
);
155 scm_remember_upto_here_1 (output_as_scm
);
156 scm_remember_upto_here_1 (scaled_bookdef
);
160 Format score, return list of Music_output objects.
162 LAYOUTBOOK should be scaled already.
165 Score::book_rendering (Output_def
*layoutbook
,
166 Output_def
*default_def
,
167 Object_key
*book_key
)
172 SCM scaled_bookdef
= SCM_EOL
;
175 if (layoutbook
&& layoutbook
->c_variable ("is-paper") == SCM_BOOL_T
)
176 scale
= scm_to_double (layoutbook
->c_variable ("output-scale"));
178 SCM outputs
= SCM_EOL
;
179 SCM
*tail
= &outputs
;
181 int outdef_count
= defs_
.size ();
183 Object_key
*key
= new Lilypond_general_key (book_key
, user_key_
, 0);
184 SCM scm_key
= key
->unprotect ();
186 for (int i
= 0; !i
|| i
< outdef_count
; i
++)
188 Output_def
*def
= outdef_count
? defs_
[i
] : default_def
;
189 SCM scaled
= SCM_EOL
;
191 if (def
->c_variable ("is-layout") == SCM_BOOL_T
)
193 def
= scale_output_def (def
, scale
);
194 def
->parent_
= layoutbook
;
196 scaled
= def
->unprotect ();
199 /* TODO: fix or junk --no-layout. */
200 SCM context
= ly_run_translator (music_
, def
->self_scm (), scm_key
);
201 if (dynamic_cast<Global_context
*> (unsmob_context (context
)))
203 SCM s
= ly_format_output (context
);
205 *tail
= scm_cons (s
, SCM_EOL
);
206 tail
= SCM_CDRLOC (*tail
);
209 scm_remember_upto_here_1 (scaled
);
212 scm_remember_upto_here_1 (scm_key
);
213 scm_remember_upto_here_1 (scaled_bookdef
);
218 Score::set_music (SCM music
)
220 if (unsmob_music (music_
))
222 unsmob_music (music
)->origin ()->error (_ ("already have music in score"));
223 unsmob_music (music_
)->origin ()->error (_ ("this is the previous music"));
225 Music
*m
= unsmob_music (music
);
226 if (m
&& to_boolean (m
->get_property ("error-found")))
228 m
->origin ()->error (_ ("errors found, ignoring music expression"));
230 this->error_found_
= this->error_found_
231 || to_boolean (m
->get_property ("error-found"));
234 if (this->error_found_
)
235 this->music_
= SCM_EOL
;
237 this->music_
= music
;
241 Score::get_music () const
247 Score::add_output_def (Output_def
*def
)
249 defs_
.push_back (def
);