]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/paper-book.cc (output): call output-preview-framework
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 23 Jul 2004 23:23:53 +0000 (23:23 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 23 Jul 2004 23:23:53 +0000 (23:23 +0000)
(post_processing): new function. Do PDF/PNG conversion.

* lily/paper-outputter.cc (close): new function.

* scm/framework-ps.scm (convert-to-pdf): new function. Call
ps2pdf.
(output-preview-framework): new function. Generate a preview .ps

ChangeLog
lily/include/main.hh
lily/include/paper-book.hh
lily/include/paper-outputter.hh
lily/main.cc
lily/paper-book.cc
lily/paper-outputter.cc
scm/framework-ps.scm
scm/framework-tex.scm

index 64392910a035a538a6d26e94cc4f54198901e918..63814c51b3240360390f023268cbc1ced01a3b4d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
+2004-07-24  Han-Wen Nienhuys   <hanwen@xs4all.nl>
+
+       * lily/paper-book.cc (output): call output-preview-framework
+       (post_processing): new function. Do PDF/PNG conversion.
+
+       * lily/paper-outputter.cc (close): new function.
+
+       * scm/framework-ps.scm (convert-to-pdf): new function. Call
+       ps2pdf.
+       (output-preview-framework): new function. Generate a preview .ps
+       
+
 2004-07-23  Han-Wen Nienhuys   <hanwen@xs4all.nl>
 
+       * VERSION: release 2.3.8
+       
        * lily/note-head.cc: remove ledger line handling.
 
        * lily/ambitus.cc (print): strip away accidental / note head code,
index 62aeb4fbea2dde242078d8bb4930ed4b63438d79..bafde2f92ea88fa484b1b84b4149ba51172a03a3 100644 (file)
@@ -35,8 +35,9 @@ extern bool safe_global_b;
 extern bool verbose_global_b;
 extern bool store_locations_global_b;
 extern bool internal_type_checking_global_b;
-extern bool debug_beam_quanting_flag;
-
+extern bool make_png;
+extern bool make_pdf;
+extern bool make_preview;
 
 /* misc */
 extern Array<String> failed_files;
index 3654b87107b2e82f44cdad0db8c7af4b1ec1710a..e2b678d30c5e75975ecadbfff0ddaa8e730cd612 100644 (file)
@@ -48,6 +48,7 @@ public:
   Stencil score_title (int);
   void classic_output (String);
   void output (String);
+  void post_processing (SCM, SCM);
 };
 
 DECLARE_UNSMOB (Paper_book, paper_book)
index 96544542e1391d3bfea44c8d96ea6c016d024aa1..fc6a20b7124d72f8e1ecbb36ae2f6ee08779abfb 100644 (file)
@@ -37,6 +37,7 @@ public:
   Paper_outputter (String nm, String format);
   SCM scheme_to_string (SCM);
   void output_stencil (Stencil);
+  void close();
 };
 
 Paper_outputter *get_paper_outputter (String, String);
index 8b5478828bc7fecef4834ccca64ce438c51afd0a..ce647209779cb5f1a23590f390381657e4441394 100644 (file)
@@ -63,7 +63,9 @@ bool verbose_global_b = false;
 */
 String init_scheme_code_string = "(begin #t ";
 
