lilypond-0.1.56
[lilypond.git] / lily / paper-def.cc
blob92b126428c8254d051e4559a6b7534ce12df4f8a
1 /*
2 paper-def.cc -- implement Paper_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
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"
23 Paper_def::Paper_def()
25 lookup_p_ = 0;
26 real_vars_p_ = new Dictionary<Real>;
29 Paper_def::~Paper_def()
31 delete real_vars_p_;
32 delete lookup_p_;
35 Paper_def::Paper_def (Paper_def const&s)
36 : Music_output_def (s)
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_);
43 void
44 Paper_def::set_var (String s, Real r)
46 real_vars_p_->elem (s) = r;
49 Real
50 Paper_def::get_var (String s) const
52 if (! real_vars_p_->elt_b (s))
53 error (_("unknown paper variable `") + s+"'");
54 return real_vars_p_->elem (s);
57 Interval
58 Paper_def::line_dimensions_int (int n) const
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 ());
66 if (n >= shape_int_a_.size ())
67 n = shape_int_a_.size () -1;
69 return shape_int_a_[n];
72 Real
73 Paper_def::linewidth_f () const
75 return get_var ("linewidth");
78 Real
79 Paper_def::duration_to_dist (Moment d,Real k) const
81 if (get_var("geometric"))
82 return geometric_spacing(d);
83 return arithmetic_spacing(d,k);
87 /**
88 Get the measure wide constant for arithmetic.
90 @see
91 John S. Gourlay. ``Spacing a Line of Music,'' Technical Report
92 OSU-CISRC-10/87-TR35, Department of Computer and Information Science,
93 The Ohio State University, 1987.
96 Real
97 Paper_def::arithmetic_constant(Moment d) const
99 return get_var("arithmetic_basicspace") - log_2(Moment(1,8) <? d);
102 Real
103 Paper_def::arithmetic_spacing(Moment d ,Real k) const
105 return (log_2(d) + k)* get_var("arithmetic_multiplier");
108 Real
109 Paper_def::geometric_spacing(Moment d) const
111 Real dur_f = (d) ?pow (get_var ("geometric"), log_2(d)) : 0;
112 return get_var ("basicspace") + get_var ("unitspace") * dur_f;
115 void
116 Paper_def::set (Lookup*l)
118 assert (l != lookup_p_);
119 delete lookup_p_;
120 lookup_p_ = l;
121 lookup_p_->paper_l_ = this;
124 Real
125 Paper_def::interline_f() const
127 return get_var ("interline");
131 Real
132 Paper_def::rule_thickness() const
134 return get_var ("rulethickness");
137 Real
138 Paper_def::interbeam_f() const
140 return get_var ("interbeam");
142 Real
143 Paper_def::internote_f() const
145 return interline_f() / 2;
148 Real
149 Paper_def::note_width() const
151 return get_var ("notewidth");
154 void
155 Paper_def::print() const
157 #ifndef NPRINT
158 Music_output_def::print ();
159 DOUT << "Paper {";
160 lookup_p_->print();
161 for (Assoc_iter<String,Real> i (*real_vars_p_); i.ok(); i++)
163 DOUT << i.key() << "= " << i.val () << "\n";
165 DOUT << "}\n";
166 #endif
169 Lookup const *
170 Paper_def::lookup_l()
172 assert (lookup_p_);
173 return lookup_p_;
176 IMPLEMENT_IS_TYPE_B1(Paper_def, Music_output_def);
178 String
179 Paper_def::TeX_output_settings_str () const
181 String s("\n ");
182 for (Assoc_iter<String,Real> i (*real_vars_p_); i.ok(); i++)
183 s += String ("\\def\\mudelapaper") + i.key () + "{" + i.val () + "}\n";
184 s += lookup_p_->texsetting + "%(Tex id)\n";
185 return s;
188 int Paper_def::default_count_i_ = 0;
191 Paper_def::get_next_default_count () const
193 return default_count_i_ ++;