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