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"
16 #include "paper-score.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 shape_int_a_ = s.shape_int_a_;
47 lookup_p_tab_p_ = new Hash_table<int, Lookup*>;
48 lookup_p_tab_p_->hash_func_ = int_hash;
50 for (Hash_table_iter<int, Lookup*> ai(*s.lookup_p_tab_p_); ai.ok (); ai++)
52 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 Real lw = get_realvar (linewidth_scm_sym);
112 Real ind = n? 0.0:get_var ("indent");
114 return Interval (ind, lw);
117 if (n >= shape_int_a_.size ())
118 n = shape_int_a_.size () -1;
120 return shape_int_a_[n];
125 Paper_def::length_mom_to_dist (Moment d,Real k) const
127 return arithmetic_spacing (d,k);
132 Get the measure wide constant for arithmetic spacing.
135 John S. Gourlay. ``Spacing a Line of Music,'' Technical Report
136 OSU-CISRC-10/87-TR35, Department of Computer and Information Science,
137 The Ohio State University, 1987.
141 Paper_def::arithmetic_constant (Moment d) const
143 return get_var ("arithmetic_basicspace") - log_2 (Moment (1,8) <? d);
147 Paper_def::arithmetic_spacing (Moment d ,Real k) const
149 return (log_2 (d) + k)* get_var ("arithmetic_multiplier");
153 Paper_def::set_lookup (int i, Lookup*l)
155 if (lookup_p_tab_p_->elem_b (i))
157 delete lookup_p_tab_p_->elem (i);
159 (*lookup_p_tab_p_)[i] = l;
164 Paper_def::interbeam_f (int multiplicity_i) const
166 if (multiplicity_i <= 3)
167 return get_realvar (interbeam_scm_sym);
169 return get_realvar (interbeam4_scm_sym);
174 Paper_def::print () const
177 Music_output_def::print ();
178 DEBUG_OUT << "Paper {";
180 for (Hash_table_iter<int, Lookup*> ai(*lookup_p_tab_p_); ai.ok (); ai++)
182 DEBUG_OUT << "Lookup: " << ai.key () << " = " << ai.val ()->font_name_ << '\n';
190 Paper_def::lookup_l (int i) const
192 return (*lookup_p_tab_p_)[i];
197 int Paper_def::default_count_i_ = 0;
200 Paper_def::get_next_default_count () const
202 return default_count_i_ ++;
206 Paper_def::reset_default_count()
208 default_count_i_ = 0;
212 Paper_def::paper_outputter_p (Paper_stream* os_p, Header* header_l, String origin_str) const
214 Paper_outputter* p = new Paper_outputter (os_p);
216 // for now; breaks -fscm output
217 p->output_comment (_ ("Outputting Score, defined at: "));
218 p->output_comment (origin_str);
222 p->output_scope (header_global_p, "mudela");
224 p->output_scope (header_l, "mudela");
226 p->output_scope (scope_p_, "mudelapaper");
229 // *p->outstream_l_ << *scope_p_->elem (String (output_global_ch) + "setting")->access_content_String (false);
231 SCM scm = gh_list (ly_symbol ("experimental-on"), SCM_UNDEFINED);
232 p->output_scheme (scm);
233 scm = gh_list (ly_symbol ("header-end"), SCM_UNDEFINED);
234 p->output_scheme (scm);
240 Paper_def::paper_stream_p () const
242 String outname = base_output_str ();
245 outname += String (".") + output_global_ch;
246 *mlog << _f ("paper output to %s...",
247 outname == "-" ? String ("<stdout>") : outname) << endl;
249 target_str_global_array.push (outname);
250 return new Paper_stream (outname);
255 Paper_def::base_output_str () const
257 String str = get_default_output ();
261 str = default_outname_base_global;
262 int def = get_next_default_count ();
264 str += "-" + to_str (def);