]> git.donarmstrong.com Git - lilypond.git/blob - lily/default-actions.cc
34f7c62224d6ec970a73c7bb371c635269c9ba42
[lilypond.git] / lily / default-actions.cc
1 /*
2   default-actions.cc -- implement default toplevel actions for .ly
3   file.
4
5   source file of the GNU LilyPond music typesetter
6
7   (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
8
9 */
10
11 #include "lily-parser.hh"
12 #include "lily-lexer.hh"
13 #include "lilypond-key.hh"
14 #include "book.hh"
15 #include "paper-book.hh"
16 #include "score.hh"
17 #include "file-name.hh"
18 #include "output-def.hh"
19
20
21
22
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",
26            2, 0, 0,
27            (SCM parser_smob, SCM score_smob),
28            "Print score, i.e., the classic way.")
29 {
30   Lily_parser *parser = unsmob_lily_parser (parser_smob);
31   Score *score = unsmob_score (score_smob);
32
33   Object_key *key = new Lilypond_general_key (0, score->user_key_, 0);
34
35   if (score->error_found_)
36     return SCM_UNSPECIFIED;
37
38   SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "parser");
39   SCM_ASSERT_TYPE (score, score_smob, SCM_ARG2, __FUNCTION__, "score");
40
41   SCM header = ly_c_module_p (score->header_)
42     ? score->header_
43     : parser->lexer_->lookup_identifier ("$globalheader");
44
45   File_name outname (parser->output_basename_);
46   int *c = &parser->book_count_;
47   if (*c)
48     outname.base_ += "-" + to_string (*c);
49   (*c)++;
50
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 ());
56
57   if (score->defs_.is_empty ())
58     {
59       Output_def *layout = get_layout (parser);
60       default_rendering (score->get_music (),
61                          layout->self_scm (),
62                          paper,
63                          header, os, key->self_scm ());
64       
65       scm_gc_unprotect_object (layout->self_scm ());
66     }
67
68   scm_gc_unprotect_object (paper);
69   scm_gc_unprotect_object (key->self_scm ());
70   return SCM_UNSPECIFIED;
71 }
72
73
74 LY_DEFINE (ly_parser_print_book, "ly:parser-print-book",
75            2, 0, 0, (SCM parser_smob, SCM book_smob),
76            "Print book.")
77 {
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"));
81
82   SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "Lilypond parser");
83   SCM_ASSERT_TYPE (book, book_smob, SCM_ARG2, __FUNCTION__, "Book");
84
85   /*  ugh. changing argument.*/
86   book->paper_ = bp;
87
88   File_name outname (parser->output_basename_);
89   int *c = &parser->book_count_;
90   if (*c)
91     outname.base_ += "-" + to_string (*c);
92   (*c)++;
93
94   Output_def *layout = get_layout (parser);
95   Paper_book *pb = book->process (outname.to_string (), layout);
96
97   if (pb)
98     {
99       pb->output (outname.to_string ());
100       scm_gc_unprotect_object (pb->self_scm ());
101     }
102
103   scm_gc_unprotect_object (layout->self_scm ());
104   return SCM_UNSPECIFIED;
105 }
106