]> git.donarmstrong.com Git - lilypond.git/blob - lily/score.cc
Issue 4135/2: Replace mark_smob static member functions with non-static members
[lilypond.git] / lily / score.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "score.hh"
21
22 #include <cstdio>
23
24 using namespace std;
25
26 #include "book.hh"
27 #include "cpu-timer.hh"
28 #include "global-context.hh"
29 #include "international.hh"
30 #include "lily-parser.hh"
31 #include "main.hh"
32 #include "music.hh"
33 #include "music.hh"
34 #include "output-def.hh"
35 #include "paper-book.hh"
36 #include "paper-score.hh"
37 #include "warn.hh"
38
39
40 Input *
41 Score::origin () const
42 {
43   return Input::unsmob (input_location_);
44 }
45
46 Score::Score ()
47 {
48   header_ = SCM_EOL;
49   music_ = SCM_EOL;
50   input_location_ = SCM_EOL;
51
52   error_found_ = false;
53
54   smobify_self ();
55   input_location_ = Input ().smobbed_copy ();
56 }
57
58 Score::~Score ()
59 {
60 }
61
62 const char Score::type_p_name_[] = "ly:score?";
63
64 SCM
65 Score::mark_smob ()
66 {
67   scm_gc_mark (header_);
68   for (vsize i = defs_.size (); i--;)
69     scm_gc_mark (defs_[i]->self_scm ());
70
71   scm_gc_mark (input_location_);
72   return music_;
73 }
74
75 int
76 Score::print_smob (SCM, SCM p, scm_print_state *)
77 {
78   scm_puts ("#<Score>", p);
79
80   return 1;
81 }
82
83 Score::Score (Score const &s)
84 {
85   header_ = SCM_EOL;
86   music_ = SCM_EOL;
87   input_location_ = SCM_EOL;
88   error_found_ = s.error_found_;
89
90   smobify_self ();
91   input_location_ = s.origin ()->smobbed_copy ();
92
93   Music *m = Music::unsmob (s.music_);
94   if (m)
95     {
96       Music *mclone = m->clone ();
97       music_ = mclone->unprotect ();
98     }
99   else
100     music_ = SCM_EOL;
101
102   for (vsize i = 0, n = s.defs_.size (); i < n; i++)
103     {
104       Output_def *copy = s.defs_[i]->clone ();
105       defs_.push_back (copy);
106       copy->unprotect ();
107     }
108   header_ = ly_make_module (false);
109   if (ly_is_module (s.header_))
110     ly_module_copy (header_, s.header_);
111 }
112
113 /*
114   Format score, return list of Music_output objects.
115
116   LAYOUTBOOK should be scaled already.
117 */
118 SCM
119 Score::book_rendering (Output_def *layoutbook,
120                        Output_def *default_def)
121 {
122   if (error_found_)
123     return SCM_EOL;
124
125   Real scale = 1.0;
126
127   if (layoutbook && layoutbook->c_variable ("is-paper") == SCM_BOOL_T)
128     scale = scm_to_double (layoutbook->c_variable ("output-scale"));
129
130   SCM outputs = SCM_EOL;
131
132   int outdef_count = defs_.size ();
133
134   for (int i = 0; !i || i < outdef_count; i++)
135     {
136       Output_def *def = outdef_count ? defs_[i] : default_def;
137       SCM scaled = def->self_scm ();
138
139       if (def->c_variable ("is-layout") == SCM_BOOL_T)
140         {
141           def = scale_output_def (def, scale);
142           def->parent_ = layoutbook;
143
144           scaled = def->unprotect ();
145         }
146
147       /* TODO: fix or junk --no-layout.  */
148       SCM context = ly_run_translator (music_, scaled);
149       if (dynamic_cast<Global_context *> (Context::unsmob (context)))
150         {
151           SCM s = ly_format_output (context);
152
153           outputs = scm_cons (s, outputs);
154         }
155
156       scm_remember_upto_here_1 (scaled);
157     }
158
159   return scm_reverse_x (outputs, SCM_EOL);
160 }
161
162 void
163 Score::set_music (SCM music)
164 {
165   if (Music::unsmob (music_))
166     {
167       Music::unsmob (music)->origin ()->error (_ ("already have music in score"));
168       Music::unsmob (music_)->origin ()->error (_ ("this is the previous music"));
169     }
170   Music *m = Music::unsmob (music);
171   if (m && to_boolean (m->get_property ("error-found")))
172     {
173       m->origin ()->error (_ ("errors found, ignoring music expression"));
174
175       this->error_found_ = this->error_found_
176                            || to_boolean (m->get_property ("error-found"));
177     }
178
179   if (this->error_found_)
180     this->music_ = SCM_EOL;
181   else
182     this->music_ = music;
183 }
184
185 SCM
186 Score::get_music () const
187 {
188   return music_;
189 }
190
191 void
192 Score::add_output_def (Output_def *def)
193 {
194   defs_.push_back (def);
195 }
196
197 SCM
198 Score::get_header () const
199 {
200   return header_;
201 }
202
203 void
204 Score::set_header (SCM module)
205 {
206   assert (ly_is_module (module));
207   header_ = module;
208 }