]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
release: 1.3.93
[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   SCM val ;
60   if (!scope_p_->try_retrieve (s, &val))
61     {
62       programming_error ("unknown paper variable: " +  ly_symbol2string (s));
63       return 0.0;
64     }
65
66   if (gh_number_p (val))
67     {
68       return gh_scm2double (val);
69     }
70   else
71     {
72       programming_error ("not a real variable");
73       return 0.0;
74     }
75 }
76
77 /*
78   FIXME. This is broken until we have a generic way of
79   putting lists inside the \paper block.
80  */
81 Interval
82 Paper_def::line_dimensions_int (int n) const
83 {
84   Real lw =  get_var ("linewidth");
85   Real ind = n? 0.0:get_var ("indent");
86
87   return Interval (ind, lw);
88 }
89
90 void
91 Paper_def::set_lookup (int i, SCM l)
92 {
93   assert (unsmob_lookup (l));
94   lookup_alist_ = scm_assq_set_x(lookup_alist_, gh_int2scm (i), l);
95 }
96
97 Lookup const *
98 Paper_def::lookup_l (int i) const
99 {
100   SCM l = scm_assq (gh_int2scm(i), lookup_alist_);
101   return l == SCM_BOOL_F ? 0 :  unsmob_lookup (gh_cdr (l));
102 }
103
104 int Paper_def::default_count_i_ = 0;
105
106 int
107 Paper_def::get_next_default_count () const
108 {
109   return default_count_i_ ++;
110 }
111
112 void
113 Paper_def::reset_default_count()
114 {
115   default_count_i_ = 0;
116 }
117
118
119 Paper_stream*
120 Paper_def::paper_stream_p () const
121 {
122   String outname = base_output_str ();
123
124   if (outname != "-")
125     outname += String (".") + output_global_ch;
126   progress_indication (_f ("paper output to %s...",
127                            outname == "-" ? String ("<stdout>") : outname));
128
129   target_str_global_array.push (outname);
130   return new Paper_stream (outname);
131 }
132
133
134 String
135 Paper_def::base_output_str () const
136 {
137   String str = get_default_output ();
138
139   if (str.empty_b ())
140     {
141       str = default_outname_base_global;
142       int def = get_next_default_count ();
143       if (def)
144         str += "-" + to_str (def);
145     }
146   return str;
147 }
148
149