source file of the GNU LilyPond music typesetter
- (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
Jan Nieuwenhuizen <janneke@gnu.org>
*/
#include <time.h>
-#include <fstream.h>
+#include <math.h>
#include "dimensions.hh"
-#include "dictionary-iter.hh"
#include "virtual-methods.hh"
#include "paper-outputter.hh"
-#include "paper-stream.hh"
-#include "molecule.hh"
+#include "stencil.hh"
#include "array.hh"
#include "string-convert.hh"
-#include "debug.hh"
-#include "lookup.hh"
+#include "warn.hh"
+#include "font-metric.hh"
#include "main.hh"
-#include "scope.hh"
-#include "identifier.hh"
+#include "scm-hash.hh"
#include "lily-version.hh"
-#include "atom.hh"
+#include "paper-def.hh"
+#include "input-file-results.hh"
+#include "ly-module.hh"
-Paper_outputter::Paper_outputter (Paper_stream *s)
-{
- outstream_l_ = s;
- output_header ();
-}
-Paper_outputter::~Paper_outputter ()
-{
- SCM scm = gh_list (ly_symbol ("end-output"), SCM_UNDEFINED);
- output_scheme (scm);
-}
+#include "input-smob.hh" // output_expr
-void
-Paper_outputter::output_header ()
+
+Paper_outputter::Paper_outputter (String name)
{
-#if 0
- int gobble = 10000;
- {// alloc big chunk of memory.
- SCM beg = SCM_EOL;
- String bigstr = String_convert::char_str (' ', 50);
- for (int i = gobble; i--; )
- {
- beg = gh_cons (gh_str02scm (bigstr.ch_C()), beg);
- }
- }
-#endif
-
if (safe_global_b)
{
- ly_set_scm ("security-paranoia", SCM_BOOL_T);
- // gh_eval_str ("(set! security-paranoia #t)");
+ gh_define ("security-paranoia", SCM_BOOL_T);
}
- String s = String ("(eval (") + output_global_ch + "-scm 'all-definitions))";
- gh_eval_str (s.ch_C());
-
- String creator;
- if (no_timestamps_global_b)
- creator = gnu_lilypond_str ();
- else
- creator = gnu_lilypond_version_str ();
- String generate;
- if (no_timestamps_global_b)
- generate = ".\n";
- else
- {
- generate = _ (", at ");
- time_t t (time (0));
- generate += ctime (&t);
- //urg
- }
+ file_ = scm_open_file (scm_makfrom0str (name.to_str0 ()),
+ scm_makfrom0str ("w"));
- SCM args_scm =
- gh_list (gh_str02scm (creator.ch_l ()),
- gh_str02scm (generate.ch_l ()), SCM_UNDEFINED);
+ static SCM find_dumper;
+ if (!find_dumper)
+ find_dumper = scm_c_eval_string ("find-dumper");
-#ifndef NPRINT
- DOUT << "output_header\n";
- if (check_debug && !monitor->silent_b ("Guile"))
- {
- gh_display (args_scm); gh_newline ();
- }
-#endif
+
+ output_func_ = scm_call_1 (find_dumper,scm_makfrom0str (output_format_global.to_str0 ()));
+ output_scheme (gh_cons (ly_symbol2scm ("top-of-file"), SCM_EOL));
+}
- SCM scm = gh_cons (ly_symbol ("header"), args_scm);
- output_scheme (scm);
+Paper_outputter::~Paper_outputter ()
+{
+ scm_close_port (file_);
+ file_ = SCM_EOL;
}
void
-Paper_outputter::output_molecule (Molecule const*m, Offset o, char const *nm)
+Paper_outputter::output_scheme (SCM scm)
{
- if (check_debug)
- *outstream_l_ << String ("\n%start: ") << nm << "\n";
-
-
- if (check_debug)
- {
- output_comment (nm);
- }
-
-#ifdef ATOM_SMOB
- for (SCM ptr = m->atom_list_; ptr != SCM_EOL; ptr = SCM_CDR(ptr))
- {
- Atom *i = Atom::atom_l (SCM_CAR(ptr));
-#else
- for (Cons<Atom> *ptr = m->atom_list_; ptr; ptr = ptr->next_)
- {
- Atom * i = ptr->car_;
-#endif
- Offset a_off = i->off_;
- a_off += o;
-
- if (!i->func_)
- continue;
-
- assert (a_off.length () < 100 CM);
-
- if (i->font_)
- {
- output_scheme (gh_list (ly_symbol ("select-font"),
- gh_str02scm (symbol_to_string (i->font_).ch_C()),
- SCM_UNDEFINED));
- }
-
- SCM box_scm
- = gh_list (ly_symbol ("placebox"),
- gh_double2scm (a_off.x ()),
- gh_double2scm (a_off.y ()),
- SCM(i->func_),
- SCM_UNDEFINED);
-
- output_scheme (box_scm);
- }
+ gh_call2 (output_func_, scm, file_);
}
void
-Paper_outputter::output_comment (String str)
+Paper_outputter::output_metadata (SCM scopes, Paper_def *paper)
{
- if (String (output_global_ch) == "scm")
- {
- *outstream_l_ << "; " << str << '\n';
- }
- else
- {
- *outstream_l_ << "% " << str << "\n";
- }
+ SCM fields = SCM_EOL;
+ for (int i = dump_header_fieldnames_global.size (); i--; )
+ fields
+ = gh_cons (ly_symbol2scm (dump_header_fieldnames_global[i].to_str0 ()),
+ fields);
+ output_scheme (scm_list_n (ly_symbol2scm ("output-scopes"),
+ paper->self_scm (),
+ scm_list_n (ly_symbol2scm ("quote"),
+ scopes, SCM_UNDEFINED),
+ scm_list_n (ly_symbol2scm ("quote"),
+ fields, SCM_UNDEFINED),
+ scm_makfrom0str (basename_.to_str0 ()),
+ SCM_UNDEFINED));
}
-
void
-Paper_outputter::output_scheme (SCM scm)
+Paper_outputter::output_header (Paper_def *paper)
{
- if (String (output_global_ch) == "scm")
- {
- static SCM port = 0;
-
- // urg
- if (!port)
- {
- int fd = 1;
- ofstream * of = dynamic_cast<ofstream*> (outstream_l_->os);
- if (of)
- fd = of->rdbuf()->fd();
- FILE *file = fdopen (fd, "a");
- port = scm_standard_stream_to_port (file, "a", "");
- scm_display (gh_str02scm ("(load 'lily.scm)\n"), port);
- }
-
- scm_display (gh_str02scm ("("), port);
- scm_write (scm, port);
- scm_display (gh_str02scm (")\n"),port);
- scm_fflush (port);
- }
- else
- {
- SCM result = scm_eval (scm);
- char *c=gh_scm2newstr (result, NULL);
-
- *outstream_l_ << c;
- free (c);
- }
+ output_music_output_def (paper);
+ output_scheme (scm_list_1 (ly_symbol2scm ("header-end")));
+ output_scheme (scm_list_2 (ly_symbol2scm ("define-fonts"),
+ ly_quote_scm (paper->font_descriptions ())));
}
void
-Paper_outputter::output_scope (Scope *scope, String prefix)
+Paper_outputter::output_line (SCM line, bool is_last)
{
- for (Scope_iter i (*scope); i.ok (); i++)
+ Offset dim = ly_scm2offset (ly_car (line));
+ Real width = dim[X_AXIS];
+ Real height = dim[Y_AXIS];
+
+ if (height > 50 CM)
{
- if (dynamic_cast<String_identifier*> (i.val ()))
- {
- String val = *i.val()->access_content_String (false);
+ programming_error ("Improbable system height.");
+ height = 50 CM;
+ }
- output_String_def (prefix + i.key (), val);
- }
- else if(dynamic_cast<Real_identifier*> (i.val ()))
- {
- Real val = *i.val ()->access_content_Real (false);
+ output_scheme (scm_list_3 (ly_symbol2scm ("start-system"),
+ gh_double2scm (width), gh_double2scm (height)));
- output_Real_def (prefix + i.key (), val);
- }
- else if (dynamic_cast<int_identifier*> (i.val ()))
- {
- int val = *i.val ()->access_content_int (false);
-
- output_int_def (prefix + i.key (), val);
- }
+ for (SCM s = ly_cdr (line); gh_pair_p (s); s = ly_cdr (s))
+ {
+ Stencil *stil = unsmob_stencil (ly_cdar (s));
+ output_expr (stil->get_expr (), ly_scm2offset (ly_caar (s)));
}
-}
-void
-Paper_outputter::output_version ()
-{
- String id_str = "Lily was here";
- if (no_timestamps_global_b)
- id_str += ".";
+ if (is_last)
+ output_scheme (scm_list_1 (ly_symbol2scm ("stop-last-system")));
else
- id_str += String (", ") + version_str ();
- output_String_def ( "LilyIdString", id_str);
-}
-
-void
-Paper_outputter::start_line ()
-{
- SCM scm = gh_list (ly_symbol ("start-line"), SCM_UNDEFINED);
- output_scheme (scm);
-}
-
-void
-Paper_outputter::output_font_def (int i, String str)
-{
- SCM scm = gh_list (ly_symbol ("font-def"),
- gh_int2scm (i),
- gh_str02scm (str.ch_l ()),
- SCM_UNDEFINED);
-
- output_scheme (scm);
+ output_scheme (scm_list_1 (ly_symbol2scm ("stop-system")));
}
void
-Paper_outputter::output_Real_def (String k, Real v)
+Paper_outputter::output_music_output_def (Music_output_def* odef)
{
-
- SCM scm = gh_list (ly_symbol ("lily-def"),
- gh_str02scm (k.ch_l ()),
- gh_str02scm (to_str(v).ch_l ()),
- SCM_UNDEFINED);
- output_scheme (scm);
-
- gh_define (k.ch_l (), gh_double2scm (v));
+ output_scheme (scm_list_n (ly_symbol2scm ("output-paper-def"),
+ odef->self_scm (), SCM_UNDEFINED));
}
+/* TODO: replaceme/rewriteme, see output-ps.scm: output-stencil */
void
-Paper_outputter::output_String_def (String k, String v)
+Paper_outputter::output_expr (SCM expr, Offset o)
{
+ while (1)
+ {
+ if (!gh_pair_p (expr))
+ return;
- SCM scm = gh_list (ly_symbol ("lily-def"),
- gh_str02scm (k.ch_l ()),
- gh_str02scm (v.ch_l ()),
- SCM_UNDEFINED);
- output_scheme (scm);
-
- gh_define (k.ch_l (), gh_str02scm (v.ch_l ()));
-}
-
-void
-Paper_outputter::output_int_def (String k, int v)
-{
- SCM scm = gh_list (ly_symbol ("lily-def"),
- gh_str02scm (k.ch_l ()),
- gh_str02scm (to_str (v).ch_l ()),
- SCM_UNDEFINED);
- output_scheme (scm);
-
- gh_define (k.ch_l (), gh_int2scm (v));
+ SCM head =ly_car (expr);
+ if (unsmob_input (head))
+ {
+ Input * ip = unsmob_input (head);
+
+ output_scheme (scm_list_n (ly_symbol2scm ("define-origin"),
+ scm_makfrom0str (ip->file_string ().to_str0 ()),
+ gh_int2scm (ip->line_number ()),
+ gh_int2scm (ip->column_number ()),
+ SCM_UNDEFINED));
+ expr = ly_cadr (expr);
+ }
+ else if (head == ly_symbol2scm ("no-origin"))
+ {
+ output_scheme (scm_list_n (head, SCM_UNDEFINED));
+ expr = ly_cadr (expr);
+ }
+ else if (head == ly_symbol2scm ("translate-stencil"))
+ {
+ o += ly_scm2offset (ly_cadr (expr));
+ expr = ly_caddr (expr);
+ }
+ else if (head == ly_symbol2scm ("combine-stencil"))
+ {
+ output_expr (ly_cadr (expr), o);
+ expr = ly_caddr (expr);
+ }
+ else
+ {
+ output_scheme (scm_list_n (ly_symbol2scm ("placebox"),
+ gh_double2scm (o[X_AXIS]),
+ gh_double2scm (o[Y_AXIS]),
+ expr,
+ SCM_UNDEFINED));
+ return;
+ }
+ }
}
-
-
-void
-Paper_outputter::stop_line ()
-{
- SCM scm = gh_list (ly_symbol ("stop-line"), SCM_UNDEFINED);
- output_scheme (scm);
-}