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