]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
release: 1.3.74
[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, SCM l)
91 {
92   assert (unsmob_lookup (l));
93   lookup_alist_ = scm_assq_set_x(lookup_alist_, gh_int2scm (i), l);
94 }
95
96
97 /*
98   junkme.
99  */
100 Real
101 Paper_def::interbeam_f (int multiplicity_i) const
102 {
103   if (multiplicity_i <= 3)
104     return get_var ("interbeam");
105   else
106     return get_var ("interbeam4");
107 }
108
109
110 void
111 Paper_def::print () const
112 {
113 #ifndef NPRINT
114   Music_output_def::print ();
115   if (flower_dstream)
116     gh_display (lookup_alist_);
117 #endif
118 }
119
120 Lookup const *
121 Paper_def::lookup_l (int i) const
122 {
123   SCM l = scm_assq (gh_int2scm(i), lookup_alist_);
124   return l == SCM_BOOL_F ? 0 :  unsmob_lookup (gh_cdr (l));
125 }
126
127 int Paper_def::default_count_i_ = 0;
128
129 int
130 Paper_def::get_next_default_count () const
131 {
132   return default_count_i_ ++;
133 }
134
135 void
136 Paper_def::reset_default_count()
137 {
138   default_count_i_ = 0;
139 }
140
141
142 Paper_stream*
143 Paper_def::paper_stream_p () const
144 {
145   String outname = base_output_str ();
146
147   if (outname != "-")
148     outname += String (".") + output_global_ch;
149   progress_indication (_f ("paper output to %s...",
150                            outname == "-" ? String ("<stdout>") : outname));
151
152   target_str_global_array.push (outname);
153   return new Paper_stream (outname);
154 }
155
156
157 String
158 Paper_def::base_output_str () const
159 {
160   String str = get_default_output ();
161
162   if (str.empty_b ())
163     {
164       str = default_outname_base_global;
165       int def = get_next_default_count ();
166       if (def)
167         str += "-" + to_str (def);
168     }
169   return str;
170 }
171
172