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>
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 #define SCMVAR(s) { static SCM sym; \
28 sym = scm_protect_object (ly_symbol (#s));\
29 return get_realvar (sym); }
32 Paper_def::Paper_def ()
34 lookup_p_tab_p_ = new Hash_table<int, Lookup*>;
35 lookup_p_tab_p_->hash_func_ = int_hash;
39 Paper_def::~Paper_def ()
41 for (Hash_table_iter<int, Lookup*> ai(*lookup_p_tab_p_); ai.ok (); ai++)
46 delete lookup_p_tab_p_;
49 Paper_def::Paper_def (Paper_def const&s)
50 : Music_output_def (s)
52 lookup_p_tab_p_ = new Hash_table<int, Lookup*>;
53 lookup_p_tab_p_->hash_func_ = int_hash;
55 for (Hash_table_iter<int, Lookup*> ai(*s.lookup_p_tab_p_); ai.ok (); ai++)
57 Lookup * l = new Lookup (*ai.val ());
59 set_lookup (ai.key(), l);
64 Paper_def::get_var (String s) const
66 return get_realvar (ly_symbol (s));
70 Paper_def::get_realvar (SCM s) const
72 if (!scope_p_->elem_b (s))
73 error (_f ("unknown paper variable: `%s\'", symbol_to_string (s)));
74 Real * p = scope_p_->elem (s)->access_content_Real (false);
77 error (_("not a real variable"));
85 Paper_def::line_dimensions_int (int n) const
87 if (!shape_int_a_.size ())
89 return Interval (0, linewidth_f ());
91 return Interval (get_var ("indent"), linewidth_f ());
93 if (n >= shape_int_a_.size ())
94 n = shape_int_a_.size () -1;
96 return shape_int_a_[n];
100 Paper_def::beam_thickness_f () const
102 SCMVAR(beam_thickness);
106 Paper_def::linewidth_f () const
112 Paper_def::length_mom_to_dist (Moment d,Real k) const
114 return arithmetic_spacing (d,k);
119 Get the measure wide constant for arithmetic spacing.
122 John S. Gourlay. ``Spacing a Line of Music,'' Technical Report
123 OSU-CISRC-10/87-TR35, Department of Computer and Information Science,
124 The Ohio State University, 1987.
128 Paper_def::arithmetic_constant (Moment d) const
130 return get_var ("arithmetic_basicspace") - log_2 (Moment (1,8) <? d);
134 Paper_def::arithmetic_spacing (Moment d ,Real k) const
136 return (log_2 (d) + k)* get_var ("arithmetic_multiplier");
140 Paper_def::set_lookup (int i, Lookup*l)
142 if (lookup_p_tab_p_->elem_b (i))
144 delete lookup_p_tab_p_->elem (i);
147 (*lookup_p_tab_p_)[i] = l;
152 Paper_def::interline_f () const
158 Paper_def::rule_thickness () const
160 SCMVAR(rulethickness);
164 Paper_def::staffline_f () const
166 SCMVAR(rulethickness)
170 Paper_def::staffheight_f () const
176 Paper_def::interbeam_f (int multiplicity_i) const
178 if (multiplicity_i <= 3)
185 Paper_def::internote_f () const
187 return interline_f () /2.0 ;
191 Paper_def::note_width () const
197 Paper_def::print () const
200 Music_output_def::print ();
203 for (Hash_table_iter<int, Lookup*> ai(*lookup_p_tab_p_); ai.ok (); ai++)
205 DOUT << "Lookup: " << ai.key () << " = " << ai.val ()->font_name_ << '\n';
213 Paper_def::lookup_l (int i) const
215 return (*lookup_p_tab_p_)[i];
220 int Paper_def::default_count_i_ = 0;
223 Paper_def::get_next_default_count () const
225 return default_count_i_ ++;
229 Paper_def::reset_default_count()
231 default_count_i_ = 0;
235 Paper_def::paper_outputter_p (Paper_stream* os_p, Header* header_l, String origin_str) const
237 Paper_outputter* p = new Paper_outputter (os_p);
239 // for now; breaks -fscm output
240 p->output_comment (_ ("outputting Score, defined at: "));
241 p->output_comment (origin_str);
245 p->output_scope (header_global_p, "mudela");
247 p->output_scope (header_l, "mudela");
249 p->output_scope (scope_p_, "mudelapaper");
251 if (output_global_ch == String("tex"))
253 *p->outstream_l_ << *scope_p_->elem ("texsetting")->access_content_String (false);
257 SCM scm = gh_list (ly_symbol ("experimental-on"), SCM_UNDEFINED);
258 p->output_scheme (scm);
259 scm = gh_list (ly_symbol ("header-end"), SCM_UNDEFINED);
260 p->output_scheme (scm);
266 Paper_def::paper_stream_p () const
268 String outname = base_output_str ();
271 outname += String (".") + output_global_ch;
272 *mlog << _f ("Paper output to %s...",
273 outname == "-" ? String ("<stdout>") : outname) << endl;
275 target_str_global_array.push (outname);
276 return new Paper_stream (outname);
281 Paper_def::base_output_str () const
283 String str = get_default_output ();
287 str = default_outname_base_global;
288 int def = get_next_default_count ();
290 str += "-" + to_str (def);