]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
release: 1.3.73
[lilypond.git] / lily / paper-def.cc
1 /*
2   paper-def.cc -- implement Paper_def
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include <math.h>
10
11 #include "string.hh"
12 #include "misc.hh"
13 #include "paper-def.hh"
14 #include "debug.hh"
15 #include "lookup.hh"
16 #include "main.hh"
17 #include "scope.hh"
18 #include "file-results.hh" // urg? header_global_p
19 #include "paper-stream.hh"
20
21 Paper_def::Paper_def ()
22 {
23   lookup_alist_ = SCM_EOL;
24 }
25
26
27 Paper_def::~Paper_def ()
28 {
29 }
30
31 Paper_def::Paper_def (Paper_def const&src)
32   : Music_output_def (src)
33 {
34   SCM n  = SCM_EOL;
35   for (SCM s = src.lookup_alist_; gh_pair_p(s); s = gh_cdr (s))
36     {
37       n = scm_acons (gh_caar(s), gh_cdar (s), n);
38     }
39
40   lookup_alist_  = n;
41 }
42
43
44 Real
45 Paper_def::get_var (String s) const
46 {
47   return get_realvar (ly_symbol2scm (s.ch_C()));
48 }
49
50 SCM
51 Paper_def::get_scmvar (String s) const
52 {
53   return  scope_p_->scm_elem (ly_symbol2scm (s.ch_C()));
54 }
55
56 Real
57 Paper_def::get_realvar (SCM s) const
58 {
59   if (!scope_p_->elem_b (s))
60     {
61       programming_error ("unknown paper variable: " +  ly_symbol2string (s));
62       return 0.0;
63     }
64   SCM val = scope_p_->scm_elem (s);
65   if (gh_number_p (val))
66     {
67       return gh_scm2double (val);
68     }
69   else
70     {
71       programming_error ("not a real variable");
72       return 0.0;
73     }
74 }
75
76 /*
77   FIXME. This is broken until we have a generic way of
78   putting lists inside the \paper block.
79  */
80 Interval
81 Paper_def::line_dimensions_int (int n) const
82 {
83   Real lw =  get_var ("linewidth");
84   Real ind = n? 0.0:get_var ("indent");
85
86   return Interval (ind, lw);
87 }
88
89 void
90 Paper_def::set_lookup (int i, Lookup*l)
91 {
92   lookup_alist_ = scm_assq_set_x(lookup_alist_, gh_int2scm (i), l->self_scm_);
93 }
94
95
96 /*
97   junkme.
98  */
99 Real
100 Paper_def::interbeam_f (int multiplicity_i) const
101 {
102   if (multiplicity_i <= 3)
103     return get_var ("interbeam");
104   else
105     return get_var ("interbeam4");
106 }
107
108
109 void
110 Paper_def::print () const
111 {
112 #ifndef NPRINT
113   Music_output_def::print ();
114   if (flower_dstream)
115     gh_display (lookup_alist_);
116 #endif
117 }
118
119 Lookup const *
120 Paper_def::lookup_l (int i) const
121 {
122   SCM l = scm_assq (gh_int2scm(i), lookup_alist_);
123   return l == SCM_BOOL_F ? 0 :  unsmob_lookup (gh_cdr (l));
124 }
125
126 int Paper_def::default_count_i_ = 0;
127
128 int
129 Paper_def::get_next_default_count () const
130 {
131   return default_count_i_ ++;
132 }
133
134 void
135 Paper_def::reset_default_count()
136 {
137   default_count_i_ = 0;
138 }
139
140
141 Paper_stream*
142 Paper_def::paper_stream_p () const
143 {
144   String outname = base_output_str ();
145
146   if (outname != "-")
147     outname += String (".") + output_global_ch;
148   progress_indication (_f ("paper output to %s...",
149                            outname == "-" ? String ("<stdout>") : outname));
150
151   target_str_global_array.push (outname);
152   return new Paper_stream (outname);
153 }
154
155
156 String
157 Paper_def::base_output_str () const
158 {
159   String str = get_default_output ();
160
161   if (str.empty_b ())
162     {
163       str = default_outname_base_global;
164       int def = get_next_default_count ();
165       if (def)
166         str += "-" + to_str (def);
167     }
168   return str;
169 }
170
171