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>
13 #include "paper-def.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
++)
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
);
53 Paper_def::get_var (String s
) const
55 return get_realvar (ly_symbol2scm (s
.ch_C()));
59 Paper_def::get_scmvar (String s
) const
61 return scope_p_
->scm_elem (ly_symbol2scm (s
.ch_C()));
65 Paper_def::get_realvar (SCM s
) const
67 if (!scope_p_
->elem_b (s
))
69 programming_error ("unknown paper variable: " + ly_symbol2string (s
));
72 SCM val
= scope_p_
->scm_elem (s
);
73 if (gh_number_p (val
))
75 return gh_scm2double (val
);
79 non_fatal_error (_("not a real variable"));
85 FIXME. This is broken until we have a generic way of
86 putting lists inside the \paper block.
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
);
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 ())
105 (*lookup_p_tab_p_
)[i
] = l
;
113 Paper_def::interbeam_f (int multiplicity_i
) const
115 if (multiplicity_i
<= 3)
116 return get_var ("interbeam");
118 return get_var ("interbeam4");
123 Paper_def::print () const
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';
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_
++;
155 Paper_def::reset_default_count()
157 default_count_i_
= 0;
162 Paper_def::paper_stream_p () const
164 String outname
= base_output_str ();
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
);
178 Paper_def::base_output_str () const
180 String str
= get_default_output ();
184 str
= default_outname_base_global
;
185 int def
= get_next_default_count ();
187 str
+= "-" + to_str (def
);