]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/paper-outputter.cc
* scm/output-tex.scm (output-scopes): don't dump fraction exactly.
[lilypond.git] / lily / paper-outputter.cc
index a504341828d3342d87d5c3278e32d3109f8b8e31..561c830387d5bda41d73c3fe6ae8346f3fda849d 100644 (file)
 #include "ly-modules.hh"
 
 
-
-/*
-  TODO: this entire class should be implemented at Scheme level.
-
-
-  
- */
 Paper_outputter::Paper_outputter (String name)
 {
   if (safe_global_b)
@@ -43,14 +36,13 @@ Paper_outputter::Paper_outputter (String name)
   file_ = scm_open_file (scm_makfrom0str (name.to_str0 ()),
                            scm_makfrom0str ("w"));
 
-  /*
-    ugh.
-   */
-  SCM exp = scm_list_n (ly_symbol2scm ("find-dumper"),
-                       scm_makfrom0str (output_format_global.to_str0 ()),
-                       SCM_UNDEFINED);
+  static SCM find_dumper;
+  if (!find_dumper)
+    find_dumper = scm_c_eval_string ("find-dumper");
 
-  output_func_  = scm_primitive_eval (exp);
+  
+  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));
 }
 
 Paper_outputter::~Paper_outputter ()
@@ -59,46 +51,6 @@ Paper_outputter::~Paper_outputter ()
   file_ = SCM_EOL;
 }
 
-
-/*
-  TODO: move this to Scheme  
- */
-void
-Paper_outputter::output_header ()
-{
-  time_t t (time (0));
-  String generate = ctime (&t);
-  generate = generate.left_string (generate.length () - 1) + " " + *tzname;
-  
-  /* Fixed length time stamp */
-  generate = generate + to_string (' ', (50 - generate.length ()) >? 0);
-  
-  /* Fixed length creator string */
-  String creator = gnu_lilypond_version_string ();
-  creator += " (http://lilypond.org)";
-  creator = creator + to_string (' ', (50 - creator.length ()) >? 0);
-  
-  SCM args_scm = scm_list_n (scm_makfrom0str (creator.to_str0 ()),
-                            scm_makfrom0str (generate.to_str0 ()),
-                            SCM_UNDEFINED);
-
-
-  SCM scm = gh_cons (ly_symbol2scm ("header"), args_scm);
-
-  output_scheme (scm);
-}
-
-
-
-void
-Paper_outputter::output_comment (String str)
-{
-  output_scheme (scm_list_n (ly_symbol2scm ("comment"),
-                         scm_makfrom0str ((char*)str.to_str0 ()),
-                         SCM_UNDEFINED)
-                );
-}
-
 void
 Paper_outputter::output_scheme (SCM scm)
 {
@@ -106,105 +58,26 @@ Paper_outputter::output_scheme (SCM scm)
 }
 
 void
-Paper_outputter::output_scope (SCM mod, String prefix)
+Paper_outputter::output_metadata (SCM scopes)
 {
-  if (!SCM_MODULEP (mod))
-    return ;
+  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);
   
-  SCM al = ly_module_to_alist (mod);
-  for (SCM s = al ; gh_pair_p (s); s = ly_cdr (s))
-    {
-      SCM k = ly_caar (s);
-      SCM v = ly_cdar (s);
-      String s = ly_symbol2string (k);
-      
-      if (gh_string_p (v))
-       {
-         output_String_def (prefix + s, ly_scm2string (v));
-       }
-      else if (scm_integer_p (v) == SCM_BOOL_T && scm_exact_p (v) == SCM_BOOL_T)
-       {
-         output_int_def (prefix + s, gh_scm2int (v));    
-       }
-      else if (gh_number_p (v))
-       {
-         output_Real_def (prefix + s, gh_scm2double (v));
-       }
-    }
-}
-
-void
-Paper_outputter::output_version ()
-{
-  String id_string = "Engraved by LilyPond";
-  id_string += String_convert::pad_to (String (", ") + version_string (), 40);
-
-  output_String_def ("lilypondtagline", id_string);
-  output_String_def ("LilyPondVersion", version_string ());
-  output_String_def ("lilypondpaperunit", String (INTERNAL_UNIT));  
-}
-
-
-void
-Paper_outputter::output_Real_def (String k, Real v)
-{
-  
-  SCM scm = scm_list_n (ly_symbol2scm ("lily-def"),
-                       scm_makfrom0str (k.get_str0 ()),
-                       scm_makfrom0str (to_string (v).get_str0 ()),
-                       SCM_UNDEFINED);
-  output_scheme (scm);
-}
-
-void
-Paper_outputter::output_String_def (String k, String v)
-{
-  
-  SCM scm = scm_list_n (ly_symbol2scm ("lily-def"),
-                    scm_makfrom0str (k.get_str0 ()),
-                    scm_makfrom0str (v.get_str0 ()),
-                    SCM_UNDEFINED);
-  output_scheme (scm);
-}
-
-void
-Paper_outputter::output_int_def (String k, int v)
-{
-  SCM scm = scm_list_n (ly_symbol2scm ("lily-def"),
-                    scm_makfrom0str (k.get_str0 ()),
-                    scm_makfrom0str (to_string (v).get_str0 ()),
-                    SCM_UNDEFINED);
-  output_scheme (scm);
-}
-
-void
-Paper_outputter::write_header_field_to_file (String filename, SCM key, SCM value)
-{
-  output_scheme (scm_list_n (ly_symbol2scm ("header-to-file"),
-                            scm_makfrom0str (filename.to_str0 ()),
-                            ly_quote_scm (key), value,
+  output_scheme (scm_list_n (ly_symbol2scm ("output-scopes"),
+                            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::write_header_fields_to_file (SCM mod)
+Paper_outputter::output_music_output_def (Music_output_def* odef)
 {
-  if (ly_module_p (mod)&&
-      dump_header_fieldnames_global.size ())
-    {
-      SCM fields = ly_module_to_alist (mod);
-      for (int i = 0; i < dump_header_fieldnames_global.size (); i++)
-       {
-         String key = dump_header_fieldnames_global[i];
-         SCM val = gh_assoc (ly_symbol2scm (key.to_str0 ()), fields);
-         String s;
-         /* Only write header field to file if it exists */
-         if (gh_pair_p (val) && gh_string_p (ly_cdr (val)))
-           {
-             s = ly_scm2string (ly_cdr (val));
-             /* Always write header field file, even if string is empty ... */
-             write_header_field_to_file (basename_ , ly_car (val), ly_cdr (val));
-           }
-       }
-    }
+  output_scheme (scm_list_n (ly_symbol2scm ("output-paper-def"),
+                            odef->self_scm (), SCM_UNDEFINED));
 }