lilypond-1.3.65
[lilypond.git] / lily / paper-def.cc
blobbae8a1b395b9491922ca4f7bdc825696baf25484
1 /*
2 paper-def.cc -- implement Paper_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include <math.h>
11 #include "string.hh"
12 #include "misc.hh"
13 #include "paper-def.hh"
14 #include "debug.hh"
15 #include "lookup.hh"
16 #include "main.hh"
17 #include "scope.hh"
18 #include "file-results.hh" // urg? header_global_p
19 #include "paper-stream.hh"
21 Paper_def::Paper_def ()
23 lookup_p_tab_p_ = new map<int, Lookup*>;
27 Paper_def::~Paper_def ()
29 for (map<int,Lookup*>::const_iterator ai = lookup_p_tab_p_->begin();
30 ai != lookup_p_tab_p_->end (); ai++)
32 delete (*ai).second;
35 delete lookup_p_tab_p_;
38 Paper_def::Paper_def (Paper_def const&s)
39 : Music_output_def (s)
41 lookup_p_tab_p_ = new map<int, Lookup*>;
43 for (map<int,Lookup*>::const_iterator ai = s.lookup_p_tab_p_->begin();
44 ai != s.lookup_p_tab_p_->end (); ai++)
46 Lookup * l = new Lookup (* (*ai).second);
47 set_lookup ((*ai).first, l);
52 Real
53 Paper_def::get_var (String s) const
55 return get_realvar (ly_symbol2scm (s.ch_C()));
58 SCM
59 Paper_def::get_scmvar (String s) const
61 return scope_p_->scm_elem (ly_symbol2scm (s.ch_C()));
64 Real
65 Paper_def::get_realvar (SCM s) const
67 if (!scope_p_->elem_b (s))
69 programming_error ("unknown paper variable: " + ly_symbol2string (s));
70 return 0.0;
72 SCM val = scope_p_->scm_elem (s);
73 if (gh_number_p (val))
75 return gh_scm2double (val);
77 else
79 non_fatal_error (_("not a real variable"));
80 return 0.0;
85 FIXME. This is broken until we have a generic way of
86 putting lists inside the \paper block.
88 Interval
89 Paper_def::line_dimensions_int (int n) const
91 Real lw = get_var ("linewidth");
92 Real ind = n? 0.0:get_var ("indent");
94 return Interval (ind, lw);
97 void
98 Paper_def::set_lookup (int i, Lookup*l)
100 map<int,Lookup*> :: const_iterator it (lookup_p_tab_p_->find (i));
101 if (it != lookup_p_tab_p_->end ())
103 delete (*it).second;
105 (*lookup_p_tab_p_)[i] = l;
110 junkme.
112 Real
113 Paper_def::interbeam_f (int multiplicity_i) const
115 if (multiplicity_i <= 3)
116 return get_var ("interbeam");
117 else
118 return get_var ("interbeam4");
122 void
123 Paper_def::print () const
125 #ifndef NPRINT
126 Music_output_def::print ();
127 DEBUG_OUT << "Paper {";
128 for (map<int,Lookup*>::const_iterator ai = lookup_p_tab_p_->begin();
129 ai != lookup_p_tab_p_->end (); ai++)
131 DEBUG_OUT << "Lookup: " << (*ai).first
132 << " = " << (*ai).second->font_name_ << '\n';
134 DEBUG_OUT << "}\n";
135 #endif
138 Lookup const *
139 Paper_def::lookup_l (int i) const
141 return (*lookup_p_tab_p_)[i];
146 int Paper_def::default_count_i_ = 0;
149 Paper_def::get_next_default_count () const
151 return default_count_i_ ++;
154 void
155 Paper_def::reset_default_count()
157 default_count_i_ = 0;
161 Paper_stream*
162 Paper_def::paper_stream_p () const
164 String outname = base_output_str ();
166 if (outname != "-")
167 outname += String (".") + output_global_ch;
168 progress_indication (_f ("paper output to %s...",
169 outname == "-" ? String ("<stdout>") : outname));
172 target_str_global_array.push (outname);
173 return new Paper_stream (outname);
177 String
178 Paper_def::base_output_str () const
180 String str = get_default_output ();
182 if (str.empty_b ())
184 str = default_outname_base_global;
185 int def = get_next_default_count ();
186 if (def)
187 str += "-" + to_str (def);
189 return str;