]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
release: 0.1.7
[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 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include <math.h>
10 #include "string.hh"
11 #include "assoc.hh"
12 #include "misc.hh"
13 #include "paper-def.hh"
14 #include "debug.hh"
15 #include "lookup.hh"
16 #include "dimen.hh"
17 #include "input-translator.hh"
18 #include "engraver-group.hh"
19 #include "assoc-iter.hh"
20
21 void
22 Paper_def::set_var(String s, Real r)
23 {
24    real_vars_p_->elem(s) = r;
25 }
26
27 Real
28 Paper_def::get_var(String s)const
29 {
30     if(! real_vars_p_->elt_b(s))
31         error ( "unknown paper variable `"  + s+"'");
32     return real_vars_p_->elem(s);
33 }
34
35 Real
36 Paper_def::linewidth_f() const
37 {
38     return get_var("linewidth");
39 }
40
41 Real
42 Paper_def::duration_to_dist(Moment d)
43 {
44     Real dur_f = (d) ?pow(get_var("geometric"), log_2(d)) : 0;
45     return get_var("basicspace") + get_var("unitspace")  * dur_f;
46 }
47
48
49 Paper_def::Paper_def()
50 {
51     itrans_p_ = 0;
52     lookup_p_ = 0;
53     real_vars_p_ = new Assoc<String,Real>;
54 }
55
56 Paper_def::~Paper_def()
57 {
58     delete itrans_p_;
59     delete real_vars_p_;
60     delete lookup_p_;
61 }
62
63 Paper_def::Paper_def(Paper_def const&s)
64 {
65     itrans_p_ = s.itrans_p_ ? new Input_translator( *s.itrans_p_):0;
66     lookup_p_ = s.lookup_p_? new Lookup(*s.lookup_p_) : 0;
67     lookup_p_->paper_l_ = this;
68     real_vars_p_ = new Assoc<String,Real> (*s.real_vars_p_);
69     outfile_str_ = s.outfile_str_;
70 }
71
72 void
73 Paper_def::set(Input_translator * itrans_p)
74 {
75     delete itrans_p_;
76     itrans_p_  = itrans_p;
77 }
78
79 void
80 Paper_def::set(Lookup*l)
81 {
82     assert(l != lookup_p_);
83     delete lookup_p_;
84     lookup_p_ = l;
85     lookup_p_->paper_l_ = this;
86 }
87
88 Real
89 Paper_def::interline_f() const
90 {
91     return get_var("interline");
92 }
93
94
95 Real
96 Paper_def::rule_thickness()const
97 {
98     return get_var("rule_thickness");
99 }
100
101 Real
102 Paper_def::interbeam_f() const
103 {
104     return get_var("interbeam");
105 }
106 Real
107 Paper_def::internote_f() const
108 {
109     return interline_f() / 2; 
110 }
111
112 Real
113 Paper_def::note_width()const
114 {
115     return get_var("notewidth");
116 }
117
118 void
119 Paper_def::print() const
120 {
121 #ifndef NPRINT
122     mtor << "Paper {";
123     mtor << "out: " <<outfile_str_;
124     lookup_p_->print();
125     itrans_p_->print();
126     for (Assoc_iter<String,Real> i(*real_vars_p_); i.ok(); i++) {
127         mtor << i.key() << "= " << i.val() << "\n";
128     }
129     mtor << "}\n";
130 #endif
131 }
132
133 Lookup const *
134 Paper_def::lookup_l()
135 {
136     assert( lookup_p_ );
137     return lookup_p_;
138 }
139
140 Global_translator*
141 Paper_def::get_global_translator_p() const
142 {
143     return  itrans_p_->get_group_engraver_p()->global_l();
144 }