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);
59 Paper_def::get_var (String s) const
61 return get_realvar (ly_symbol (s));
65 Paper_def::get_realvar (SCM s) const
67 if (!scope_p_->elem_b (s))
68 error (_f ("unknown paper variable: `%s'", symbol_to_string (s)));
69 Real * p = scope_p_->elem (s)->access_content_Real (false);
72 error (_("not a real variable"));
80 Paper_def::line_dimensions_int (int n) const
82 if (!shape_int_a_.size ())
84 Real lw = get_var ("linewidth");
85 Real ind = n? 0.0:get_var ("indent");
87 return Interval (ind, lw);
90 if (n >= shape_int_a_.size ())
91 n = shape_int_a_.size () -1;
93 return shape_int_a_[n];
98 Paper_def::length_mom_to_dist (Moment d,Real k) const
100 return arithmetic_spacing (d,k);
105 Get the measure wide constant for arithmetic spacing.
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::set_lookup (int i, Lookup*l)
128 if (lookup_p_tab_p_->elem_b (i))
130 delete lookup_p_tab_p_->elem (i);
132 (*lookup_p_tab_p_)[i] = l;
137 Paper_def::interbeam_f (int multiplicity_i) const
139 if (multiplicity_i <= 3)
140 return get_var ("interbeam");
142 return get_var ("interbeam4");
147 Paper_def::print () const
150 Music_output_def::print ();
151 DEBUG_OUT << "Paper {";
153 for (Hash_table_iter<int, Lookup*> ai(*lookup_p_tab_p_); ai.ok (); ai++)
155 DEBUG_OUT << "Lookup: " << ai.key () << " = " << ai.val ()->font_name_ << '\n';
163 Paper_def::lookup_l (int i) const
165 return (*lookup_p_tab_p_)[i];
170 int Paper_def::default_count_i_ = 0;
173 Paper_def::get_next_default_count () const
175 return default_count_i_ ++;
179 Paper_def::reset_default_count()
181 default_count_i_ = 0;
185 Paper_def::paper_outputter_p (Paper_stream* os_p, Scope* header_l, String origin_str) const
187 Paper_outputter* p = new Paper_outputter (os_p);
189 // for now; breaks -fscm output
190 p->output_comment (_ ("Outputting Score, defined at: "));
191 p->output_comment (origin_str);
195 p->output_scope (header_global_p, "mudela");
197 p->output_scope (header_l, "mudela");
199 p->output_scope (scope_p_, "mudelapaper");
202 // *p->outstream_l_ << *scope_p_->elem (String (output_global_ch) + "setting")->access_content_String (false);
204 SCM scm = gh_list (ly_symbol ("experimental-on"), SCM_UNDEFINED);
205 p->output_scheme (scm);
206 scm = gh_list (ly_symbol ("header-end"), SCM_UNDEFINED);
207 p->output_scheme (scm);
213 Paper_def::paper_stream_p () const
215 String outname = base_output_str ();
218 outname += String (".") + output_global_ch;
219 *mlog << _f ("paper output to %s...",
220 outname == "-" ? String ("<stdout>") : outname) << endl;
222 target_str_global_array.push (outname);
223 return new Paper_stream (outname);
228 Paper_def::base_output_str () const
230 String str = get_default_output ();
234 str = default_outname_base_global;
235 int def = get_next_default_count ();
237 str += "-" + to_str (def);