new function.
(LY_DEFINE): change name ly:parser-define -> ly:parser-define!
2005-07-11 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * lily/lily-parser-scheme.cc (LY_DEFINE): ly:parser-output-name:
+ new function.
+ (LY_DEFINE): change name ly:parser-define -> ly:parser-define!
+
* scm/framework-*.scm: use port arguments throughout.
* lily/include/lily-guile.hh: rename ly_c_X_p -> ly_is_X
*/
#include "book.hh"
+
#include "output-def.hh"
#include "score.hh"
+#include "paper-book.hh"
#include "ly-module.hh"
LY_DEFINE (ly_make_book, "ly:make-book",
Book *book = new Book;
book->paper_ = odef;
- if (ly_c_module_p (header))
+ if (ly_is_module (header))
book->header_ = header;
book->scores_ = scm_append (scm_list_2 (scores, book->scores_));
scm_gc_unprotect_object (x);
return x;
}
+
+LY_DEFINE (ly_parser_print_book, "ly:book-process",
+ 3, 0, 0, (SCM book_smob,
+ SCM default_paper,
+ SCM default_layout,
+ SCM basename),
+ "Print book.")
+{
+ Book *book = unsmob_book (book_smob);
+
+ SCM_ASSERT_TYPE (book, book_smob, SCM_ARG1, __FUNCTION__, "Book");
+ SCM_ASSERT_TYPE (unsmob_output_def (default_paper),
+ default_layout, SCM_ARG2, __FUNCTION__, "\\paper block");
+ SCM_ASSERT_TYPE (unsmob_output_def (default_layout),
+ default_layout, SCM_ARG3, __FUNCTION__, "\\layout block");
+ SCM_ASSERT_TYPE (scm_is_string (basename), basename, SCM_ARG4, __FUNCTION__, "string");
+
+ String base = ly_scm2string (basename);
+ Paper_book *pb = book->process (base,
+ unsmob_output_def (default_paper),
+ unsmob_output_def (default_layout)
+ );
+ if (pb)
+ {
+ pb->output (base);
+ scm_gc_unprotect_object (pb->self_scm ());
+ }
+
+ return SCM_UNSPECIFIED;
+}
+
/* This function does not dump the output; outname is required eg. for
dumping header fields. */
Paper_book *
-Book::process (String outname, Output_def *default_def)
+Book::process (String outname,
+ Output_def *default_paper,
+ Output_def *default_layout)
{
for (SCM s = scores_; s != SCM_EOL; s = scm_cdr (s))
if (Score *score = unsmob_score (scm_car (s)))
if (score->error_found_)
return 0;
+ Output_def *paper = paper_ ? default_paper : paper_;
+
Paper_book *paper_book = new Paper_book ();
- Real scale = scm_to_double (paper_->c_variable ("outputscale"));
- Output_def *scaled_bookdef = scale_output_def (paper_, scale);
+ Real scale = scm_to_double (paper->c_variable ("outputscale"));
+ Output_def *scaled_bookdef = scale_output_def (paper, scale);
Object_key *key = new Lilypond_general_key (0, user_key_, 0);
SCM scm_key = key->self_scm ();
if (Score *score = unsmob_score (scm_car (s)))
{
SCM outputs = score
- ->book_rendering (paper_book->paper_, default_def, key);
+ ->book_rendering (paper_book->paper_, default_layout, key);
while (scm_is_pair (outputs))
{
else if (Paper_score *pscore = dynamic_cast<Paper_score *> (output))
{
SCM systems = pscore->get_paper_systems ();
- if (ly_c_module_p (score->header_))
+ if (ly_is_module (score->header_))
paper_book->add_score (score->header_);
paper_book->add_score (systems);
}
*/
-#include "lily-parser.hh"
-#include "lily-lexer.hh"
-#include "lilypond-key.hh"
-#include "book.hh"
-#include "paper-book.hh"
-#include "score.hh"
-#include "file-name.hh"
-#include "output-def.hh"
-
-
-
-
-/* TODO: move this to Scheme? Why take the parser arg, and all the back
- & forth between scm and c++? */
-LY_DEFINE (ly_parser_print_score, "ly:parser-print-score",
- 2, 0, 0,
- (SCM parser_smob, SCM score_smob),
- "Print score, i.e., the classic way.")
-{
- Lily_parser *parser = unsmob_lily_parser (parser_smob);
- Score *score = unsmob_score (score_smob);
-
- Object_key *key = new Lilypond_general_key (0, score->user_key_, 0);
-
- if (score->error_found_)
- return SCM_UNSPECIFIED;
-
- SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "parser");
- SCM_ASSERT_TYPE (score, score_smob, SCM_ARG2, __FUNCTION__, "score");
-
- SCM header = ly_c_module_p (score->header_)
- ? score->header_
- : parser->lexer_->lookup_identifier ("$globalheader");
-
- File_name outname (parser->output_basename_);
- int *c = &parser->book_count_;
- if (*c)
- outname.base_ += "-" + to_string (*c);
- (*c)++;
-
- SCM os = scm_makfrom0str (outname.to_string ().to_str0 ());
- SCM paper = get_paper (parser)->self_scm ();
- for (int i = 0; i < score->defs_.size (); i++)
- default_rendering (score->get_music (), score->defs_[i]->self_scm (),
- paper, header, os, key->self_scm ());
-
- if (score->defs_.is_empty ())
- {
- Output_def *layout = get_layout (parser);
- default_rendering (score->get_music (),
- layout->self_scm (),
- paper,
- header, os, key->self_scm ());
-
- scm_gc_unprotect_object (layout->self_scm ());
- }
-
- scm_gc_unprotect_object (paper);
- scm_gc_unprotect_object (key->self_scm ());
- return SCM_UNSPECIFIED;
-}
-
-
-LY_DEFINE (ly_parser_print_book, "ly:parser-print-book",
- 2, 0, 0, (SCM parser_smob, SCM book_smob),
- "Print book.")
-{
- Lily_parser *parser = unsmob_lily_parser (parser_smob);
- Book *book = unsmob_book (book_smob);
- Output_def *bp = unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"));
-
- SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "Lilypond parser");
- SCM_ASSERT_TYPE (book, book_smob, SCM_ARG2, __FUNCTION__, "Book");
-
- /* ugh. changing argument.*/
- book->paper_ = bp;
-
- File_name outname (parser->output_basename_);
- int *c = &parser->book_count_;
- if (*c)
- outname.base_ += "-" + to_string (*c);
- (*c)++;
-
- Output_def *layout = get_layout (parser);
- Paper_book *pb = book->process (outname.to_string (), layout);
-
- if (pb)
- {
- pb->output (outname.to_string ());
- scm_gc_unprotect_object (pb->self_scm ());
- }
-
- scm_gc_unprotect_object (layout->self_scm ());
- return SCM_UNSPECIFIED;
-}
-
Book ();
void add_score (SCM);
- Paper_book *process (String, Output_def *);
+ Paper_book *process (String,
+ Output_def *def_paper,
+ Output_def *def_layout);
void set_keys ();
};
SCM ly_modules_lookup (SCM modules, SCM sym, SCM);
SCM ly_module_symbols (SCM mod);
void ly_reexport_module (SCM mod);
-inline bool ly_c_module_p (SCM x) { return SCM_MODULEP (x); }
+inline bool ly_is_module (SCM x) { return SCM_MODULEP (x); }
void ly_clear_anonymous_modules ();
SCM ly_use_module (SCM mod, SCM used);
return scm_gc_unprotect_object (clone->self_scm ());
}
-LY_DEFINE (ly_parser_define, "ly:parser-define",
+LY_DEFINE (ly_parser_define, "ly:parser-define!",
3, 0, 0, (SCM parser_smob, SCM symbol, SCM val),
"Bind SYMBOL to VAL in PARSER_SMOB's module.")
{
return SCM_UNSPECIFIED;
}
+
+
+LY_DEFINE (ly_parser_output_name, "ly:parser-output-name",
+ 1, 0, 0, (SCM parser),
+ "Return the base name of the output file.")
+{
+ Lily_parser *p = unsmob_lily_parser (parser);
+ SCM_ASSERT_TYPE (p, parser, SCM_ARG1, __FUNCTION__, "Lilypond parser");
+
+ return scm_from_locale_string (p->output_basename_.to_str0 ());
+}
+
input_origin_ = s.input_origin_;
scope_ = ly_make_anonymous_module (false);
- if (ly_c_module_p (s.scope_))
+ if (ly_is_module (s.scope_))
ly_module_copy (scope_, s.scope_);
}
SCM_ASSERT_TYPE (pb, book, SCM_ARG1, __FUNCTION__, "Paper_book");
SCM scopes = SCM_EOL;
- if (ly_c_module_p (pb->header_))
+ if (ly_is_module (pb->header_))
scopes = scm_cons (pb->header_, scopes);
return scopes;
pages ();
SCM scopes = SCM_EOL;
- if (ly_c_module_p (header_))
+ if (ly_is_module (header_))
scopes = scm_cons (header_, scopes);
String mod_nm = "scm framework-" + output_backend_global;
systems ();
SCM scopes = SCM_EOL;
- if (ly_c_module_p (header_))
+ if (ly_is_module (header_))
scopes = scm_cons (header_, scopes);
- if (ly_c_module_p (header_0_))
+ if (ly_is_module (header_0_))
scopes = scm_cons (header_0_, scopes);
String format = output_backend_global;
Stencil title;
SCM scopes = SCM_EOL;
- if (ly_c_module_p (header_))
+ if (ly_is_module (header_))
scopes = scm_cons (header_, scopes);
SCM tit = SCM_EOL;
Stencil title;
SCM scopes = SCM_EOL;
- if (ly_c_module_p (header_))
+ if (ly_is_module (header_))
scopes = scm_cons (header_, scopes);
- if (ly_c_module_p (header))
+ if (ly_is_module (header))
scopes = scm_cons (header, scopes);
SCM tit = SCM_EOL;
void
set_system_penalty (Paper_system *ps, SCM header)
{
- if (ly_c_module_p (header))
+ if (ly_is_module (header))
{
SCM force = ly_module_lookup (header, ly_symbol2scm ("breakbefore"));
if (SCM_VARIABLEP (force)
SCM header = SCM_EOL;
for (SCM s = scm_reverse (scores_); s != SCM_EOL; s = scm_cdr (s))
{
- if (ly_c_module_p (scm_car (s)))
+ if (ly_is_module (scm_car (s)))
{
header = scm_car (s);
if (header_0_ == SCM_EOL)
*/
#include "score.hh"
+
#include "music.hh"
#include "output-def.hh"
#include "global-context.hh"
+#include "lilypond-key.hh"
+
LY_DEFINE (ly_make_score, "ly:make-score",
1, 0, 0,
scm_remember_upto_here_1 (prot);
return output;
}
+
+LY_DEFINE (ly_score_process, "ly:score-process",
+ 2, 0, 0,
+ (SCM score_smob,
+ SCM default_header,
+ SCM default_paper,
+ SCM default_layout,
+ SCM basename),
+ "Print score, i.e., the classic way.")
+{
+ Score *score = unsmob_score (score_smob);
+
+ SCM_ASSERT_TYPE (score, score_smob, SCM_ARG1, __FUNCTION__, "score");
+
+ SCM_ASSERT_TYPE (ly_is_module (default_header),
+ default_header, SCM_ARG2, __FUNCTION__, "module");
+ SCM_ASSERT_TYPE (unsmob_output_def (default_paper),
+ default_header, SCM_ARG3, __FUNCTION__, "\\paper block");
+ SCM_ASSERT_TYPE (unsmob_output_def (default_layout),
+ default_header, SCM_ARG4, __FUNCTION__, "\\layout block");
+ SCM_ASSERT_TYPE (scm_is_string (basename),
+ default_header, SCM_ARG5, __FUNCTION__, "basename");
+
+ Object_key *key = new Lilypond_general_key (0, score->user_key_, 0);
+
+ if (score->error_found_)
+ return SCM_UNSPECIFIED;
+
+ SCM header = ly_is_module (score->header_)
+ ? score->header_
+ : default_header;
+
+ for (int i = 0; i < score->defs_.size (); i++)
+ default_rendering (score->get_music (), score->defs_[i]->self_scm (),
+ default_paper, header, basename, key->self_scm ());
+
+ if (score->defs_.is_empty ())
+ {
+ default_rendering (score->get_music (),
+ default_layout,
+ default_paper,
+ header, basename, key->self_scm ());
+ }
+
+ scm_gc_unprotect_object (key->self_scm ());
+ return SCM_UNSPECIFIED;
+}
+
+
#include "global-context.hh"
#include "lily-parser.hh"
#include "lilypond-key.hh"
-#include "ly-smobs.icc"
#include "main.hh"
-#include "music-iterator.hh"
#include "music.hh"
#include "output-def.hh"
-#include "output-def.hh"
#include "paper-book.hh"
#include "paper-score.hh"
-#include "scm-hash.hh"
#include "warn.hh"
+
+#include "music.hh"
+#include "ly-smobs.icc"
+
Score::Score ()
: Input ()
{
scm_gc_unprotect_object (copy->self_scm ());
}
header_ = ly_make_anonymous_module (false);
- if (ly_c_module_p (s.header_))
+ if (ly_is_module (s.header_))
ly_module_copy (header_, s.header_);
texts_ = s.texts_;
paper_book->header_ = header;
paper_book->paper_ = unsmob_output_def (scaled_bookdef);
- if (ly_c_module_p (header))
+ if (ly_is_module (header))
paper_book->add_score (header);
SCM systems = pscore->get_paper_systems ();
%% MAKE-HASH-TABLE in GUILE 1.6 takes mandatory size parameter.
#(define musicQuotes (make-hash-table 29))
-#(define toplevel-book-handler ly:parser-print-book)
+#(define toplevel-book-handler print-book-with-defaults)
#(define toplevel-music-handler collect-music-for-book)
#(define toplevel-score-handler collect-scores-for-book)
#(define toplevel-text-handler collect-scores-for-book)
(version-not-seen-message input-file-name))
#(if (pair? toplevel-scores)
- (ly:parser-print-book parser
+ (toplevel-book-handler
+ parser
(apply ly:make-book $defaultpaper $globalheader toplevel-scores)))
-
'dummy rule for 2.6'))
+
def conv (str):
return re.sub('ly:get-default-font', 'ly:grob-default-font', str)
conversions.append (((2, 7, 0), conv,
-
- 'ly:get-default-font -> ly:grob-default-font'))
+ 'ly:get-default-font -> ly:grob-default-font'))
+
+def conv (str):
+ return re.sub('ly:parser-define', 'ly:parser-define!', str)
+
+conversions.append (((2, 7, 0), conv,
+ 'ly:parser-define -> ly:parser-define!'))
################################################################
(display (format "@image{~a-~a}\n"
basename (1+ c)) texi-system-port))
(iota (length stencils)))
- (display "@c eof - 'eof' is a Makefile marker; don not remove. " texi-system-port)
+ (display "@c eof - 'eof' is a Makefile marker; do not remove. " texi-system-port)
(display "% eof - 'eof' is Makefile marker; do not remove. " tex-system-port)
(dump-infinite-stack-EPS stencils))
(set! music (func music parser)))
toplevel-music-functions)
-; (display-scheme-music music)
(ly:make-score music))
-
(define-public (collect-music-for-book parser music)
(collect-scores-for-book parser (scorify-music music parser)))
-
+
+(define-public (print-book-with-defaults parser book)
+ (let*
+ ((paper (ly:parser-lookup parser '$defaultpaper))
+ (layout (ly:parser-lookup parser '$defaultlayout))
+ (count (ly:parser-lookup parser 'book-count))
+ (base (ly:parser-output-name parser)))
+
+ (if (not (integer? count))
+ (set! count 0))
+
+ (if (> count 0)
+ (set! (base (format #f "~a-~a" count))))
+
+ (ly:parser-define! book-count (1+ count))
+
+
+ (ly:book-process book paper layout base)
+ ))
+
+(define-public (print-score-with-defaults parser score)
+ (let*
+ ((paper (ly:parser-lookup parser '$defaultpaper))
+ (layout (ly:parser-lookup parser '$defaultlayout))
+ (layout (ly:parser-lookup parser '$globalheader))
+ (count (ly:parser-lookup parser 'book-count))i
+ (base (ly:parser-output-name parser)))
+
+ (if (not (integer? count))
+ (set! count 0))
+
+ (if (> count 0)
+ (set! (base (format #f "~a-~a" count))))
+
+ (ly:parser-define! book-count (1+ count))
+
+
+ (ly:score-process score header paper layout base)
+ ))
+
;;;;;;;;;;;;;;;;
-; alist
+;; alist
(define-public assoc-get ly:assoc-get)
(define-public (uniqued-alist alist acc)
ly:output-def-lookup
ly:parse-string
ly:parser-parse-string
- ly:parser-print-book
- ly:parser-print-score
ly:pitch-alteration
ly:pitch-diff
ly:pitch-notename
PREAMBLE_LY = r'''%%%% Generated by %(program_name)s
%%%% Options: [%(option_string)s]
-#(set! toplevel-score-handler ly:parser-print-score)
+#(set! toplevel-score-handler print-score-with-defaults)
#(set! toplevel-music-handler (lambda (p m)
- (ly:parser-print-score
+ (print-score-with-defaults
p (scorify-music m p))))
#(ly:set-option (quote no-point-and-click))