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