]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
release: 1.1.13
[lilypond.git] / lily / paper-def.cc
1 /*
2   paper-def.cc -- implement Paper_def
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include <math.h>
10 #include "string.hh"
11 #include "assoc.hh"
12 #include "misc.hh"
13 #include "paper-def.hh"
14 #include "debug.hh"
15 #include "lookup.hh"
16 #include "assoc-iter.hh"
17 #include "score-engraver.hh"
18 #include "p-score.hh"
19 #include "identifier.hh"
20 #include "main.hh"
21 #include "scope.hh"
22 #include "dictionary-iter.hh"
23 #include "file-results.hh" // urg? header_global_p
24 #include "paper-outputter.hh"
25 #include "paper-stream.hh"
26
27 Paper_def::Paper_def ()
28 {
29   lookup_p_assoc_p_ = new Assoc<int, Lookup*>;
30 }
31
32
33 Paper_def::~Paper_def ()
34 {
35   for (Assoc_iter<int, Lookup*> ai(*lookup_p_assoc_p_); ai.ok (); ai++)
36     {
37       delete ai.val ();
38     }
39   
40   delete lookup_p_assoc_p_;
41 }
42
43 Paper_def::Paper_def (Paper_def const&s)
44   : Music_output_def (s)
45 {
46   lookup_p_assoc_p_ = new Assoc<int, Lookup*>;
47   for (Assoc_iter<int, Lookup*> ai(*s.lookup_p_assoc_p_); ai.ok (); ai++)
48     {
49       Lookup * l = new Lookup (*ai.val ());
50       l->paper_l_ = this;
51       set_lookup (ai.key(), l);
52     }
53 }
54
55 Real
56 Paper_def::get_var (String s) const
57 {
58   if (!scope_p_->elem_b (s))
59     error (_f ("unknown paper variable: `%s\'", s));
60   Real * p = scope_p_->elem (s)->access_content_Real (false);
61   if (!p)
62     {
63       error (_ ("not a real variable"));
64       return 0.0;
65     }
66
67   return *p;
68 }
69
70 Interval
71 Paper_def::line_dimensions_int (int n) const
72 {
73   if (!shape_int_a_.size ())
74     if (n)
75       return Interval (0, linewidth_f ());
76     else
77       return Interval (get_var ("indent"), linewidth_f ());
78
79   if (n >= shape_int_a_.size ())
80     n = shape_int_a_.size () -1;
81
82   return shape_int_a_[n];
83 }
84
85 Real
86 Paper_def::beam_thickness_f () const
87 {
88   return get_var ("beam_thickness");
89 }
90
91 Real
92 Paper_def::linewidth_f () const
93 {
94   return get_var ("linewidth");
95 }
96
97 Real
98 Paper_def::duration_to_dist (Moment d,Real k) const
99 {
100   return arithmetic_spacing (d,k);
101 }
102
103
104 /**
105   Get the measure wide constant for arithmetic spacing.
106
107   @see
108   John S. Gourlay. ``Spacing a Line of Music,'' Technical Report
109   OSU-CISRC-10/87-TR35, Department of Computer and Information Science,
110   The Ohio State University, 1987.
111
112   */
113 Real
114 Paper_def::arithmetic_constant (Moment d) const
115 {
116   return get_var ("arithmetic_basicspace") - log_2 (Moment (1,8) <? d);
117 }
118
119 Real
120 Paper_def::arithmetic_spacing (Moment d ,Real k) const
121 {
122   return (log_2 (d) + k)* get_var ("arithmetic_multiplier");
123 }
124
125 void
126 Paper_def::set_lookup (int i, Lookup*l)
127 {
128   if (lookup_p_assoc_p_->elem_b (i))
129     {
130       delete lookup_p_assoc_p_->elem (i);
131     }
132   l ->paper_l_ = this;
133   (*lookup_p_assoc_p_)[i] = l;
134 }
135
136 Real
137 Paper_def::interline_f () const
138 {
139   return get_var ("interline");
140 }
141
142 Real
143 Paper_def::rule_thickness () const
144 {
145   return get_var ("rulethickness");
146 }
147
148 Real
149 Paper_def::staffline_f () const
150 {
151   return get_var ("rulethickness");
152 }
153
154 Real
155 Paper_def::staffheight_f () const
156 {
157   return get_var ("staffheight");
158 }
159
160 Real
161 Paper_def::interbeam_f (int multiplicity_i) const
162 {
163   if (multiplicity_i <= 3)
164     return get_var ("interbeam");
165   else
166     return get_var ("interbeam4");
167 }
168
169 Real
170 Paper_def::internote_f () const
171 {
172   return get_var ("interline") /2.0 ;
173 }
174
175 Real
176 Paper_def::note_width () const
177 {
178   return get_var ("notewidth");
179 }
180
181 void
182 Paper_def::print () const
183 {
184 #ifndef NPRINT
185   Music_output_def::print ();
186   DOUT << "Paper {";
187
188   for (Assoc_iter<int, Lookup*> ai(*lookup_p_assoc_p_); ai.ok (); ai++)
189     {
190       DOUT << "Lookup: " << ai.key () ;
191       ai.val ()->print ();
192     }
193
194   DOUT << "}\n";
195 #endif
196 }
197
198 Lookup const *
199 Paper_def::lookup_l (int i) const
200 {
201   return (*lookup_p_assoc_p_)[i];
202 }
203
204
205
206 int Paper_def::default_count_i_ = 0;
207
208 int
209 Paper_def::get_next_default_count () const
210 {
211   return default_count_i_ ++;
212 }
213
214 void
215 Paper_def::reset_default_count()
216 {
217   default_count_i_ = 0;
218 }
219
220 extern char const* lily_version_number_sz ();
221
222 Paper_outputter*
223 Paper_def::paper_outputter_p (Paper_stream* os_p, Header* header_l, String origin_str) const
224 {
225   Paper_outputter* p = new Paper_outputter (os_p);
226
227   // for now; breaks -fscm output
228   p->output_comment (_ ("outputting Score, defined at: "));
229   p->output_comment (origin_str);
230
231   p->output_version();
232   if (header_global_p)
233     p->output_scope (header_global_p, "mudela");
234   if (header_l)
235     p->output_scope (header_l, "mudela");
236   if (scope_p_)
237     p->output_scope (scope_p_, "mudelapaper");
238   
239   if (output_global_ch == String("tex"))
240     {
241       *p->outstream_l_ << *scope_p_->elem ("texsetting")->access_content_String (false);
242     }
243   
244
245   SCM scm = gh_list (ly_symbol ("experimental-on"), SCM_UNDEFINED);
246   p->output_scheme (scm);
247   scm = gh_list (ly_symbol ("header-end"), SCM_UNDEFINED);
248   p->output_scheme (scm);
249
250   return p;
251 }
252
253 Paper_stream*
254 Paper_def::paper_stream_p () const
255 {
256   String outname = base_output_str ();
257
258   if (outname != "-")
259     outname += String (".") + output_global_ch;
260   *mlog << _f ("Paper output to %s...", 
261                outname == "-" ? String ("<stdout>") : outname) << endl;
262
263   target_str_global_array.push (outname);
264   return new Paper_stream (outname);
265 }
266
267
268 String
269 Paper_def::base_output_str () const
270 {
271   String str = get_default_output ();
272
273   if (str.empty_b ())
274     {
275       str = default_outname_base_global;
276       int def = get_next_default_count ();
277       if (def)
278         str += "-" + to_str (def);
279     }
280   return str;
281 }
282