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