+2005-01-05 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+ * scm/lily.scm (completize-formats): new function
+ (postprocess-output): new function
+
+ * lily/paper-book.cc (classic_output): change calling
+ convention. Give basename as first argument.
+ remove Paper_book::post_processing().
+
+ * lily/lily-guile.cc (LY_DEFINE): ly:output-backend, new function.
+
2005-01-04 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * lily/paper-outputter.cc (LY_DEFINE): new function
+ ly:outputter-close.
+
* lily/main.cc: change --format,-f to --backend,-b
* lily/include/main.hh: rename format to backend.
some internal variables. Use @code{-e '(ly:option-usage)'} for more
information.
-
@item -f,--format=@var{format}
+which formats should be written. Choices are @code{svg}, @code{ps},
+@code{pdf}, @code{png}, @code{tex}, @code{dvi}.
+
+@item -b,--backend=@var{format}
the output format to use for the back-end. Choices are
@table @code
@item tex
%% A simple piece in LilyPond, a scale.
\relative {
- c' d e f g a b c
+ c d e f g a b c
}
%% Optional helper for automatic updating by convert-ly. May be omitted.
extern bool make_ps;
extern bool make_pdf;
extern bool make_tex;
+extern String output_format_global;
+
extern bool make_preview;
extern bool make_pages;
+/*
+ misc.hh -- declare miscellaneous functions.
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
#ifndef MISC_HH
#define MISC_HH
else return 0;
}
-
+Array<String> split_string (String s, char c);
inline Real
linear_interpolate (Real x, Real x1, Real x2, Real y1, Real y2)
(x - x1) / (x2 - x1) * y2 ;
}
-
-
#endif
#include "pitch.hh"
#include "dimensions.hh"
#include "source-file.hh"
+#include "misc.hh"
// #define TEST_GC
return scm_makfrom0str (gettext (scm_i_string_chars (string)));
}
+
+
+
+LY_DEFINE (ly_output_backend, "ly:output-backend",
+ 0, 0, 0, (),
+ "Return name of output backend.")
+{
+ return scm_makfrom0str (output_backend_global.to_str0 ());
+}
+
+
+LY_DEFINE (ly_output_formats, "ly:output-formats",
+ 0, 0, 0, (),
+ "Formats passed to --format as a list of strings, "
+ "used for the output.")
+{
+ Array<String> output_formats = split_string (output_format_global, ',');
+
+ SCM lst = SCM_EOL;
+ int output_formats_count = output_formats.size ();
+ for (int i = 0; i < output_formats_count; i ++)
+ lst = scm_cons (scm_makfrom0str (output_formats[i].to_str0 ()), lst);
+
+ return lst;
+}
One of tex, ps, scm, as.
*/
String output_backend_global = "ps";
+String output_format_global = "pdf";
/* Current output name. */
String output_name_global;
*/
String init_scheme_code_string = "(begin #t ";
-bool make_pdf = false;
-bool make_dvi = false;
-bool make_ps = false;
-bool make_png = false;
bool make_preview = false;
bool make_pages = true;
-bool make_tex = false;
+
/*
* Miscellaneous global stuff.
/* Bug in option parser: --output =foe is taken as an abbreviation
for --output-format. */
{_i ("EXT"), "backend", 'b', _i ("select back-end to use")},
+ {_i ("EXTs"), "format", 'f', _i ("list of formats to dump")},
{0, "help", 'h', _i ("print this help")},
{_i ("FIELD"), "header", 'H', _i ("write header field to BASENAME.FIELD")},
{_i ("DIR"), "include", 'I', _i ("add DIR to search path")},
scm_c_eval_string (s.to_str0 ());
}
-static void
-determine_output_options ()
-{
- bool found_gnome = (output_backend_global == "gnome");
- bool found_svg = (output_backend_global == "svg");
- bool found_tex = (output_backend_global == "tex");
-
-
- if (make_pdf || make_png)
- {
- make_ps = true;
- }
- if (make_ps && found_tex)
- {
- make_dvi = true;
- }
- if (make_dvi && found_tex)
- {
- make_tex = true;
- }
- if (!found_gnome
- && !found_svg
- && !(make_dvi
- || make_tex
- || make_ps
- || make_png
- || make_pdf))
- {
- make_pdf = true;
- make_ps = true;
- if (found_tex)
- {
- make_dvi = true;
- make_tex = true;
- }
- }
-}
-
void init_global_tweak_registry ();
static void
call_constructors ();
init_global_tweak_registry ();
init_freetype ();
- determine_output_options ();
all_fonts_global = new All_font_metrics (global_path.to_string ());
init_scheme_code_string += ")";
warranty ();
exit (0);
break;
- case 'f':
- if (option_parser->optional_argument_str0_ == "help")
- {
- printf (_ ("This option is for developers only.").to_str0 ());
- printf (_ ("Read the sources for more information.").to_str0 ());
- exit (0);
- }
+ case 'b':
output_backend_global = option_parser->optional_argument_str0_;
break;
+
+ case 'f':
+ output_format_global = option_parser->optional_argument_str0_;
+ break;
+
case 'H':
dump_header_fieldnames_global
.push (option_parser->optional_argument_str0_);
Jan Nieuwenhuizen <janneke@gnu.org>
*/
+#include <math.h>
+
#include "misc.hh"
+#include "string.hh"
-#include <math.h>
/*
Return the 2-log, rounded down
return log (x) /log (2.0);
}
-
+Array<String>
+split_string (String s, char c)
+{
+ Array<String> rv;
+ while (s.length ())
+ {
+ int i = s.index (c);
+
+ if (i == 0)
+ {
+ s = s.nomid_string (0, 1);
+ continue;
+ }
+
+ if (i < 0)
+ i = s.length () ;
+
+ rv.push (s.cut_string (0, i));
+ s = s.nomid_string (0, i);
+ }
+
+ return rv;
+}
return 1;
}
-Array<String>
-split_string (String s, char c)
-{
- Array<String> rv;
- while (s.length ())
- {
- int i = s.index (c);
-
- if (i == 0)
- {
- s = s.nomid_string (0, 1);
- continue;
- }
-
- if (i < 0)
- i = s.length () ;
-
- rv.push (s.cut_string (0, i));
- s = s.nomid_string (0, i);
- }
-
- return rv;
-}
-
SCM
dump_fields ()
{
return fields;
}
-void
-Paper_book::post_processing (SCM module,
- SCM file_name)
-{
- struct
- {
- bool do_it_;
- char const *func_name_;
- } settings[] = {
- {make_tex, "convert-to-tex"},
- {make_dvi, "convert-to-dvi"},
- {make_ps, "convert-to-ps"},
- {make_pdf, "convert-to-pdf"},
- {make_png, "convert-to-png"},
- {0, 0},
- };
-
- for (int i = 0; settings[i].func_name_; i++)
- {
- if (settings[i].do_it_)
- {
- SCM func = scm_c_module_lookup (module, settings[i].func_name_);
- 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)
{
/* Generate all stencils to trigger font loads. */
pages ();
- String format = output_backend_global;
- String file_name = outname;
-
- if (file_name != "-")
- file_name += "." + format;
-
- Paper_outputter *out = get_paper_outputter (file_name, format);
-
SCM scopes = SCM_EOL;
if (ly_c_module_p (header_))
scopes = scm_cons (header_, scopes);
- String mod_nm = "scm framework-" + format;
+ String mod_nm = "scm framework-" + output_backend_global;
SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
if (make_pages)
SCM func = scm_c_module_lookup (mod, "output-framework");
func = scm_variable_ref (func);
- scm_apply_0 (func, scm_list_n (out->self_scm (),
+ scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
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 ()));
}
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 (),
+ scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
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");
}
func = scm_variable_ref (func);
- Paper_outputter *out = get_paper_outputter (outname + "." + format,
- format);
-
- scm_apply_0 (func, scm_list_n (out->self_scm (), self_scm (), scopes,
+ scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
+ self_scm (),
+ scopes,
dump_fields (),
- scm_makfrom0str (outname.to_str0 ()),
SCM_UNDEFINED));
- scm_gc_unprotect_object (out->self_scm ());
progress_indication ("\n");
}
(void*) this, Offset (0,0));
}
-Paper_outputter *
-get_paper_outputter (String outname, String f)
+LY_DEFINE (ly_make_paper_outputter, "ly:make-paper-outputter",
+ 2, 0, 0, (SCM outname, SCM format),
+ "Create an outputter that evaluates within "
+ "@code{output-}@var{format}, writing to file @var{outname}.")
{
+ SCM_ASSERT_TYPE(scm_is_string (outname), outname, SCM_ARG1, __FUNCTION__,
+ "String");
+ SCM_ASSERT_TYPE(scm_is_string (format), format, SCM_ARG2, __FUNCTION__,
+ "String");
+
+ String outname_str = ly_scm2string (outname);
+ String f = ly_scm2string (format);
+
progress_indication (_f ("Layout output to `%s'...",
- outname == "-" ? String ("<stdout>") : outname));
+ outname_str == "-"
+ ? String ("<stdout>")
+ : outname_str));
progress_indication ("\n");
- return new Paper_outputter (outname, f);
+ Paper_outputter *po = new Paper_outputter (outname_str, f);
+
+ scm_gc_unprotect_object (po->self_scm ());
+ return po->self_scm ();
}
/* FIXME: why is output_* wrapper called dump? */
return po->dump_string (str);
}
+
+LY_DEFINE (ly_outputter_close, "ly:outputter-close",
+ 1, 0, 0, (SCM outputter),
+ "Close port of @var{outputter}.")
+{
+ Paper_outputter *po = unsmob_outputter (outputter);
+ SCM_ASSERT_TYPE (po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter");
+
+ po->close ();
+ return SCM_UNSPECIFIED;
+}
+
void
Paper_outputter::close ()
{
(srfi srfi-13)
(lily))
+(define framework-ps-module (current-module))
+
(define (stderr string . rest)
(apply format (cons (current-error-port) (cons string rest)))
(force-output (current-error-port)))
(load-fonts paper)
(define-fonts paper)))
-(define-public (output-framework outputter book scopes fields basename)
- (let* ((paper (ly:paper-book-paper book))
+
+
+
+(define-public (output-framework basename book scopes fields )
+ (let* ((filename (format "~a.ps" basename))
+ (outputter (ly:make-paper-outputter filename
+ (ly:output-backend)))
+ (paper (ly:paper-book-paper book))
(pages (ly:paper-book-pages book))
(landscape? (eq? (ly:output-def-lookup paper 'landscape) #t))
(page-number (1- (ly:output-def-lookup paper 'firstpagenumber)))
(page-count (length pages)))
-
+
(for-each
(lambda (x)
(ly:outputter-dump-string outputter x))
(dump-page outputter page page-number page-count landscape?))
pages)
- (ly:outputter-dump-string outputter "%%Trailer\n%%EOF\n")))
-
-(define-public (output-preview-framework outputter book scopes fields basename)
- (let* ((paper (ly:paper-book-paper book))
+ (ly:outputter-dump-string outputter "%%Trailer\n%%EOF\n")
+ (ly:outputter-close outputter)
+ (postprocess-output book framework-ps-module filename (ly:output-formats))
+))
+
+(define-public (output-preview-framework basename book scopes fields )
+ (let* ((filename (format "~a.ps" basename))
+ (outputter (ly:make-paper-outputter filename
+ (ly:output-backend)))
+ (paper (ly:paper-book-paper book))
(systems (ly:paper-book-systems book))
(scale (ly:output-def-lookup paper 'outputscale ))
(titles (take-while ly:paper-system-title? systems))
"\n"))
(ly:outputter-dump-stencil outputter dump-me)
- (ly:outputter-dump-string outputter "} stop-system\n%%Trailer\n%%EOF\n")))
+ (ly:outputter-dump-string outputter "} stop-system\n%%Trailer\n%%EOF\n")
+ (ly:outputter-close outputter)
+ (postprocess-output book framework-ps-module filename
+ (ly:output-formats))
+))
+
+
+(define-public (output-classic-framework
+ basename book scopes fields)
+ (let* ((paper (ly:paper-book-paper book))
+ (lines (ly:paper-book-systems book))
+ (last-line (car (last-pair lines))))
+ (for-each
+ (lambda (x)
+ (ly:outputter-dump-string outputter x))
+ (list
+ ;;FIXME
+ (header paper (length lines) #f)
+ "\\def\\lilypondclassic{1}%\n"
+ (output-scopes scopes fields basename)
+ (define-fonts paper)
+ (header-end)))
+
+ (for-each
+ (lambda (line) (dump-line outputter line (eq? line last-line))) lines)
+ (ly:outputter-dump-string outputter "\\lilypondend\n")
+ (ly:outputter-close outputter)
+ (postprocess-output book framework-ps-module filename (ly:output-formats))
+ ))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-public (convert-to-pdf book name)
(let* ((defs (ly:paper-book-paper book))
(srfi srfi-13)
(lily))
+(define (output-formats)
+ (define formats (ly:output-formats))
+ (set! formats (completize-formats formats))
+ (if (member "ps" formats)
+ (set! formats (cons "dvi" formats)))
+ (if (member "dvi" formats)
+ (set! formats (cons "tex" formats)))
+
+ formats)
+
+(define framework-tex-module (current-module))
(define-public (sanitize-tex-string s)
(if (ly:get-option 'safe)
(regexp-substitute/global
"}%\n\\vfill\n"
"}%\n\\vfill\n\\lilypondpagebreak\n")))
-(define-public (output-framework outputter book scopes fields basename )
- (let* ((paper (ly:paper-book-paper book))
+(define-public (output-framework basename book scopes fields)
+ (let* ((filename (format "~a.tex" basename))
+ (outputter (ly:make-paper-outputter filename "tex"))
+ (paper (ly:paper-book-paper book))
(pages (ly:paper-book-pages book))
(last-page (car (last-pair pages)))
(with-extents
(lambda (page)
(dump-page outputter page (eq? last-page page) with-extents))
pages)
- (ly:outputter-dump-string outputter "\\lilypondend\n")))
+ (ly:outputter-dump-string outputter "\\lilypondend\n")
+ (ly:outputter-close outputter)
+ (postprocess-output book framework-tex-module filename
+ (output-formats))))
(define (dump-line putter line last?)
(ly:outputter-dump-string
"}\\interscoreline\n")))
(define-public (output-classic-framework
- outputter book scopes fields basename)
- (let* ((paper (ly:paper-book-paper book))
+ basename book scopes fields)
+ (let* ((filename (format "~a.tex" basename))
+ (outputter (ly:make-paper-outputter filename "tex"))
+ (paper (ly:paper-book-paper book))
(lines (ly:paper-book-systems book))
(last-line (car (last-pair lines))))
(for-each
(for-each
(lambda (line) (dump-line outputter line (eq? line last-line))) lines)
- (ly:outputter-dump-string outputter "\\lilypondend\n")))
+ (ly:outputter-dump-string outputter "\\lilypondend\n")
+ (ly:outputter-close outputter)
+ (postprocess-output book framework-tex-module filename
+ (output-formats))
+ ))
(define-public (output-preview-framework
- outputter book scopes fields basename )
- (let* ((paper (ly:paper-book-paper book))
+ basename book scopes fields)
+ (let* ((filename (format "~a.tex" basename))
+ (outputter (ly:make-paper-outputter filename
+ "tex"))
+ (paper (ly:paper-book-paper book))
(lines (ly:paper-book-systems book))
(first-notes-index (list-index
(lambda (s) (not (ly:paper-system-title? s)))
(lambda (lst)
(dump-line outputter lst (not (ly:paper-system-title? lst))))
(take lines (1+ first-notes-index)))
- (ly:outputter-dump-string outputter "\\lilypondend\n")))
+ (ly:outputter-dump-string outputter "\\lilypondend\n")
+ (ly:outputter-close outputter)
+ (postprocess-output book framework-tex-module filename
+ (output-formats))
+
+))
(define-public (convert-to-pdf book name)
(let* ((defs (ly:paper-book-paper book))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; backend helpers.
(define-public (ly:system command)
(let* ((status 0)
name)))
(ly:system cmd)))
+(define-public (postprocess-output paper-book module filename formats)
+ (for-each (lambda (f)
+ ((eval (string->symbol (string-append "convert-to-" f))
+ module)
+ paper-book filename))
+
+ formats))
+
+(define-public (completize-formats formats)
+ (if (member "png" formats)
+ (set! formats (cons "ps" formats)))
+ (if (member "pdf" formats)
+ (set! formats (cons "ps" formats)))
+
+ formats)
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
(define-public (lilypond-main files)
"Entry point for LilyPond."
(let* ((failed '())