2 paper-outputter.cc -- implement Paper_outputter
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
15 #include "dimensions.hh"
16 #include "dictionary-iter.hh"
17 #include "virtual-methods.hh"
18 #include "paper-outputter.hh"
19 #include "paper-stream.hh"
20 #include "molecule.hh"
22 #include "string-convert.hh"
27 #include "identifier.hh"
28 #include "lily-version.hh"
31 Paper_outputter::Paper_outputter ()
33 molecules_ = gh_cons (SCM_EOL, SCM_EOL);
34 last_cons_ = molecules_;
39 Paper_outputter::output_header ()
44 gh_define ("security-paranoia", SCM_BOOL_T);
46 String s = String ("(eval (") + output_global_ch + "-scm 'all-definitions))";
47 ly_eval_str (s.ch_C ());
50 if (no_timestamps_global_b)
51 creator = gnu_lilypond_str ();
53 creator = gnu_lilypond_version_str ();
56 if (no_timestamps_global_b)
60 generate = _ (", at ");
62 generate += ctime (&t);
63 generate = generate.left_str (generate.length_i () - 1);
67 gh_list (ly_str02scm (creator.ch_l ()),
68 ly_str02scm (generate.ch_l ()), SCM_UNDEFINED);
71 SCM scm = gh_cons (ly_symbol2scm ("header"), args_scm);
76 Paper_outputter::output_molecule (SCM expr, Offset o, char const *nm)
85 SCM offset_sym = ly_symbol2scm ("translate-molecule");
86 SCM combine_sym = ly_symbol2scm ("combine-molecule");
89 if (!gh_pair_p (expr))
92 SCM head =gh_car (expr);
93 if (head == offset_sym)
95 o += scm_to (gh_cadr (expr), &o);
96 expr = gh_caddr (expr);
99 else if (head == combine_sym)
101 output_molecule (gh_cadr (expr), o, nm);
102 expr = gh_caddr (expr);
103 goto enter; // tail recursion
107 output_scheme (gh_list (ly_symbol2scm ("placebox"),
108 gh_double2scm (o[X_AXIS]),
109 gh_double2scm (o[Y_AXIS]),
117 Paper_outputter::output_comment (String str)
119 output_scheme (gh_list (ly_symbol2scm ("comment"),
120 ly_str02scm ((char*)str.ch_C()),
127 Paper_outputter::output_scheme (SCM scm)
129 SCM c = gh_cons (scm,gh_cdr (last_cons_));
130 gh_set_cdr_x(last_cons_, c);
136 Paper_outputter::dump_onto (Paper_stream *ps)
138 if (String (output_global_ch) == "scm")
139 #if 1 // both are fine
145 if (ofstream* of = dynamic_cast<ofstream*> (ps->os))
146 fd = of->rdbuf ()->fd ();
147 SCM port = scm_fdes_to_port (fd, "a", SCM_EOL);
153 scm_display (gh_str02scm (
154 ";;; Usage: guile -s x.scm > x.tex\n"
155 "(primitive-load-path 'lily.scm)\n"
157 ";(scm-tex-output)\n"
159 "(map (lambda (x) (display (eval x))) '(\n"
162 SCM newline = gh_str02scm ("\n");
163 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
165 scm_write (gh_car (s), port);
166 scm_display (newline, port);
169 scm_display (gh_str02scm ("))"), port);
170 scm_display (newline, port);
172 scm_close_port (port);
180 if (output_global_ch == String ("scm"))
182 ";;; Usage: guile -s x.scm > x.tex\n"
183 "(primitive-load-path 'lily.scm)\n"
186 "(map (lambda (x) (display (eval x))) '(\n"
188 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
190 SCM result = scm_eval (scm_listify (ly_symbol2scm ("scm->string"),
191 ly_quote_scm (gh_car (s)), SCM_UNDEFINED));
193 *ps << ly_scm2string (result);
201 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
203 SCM result = scm_eval (gh_car (s));
204 char *c=gh_scm2newstr (result, NULL);
213 Paper_outputter::output_scope (Scope *scope, String prefix)
215 for (Scope_iter i (*scope); i.ok (); i++)
217 if (dynamic_cast<String_identifier*> (i.val ()))
219 String val = *i.val()->access_content_String (false);
221 output_String_def (prefix + i.key (), val);
223 else if(dynamic_cast<Real_identifier*> (i.val ()))
225 Real val = *i.val ()->access_content_Real (false);
227 output_Real_def (prefix + i.key (), val);
229 else if (dynamic_cast<int_identifier*> (i.val ()))
231 int val = *i.val ()->access_content_int (false);
233 output_int_def (prefix + i.key (), val);
239 Paper_outputter::output_version ()
241 String id_str = "Lily was here";
242 if (no_timestamps_global_b)
245 id_str += String (", ") + version_str ();
247 output_String_def ( "mudelatagline", id_str);
248 output_String_def ( "LilyPondVersion", version_str ());
252 Paper_outputter::start_line (Real height)
256 programming_error ("Improbable system height");
259 SCM scm = gh_list (ly_symbol2scm ("start-line"),
260 gh_double2scm (height),
266 Paper_outputter::output_font_def (int i, String str)
268 SCM scm = gh_list (ly_symbol2scm ("font-def"),
270 ly_str02scm (str.ch_l ()),
277 Paper_outputter::output_Real_def (String k, Real v)
280 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
281 ly_str02scm (k.ch_l ()),
282 ly_str02scm (to_str(v).ch_l ()),
286 // gh_define (k.ch_l (), gh_double2scm (v));
290 Paper_outputter::output_String_def (String k, String v)
293 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
294 ly_str02scm (k.ch_l ()),
295 ly_str02scm (v.ch_l ()),
299 // gh_define (k.ch_l (), ly_str02scm (v.ch_l ()));
303 Paper_outputter::output_int_def (String k, int v)
305 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
306 ly_str02scm (k.ch_l ()),
307 ly_str02scm (to_str (v).ch_l ()),
311 // gh_define (k.ch_l (), gh_int2scm (v));
317 Paper_outputter::stop_line ()
319 SCM scm = gh_list (ly_symbol2scm ("stop-line"), SCM_UNDEFINED);
324 Paper_outputter::stop_last_line ()
326 SCM scm = gh_list (ly_symbol2scm ("stop-last-line"), SCM_UNDEFINED);
328 scm = gh_list (ly_symbol2scm ("end-output"), SCM_UNDEFINED);