2 score.cc -- implement Score
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2009 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"
23 #include "output-def.hh"
24 #include "paper-book.hh"
25 #include "paper-score.hh"
28 #include "ly-smobs.icc"
31 Score::origin () const
33 return unsmob_input (input_location_
);
41 input_location_
= SCM_EOL
;
46 input_location_
= make_input (Input ());
53 IMPLEMENT_SMOBS (Score
);
54 IMPLEMENT_DEFAULT_EQUAL_P (Score
);
55 IMPLEMENT_TYPE_P (Score
, "ly:score?");
58 Score::mark_smob (SCM s
)
60 Score
*sc
= (Score
*) SCM_CELL_WORD_1 (s
);
62 scm_gc_mark (sc
->header_
);
63 for (vsize i
= sc
->defs_
.size (); i
--;)
64 scm_gc_mark (sc
->defs_
[i
]->self_scm ());
66 scm_gc_mark (sc
->input_location_
);
71 Score::print_smob (SCM
, SCM p
, scm_print_state
*)
73 scm_puts ("#<Score>", p
);
78 Score::Score (Score
const &s
)
82 input_location_
= SCM_EOL
;
83 error_found_
= s
.error_found_
;
86 input_location_
= make_input (*s
.origin ());
88 Music
*m
= unsmob_music (s
.music_
);
91 Music
*mclone
= m
->clone ();
92 music_
= mclone
->unprotect ();
97 for (vsize i
= 0, n
= s
.defs_
.size (); i
< n
; i
++)
99 Output_def
*copy
= s
.defs_
[i
]->clone ();
100 defs_
.push_back (copy
);
103 header_
= ly_make_anonymous_module (false);
104 if (ly_is_module (s
.header_
))
105 ly_module_copy (header_
, s
.header_
);
110 Format score, return list of Music_output objects.
112 LAYOUTBOOK should be scaled already.
115 Score::book_rendering (Output_def
*layoutbook
,
116 Output_def
*default_def
)
121 SCM scaled_bookdef
= SCM_EOL
;
124 if (layoutbook
&& layoutbook
->c_variable ("is-paper") == SCM_BOOL_T
)
125 scale
= scm_to_double (layoutbook
->c_variable ("output-scale"));
127 SCM outputs
= SCM_EOL
;
128 SCM
*tail
= &outputs
;
130 int outdef_count
= defs_
.size ();
132 for (int i
= 0; !i
|| i
< outdef_count
; i
++)
134 Output_def
*def
= outdef_count
? defs_
[i
] : default_def
;
135 SCM scaled
= SCM_EOL
;
137 if (def
->c_variable ("is-layout") == SCM_BOOL_T
)
139 def
= scale_output_def (def
, scale
);
140 def
->parent_
= layoutbook
;
142 scaled
= def
->unprotect ();
145 /* TODO: fix or junk --no-layout. */
146 SCM context
= ly_run_translator (music_
, def
->self_scm ());
147 if (dynamic_cast<Global_context
*> (unsmob_context (context
)))
149 SCM s
= ly_format_output (context
);
151 *tail
= scm_cons (s
, SCM_EOL
);
152 tail
= SCM_CDRLOC (*tail
);
155 scm_remember_upto_here_1 (scaled
);
158 scm_remember_upto_here_1 (scaled_bookdef
);
163 Score::set_music (SCM music
)
165 if (unsmob_music (music_
))
167 unsmob_music (music
)->origin ()->error (_ ("already have music in score"));
168 unsmob_music (music_
)->origin ()->error (_ ("this is the previous music"));
170 Music
*m
= unsmob_music (music
);
171 if (m
&& to_boolean (m
->get_property ("error-found")))
173 m
->origin ()->error (_ ("errors found, ignoring music expression"));
175 this->error_found_
= this->error_found_
176 || to_boolean (m
->get_property ("error-found"));
179 if (this->error_found_
)
180 this->music_
= SCM_EOL
;
182 this->music_
= music
;
186 Score::get_music () const
192 Score::add_output_def (Output_def
*def
)
194 defs_
.push_back (def
);
198 Score::get_header () const
204 Score::set_header (SCM module
)
206 assert (ly_is_module (module
));