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"
32 Paper_outputter::Paper_outputter (Paper_stream *s)
39 Paper_outputter::~Paper_outputter ()
41 SCM scm = gh_list (ly_symbol ("end-output"), SCM_UNDEFINED);
44 if (String (output_global_ch) == "scm")
47 scm_display (gh_str02scm (")))\n"), port);
50 *outstream_l_->os << ")";
56 Paper_outputter::output_header ()
60 ly_set_scm ("security-paranoia", SCM_BOOL_T);
61 // gh_eval_str ("(set! security-paranoia #t)");
63 String s = String ("(eval (") + output_global_ch + "-scm 'all-definitions))";
64 gh_eval_str (s.ch_C ());
67 if (no_timestamps_global_b)
68 creator = gnu_lilypond_str ();
70 creator = gnu_lilypond_version_str ();
73 if (no_timestamps_global_b)
77 generate = _ (", at ");
79 generate += ctime (&t);
84 gh_list (gh_str02scm (creator.ch_l ()),
85 gh_str02scm (generate.ch_l ()), SCM_UNDEFINED);
88 DOUT << "output_header\n";
89 if (check_debug && !monitor->silent_b ("Guile"))
91 gh_display (args_scm); gh_newline ();
95 SCM scm = gh_cons (header_scm_sym, args_scm);
100 Paper_outputter::output_molecule (Molecule const*m, Offset o, char const *nm)
103 *outstream_l_ << String ("\n%start: ") << nm << "\n";
112 for (SCM ptr = m->atom_list_; ptr != SCM_EOL; ptr = SCM_CDR(ptr))
114 Atom *i = Atom::atom_l (SCM_CAR(ptr));
116 for (Cons<Atom> *ptr = m->atom_list_; ptr; ptr = ptr->next_)
118 Atom * i = ptr->car_;
120 Offset a_off = i->off_;
126 if (a_off.length () > 100 CM)
128 warning (_f("Improbable offset for object type `%s\'", nm));
132 if (abs(a_off[a]) > 50 CM)
140 output_scheme (gh_list (ly_symbol ("select-font"),
141 gh_str02scm (symbol_to_string (i->font_).ch_C()),
146 = gh_list (placebox_scm_sym,
147 gh_double2scm (a_off.x ()),
148 gh_double2scm (a_off.y ()),
152 output_scheme (box_scm);
157 Paper_outputter::output_comment (String str)
159 if (String (output_global_ch) == "scm")
161 *outstream_l_ << "; " << str << '\n';
165 *outstream_l_ << "% " << str << "\n";
171 Paper_outputter::output_scheme (SCM scm)
173 if (String (output_global_ch) == "scm")
177 we'd rather use C++ i/o iso Guile's, but how?
178 and: they can't be mixed (or synchronised) easily?
185 ofstream * of = dynamic_cast<ofstream*> (outstream_l_->os);
187 fd = of->rdbuf()->fd();
188 FILE *file = fdopen (fd, "a");
189 port = scm_standard_stream_to_port (file, "a", "");
190 scm_display (gh_str02scm (
191 "(primitive-load-path 'lily.scm)\n"
192 "(eval (tex-scm 'all-definitions))\n"
193 ";(eval (ps-scm 'all-definitions))\n"
194 "(display (map (lambda (x) (string-append (eval x) \"%\\n\")) '(\n"
198 scm_write (scm, port);
200 scm_display (gh_str02scm ("\n"), port);
203 static bool first = true;
206 *outstream_l_->os << ""
207 "(primitive-load-path 'lily.scm)\n"
208 "(eval (tex-scm 'all-definitions))\n"
209 ";(eval (ps-scm 'all-definitions))\n"
210 "(display (map (lambda (x) (string-append (eval x) \"\\n\")) '(\n"
215 why doesn't this work?
217 ERROR: In procedure gh_scm2newstr:
218 ERROR: Wrong type argument in position 3:
219 (header "GNU LilyPond 1.1.49.jcn1" ", at Tue Jun 22 20:58:17 1999")
223 ERROR: In procedure symbol->string:
224 ERROR: Wrong type argument in position 1:
225 (header "GNU LilyPond 1.1.49.jcn2" ", at Wed Jun 23 18:42:14 1999")
227 eg, two ways to print '(foo bar)'
229 SCM scm = gh_list (ly_symbol ("foo"), gh_str2scm ("bar"), SCM_UNDEFINED);
230 scm_write (scm, port);
231 puts (gh_xxx2newstr (scm, 0));
235 //p = gh_scm2newstr (scm, 0);
236 //p = gh_symbol2newstr (scm, 0);
237 //p = gh_scm2newstr (scm_symbol_to_string (scm), 0);
238 //p = gh_symbol2newstr (scm_symbol_to_string (scm), 0);
239 //*outstream_l_->os << p << endl;
240 *outstream_l_->os << symbol_to_string (scm) << endl;
245 SCM result = scm_eval (scm);
246 char *c=gh_scm2newstr (result, NULL);
254 Paper_outputter::output_scope (Scope *scope, String prefix)
256 for (Scope_iter i (*scope); i.ok (); i++)
258 if (dynamic_cast<String_identifier*> (i.val ()))
260 String val = *i.val()->access_content_String (false);
262 output_String_def (prefix + i.key (), val);
264 else if(dynamic_cast<Real_identifier*> (i.val ()))
266 Real val = *i.val ()->access_content_Real (false);
268 output_Real_def (prefix + i.key (), val);
270 else if (dynamic_cast<int_identifier*> (i.val ()))
272 int val = *i.val ()->access_content_int (false);
274 output_int_def (prefix + i.key (), val);
280 Paper_outputter::output_version ()
282 String id_str = "Lily was here";
283 if (no_timestamps_global_b)
286 id_str += String (", ") + version_str ();
288 output_String_def ( "mudelatagline", id_str);
289 output_String_def ( "LilyPondVersion", version_str ());
293 Paper_outputter::start_line (Real height)
295 SCM scm = gh_list (ly_symbol ("start-line"),
296 gh_double2scm (height),
302 Paper_outputter::output_font_def (int i, String str)
304 SCM scm = gh_list (ly_symbol ("font-def"),
306 gh_str02scm (str.ch_l ()),
313 Paper_outputter::output_Real_def (String k, Real v)
316 SCM scm = gh_list (ly_symbol ("lily-def"),
317 gh_str02scm (k.ch_l ()),
318 gh_str02scm (to_str(v).ch_l ()),
322 gh_define (k.ch_l (), gh_double2scm (v));
326 Paper_outputter::output_String_def (String k, String v)
329 SCM scm = gh_list (ly_symbol ("lily-def"),
330 gh_str02scm (k.ch_l ()),
331 gh_str02scm (v.ch_l ()),
335 gh_define (k.ch_l (), gh_str02scm (v.ch_l ()));
339 Paper_outputter::output_int_def (String k, int v)
341 SCM scm = gh_list (ly_symbol ("lily-def"),
342 gh_str02scm (k.ch_l ()),
343 gh_str02scm (to_str (v).ch_l ()),
347 gh_define (k.ch_l (), gh_int2scm (v));
353 Paper_outputter::stop_line ()
355 SCM scm = gh_list (ly_symbol ("stop-line"), SCM_UNDEFINED);
360 Paper_outputter::stop_last_line ()
362 SCM scm = gh_list (ly_symbol ("stop-last-line"), SCM_UNDEFINED);