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 "dimension.hh"
17 #include "assoc-iter.hh"
18 #include "score-engraver.hh"
20 #include "identifier.hh"
24 #include "assoc-iter.hh"
26 Paper_def::Paper_def ()
28 lookup_p_assoc_p_ = new Assoc<int, Lookup*>;
32 Paper_def::~Paper_def ()
34 for (Assoc_iter<int, Lookup*> ai(*lookup_p_assoc_p_); ai.ok (); ai++)
39 delete lookup_p_assoc_p_;
42 Paper_def::Paper_def (Paper_def const&s)
43 : Music_output_def (s)
45 lookup_p_assoc_p_ = new Assoc<int, Lookup*>;
46 for (Assoc_iter<int, Lookup*> ai(*s.lookup_p_assoc_p_); ai.ok (); ai++)
48 Lookup * l=new Lookup (*ai.val ());
50 set_lookup (ai.key(), l);
57 Paper_def::get_var (String s) const
59 if (!scope_p_->elem_b (s))
60 error (_f ("unknown paper variable: `%s\'", s));
61 Real * p = scope_p_->elem (s)->access_Real (false);
64 error (_ ("not a real variable"));
72 Paper_def::line_dimensions_int (int n) const
74 if (!shape_int_a_.size ())
76 return Interval (0, linewidth_f ());
78 return Interval (get_var ("indent"), linewidth_f ());
80 if (n >= shape_int_a_.size ())
81 n = shape_int_a_.size () -1;
83 return shape_int_a_[n];
87 Paper_def::beam_thickness_f () const
89 return get_var ("beam_thickness");
93 Paper_def::linewidth_f () const
95 return get_var ("linewidth");
99 Paper_def::duration_to_dist (Moment d,Real k) const
101 return arithmetic_spacing (d,k);
106 Get the measure wide constant for arithmetic.
109 John S. Gourlay. ``Spacing a Line of Music,'' Technical Report
110 OSU-CISRC-10/87-TR35, Department of Computer and Information Science,
111 The Ohio State University, 1987.
115 Paper_def::arithmetic_constant (Moment d) const
117 return get_var ("arithmetic_basicspace") - log_2 (Moment (1,8) <? d);
121 Paper_def::arithmetic_spacing (Moment d ,Real k) const
123 return (log_2 (d) + k)* get_var ("arithmetic_multiplier");
127 Paper_def::geometric_spacing (Moment d) const
129 Real dur_f = (d) ?pow (get_var ("geometric"), log_2 (d)) : 0;
130 return get_var ("basicspace") + get_var ("unitspace") * dur_f;
134 Paper_def::set_lookup (int i, Lookup*l)
136 if (lookup_p_assoc_p_->elem_b (i))
138 delete lookup_p_assoc_p_->elem (i);
141 (*lookup_p_assoc_p_)[i] = l;
145 Paper_def::interline_f () const
147 return get_var ("interline");
151 Paper_def::rule_thickness () const
153 return get_var ("rulethickness");
157 Paper_def::staffline_f () const
159 return get_var ("rulethickness");
163 Paper_def::staffheight_f () const
165 return get_var ("staffheight");
169 Paper_def::interbeam_f (int multiplicity_i) const
171 if (multiplicity_i <= 3)
172 return get_var ("interbeam");
174 return get_var ("interbeam4");
178 Paper_def::internote_f () const
180 return get_var ("interline") /2.0 ;
184 Paper_def::note_width () const
186 return get_var ("notewidth");
190 Paper_def::print () const
193 Music_output_def::print ();
196 for (Assoc_iter<int, Lookup*> ai(*lookup_p_assoc_p_); ai.ok (); ai++)
198 DOUT << "Lookup: " << ai.key () ;
207 Paper_def::lookup_l (int i) const
209 return (*lookup_p_assoc_p_)[i];
212 IMPLEMENT_IS_TYPE_B1 (Paper_def, Music_output_def);
215 Paper_def::TeX_output_settings_str () const
218 for (Assoc_iter<String,Identifier*> i (*scope_p_); i.ok (); i++)
219 s += String ("\\def\\mudelapaper") + i.key ()
220 + "{" + i.val ()->str () + "}\n";
221 s += *scope_p_->elem ("texsetting")->access_String ();
225 int Paper_def::default_count_i_ = 0;
228 Paper_def::get_next_default_count () const
230 return default_count_i_ ++;