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 "assoc-iter.hh"
17 #include "score-engraver.hh"
19 #include "identifier.hh"
22 #include "dictionary-iter.hh"
23 #include "file-results.hh" // urg? header_global_p
24 #include "paper-outputter.hh"
25 #include "paper-stream.hh"
27 Paper_def::Paper_def ()
29 lookup_p_assoc_p_ = new Assoc<int, Lookup*>;
33 Paper_def::~Paper_def ()
35 for (Assoc_iter<int, Lookup*> ai(*lookup_p_assoc_p_); ai.ok (); ai++)
40 delete lookup_p_assoc_p_;
43 Paper_def::Paper_def (Paper_def const&s)
44 : Music_output_def (s)
46 lookup_p_assoc_p_ = new Assoc<int, Lookup*>;
47 for (Assoc_iter<int, Lookup*> ai(*s.lookup_p_assoc_p_); ai.ok (); ai++)
49 Lookup * l = new Lookup (*ai.val ());
51 set_lookup (ai.key(), l);
56 Paper_def::get_var (String s) const
58 if (!scope_p_->elem_b (s))
59 error (_f ("unknown paper variable: `%s\'", s));
60 Real * p = scope_p_->elem (s)->access_content_Real (false);
63 error (_ ("not a real variable"));
71 Paper_def::line_dimensions_int (int n) const
73 if (!shape_int_a_.size ())
75 return Interval (0, linewidth_f ());
77 return Interval (get_var ("indent"), linewidth_f ());
79 if (n >= shape_int_a_.size ())
80 n = shape_int_a_.size () -1;
82 return shape_int_a_[n];
86 Paper_def::beam_thickness_f () const
88 return get_var ("beam_thickness");
92 Paper_def::linewidth_f () const
94 return get_var ("linewidth");
98 Paper_def::duration_to_dist (Moment d,Real k) const
100 return arithmetic_spacing (d,k);
105 Get the measure wide constant for arithmetic spacing.
108 John S. Gourlay. ``Spacing a Line of Music,'' Technical Report
109 OSU-CISRC-10/87-TR35, Department of Computer and Information Science,
110 The Ohio State University, 1987.
114 Paper_def::arithmetic_constant (Moment d) const
116 return get_var ("arithmetic_basicspace") - log_2 (Moment (1,8) <? d);
120 Paper_def::arithmetic_spacing (Moment d ,Real k) const
122 return (log_2 (d) + k)* get_var ("arithmetic_multiplier");
126 Paper_def::set_lookup (int i, Lookup*l)
128 if (lookup_p_assoc_p_->elem_b (i))
130 delete lookup_p_assoc_p_->elem (i);
133 (*lookup_p_assoc_p_)[i] = l;
137 Paper_def::interline_f () const
139 return get_var ("interline");
143 Paper_def::rule_thickness () const
145 return get_var ("rulethickness");
149 Paper_def::staffline_f () const
151 return get_var ("rulethickness");
155 Paper_def::staffheight_f () const
157 return get_var ("staffheight");
161 Paper_def::interbeam_f (int multiplicity_i) const
163 if (multiplicity_i <= 3)
164 return get_var ("interbeam");
166 return get_var ("interbeam4");
170 Paper_def::internote_f () const
172 return get_var ("interline") /2.0 ;
176 Paper_def::note_width () const
178 return get_var ("notewidth");
182 Paper_def::print () const
185 Music_output_def::print ();
188 for (Assoc_iter<int, Lookup*> ai(*lookup_p_assoc_p_); ai.ok (); ai++)
190 DOUT << "Lookup: " << ai.key () ;
199 Paper_def::lookup_l (int i) const
201 return (*lookup_p_assoc_p_)[i];
206 int Paper_def::default_count_i_ = 0;
209 Paper_def::get_next_default_count () const
211 return default_count_i_ ++;
215 Paper_def::reset_default_count()
217 default_count_i_ = 0;
220 extern char const* lily_version_number_sz ();
223 Paper_def::paper_outputter_p (Paper_stream* os_p, Header* header_l, String origin_str) const
225 Paper_outputter* p = new Paper_outputter (os_p);
227 // for now; breaks -fscm output
228 p->output_comment (_ ("outputting Score, defined at: "));
229 p->output_comment (origin_str);
233 p->output_scope (header_global_p, "mudela");
235 p->output_scope (header_l, "mudela");
237 p->output_scope (scope_p_, "mudelapaper");
239 if (output_global_ch == String("tex"))
241 *p->outstream_l_ << *scope_p_->elem ("texsetting")->access_content_String (false);
245 SCM scm = gh_list (ly_symbol ("experimental-on"), SCM_UNDEFINED);
246 p->output_scheme (scm);
247 scm = gh_list (ly_symbol ("header-end"), SCM_UNDEFINED);
248 p->output_scheme (scm);
254 Paper_def::paper_stream_p () const
256 String outname = base_output_str ();
259 outname += String (".") + output_global_ch;
260 *mlog << _f ("Paper output to %s...",
261 outname == "-" ? String ("<stdout>") : outname) << endl;
263 target_str_global_array.push (outname);
264 return new Paper_stream (outname);
269 Paper_def::base_output_str () const
271 String str = get_default_output ();
275 str = default_outname_base_global;
276 int def = get_next_default_count ();
278 str += "-" + to_str (def);