lilypond-0.1.16
[lilypond.git] / lily / paper-def.cc
blobd55e3b740d90ae0dbd1b105f85611b1bfae48dfa
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_);
41 outfile_str_ = s.outfile_str_;
44 void
45 Paper_def::set_var (String s, Real r)
47 real_vars_p_->elem (s) = r;
50 Real
51 Paper_def::get_var (String s) const
53 if (! real_vars_p_->elt_b (s))
54 error ("unknown paper variable `" + s+"'");
55 return real_vars_p_->elem (s);
58 Real
59 Paper_def::linewidth_f() const
61 return get_var ("linewidth");
64 Real
65 Paper_def::duration_to_dist (Moment d,Real k) const
67 if (get_var("geometric"))
68 return geometric_spacing(d);
69 return arithmetic_spacing(d,k);
73 /**
74 Get the measure wide constant for arithmetic.
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.
82 Real
83 Paper_def::arithmetic_constant(Moment d) const
85 return get_var("arithmetic_basicspace") - log_2(Moment(1,8) <? d);
88 Real
89 Paper_def::arithmetic_spacing(Moment d ,Real k) const
91 return (log_2(d) + k)* get_var("arithmetic_multiplier");
94 Real
95 Paper_def::geometric_spacing(Moment d) const
97 Real dur_f = (d) ?pow (get_var ("geometric"), log_2(d)) : 0;
98 return get_var ("basicspace") + get_var ("unitspace") * dur_f;
101 void
102 Paper_def::set (Lookup*l)
104 assert (l != lookup_p_);
105 delete lookup_p_;
106 lookup_p_ = l;
107 lookup_p_->paper_l_ = this;
110 Real
111 Paper_def::interline_f() const
113 return get_var ("interline");
117 Real
118 Paper_def::rule_thickness() const
120 return get_var ("rule_thickness");
123 Real
124 Paper_def::interbeam_f() const
126 return get_var ("interbeam");
128 Real
129 Paper_def::internote_f() const
131 return interline_f() / 2;
134 Real
135 Paper_def::note_width() const
137 return get_var ("notewidth");
140 void
141 Paper_def::print() const
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++)
150 DOUT << i.key() << "= " << i.val () << "\n";
152 DOUT << "}\n";
153 #endif
156 Lookup const *
157 Paper_def::lookup_l()
159 assert (lookup_p_);
160 return lookup_p_;
163 IMPLEMENT_IS_TYPE_B1(Paper_def, Music_output_def);