]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
a0e81bb96ceeffb0136686cea51c9abbae2fe783
[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 "ps-lookup.hh"
17 #include "tex-lookup.hh"
18 #include "assoc-iter.hh"
19 #include "score-engraver.hh"
20 #include "p-score.hh"
21 #include "identifier.hh"
22 #include "main.hh"
23 #include "scope.hh"
24 #include "assoc.hh"
25 #include "assoc-iter.hh"
26 #include "dimensions.hh"
27
28 IMPLEMENT_IS_TYPE_B1 (Paper_def, Music_output_def);
29
30 int Paper_def::default_count_i_ = 0;
31
32 Paper_def::Paper_def ()
33 {
34   lookup_p_assoc_p_ = new Assoc<int, Lookup*>;
35 }
36
37 Paper_def::Paper_def (Paper_def const&s)
38   : Music_output_def (s)
39 {
40   lookup_p_assoc_p_ = new Assoc<int, Lookup*>;
41   for (Assoc_iter<int, Lookup*> ai(*s.lookup_p_assoc_p_); ai.ok (); ai++)
42     {
43       Lookup * l = lookup_p (*ai.val ());
44       l->paper_l_ = this;
45       set_lookup (ai.key(), l);
46     }
47 }
48
49 Paper_def::~Paper_def ()
50 {
51   for (Assoc_iter<int, Lookup*> ai(*lookup_p_assoc_p_); ai.ok (); ai++)
52     {
53       delete ai.val ();
54     }
55   
56   delete lookup_p_assoc_p_;
57 }
58
59 /**
60   Get the measure wide constant for arithmetic.
61
62   @see
63   John S. Gourlay. ``Spacing a Line of Music,'' Technical Report
64   OSU-CISRC-10/87-TR35, Department of Computer and Information Science,
65   The Ohio State University, 1987.
66
67   */
68 Real
69 Paper_def::arithmetic_constant (Moment d) const
70 {
71   return get_var ("arithmetic_basicspace") - log_2 (Moment (1,8) <? d);
72 }
73
74 Real
75 Paper_def::arithmetic_spacing (Moment d ,Real k) const
76 {
77   return (log_2 (d) + k)* get_var ("arithmetic_multiplier");
78 }
79
80 Real
81 Paper_def::beam_thickness_f () const
82 {
83   return get_var ("beam_thickness");
84 }
85
86 Real
87 Paper_def::duration_to_dist (Moment d,Real k) const
88 {
89   return arithmetic_spacing (d,k);
90 }
91
92 int
93 Paper_def::get_next_default_count () const
94 {
95   return default_count_i_ ++;
96 }
97
98 Real
99 Paper_def::get_var (String s) const
100 {
101   if (!scope_p_->elem_b (s))
102     error (_f ("unknown paper variable: `%s\'", s));
103   Real * p = scope_p_->elem (s)->access_Real (false);
104   if (!p)
105     {
106       error (_ ("not a real variable"));
107       return 0.0;
108     }
109
110   return *p;
111 }
112
113 Interval
114 Paper_def::line_dimensions_int (int n) const
115 {
116   if (!shape_int_a_.size ())
117     if (n)
118       return Interval (0, linewidth_f ());
119     else
120       return Interval (get_var ("indent"), linewidth_f ());
121
122   if (n >= shape_int_a_.size ())
123     n = shape_int_a_.size () -1;
124
125   return shape_int_a_[n];
126 }
127
128 Real
129 Paper_def::geometric_spacing (Moment d) const
130 {
131   Real dur_f = (d) ?pow (get_var ("geometric"), log_2 (d)) : 0;
132   return get_var ("basicspace") + get_var ("unitspace")  * dur_f;
133 }
134
135 Real
136 Paper_def::interline_f () const
137 {
138   return get_var ("interline");
139 }
140
141 Real
142 Paper_def::linewidth_f () const
143 {
144   return get_var ("linewidth");
145 }
146
147 Real
148 Paper_def::rule_thickness () const
149 {
150   return get_var ("rulethickness");
151 }
152
153 Real
154 Paper_def::interbeam_f (int multiplicity_i) const
155 {
156   if (multiplicity_i <= 3)
157     return get_var ("interbeam");
158   else
159     return get_var ("interbeam4");
160 }
161
162 Real
163 Paper_def::internote_f () const
164 {
165   return get_var ("interline") /2.0 ;
166 }
167
168 // urg, how c++ sucks
169 // virtual_copy_cons wants these...
170
171 // aarg, its even worse, Paper_def gets constructed via Identifier,
172 // another input->output hardlink.
173 Lookup*
174 Paper_def::lookup_p (Lookup const& l) const
175 {
176   //  return 0;
177   return global_paper_l->lookup_p (l);
178 }
179
180 Lookup*
181 Paper_def::lookup_p (Symtables const& s) const
182 {
183   //  return 0;
184   return global_paper_l->lookup_p (s);
185 }
186
187 String
188 Paper_def::output_settings_str () const
189 {
190   return "";
191 }
192
193 Real
194 Paper_def::note_width () const
195 {
196   return get_var ("notewidth");
197 }
198
199 Paper_def*
200 Paper_def::paper_l ()
201 {
202   return this;
203 }
204
205 void
206 Paper_def::print () const
207 {
208 #ifndef NPRINT
209   Music_output_def::print ();
210   DOUT << "Paper {";
211
212   for (Assoc_iter<int, Lookup*> ai(*lookup_p_assoc_p_); ai.ok (); ai++)
213     {
214       DOUT << "Lookup: " << ai.key () ;
215       ai.val ()->print ();
216     }
217
218   DOUT << "}\n";
219 #endif
220 }
221
222 String
223 Paper_def::dimension_str (Real r) const
224 {
225   return ::dimension_str (r);
226 }
227
228 Lookup const *
229 Paper_def::lookup_l (int i) const
230 {
231   return (*lookup_p_assoc_p_)[i];
232 }
233
234 void
235 Paper_def::set_lookup (int i, Lookup*l)
236 {
237   if (lookup_p_assoc_p_->elem_b (i))
238     {
239       delete lookup_p_assoc_p_->elem (i);
240     }
241   l ->paper_l_ = this;
242   (*lookup_p_assoc_p_)[i] = l;
243 }
244
245 Real
246 Paper_def::staffline_f () const
247 {
248   return get_var ("rulethickness");
249 }
250
251 Real
252 Paper_def::staffheight_f () const
253 {
254   return get_var ("staffheight");
255 }
256
257 String
258 Paper_def::unknown_str () const
259 {
260   return "";
261 }
262