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