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)
33 if (output_global_ch == String ("scm"))
34 *outstream_l_->os << ""
35 "(primitive-load-path 'lily.scm)\n"
36 "(eval (tex-scm 'all-definitions))\n"
37 ";(eval (ps-scm 'all-definitions))\n"
38 "(display (map (lambda (x) (string-append (eval x) \"\\n\")) '(\n"
42 Paper_outputter::~Paper_outputter ()
44 SCM scm = gh_list (ly_symbol ("end-output"), SCM_UNDEFINED);
47 if (String (output_global_ch) == "scm")
49 *outstream_l_->os << ")";
54 Paper_outputter::output_header ()
58 ly_set_scm ("security-paranoia", SCM_BOOL_T);
59 // gh_eval_str ("(set! security-paranoia #t)");
61 String s = String ("(eval (") + output_global_ch + "-scm 'all-definitions))";
62 gh_eval_str (s.ch_C ());
65 if (no_timestamps_global_b)
66 creator = gnu_lilypond_str ();
68 creator = gnu_lilypond_version_str ();
71 if (no_timestamps_global_b)
75 generate = _ (", at ");
77 generate += ctime (&t);
82 gh_list (gh_str02scm (creator.ch_l ()),
83 gh_str02scm (generate.ch_l ()), SCM_UNDEFINED);
86 DOUT << "output_header\n";
87 if (check_debug && !monitor->silent_b ("Guile"))
89 gh_display (args_scm); gh_newline ();
93 SCM scm = gh_cons (header_scm_sym, args_scm);
98 Paper_outputter::output_molecule (Molecule const*m, Offset o, char const *nm)
101 *outstream_l_ << String ("\n%start: ") << nm << "\n";
110 for (SCM ptr = m->atom_list_; ptr != SCM_EOL; ptr = SCM_CDR(ptr))
112 Atom *i = Atom::atom_l (SCM_CAR(ptr));
114 for (Cons<Atom> *ptr = m->atom_list_; ptr; ptr = ptr->next_)
116 Atom * i = ptr->car_;
118 Offset a_off = i->off_;
124 if (a_off.length () > 100 CM)
126 warning (_f("Improbable offset for object type `%s\'", nm));
130 if (abs(a_off[a]) > 50 CM)
138 output_scheme (gh_list (ly_symbol ("select-font"),
139 gh_str02scm (symbol_to_string (i->font_).ch_C()),
144 = gh_list (placebox_scm_sym,
145 gh_double2scm (a_off.x ()),
146 gh_double2scm (a_off.y ()),
150 output_scheme (box_scm);
155 Paper_outputter::output_comment (String str)
157 if (String (output_global_ch) == "scm")
159 *outstream_l_ << "; " << str << '\n';
163 *outstream_l_ << "% " << str << "\n";
169 Paper_outputter::output_scheme (SCM scm)
171 if (String (output_global_ch) == "scm")
173 SCM result = scm_eval (scm_listify (ly_symbol ("scm->string"), ly_quote_scm (scm), SCM_UNDEFINED));
174 *outstream_l_->os << ly_scm2string (result) << endl;
178 SCM result = scm_eval (scm);
179 char *c=gh_scm2newstr (result, NULL);
187 Paper_outputter::output_scope (Scope *scope, String prefix)
189 for (Scope_iter i (*scope); i.ok (); i++)
191 if (dynamic_cast<String_identifier*> (i.val ()))
193 String val = *i.val()->access_content_String (false);
195 output_String_def (prefix + i.key (), val);
197 else if(dynamic_cast<Real_identifier*> (i.val ()))
199 Real val = *i.val ()->access_content_Real (false);
201 output_Real_def (prefix + i.key (), val);
203 else if (dynamic_cast<int_identifier*> (i.val ()))
205 int val = *i.val ()->access_content_int (false);
207 output_int_def (prefix + i.key (), val);
213 Paper_outputter::output_version ()
215 String id_str = "Lily was here";
216 if (no_timestamps_global_b)
219 id_str += String (", ") + version_str ();
221 output_String_def ( "mudelatagline", id_str);
222 output_String_def ( "LilyPondVersion", version_str ());
226 Paper_outputter::start_line (Real height)
228 SCM scm = gh_list (ly_symbol ("start-line"),
229 gh_double2scm (height),
235 Paper_outputter::output_font_def (int i, String str)
237 SCM scm = gh_list (ly_symbol ("font-def"),
239 gh_str02scm (str.ch_l ()),
246 Paper_outputter::output_Real_def (String k, Real v)
249 SCM scm = gh_list (ly_symbol ("lily-def"),
250 gh_str02scm (k.ch_l ()),
251 gh_str02scm (to_str(v).ch_l ()),
255 gh_define (k.ch_l (), gh_double2scm (v));
259 Paper_outputter::output_String_def (String k, String v)
262 SCM scm = gh_list (ly_symbol ("lily-def"),
263 gh_str02scm (k.ch_l ()),
264 gh_str02scm (v.ch_l ()),
268 gh_define (k.ch_l (), gh_str02scm (v.ch_l ()));
272 Paper_outputter::output_int_def (String k, int v)
274 SCM scm = gh_list (ly_symbol ("lily-def"),
275 gh_str02scm (k.ch_l ()),
276 gh_str02scm (to_str (v).ch_l ()),
280 gh_define (k.ch_l (), gh_int2scm (v));
286 Paper_outputter::stop_line ()
288 SCM scm = gh_list (ly_symbol ("stop-line"), SCM_UNDEFINED);
293 Paper_outputter::stop_last_line ()
295 SCM scm = gh_list (ly_symbol ("stop-last-line"), SCM_UNDEFINED);