]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
release: 0.1.39
[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 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 Real
58 Paper_def::linewidth_f() const
59 {
60   return get_var ("linewidth");
61 }
62
63 Real
64 Paper_def::duration_to_dist (Moment d,Real k) const
65 {
66   if (get_var("geometric"))
67     return geometric_spacing(d);
68   return arithmetic_spacing(d,k);
69 }
70
71
72 /**
73   Get the measure wide constant for arithmetic.
74
75   @see
76   John S. Gourlay. ``Spacing a Line of Music,'' Technical Report
77   OSU-CISRC-10/87-TR35, Department of Computer and Information Science,
78   The Ohio State University, 1987.
79
80   */
81 Real
82 Paper_def::arithmetic_constant(Moment d) const
83 {
84   return get_var("arithmetic_basicspace") - log_2(Moment(1,8) <? d);
85 }
86
87 Real
88 Paper_def::arithmetic_spacing(Moment d ,Real k) const
89 {
90   return (log_2(d) + k)* get_var("arithmetic_multiplier");
91 }
92
93 Real
94 Paper_def::geometric_spacing(Moment d) const
95 {
96   Real dur_f = (d) ?pow (get_var ("geometric"), log_2(d)) : 0;
97   return get_var ("basicspace") + get_var ("unitspace")  * dur_f;
98 }
99
100 void
101 Paper_def::set (Lookup*l)
102 {
103   assert (l != lookup_p_);
104   delete lookup_p_;
105   lookup_p_ = l;
106   lookup_p_->paper_l_ = this;
107 }
108
109 Real
110 Paper_def::interline_f() const
111 {
112   return get_var ("interline");
113 }
114
115
116 Real
117 Paper_def::rule_thickness() const
118 {
119   return get_var ("rule_thickness");
120 }
121
122 Real
123 Paper_def::interbeam_f() const
124 {
125   return get_var ("interbeam");
126 }
127 Real
128 Paper_def::internote_f() const
129 {
130   return interline_f() / 2;
131 }
132
133 Real
134 Paper_def::note_width() const
135 {
136   return get_var ("notewidth");
137 }
138
139 void
140 Paper_def::print() const
141 {
142 #ifndef NPRINT
143   Music_output_def::print ();
144   DOUT << "Paper {";
145   lookup_p_->print();
146   for (Assoc_iter<String,Real> i (*real_vars_p_); i.ok(); i++)
147     {
148       DOUT << i.key() << "= " << i.val () << "\n";
149     }
150   DOUT << "}\n";
151 #endif
152 }
153
154 Lookup const *
155 Paper_def::lookup_l()
156 {
157   assert (lookup_p_);
158   return lookup_p_;
159 }
160
161 IMPLEMENT_IS_TYPE_B1(Paper_def, Music_output_def);
162
163 String
164 Paper_def::TeX_output_settings_str () const
165 {
166   String s("\n ");
167   s +=  lookup_p_->texsetting + "%(Tex id)\n";
168   for (Assoc_iter<String,Real> i (*real_vars_p_); i.ok(); i++)
169     s += String ("\\def\\mudelapaper") + i.key () + "{" + i.val () + "}\n";
170   return s;
171 }
172
173 int Paper_def::default_count_i_ = 0;
174
175 int
176 Paper_def::get_next_default_count () const
177 {
178   return default_count_i_ ++;
179 }