]> git.donarmstrong.com Git - lilypond.git/blob - lily/book.cc
(scm_from_double): more compat glue.
[lilypond.git] / lily / book.cc
1 /*
2   book.cc -- implement Book
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include <stdio.h>
10
11 #include "book.hh"
12 #include "global-context.hh"
13 #include "ly-module.hh"
14 #include "main.hh"
15 #include "music-iterator.hh"
16 #include "music-output.hh"
17 #include "music.hh"
18 #include "output-def.hh"
19 #include "paper-book.hh"
20 #include "score.hh"
21 #include "stencil.hh"
22 #include "warn.hh"
23
24 #include "ly-smobs.icc"
25
26 Book::Book ()
27   : Input ()
28 {
29   bookpaper_ = 0;
30   header_ = SCM_EOL;
31   assert (!scores_.size ());
32   smobify_self ();
33 }
34
35 Book::~Book ()
36 {
37 }
38
39 IMPLEMENT_SMOBS (Book);
40 IMPLEMENT_DEFAULT_EQUAL_P (Book);
41
42 SCM
43 Book::mark_smob (SCM s)
44 {
45   Book *book = (Book*) SCM_CELL_WORD_1 (s);
46   int score_count = book->scores_.size ();
47   for (int i = 0; i < score_count; i++)
48     scm_gc_mark (book->scores_[i]->self_scm ());
49
50   if (book->bookpaper_)
51     scm_gc_mark (book->bookpaper_->self_scm ());
52   return book->header_;
53 }
54
55 int
56 Book::print_smob (SCM, SCM p, scm_print_state*)
57 {
58   scm_puts ("#<Book>", p);
59   return 1;
60 }
61
62 /* This function does not dump the output; outname is required eg. for
63    dumping header fields.  */
64 Paper_book *
65 Book::process (String outname, Output_def *default_def)
66 {
67   Paper_book *paper_book = new Paper_book ();
68   Real scale = scm_to_double (bookpaper_->c_variable ("outputscale"));
69   
70   Output_def * scaled_bookdef = scale_output_def (bookpaper_, scale);
71
72   paper_book->bookpaper_ = scaled_bookdef;
73   scm_gc_unprotect_object (scaled_bookdef->self_scm());
74   
75   paper_book->header_ = header_;
76   
77   int score_count = scores_.size ();
78   for (int i = 0; i < score_count; i++)
79     {
80       SCM systems = scores_[i]->book_rendering (outname,
81                                                 paper_book->bookpaper_,
82                                                 default_def);
83       
84       /* If the score is empty, generate no output.  Should we
85          do titling?  */
86       if (SCM_NFALSEP(scm_vector_p (systems)))
87         {
88           Score_systems sc;
89           sc.systems_ = systems;
90           sc.header_ = scores_[i]->header_;
91           paper_book->score_systems_.push (sc);
92         }
93     }
94
95   return paper_book;
96 }
97
98 LY_DEFINE(ly_make_book, "ly:make-book",
99           2, 0, 1, (SCM bookpaper, SCM header, SCM scores),
100           "Make a \\book of @var{bookpaper} and @var{header} (which may be #f as well)  "
101           "containing @code{\\scores}.")
102 {
103   Output_def * odef = unsmob_output_def (bookpaper);
104   SCM_ASSERT_TYPE (odef, bookpaper,
105                    SCM_ARG1, __FUNCTION__, "Output_def");
106
107   Book *book = new Book;
108   book->bookpaper_ = odef;
109
110   if (ly_c_module_p (header))
111     book->header_ = header;
112   
113   for (SCM s = scores; ly_c_pair_p (s); s = ly_cdr (s))
114     {
115       Score *score = unsmob_score (ly_car (s));
116       if (score)
117         book->scores_.push (score);
118     }
119   
120   SCM x = book->self_scm ();
121   scm_gc_unprotect_object (x);
122   return x;
123 }
124