-
+bool make_pdf = false;
+bool make_png = false;
+bool make_preview = false;
 
 /*
  * Miscellaneous global stuff.
@@ -129,6 +131,7 @@ static Long_option_init options_static[] =
     {_i ("FILE"), "init", 'i',  _i ("use FILE as init file")},
     {0, "no-paper", 'm',  _i ("produce MIDI output only")},
     {_i ("FILE"), "output", 'o',  _i ("write output to FILE")},
+    {0, "preview", 'p',  _i ("generate a preview")},
     {0, "safe-mode", 's',  _i ("run in safe mode")},
     {0, "version", 'v',  _i ("print version number")},
     {0, "verbose", 'V', _i ("be verbose")},
@@ -332,6 +335,9 @@ parse_argv (int argc, char **argv)
            output_name_global = file_name.to_string ();
          }
          break;
+       case 'p':
+         make_preview = true;    
+         break;
        case 'e':
          init_scheme_code_string += option_parser->optional_argument_str0_;
          break;
index 0c0a0629fc86ba765d19fac5887abee61a76ee1f..6e739723cf50f3b4e3a32b48efcd247eedf78577 100644 (file)
@@ -113,6 +113,32 @@ LY_DEFINE (ly_output_formats, "ly:output-formats",
   return lst; 
 }
 
+void
+Paper_book::post_processing (SCM module,
+                            SCM file_name)
+{
+  if (make_pdf)
+    {
+      SCM func = scm_c_module_lookup (module, "convert-to-pdf");
+      if (scm_variable_p (func) == SCM_BOOL_T)
+       {
+         func = scm_variable_ref (func);
+         if (ly_c_procedure_p (func))
+           scm_call_2 (func, self_scm(), file_name);
+       }
+    }
+
+  if (make_png)
+    {
+      SCM func = scm_c_module_lookup (module, "convert-to-png");
+      if (scm_variable_p (func) ==  SCM_BOOL_T)
+       {
+         func = scm_variable_ref (func);
+         if (ly_c_procedure_p (func))
+           scm_call_2 (func, self_scm(), file_name);
+       }
+    }
+}
 void
 Paper_book::output (String outname)
 {
@@ -126,8 +152,8 @@ Paper_book::output (String outname)
   for (SCM s = formats; ly_c_pair_p (s); s = ly_cdr (s)) 
     {
       String format = ly_scm2string (ly_car (s));
-      Paper_outputter *out = get_paper_outputter (outname + "." + format,
-                                                 format);
+      String file_name = outname + "." + format;
+      Paper_outputter *out = get_paper_outputter (file_name, format);
   
       SCM scopes = SCM_EOL;
       if (ly_c_module_p (header_))
@@ -145,8 +171,31 @@ Paper_book::output (String outname)
                                     dump_fields (),
                                     scm_makfrom0str (outname.to_str0 ()),
                                     SCM_UNDEFINED));
-
+      out->close ();
       scm_gc_unprotect_object (out->self_scm ());
+
+      post_processing (mod, scm_makfrom0str (file_name.to_str0 ()));
+      
+      if (make_preview)
+       {
+         String file_name = outname + ".preview." + format;
+         Paper_outputter *out = get_paper_outputter (file_name, format);
+  
+         SCM func = scm_c_module_lookup (mod, "output-preview-framework");
+         func = scm_variable_ref (func);
+         scm_apply_0 (func, scm_list_n (out->self_scm (),
+                                        self_scm (),
+                                        scopes,
+                                        dump_fields (),
+                                        scm_makfrom0str (outname.to_str0 ()),
+                                        SCM_UNDEFINED));
+
+         out->close ();
+         scm_gc_unprotect_object (out->self_scm ());
+
+         post_processing (mod, scm_makfrom0str (file_name.to_str0 ()));
+       }
+      
       progress_indication ("\n");
     }
 }
@@ -181,9 +230,10 @@ Paper_book::classic_output (String outname)
       Paper_outputter *out = get_paper_outputter (outname + "." + format,
                                                  format);
 
-      scm_apply_0 (func, scm_list_5 (out->self_scm (), self_scm (), scopes,
+      scm_apply_0 (func, scm_list_n (out->self_scm (), self_scm (), scopes,
                                     dump_fields (),
-                                    scm_makfrom0str (outname.to_str0 ())));
+                                    scm_makfrom0str (outname.to_str0 ()),
+                                    SCM_UNDEFINED));
 
       scm_gc_unprotect_object (out->self_scm ());
       progress_indication ("\n");
index bb9c3812cf8ed9138793f8a04dcc8f1efdaf3c48..7976b17a478963f3443f67ef2acff220e99617a9 100644 (file)
@@ -138,3 +138,9 @@ LY_DEFINE (ly_outputter_dump_string, "ly:outputter-dump-string",
   
   return po->dump_string (str);
 }
+
+void
+Paper_outputter::close ()
+{
+  scm_close_port (file_);
+}
index 50070674f6b05fb8dcc79a19d544133ec19aff39..99ed406caef891b2c280b25f084c97d24b5a66a9 100644 (file)
@@ -14,6 +14,9 @@
             (srfi srfi-13)
             (lily))
 
+(define mm-to-bigpoint
+  (/ 72 25.4))
+
 (define-public (ps-font-command font . override-coding)
   (let* ((name (ly:font-filename font))
         (magnify (ly:font-magnification font))
      (value->string (ly:output-def-lookup paper ly-key)) " def \n"))
 
   (string-append
-   "/lily-output-units 2.83464  def  %% milimeter \n"
-   "% /lily-output-units 0.996264  def  %% true points.\n"
+   "/lily-output-units " (number->string mm-to-bigpoint) "  def  %% milimeter \n"
    (output-entry "staff-line-thickness" 'linethickness)
    (output-entry "line-width" 'linewidth)
    (output-entry "paper-size" 'papersize)
    (number->string (ly:output-def-lookup paper 'outputscale))
    " lily-output-units mul def \n"))
 
-(define (header paper page-count classic?)
-  (string-append
-   "%!PS-Adobe-3.0\n"
-   "%%Creator: creator time-stamp \n"))
-
 (define (dump-page outputter page page-number page-count)
   (ly:outputter-dump-string outputter
    (string-append
   (ly:outputter-dump-stencil outputter page)
   (ly:outputter-dump-string outputter "} stop-system \nshowpage\n"))
 
+(define (eps-header bookpaper bbox)
+  (string-append "%!PS-Adobe-2.0 EPSF-2.0\n"
+                "%%Creator: creator time-stamp\n"
+                "%%BoundingBox: " (string-join (map number->string  bbox) " ") "\n"
+                "%%EndComments\n"))
+
+(define (page-header bookpaper page-count)
+  (string-append "%!PS-Adobe-3.0\n"
+                "%%Creator: creator time-stamp\n"
+                "%%Pages: " (number->string page-count) "\n"
+                "%%PageOrder: Ascend\n"
+                "%%DocumentPaperSizes: " (ly:output-def-lookup bookpaper 'papersize) "\n"))
+
+(define (preamble bookpaper)
+  (list
+   (output-variables bookpaper)
+   (ly:gulp-file "music-drawing-routines.ps")
+   (ly:gulp-file "lilyponddefs.ps")
+   (load-fonts bookpaper)
+   (define-fonts bookpaper)))
+
 (define-public (output-framework outputter book scopes fields basename)
   (let* ((bookpaper (ly:paper-book-book-paper book))
         (pages (ly:paper-book-pages book))
   (for-each
    (lambda (x)
      (ly:outputter-dump-string outputter x))
-   (list
-    (header bookpaper
-           (length pages)
-           #f)
-
-    "%%Pages: " (number->string page-count) "\n"
-    "%%PageOrder: Ascend\n"
-    "%%DocumentPaperSizes: " (ly:output-def-lookup bookpaper 'papersize) "\n"
-
-    (output-variables bookpaper)
-    (ly:gulp-file "music-drawing-routines.ps")
-    (ly:gulp-file "lilyponddefs.ps")
-    (load-fonts bookpaper)
-    (define-fonts bookpaper)))
-
+   (cons
+    (page-header bookpaper page-count)
+    (preamble bookpaper)))
+  
   (for-each
    (lambda (page)
      (set! page-number (1+ page-number))
    pages)
   (ly:outputter-dump-string outputter "%%Trailer\n%%EOF\n")))
 
-(define-public (output-classic-framework outputter book scopes fields
-                                           basename)
+(define-public (output-preview-framework outputter book scopes fields basename)
   (let* ((bookpaper (ly:paper-book-book-paper book))
-        (lines (ly:paper-book-lines book))
-        (y 0.0)
-        ;; What the F*** is 2.83463?
-        (scale (* 2.83464 (ly:output-def-lookup bookpaper 'outputscale)))
-        (total-y
-         (apply + (map (lambda (z) (ly:paper-system-extent z Y)) lines)))
-        (x-ext '(-8 . 0))
-        (lineno 0))
-
-    (define (dump-line outputter system)
-      (let ((stil (ly:paper-system-stencil system)))
-       
-       (ly:outputter-dump-string
-        outputter
-        (string-append
-         " 0.0 "
-         (ly:number->string y)
-         " start-system {\n set-ps-scale-to-lily-scale\n"))
-       (set! y (+ y (ly:paper-system-extent system Y)))
-       (ly:outputter-dump-stencil outputter stil)
-       (ly:outputter-dump-string
-        outputter
-        "} stop-system\n")))
-
-    (define (to-pt x)
-      (inexact->exact (round (* scale x))))
-
-    (define (bbox llx lly urx ury)
-      (string-append
-       "%%BoundingBox: "
-       (ly:number->string (to-pt llx)) " "
-       (ly:number->string (to-pt lly)) " "
-       (ly:number->string (to-pt urx)) " "
-       (ly:number->string (to-pt ury)) "\n"))
-
-    (for-each
-     (lambda (ell)
-       (set! x-ext (interval-union x-ext
-                                  (cons 0.0 (ly:paper-system-extent ell X)))))
-     lines)
-
+        (systems (ly:paper-book-lines book))
+        (scale  (ly:output-def-lookup bookpaper 'outputscale ))
+        (titles (take-while ly:paper-system-title? systems))
+        (non-title (find (lambda (x) (not (ly:paper-system-title? x))) systems))
+        (dump-me
+         (stack-stencils Y DOWN 0.0 
+                         (map ly:paper-system-stencil
+                              (append titles (list non-title)))))
+        (xext (ly:stencil-extent dump-me X))
+        (yext (ly:stencil-extent dump-me Y))
+        )
+    
   (for-each
    (lambda (x)
      (ly:outputter-dump-string outputter x))
-   (list
-    "%!PS-Adobe-2.0 EPSF-2.0\n"
-    "%%Creator: LilyPond \n"
+   (cons
+    (eps-header bookpaper
+               (map
+                (lambda (x)
+                  (inexact->exact
+                   (round (* x scale mm-to-bigpoint))))
+                (list (car xext) (car yext)
+                      (cdr xext) (cdr yext))))
+    (preamble bookpaper)))
 
-;;    (bbox (car x-ext) 0 (cdr x-ext) total-y)    ; doesn't work well
 
-    "%%EndComments\n"
-    (output-variables bookpaper)
-    (ly:gulp-file "music-drawing-routines.ps")
-    (ly:gulp-file "lilyponddefs.ps")
-    (load-fonts bookpaper)
-    (define-fonts bookpaper)))
+  (ly:outputter-dump-string outputter
+                           (string-append "0 0 start-system { "
+                                          "set-ps-scale-to-lily-scale "
+                                          "\n"))
+  (ly:outputter-dump-stencil outputter dump-me)
+  (ly:outputter-dump-string outputter "} stop-system\n%%Trailer\n%%EOF\n")))
+
+(define-public (convert-to-pdf book name)
+  (display
+   (string-append
+    "Converting to "
+    (regexp-substitute/global #f "\\.ps" name 'pre ".pdf" 'post)
+    "\n"))
+  (system (string-append "ps2pdf -sPAPERSIZE="
+                        (ly:output-def-lookup
+                         (ly:paper-book-book-paper book)
+                         'papersize)
+                        " "
+                        name)))
 
-;; ;   page-number page-count))
-  (for-each
-   (lambda (line) (set! lineno (1+ lineno)) (dump-line outputter line))
-   lines)
-  (ly:outputter-dump-string outputter "\n")))
+
+(define-public (convert-to-png book name)
+  (display
+   (string-append
+    "Converting to "
+    (regexp-substitute/global #f "\\.ps" name 'pre ".png" 'post)
+    "\n"))
+  (system (string-append "ps2pdf -sPAPERSIZE="
+                        (ly:output-def-lookup
+                         (ly:paper-book-book-paper book)
+                         'papersize)
+                        " "
+                        name)))
+
+
+; %%BoundingBox: 70 597 207 657
index e268f4173ace521e6143b09b614f309ff7ee5044..f032dec4821dfbed401fb2f8913de8bee10227a2 100644 (file)
        "}\\vss\n}\n\\vfill\n"
        "}\\vss\n}\n\\vfill\\lilypondpagebreak\n")))
 
-(define-public (output-framework outputter book scopes fields basename)
+(define-public (output-framework outputter book scopes fields basename options)
   (let* ((bookpaper (ly:paper-book-book-paper book))
         (pages (ly:paper-book-pages book))
         (last-page (car (last-pair pages)))
 
 
 (define-public (output-preview-framework
-               outputter book scopes fields basename)
+               outputter book scopes fields basename options)
   (let* ((bookpaper (ly:paper-book-book-paper book))
         (lines (ly:paper-book-lines book)))
     (for-each