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