2 paper-def.cc -- implement Paper_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "paper-def.hh"
15 #include "score-engraver.hh"
17 #include "identifier.hh"
20 #include "dictionary-iter.hh"
21 #include "file-results.hh" // urg? header_global_p
22 #include "paper-outputter.hh"
23 #include "paper-stream.hh"
26 Paper_def::Paper_def ()
28 lookup_p_tab_p_ = new Hash_table<int, Lookup*>;
29 lookup_p_tab_p_->hash_func_ = int_hash;
33 Paper_def::~Paper_def ()
35 for (Hash_table_iter<int, Lookup*> ai(*lookup_p_tab_p_); ai.ok (); ai++)
40 delete lookup_p_tab_p_;
43 Paper_def::Paper_def (Paper_def const&s)
44 : Music_output_def (s)
46 lookup_p_tab_p_ = new Hash_table<int, Lookup*>;
47 lookup_p_tab_p_->hash_func_ = int_hash;
49 for (Hash_table_iter<int, Lookup*> ai(*s.lookup_p_tab_p_); ai.ok (); ai++)
51 Lookup * l = new Lookup (*ai.val ());
53 set_lookup (ai.key(), l);
58 Paper_def::get_scm_var (SCM s) const
60 if (!scope_p_->elem_b (s))
63 Identifier * id = scope_p_->elem (s);
71 if (dynamic_cast<Real_identifier*> (id))
73 Real r = *id->access_content_Real (false);
74 val = gh_double2scm (r);
86 Paper_def::get_var (String s) const
88 return get_realvar (ly_symbol (s));
92 Paper_def::get_realvar (SCM s) const
94 if (!scope_p_->elem_b (s))
95 error (_f ("unknown paper variable: `%s\'", symbol_to_string (s)));
96 Real * p = scope_p_->elem (s)->access_content_Real (false);
99 error (_("not a real variable"));
107 Paper_def::line_dimensions_int (int n) const
109 if (!shape_int_a_.size ())
111 return Interval (0, linewidth_f ());
113 return Interval (get_var ("indent"), linewidth_f ());
115 if (n >= shape_int_a_.size ())
116 n = shape_int_a_.size () -1;
118 return shape_int_a_[n];
122 Paper_def::beam_thickness_f () const
124 return get_realvar (beam_thickness_scm_sym);
128 Paper_def::linewidth_f () const
130 return get_realvar (linewidth_scm_sym);
134 Paper_def::length_mom_to_dist (Moment d,Real k) const
136 return arithmetic_spacing (d,k);
141 Get the measure wide constant for arithmetic spacing.
144 John S. Gourlay. ``Spacing a Line of Music,'' Technical Report
145 OSU-CISRC-10/87-TR35, Department of Computer and Information Science,
146 The Ohio State University, 1987.
150 Paper_def::arithmetic_constant (Moment d) const
152 return get_var ("arithmetic_basicspace") - log_2 (Moment (1,8) <? d);
156 Paper_def::arithmetic_spacing (Moment d ,Real k) const
158 return (log_2 (d) + k)* get_var ("arithmetic_multiplier");
162 Paper_def::set_lookup (int i, Lookup*l)
164 if (lookup_p_tab_p_->elem_b (i))
166 delete lookup_p_tab_p_->elem (i);
169 (*lookup_p_tab_p_)[i] = l;
174 Paper_def::rule_thickness () const
176 return get_realvar (rulethickness_scm_sym);
180 Paper_def::staffline_f () const
182 return get_realvar (rulethickness_scm_sym);
186 Paper_def::staffheight_f () const
188 return get_realvar (staffheight_scm_sym);
192 Paper_def::interbeam_f (int multiplicity_i) const
194 if (multiplicity_i <= 3)
195 return get_realvar (interbeam_scm_sym);
197 return get_realvar (interbeam4_scm_sym);
201 Paper_def::note_width () const
203 return get_realvar (notewidth_scm_sym);
207 Paper_def::print () const
210 Music_output_def::print ();
213 for (Hash_table_iter<int, Lookup*> ai(*lookup_p_tab_p_); ai.ok (); ai++)
215 DOUT << "Lookup: " << ai.key () << " = " << ai.val ()->font_name_ << '\n';
223 Paper_def::lookup_l (int i) const
225 return (*lookup_p_tab_p_)[i];
230 int Paper_def::default_count_i_ = 0;
233 Paper_def::get_next_default_count () const
235 return default_count_i_ ++;
239 Paper_def::reset_default_count()
241 default_count_i_ = 0;
245 Paper_def::paper_outputter_p (Paper_stream* os_p, Header* header_l, String origin_str) const
247 Paper_outputter* p = new Paper_outputter (os_p);
249 // for now; breaks -fscm output
250 p->output_comment (_ ("outputting Score, defined at: "));
251 p->output_comment (origin_str);
255 p->output_scope (header_global_p, "mudela");
257 p->output_scope (header_l, "mudela");
259 p->output_scope (scope_p_, "mudelapaper");
262 *p->outstream_l_ << *scope_p_->elem (String (output_global_ch) + "setting")->access_content_String (false);
264 SCM scm = gh_list (ly_symbol ("experimental-on"), SCM_UNDEFINED);
265 p->output_scheme (scm);
266 scm = gh_list (ly_symbol ("header-end"), SCM_UNDEFINED);
267 p->output_scheme (scm);
273 Paper_def::paper_stream_p () const
275 String outname = base_output_str ();
278 outname += String (".") + output_global_ch;
279 *mlog << _f ("Paper output to %s...",
280 outname == "-" ? String ("<stdout>") : outname) << endl;
282 target_str_global_array.push (outname);
283 return new Paper_stream (outname);
288 Paper_def::base_output_str () const
290 String str = get_default_output ();
294 str = default_outname_base_global;
295 int def = get_next_default_count ();
297 str += "-" + to_str (def);