From: Han-Wen Nienhuys Date: Fri, 23 Jul 2004 23:23:53 +0000 (+0000) Subject: * lily/paper-book.cc (output): call output-preview-framework X-Git-Tag: release/2.3.10~61 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=6d2e47f69fe7ca82e89334abaa640e82cd1581ef;p=lilypond.git * 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 --- diff --git a/ChangeLog b/ChangeLog index 64392910a0..63814c51b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ +2004-07-24 Han-Wen Nienhuys + + * 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 + * VERSION: release 2.3.8 + * lily/note-head.cc: remove ledger line handling. * lily/ambitus.cc (print): strip away accidental / note head code, diff --git a/lily/include/main.hh b/lily/include/main.hh index 62aeb4fbea..bafde2f92e 100644 --- a/lily/include/main.hh +++ b/lily/include/main.hh @@ -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 failed_files; diff --git a/lily/include/paper-book.hh b/lily/include/paper-book.hh index 3654b87107..e2b678d30c 100644 --- a/lily/include/paper-book.hh +++ b/lily/include/paper-book.hh @@ -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) diff --git a/lily/include/paper-outputter.hh b/lily/include/paper-outputter.hh index 96544542e1..fc6a20b712 100644 --- a/lily/include/paper-outputter.hh +++ b/lily/include/paper-outputter.hh @@ -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); diff --git a/lily/main.cc b/lily/main.cc index 8b5478828b..ce64720977 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -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; diff --git a/lily/paper-book.cc b/lily/paper-book.cc index 0c0a0629fc..6e739723cf 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -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"); diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index bb9c3812cf..7976b17a47 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -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_); +} diff --git a/scm/framework-ps.scm b/scm/framework-ps.scm index 50070674f6..99ed406cae 100644 --- a/scm/framework-ps.scm +++ b/scm/framework-ps.scm @@ -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)) @@ -157,8 +160,7 @@ (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) @@ -167,11 +169,6 @@ (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 @@ -183,6 +180,27 @@ (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)) @@ -191,21 +209,10 @@ (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)) @@ -213,68 +220,67 @@ 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 diff --git a/scm/framework-tex.scm b/scm/framework-tex.scm index e268f4173a..f032dec482 100644 --- a/scm/framework-tex.scm +++ b/scm/framework-tex.scm @@ -149,7 +149,7 @@ "}\\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))) @@ -203,7 +203,7 @@ (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