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"
24 #include "dictionary-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 = global_lookup_l->lookup_p (*ai.val ());
50 set_lookup (ai.key(), l);
55 Paper_def::get_var (String s) const
57 if (!scope_p_->elem_b (s))
58 error (_f ("unknown paper variable: `%s\'", s));
59 Real * p = scope_p_->elem (s)->access_Real (false);
62 error (_ ("not a real variable"));
70 Paper_def::line_dimensions_int (int n) const
72 if (!shape_int_a_.size ())
74 return Interval (0, linewidth_f ());
76 return Interval (get_var ("indent"), linewidth_f ());
78 if (n >= shape_int_a_.size ())
79 n = shape_int_a_.size () -1;
81 return shape_int_a_[n];
85 Paper_def::beam_thickness_f () const
87 return get_var ("beam_thickness");
91 Paper_def::linewidth_f () const
93 return get_var ("linewidth");
97 Paper_def::duration_to_dist (Moment d,Real k) const
99 return arithmetic_spacing (d,k);
104 Get the measure wide constant for arithmetic.
107 John S. Gourlay. ``Spacing a Line of Music,'' Technical Report
108 OSU-CISRC-10/87-TR35, Department of Computer and Information Science,
109 The Ohio State University, 1987.
113 Paper_def::arithmetic_constant (Moment d) const
115 return get_var ("arithmetic_basicspace") - log_2 (Moment (1,8) <? d);
119 Paper_def::arithmetic_spacing (Moment d ,Real k) const
121 return (log_2 (d) + k)* get_var ("arithmetic_multiplier");
125 Paper_def::geometric_spacing (Moment d) const
127 Real dur_f = (d) ?pow (get_var ("geometric"), log_2 (d)) : 0;
128 return get_var ("basicspace") + get_var ("unitspace") * dur_f;
132 Paper_def::set_lookup (int i, Lookup*l)
134 if (lookup_p_assoc_p_->elem_b (i))
136 delete lookup_p_assoc_p_->elem (i);
139 (*lookup_p_assoc_p_)[i] = l;
143 Paper_def::interline_f () const
145 return get_var ("interline");
149 Paper_def::rule_thickness () const
151 return get_var ("rulethickness");
155 Paper_def::staffline_f () const
157 return get_var ("rulethickness");
161 Paper_def::staffheight_f () const
163 return get_var ("staffheight");
167 Paper_def::interbeam_f (int multiplicity_i) const
169 if (multiplicity_i <= 3)
170 return get_var ("interbeam");
172 return get_var ("interbeam4");
176 Paper_def::internote_f () const
178 return get_var ("interline") /2.0 ;
182 Paper_def::note_width () const
184 return get_var ("notewidth");
188 Paper_def::print () const
191 Music_output_def::print ();
194 for (Assoc_iter<int, Lookup*> ai(*lookup_p_assoc_p_); ai.ok (); ai++)
196 DOUT << "Lookup: " << ai.key () ;
205 Paper_def::lookup_l (int i) const
207 return (*lookup_p_assoc_p_)[i];
210 IMPLEMENT_IS_TYPE_B1 (Paper_def, Music_output_def);
213 Paper_def::ps_output_settings_str () const
216 for (Dictionary_iter<Identifier*> i (*scope_p_); i.ok (); i++)
217 s += String ("/mudelapaper") + i.key ()
218 + "{" + i.val ()->str () + "} bind def\n";
219 s += *scope_p_->elem ("pssetting")->access_String ();
224 Paper_def::tex_output_settings_str () const
227 for (Dictionary_iter<Identifier*> i (*scope_p_); i.ok (); i++)
228 s += String ("\\def\\mudelapaper") + i.key ()
229 + "{" + i.val ()->str () + "}\n";
230 s += *scope_p_->elem ("texsetting")->access_String ();
234 int Paper_def::default_count_i_ = 0;
237 Paper_def::get_next_default_count () const
239 return default_count_i_ ++;