2 paper-def.cc -- implement Paper_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "paper-def.hh"
18 #include "file-results.hh" // urg? header_global_p
19 #include "paper-stream.hh"
21 Paper_def::Paper_def ()
23 lookup_alist_ = SCM_EOL;
27 Paper_def::~Paper_def ()
31 Paper_def::Paper_def (Paper_def const&src)
32 : Music_output_def (src)
35 for (SCM s = src.lookup_alist_; gh_pair_p(s); s = gh_cdr (s))
37 n = scm_acons (gh_caar(s), gh_cdar (s), n);
45 Paper_def::get_var (String s) const
47 return get_realvar (ly_symbol2scm (s.ch_C()));
51 Paper_def::get_scmvar (String s) const
53 return scope_p_->scm_elem (ly_symbol2scm (s.ch_C()));
57 Paper_def::get_realvar (SCM s) const
60 if (!scope_p_->try_retrieve (s, &val))
62 programming_error ("unknown paper variable: " + ly_symbol2string (s));
66 if (gh_number_p (val))
68 return gh_scm2double (val);
72 programming_error ("not a real variable");
78 FIXME. This is broken until we have a generic way of
79 putting lists inside the \paper block.
82 Paper_def::line_dimensions_int (int n) const
84 Real lw = get_var ("linewidth");
85 Real ind = n? 0.0:get_var ("indent");
87 return Interval (ind, lw);
91 Paper_def::set_lookup (int i, SCM l)
93 assert (unsmob_lookup (l));
94 lookup_alist_ = scm_assq_set_x(lookup_alist_, gh_int2scm (i), l);
98 Paper_def::lookup_l (int i) const
100 SCM l = scm_assq (gh_int2scm(i), lookup_alist_);
101 return l == SCM_BOOL_F ? 0 : unsmob_lookup (gh_cdr (l));
104 int Paper_def::default_count_i_ = 0;
107 Paper_def::get_next_default_count () const
109 return default_count_i_ ++;
113 Paper_def::reset_default_count()
115 default_count_i_ = 0;
120 Paper_def::paper_stream_p () const
122 String outname = base_output_str ();
125 outname += String (".") + output_global_ch;
126 progress_indication (_f ("paper output to %s...",
127 outname == "-" ? String ("<stdout>") : outname));
129 target_str_global_array.push (outname);
130 return new Paper_stream (outname);
135 Paper_def::base_output_str () const
137 String str = get_default_output ();
141 str = default_outname_base_global;
142 int def = get_next_default_count ();
144 str += "-" + to_str (def);