2 paper-def.cc -- implement Paper_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "paper-def.hh"
16 #include "ps-lookup.hh"
17 #include "tex-lookup.hh"
18 #include "assoc-iter.hh"
19 #include "score-engraver.hh"
21 #include "identifier.hh"
25 #include "assoc-iter.hh"
26 #include "dimensions.hh"
28 IMPLEMENT_IS_TYPE_B1 (Paper_def, Music_output_def);
30 int Paper_def::default_count_i_ = 0;
32 Paper_def::Paper_def ()
34 lookup_p_assoc_p_ = new Assoc<int, Lookup*>;
37 Paper_def::Paper_def (Paper_def const&s)
38 : Music_output_def (s)
40 lookup_p_assoc_p_ = new Assoc<int, Lookup*>;
41 for (Assoc_iter<int, Lookup*> ai(*s.lookup_p_assoc_p_); ai.ok (); ai++)
43 Lookup * l = lookup_p (*ai.val ());
45 set_lookup (ai.key(), l);
49 Paper_def::~Paper_def ()
51 for (Assoc_iter<int, Lookup*> ai(*lookup_p_assoc_p_); ai.ok (); ai++)
56 delete lookup_p_assoc_p_;
60 Get the measure wide constant for arithmetic.
63 John S. Gourlay. ``Spacing a Line of Music,'' Technical Report
64 OSU-CISRC-10/87-TR35, Department of Computer and Information Science,
65 The Ohio State University, 1987.
69 Paper_def::arithmetic_constant (Moment d) const
71 return get_var ("arithmetic_basicspace") - log_2 (Moment (1,8) <? d);
75 Paper_def::arithmetic_spacing (Moment d ,Real k) const
77 return (log_2 (d) + k)* get_var ("arithmetic_multiplier");
81 Paper_def::beam_thickness_f () const
83 return get_var ("beam_thickness");
87 Paper_def::duration_to_dist (Moment d,Real k) const
89 return arithmetic_spacing (d,k);
93 Paper_def::get_next_default_count () const
95 return default_count_i_ ++;
99 Paper_def::get_var (String s) const
101 if (!scope_p_->elem_b (s))
102 error (_f ("unknown paper variable: `%s\'", s));
103 Real * p = scope_p_->elem (s)->access_Real (false);
106 error (_ ("not a real variable"));
114 Paper_def::line_dimensions_int (int n) const
116 if (!shape_int_a_.size ())
118 return Interval (0, linewidth_f ());
120 return Interval (get_var ("indent"), linewidth_f ());
122 if (n >= shape_int_a_.size ())
123 n = shape_int_a_.size () -1;
125 return shape_int_a_[n];
129 Paper_def::geometric_spacing (Moment d) const
131 Real dur_f = (d) ?pow (get_var ("geometric"), log_2 (d)) : 0;
132 return get_var ("basicspace") + get_var ("unitspace") * dur_f;
136 Paper_def::interline_f () const
138 return get_var ("interline");
142 Paper_def::linewidth_f () const
144 return get_var ("linewidth");
148 Paper_def::rule_thickness () const
150 return get_var ("rulethickness");
154 Paper_def::interbeam_f (int multiplicity_i) const
156 if (multiplicity_i <= 3)
157 return get_var ("interbeam");
159 return get_var ("interbeam4");
163 Paper_def::internote_f () const
165 return get_var ("interline") /2.0 ;
168 // urg, how c++ sucks
169 // virtual_copy_cons wants these...
171 // aarg, its even worse, Paper_def gets constructed via Identifier,
172 // another input->output hardlink.
174 Paper_def::lookup_p (Lookup const& l) const
177 return global_paper_l->lookup_p (l);
181 Paper_def::lookup_p (Symtables const& s) const
184 return global_paper_l->lookup_p (s);
188 Paper_def::output_settings_str () const
194 Paper_def::note_width () const
196 return get_var ("notewidth");
200 Paper_def::paper_l ()
206 Paper_def::print () const
209 Music_output_def::print ();
212 for (Assoc_iter<int, Lookup*> ai(*lookup_p_assoc_p_); ai.ok (); ai++)
214 DOUT << "Lookup: " << ai.key () ;
223 Paper_def::dimension_str (Real r) const
225 return ::dimension_str (r);
229 Paper_def::lookup_l (int i) const
231 return (*lookup_p_assoc_p_)[i];
235 Paper_def::set_lookup (int i, Lookup*l)
237 if (lookup_p_assoc_p_->elem_b (i))
239 delete lookup_p_assoc_p_->elem (i);
242 (*lookup_p_assoc_p_)[i] = l;
246 Paper_def::staffline_f () const
248 return get_var ("rulethickness");
252 Paper_def::staffheight_f () const
254 return get_var ("staffheight");
258 Paper_def::unknown_str () const