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>
10 #include "all-font-metrics.hh"
13 #include "paper-def.hh"
16 #include "score-engraver.hh"
17 #include "paper-score.hh"
18 #include "identifier.hh"
21 #include "dictionary-iter.hh"
22 #include "file-results.hh" // urg? header_global_p
23 #include "paper-outputter.hh"
24 #include "paper-stream.hh"
27 Paper_def::Paper_def ()
29 lookup_p_tab_p_ = new Hash_table<int, Lookup*>;
30 lookup_p_tab_p_->hash_func_ = int_hash;
34 Paper_def::~Paper_def ()
36 for (Hash_table_iter<int, Lookup*> ai(*lookup_p_tab_p_); ai.ok (); ai++)
41 delete lookup_p_tab_p_;
44 Paper_def::Paper_def (Paper_def const&s)
45 : Music_output_def (s)
47 shape_int_a_ = s.shape_int_a_;
48 lookup_p_tab_p_ = new Hash_table<int, Lookup*>;
49 lookup_p_tab_p_->hash_func_ = int_hash;
51 for (Hash_table_iter<int, Lookup*> ai(*s.lookup_p_tab_p_); ai.ok (); ai++)
53 Lookup * l = new Lookup (*ai.val ());
54 set_lookup (ai.key(), l);
60 Paper_def::get_var (String s) const
62 return get_realvar (ly_symbol2scm (s.ch_C()));
66 Paper_def::get_realvar (SCM s) const
68 if (!scope_p_->elem_b (s))
69 error (_f ("unknown paper variable: `%s'", ly_symbol2string (s)));
70 Real * p = scope_p_->elem (s)->access_content_Real (false);
73 error (_("not a real variable"));
82 Paper_def::line_dimensions_int (int n) const
84 SCM s = default_properties_ [ly_symbol2scm ("margin-shape")];
87 Real lw = get_var ("linewidth");
88 Real ind = n? 0.0:get_var ("indent");
90 return Interval (ind, lw);
95 while (gh_pair_p (s) && n --)
106 SCM pair = gh_car (s);
108 return Interval (gh_scm2double (gh_car (pair)),
109 gh_scm2double (gh_cdr (pair)));
113 Paper_def::length_mom_to_dist (Moment d,Real k) const
115 return arithmetic_spacing (d,k);
120 Get the measure wide constant for arithmetic spacing.
123 John S. Gourlay. ``Spacing a Line of Music,'' Technical Report
124 OSU-CISRC-10/87-TR35, Department of Computer and Information Science,
125 The Ohio State University, 1987.
129 Paper_def::arithmetic_constant (Moment d) const
131 return get_var ("arithmetic_basicspace") - log_2 (Moment (1,8) <? d);
135 Paper_def::arithmetic_spacing (Moment d ,Real k) const
137 return (log_2 (d) + k)* get_var ("arithmetic_multiplier");
141 Paper_def::set_lookup (int i, Lookup*l)
143 if (lookup_p_tab_p_->elem_b (i))
145 delete lookup_p_tab_p_->elem (i);
147 (*lookup_p_tab_p_)[i] = l;
152 Paper_def::interbeam_f (int multiplicity_i) const
154 if (multiplicity_i <= 3)
155 return get_var ("interbeam");
157 return get_var ("interbeam4");
162 Paper_def::print () const
165 Music_output_def::print ();
166 DEBUG_OUT << "Paper {";
168 for (Hash_table_iter<int, Lookup*> ai(*lookup_p_tab_p_); ai.ok (); ai++)
170 DEBUG_OUT << "Lookup: " << ai.key () << " = " << ai.val ()->font_name_ << '\n';
178 Paper_def::lookup_l (int i) const
180 return (*lookup_p_tab_p_)[i];
185 int Paper_def::default_count_i_ = 0;
188 Paper_def::get_next_default_count () const
190 return default_count_i_ ++;
194 Paper_def::reset_default_count()
196 default_count_i_ = 0;
201 Paper_def::paper_stream_p () const
203 String outname = base_output_str ();
206 outname += String (".") + output_global_ch;
207 *mlog << _f ("paper output to %s...",
208 outname == "-" ? String ("<stdout>") : outname) << endl;
210 target_str_global_array.push (outname);
211 return new Paper_stream (outname);
216 Paper_def::base_output_str () const
218 String str = get_default_output ();
222 str = default_outname_base_global;
223 int def = get_next_default_count ();
225 str += "-" + to_str (def);