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.
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::geometric_spacing (Moment d) const
128 Real dur_f = (d) ?pow (get_var ("geometric"), log_2 (d)) : 0;
129 return get_var ("basicspace") + get_var ("unitspace") * dur_f;
133 Paper_def::set_lookup (int i, Lookup*l)
135 if (lookup_p_assoc_p_->elem_b (i))
137 delete lookup_p_assoc_p_->elem (i);
140 (*lookup_p_assoc_p_)[i] = l;
144 Paper_def::interline_f () const
146 return get_var ("interline");
150 Paper_def::rule_thickness () const
152 return get_var ("rulethickness");
156 Paper_def::staffline_f () const
158 return get_var ("rulethickness");
162 Paper_def::staffheight_f () const
164 return get_var ("staffheight");
168 Paper_def::interbeam_f (int multiplicity_i) const
170 if (multiplicity_i <= 3)
171 return get_var ("interbeam");
173 return get_var ("interbeam4");
177 Paper_def::internote_f () const
179 return get_var ("interline") /2.0 ;
183 Paper_def::note_width () const
185 return get_var ("notewidth");
189 Paper_def::print () const
192 Music_output_def::print ();
195 for (Assoc_iter<int, Lookup*> ai(*lookup_p_assoc_p_); ai.ok (); ai++)
197 DOUT << "Lookup: " << ai.key () ;
206 Paper_def::lookup_l (int i) const
208 return (*lookup_p_assoc_p_)[i];
213 int Paper_def::default_count_i_ = 0;
216 Paper_def::get_next_default_count () const
218 return default_count_i_ ++;
222 Paper_def::reset_default_count()
224 default_count_i_ = 0;
228 extern char const* lily_version_number_sz ();
231 output_def (Paper_outputter* p, String key, String val)
234 gh_cons (gh_str02scm (key.ch_l ()), gh_cons (gh_str02scm (val.ch_l ()), SCM_EOL));
236 ly_append (ly_lambda_o (),
237 ly_list1 (ly_append (ly_func_o ("lily-def"), args_scm)));
238 p->output_scheme (scm);
242 output_header (Paper_outputter* p, Scope *head)
247 String id_str = "Lily was here";
248 if (no_timestamps_global_b)
251 id_str += String (", ") + lily_version_number_sz ();
252 output_def (p, "LilyIdString", id_str);
254 for (Dictionary_iter<Identifier*> i (*head); i.ok (); i++)
256 if (!i.val ()->access_content_String (false))
259 String val = *i.val()->access_content_String (false);
260 output_def (p, "mudela" + i.key (), val);
265 Paper_def::output_settings (Paper_outputter* p) const
267 for (Dictionary_iter<Identifier*> i (*scope_p_); i.ok (); i++)
268 output_def (p, String ("mudelapaper") + i.key (), i.val ()->str ());
269 p->output_string (*scope_p_->elem (String (output_global_ch) + "setting")->access_content_String (false));
273 Paper_def::paper_outputter_p (Paper_stream* os_p, Header* header_l, String origin_str) const
275 Paper_outputter* p = new Paper_outputter (os_p);
277 output_header (p, header_global_p);
279 // for now; breaks -fscm output
280 p->output_comment (_ ("outputting Score, defined at: "));
281 p->output_comment (origin_str);
284 output_header (p, header_l);
289 ly_append (ly_lambda_o (),
290 ly_list1 (ly_append (ly_func_o ("experimental-on"), SCM_EOL)));
292 p->output_scheme (scm);
295 ly_append (ly_lambda_o (),
296 ly_list1 (ly_append (ly_func_o ("header-end"), SCM_EOL)));
298 p->output_scheme (scm);
304 Paper_def::paper_stream_p () const
306 String outname = base_output_str ();
309 outname += String (".") + output_global_ch;
310 *mlog << _f ("Paper output to %s...",
311 outname == "-" ? String ("<stdout>") : outname ) << endl;
312 target_str_global_array.push (outname);
313 return new Paper_stream (outname);
318 Paper_def::base_output_str () const
320 String str = get_default_output ();
324 str = default_outname_base_global;
325 int def = get_next_default_count ();
327 str += "-" + to_str (def);