]> git.donarmstrong.com Git - lilypond.git/blob - lily/book-scheme.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / book-scheme.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2004--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "book.hh"
21
22 #include "output-def.hh"
23 #include "score.hh"
24 #include "paper-book.hh"
25 #include "ly-module.hh"
26
27 LY_DEFINE (ly_make_book, "ly:make-book",
28            2, 0, 1, (SCM paper, SCM header, SCM scores),
29            "Make a @code{\\book} of @var{paper} and @var{header}"
30            " (which may be @code{#f} as well) containing @code{\\scores}.")
31 {
32   Output_def *odef = unsmob_output_def (paper);
33   LY_ASSERT_SMOB (Output_def, paper, 1);
34
35   Book *book = new Book;
36   book->paper_ = odef;
37
38   if (ly_is_module (header))
39     book->header_ = header;
40
41   book->scores_ = scm_append (scm_list_2 (scores, book->scores_));
42
43   SCM x = book->self_scm ();
44   book->unprotect ();
45   return x;
46 }
47
48 LY_DEFINE (ly_make_book_part, "ly:make-book-part",
49            1, 0, 0, (SCM scores),
50            "Make a @code{\\bookpart} containing @code{\\scores}.")
51 {
52   Book *book = new Book;
53   book->scores_ = scm_append (scm_list_2 (scores, book->scores_));
54
55   SCM x = book->self_scm ();
56   book->unprotect ();
57   return x;
58 }
59
60 LY_DEFINE (ly_book_process, "ly:book-process",
61            4, 0, 0, (SCM book_smob,
62                      SCM default_paper,
63                      SCM default_layout,
64                      SCM output),
65            "Print book.  @var{output} is passed to the backend unchanged."
66            "  For example, it may be a string (for file based outputs)"
67            " or a socket (for network based output).")
68 {
69   Book *book = unsmob_book (book_smob);
70
71   LY_ASSERT_SMOB (Book, book_smob, 1);
72   LY_ASSERT_SMOB (Output_def, default_paper, 2);
73   LY_ASSERT_SMOB (Output_def, default_layout, 3);
74
75   Paper_book *pb = book->process (unsmob_output_def (default_paper),
76                                   unsmob_output_def (default_layout));
77   if (pb)
78     {
79       pb->output (output);
80       pb->unprotect ();
81     }
82
83   return SCM_UNSPECIFIED;
84 }
85
86 LY_DEFINE (ly_book_process_to_systems, "ly:book-process-to-systems",
87            4, 0, 0, (SCM book_smob,
88                      SCM default_paper,
89                      SCM default_layout,
90                      SCM output),
91            "Print book.  @var{output} is passed to the backend unchanged."
92            "  For example, it may be a string (for file based outputs)"
93            " or a socket (for network based output).")
94 {
95   LY_ASSERT_SMOB (Book, book_smob, 1);
96   LY_ASSERT_SMOB (Output_def, default_paper, 2);
97   LY_ASSERT_SMOB (Output_def, default_layout, 3);
98
99   Book *book = unsmob_book (book_smob);
100
101   Paper_book *pb = book->process (unsmob_output_def (default_paper),
102                                   unsmob_output_def (default_layout));
103   if (pb)
104     {
105       pb->classic_output (output);
106       pb->unprotect ();
107     }
108
109   return SCM_UNSPECIFIED;
110 }
111
112 LY_DEFINE (ly_book_add_score_x, "ly:book-add-score!",
113            2, 0, 0, (SCM book_smob, SCM score),
114            "Add @var{score} to @var{book-smob} score list.")
115 {
116   LY_ASSERT_SMOB (Book, book_smob, 1);
117   Book *book = unsmob_book (book_smob);
118   book->add_score (score);
119   return SCM_UNSPECIFIED;
120 }
121
122 LY_DEFINE (ly_book_add_bookpart_x, "ly:book-add-bookpart!",
123            2, 0, 0, (SCM book_smob, SCM book_part),
124            "Add @var{book-part} to @var{book-smob} book part list.")
125 {
126   LY_ASSERT_SMOB (Book, book_smob, 1);
127   Book *book = unsmob_book (book_smob);
128   book->add_bookpart (book_part);
129   return SCM_UNSPECIFIED;
130 }
131
132 LY_DEFINE (ly_book_book_parts, "ly:book-book-parts",
133            1, 0, 0, (SCM book),
134            "Return book parts in @var{book}.")
135 {
136   LY_ASSERT_SMOB (Book, book, 1);
137   Book *b = unsmob_book (book);
138   return b->bookparts_;
139 }
140
141 LY_DEFINE (ly_book_paper, "ly:book-paper",
142            1, 0, 0, (SCM book),
143            "Return paper in @var{book}.")
144 {
145   LY_ASSERT_SMOB (Book, book, 1);
146   Book *b = unsmob_book (book);
147   return b->paper_ ? b->paper_->self_scm () : SCM_BOOL_F;
148 }
149
150 LY_DEFINE (ly_book_header, "ly:book-header",
151            1, 0, 0, (SCM book),
152            "Return header in @var{book}.")
153 {
154   LY_ASSERT_SMOB (Book, book, 1);
155   Book *b = unsmob_book (book);
156   return b->header_ ? b->header_ : SCM_BOOL_F;
157 }
158
159 LY_DEFINE (ly_book_set_header_x, "ly:book-set-header!",
160            2, 0, 0, (SCM book, SCM module),
161            "Set the book header.")
162 {
163   LY_ASSERT_SMOB (Book, book, 1);
164   SCM_ASSERT_TYPE (ly_is_module (module), module, SCM_ARG2, __FUNCTION__,
165                    "module");
166
167   Book *b = unsmob_book (book);
168   b->header_ = (module);
169   return SCM_UNSPECIFIED;
170 }
171
172 LY_DEFINE (ly_book_scores, "ly:book-scores",
173            1, 0, 0, (SCM book),
174            "Return scores in @var{book}.")
175 {
176   LY_ASSERT_SMOB (Book, book, 1);
177   Book *b = unsmob_book (book);
178   return b->scores_;
179 }
180
181 #include "ly-smobs.icc"
182
183 IMPLEMENT_TYPE_P (Book, "ly:book?");