2 paper-outputter.cc -- implement Paper_outputter
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
13 #include "dimensions.hh"
14 #include "dictionary-iter.hh"
15 #include "virtual-methods.hh"
16 #include "paper-outputter.hh"
17 #include "paper-stream.hh"
18 #include "molecule.hh"
20 #include "string-convert.hh"
25 #include "identifier.hh"
26 #include "lily-version.hh"
29 Paper_outputter::Paper_outputter (Paper_stream *s)
35 if (output_global_ch == String ("scm"))
38 ofstream * of = dynamic_cast<ofstream*> (outstream_l_->os);
40 fd = of->rdbuf()->fd();
41 FILE *file = fdopen (fd, "a");
42 port_ = scm_standard_stream_to_port (file, "a", "");
43 scm_display (gh_str02scm (
44 "(primitive-load-path 'lily.scm)\n"
45 "(eval (tex-scm 'all-definitions))\n"
46 ";(eval (ps-scm 'all-definitions))\n"
47 "(display (map (lambda (x) (string-append (eval x) \"%\\n\")) '(\n"
53 if (output_global_ch == String ("scm"))
54 *outstream_l_->os << ""
55 "(primitive-load-path 'lily.scm)\n"
56 "(eval (tex-scm 'all-definitions))\n"
57 ";(eval (ps-scm 'all-definitions))\n"
58 "(display (map (lambda (x) (string-append (eval x) \"\\n\")) '(\n"
63 Paper_outputter::~Paper_outputter ()
65 SCM scm = gh_list (ly_symbol ("end-output"), SCM_UNDEFINED);
69 if (String (output_global_ch) == "scm")
71 scm_display (gh_str02scm (")))\n"), port_);
75 if (String (output_global_ch) == "scm")
77 *outstream_l_->os << ")))";
83 Paper_outputter::output_header ()
87 ly_set_scm ("security-paranoia", SCM_BOOL_T);
88 // gh_eval_str ("(set! security-paranoia #t)");
90 String s = String ("(eval (") + output_global_ch + "-scm 'all-definitions))";
91 gh_eval_str (s.ch_C ());
94 if (no_timestamps_global_b)
95 creator = gnu_lilypond_str ();
97 creator = gnu_lilypond_version_str ();
100 if (no_timestamps_global_b)
104 generate = _ (", at ");
106 generate += ctime (&t);
111 gh_list (gh_str02scm (creator.ch_l ()),
112 gh_str02scm (generate.ch_l ()), SCM_UNDEFINED);
115 DOUT << "output_header\n";
116 if (check_debug && !monitor->silent_b ("Guile"))
118 gh_display (args_scm); gh_newline ();
122 SCM scm = gh_cons (header_scm_sym, args_scm);
127 Paper_outputter::output_molecule (Molecule const*m, Offset o, char const *nm)
130 *outstream_l_ << String ("\n%start: ") << nm << "\n";
139 for (SCM ptr = m->atom_list_; ptr != SCM_EOL; ptr = SCM_CDR(ptr))
141 Atom *i = Atom::atom_l (SCM_CAR(ptr));
143 for (Cons<Atom> *ptr = m->atom_list_; ptr; ptr = ptr->next_)
145 Atom * i = ptr->car_;
150 Offset a_off = i->off_;
156 if (a_off.length () > 100 CM)
158 warning (_f("Improbable offset for object type `%s\'", nm));
162 if (abs(a_off[a]) > 50 CM)
170 output_scheme (gh_list (ly_symbol ("select-font"),
171 gh_str02scm (symbol_to_string (i->font_).ch_C()),
176 = gh_list (placebox_scm_sym,
177 gh_double2scm (a_off.x ()),
178 gh_double2scm (a_off.y ()),
182 output_scheme (box_scm);
187 Paper_outputter::output_comment (String str)
189 if (String (output_global_ch) == "scm")
191 *outstream_l_ << "; " << str << '\n';
195 *outstream_l_ << "% " << str << "\n";
201 Paper_outputter::output_scheme (SCM scm)
204 if (String (output_global_ch) == "scm")
206 scm_write (scm, port_);
207 scm_display (gh_str02scm ("\n"), port_);
211 if (String (output_global_ch) == "scm")
213 SCM result = scm_eval (scm_listify (ly_symbol ("scm->string"), ly_quote_scm (scm), SCM_UNDEFINED));
214 *outstream_l_->os << ly_scm2string (result) << endl;
219 SCM result = scm_eval (scm);
220 char *c=gh_scm2newstr (result, NULL);
228 Paper_outputter::output_scope (Scope *scope, String prefix)
230 for (Scope_iter i (*scope); i.ok (); i++)
232 if (dynamic_cast<String_identifier*> (i.val ()))
234 String val = *i.val()->access_content_String (false);
236 output_String_def (prefix + i.key (), val);
238 else if(dynamic_cast<Real_identifier*> (i.val ()))
240 Real val = *i.val ()->access_content_Real (false);
242 output_Real_def (prefix + i.key (), val);
244 else if (dynamic_cast<int_identifier*> (i.val ()))
246 int val = *i.val ()->access_content_int (false);
248 output_int_def (prefix + i.key (), val);
254 Paper_outputter::output_version ()
256 String id_str = "Lily was here";
257 if (no_timestamps_global_b)
260 id_str += String (", ") + version_str ();
262 output_String_def ( "mudelatagline", id_str);
263 output_String_def ( "LilyPondVersion", version_str ());
267 Paper_outputter::start_line (Real height)
269 SCM scm = gh_list (ly_symbol ("start-line"),
270 gh_double2scm (height),
276 Paper_outputter::output_font_def (int i, String str)
278 SCM scm = gh_list (ly_symbol ("font-def"),
280 gh_str02scm (str.ch_l ()),
287 Paper_outputter::output_Real_def (String k, Real v)
290 SCM scm = gh_list (ly_symbol ("lily-def"),
291 gh_str02scm (k.ch_l ()),
292 gh_str02scm (to_str(v).ch_l ()),
296 gh_define (k.ch_l (), gh_double2scm (v));
300 Paper_outputter::output_String_def (String k, String v)
303 SCM scm = gh_list (ly_symbol ("lily-def"),
304 gh_str02scm (k.ch_l ()),
305 gh_str02scm (v.ch_l ()),
309 gh_define (k.ch_l (), gh_str02scm (v.ch_l ()));
313 Paper_outputter::output_int_def (String k, int v)
315 SCM scm = gh_list (ly_symbol ("lily-def"),
316 gh_str02scm (k.ch_l ()),
317 gh_str02scm (to_str (v).ch_l ()),
321 gh_define (k.ch_l (), gh_int2scm (v));
327 Paper_outputter::stop_line ()
329 SCM scm = gh_list (ly_symbol ("stop-line"), SCM_UNDEFINED);
334 Paper_outputter::stop_last_line ()
336 SCM scm = gh_list (ly_symbol ("stop-last-line"), SCM_UNDEFINED);