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