2 default-actions.cc -- implement default toplevel actions for .ly
5 source file of the GNU LilyPond music typesetter
7 (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "lily-parser.hh"
12 #include "lily-lexer.hh"
13 #include "lilypond-key.hh"
15 #include "paper-book.hh"
17 #include "file-name.hh"
18 #include "output-def.hh"
23 /* TODO: move this to Scheme? Why take the parser arg, and all the back
24 & forth between scm and c++? */
25 LY_DEFINE (ly_parser_print_score
, "ly:parser-print-score",
27 (SCM parser_smob
, SCM score_smob
),
28 "Print score, i.e., the classic way.")
30 Lily_parser
*parser
= unsmob_lily_parser (parser_smob
);
31 Score
*score
= unsmob_score (score_smob
);
33 Object_key
*key
= new Lilypond_general_key (0, score
->user_key_
, 0);
35 if (score
->error_found_
)
36 return SCM_UNSPECIFIED
;
38 SCM_ASSERT_TYPE (parser
, parser_smob
, SCM_ARG1
, __FUNCTION__
, "parser");
39 SCM_ASSERT_TYPE (score
, score_smob
, SCM_ARG2
, __FUNCTION__
, "score");
41 SCM header
= ly_c_module_p (score
->header_
)
43 : parser
->lexer_
->lookup_identifier ("$globalheader");
45 File_name
outname (parser
->output_basename_
);
46 int *c
= &parser
->book_count_
;
48 outname
.base_
+= "-" + to_string (*c
);
51 SCM os
= scm_makfrom0str (outname
.to_string ().to_str0 ());
52 SCM paper
= get_paper (parser
)->self_scm ();
53 for (int i
= 0; i
< score
->defs_
.size (); i
++)
54 default_rendering (score
->get_music (), score
->defs_
[i
]->self_scm (),
55 paper
, header
, os
, key
->self_scm ());
57 if (score
->defs_
.is_empty ())
59 Output_def
*layout
= get_layout (parser
);
60 default_rendering (score
->get_music (),
63 header
, os
, key
->self_scm ());
65 scm_gc_unprotect_object (layout
->self_scm ());
68 scm_gc_unprotect_object (paper
);
69 scm_gc_unprotect_object (key
->self_scm ());
70 return SCM_UNSPECIFIED
;
74 LY_DEFINE (ly_parser_print_book
, "ly:parser-print-book",
75 2, 0, 0, (SCM parser_smob
, SCM book_smob
),
78 Lily_parser
*parser
= unsmob_lily_parser (parser_smob
);
79 Book
*book
= unsmob_book (book_smob
);
80 Output_def
*bp
= unsmob_output_def (parser
->lexer_
->lookup_identifier ("$defaultpaper"));
82 SCM_ASSERT_TYPE (parser
, parser_smob
, SCM_ARG1
, __FUNCTION__
, "Lilypond parser");
83 SCM_ASSERT_TYPE (book
, book_smob
, SCM_ARG2
, __FUNCTION__
, "Book");
85 /* ugh. changing argument.*/
88 File_name
outname (parser
->output_basename_
);
89 int *c
= &parser
->book_count_
;
91 outname
.base_
+= "-" + to_string (*c
);
94 Output_def
*layout
= get_layout (parser
);
95 Paper_book
*pb
= book
->process (outname
.to_string (), layout
);
99 pb
->output (outname
.to_string ());
100 scm_gc_unprotect_object (pb
->self_scm ());
103 scm_gc_unprotect_object (layout
->self_scm ());
104 return SCM_UNSPECIFIED
;