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