]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
4cf44b1f8d9b2f8f9ad505c7c0ebc7be9b4898a7
[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     outfile_str_ = "lelie.tex";
55 }
56
57 Paper_def::~Paper_def()
58 {
59     delete itrans_p_;
60     delete real_vars_p_;
61     delete lookup_p_;
62 }
63
64 Paper_def::Paper_def(Paper_def const&s)
65 {
66     itrans_p_ = s.itrans_p_ ? new Input_translator( *s.itrans_p_):0;
67     lookup_p_ = s.lookup_p_? new Lookup(*s.lookup_p_) : 0;
68     lookup_p_->paper_l_ = this;
69     real_vars_p_ = new Assoc<String,Real> (*s.real_vars_p_);
70     outfile_str_ = s.outfile_str_;
71 }
72
73 void
74 Paper_def::set(Input_translator * itrans_p)
75 {
76     delete itrans_p_;
77     itrans_p_  = itrans_p;
78 }
79
80 void
81 Paper_def::set(Lookup*l)
82 {
83     assert(l != lookup_p_);
84     delete lookup_p_;
85     lookup_p_ = l;
86     lookup_p_->paper_l_ = this;
87 }
88
89 Real
90 Paper_def::interline_f() const
91 {
92     return get_var("interline");
93 }
94
95
96 Real
97 Paper_def::rule_thickness()const
98 {
99     return get_var("rule_thickness");
100 }
101
102 Real
103 Paper_def::interbeam_f() const
104 {
105     return get_var("interbeam");
106 }
107 Real
108 Paper_def::internote_f() const
109 {
110     return interline_f() / 2; 
111 }
112
113 Real
114 Paper_def::note_width()const
115 {
116     return get_var("notewidth");
117 }
118
119 void
120 Paper_def::print() const
121 {
122 #ifndef NPRINT
123     mtor << "Paper {";
124     mtor << "out: " <<outfile_str_;
125     lookup_p_->print();
126     itrans_p_->print();
127     for (Assoc_iter<String,Real> i(*real_vars_p_); i.ok(); i++) {
128         mtor << i.key() << "= " << i.val() << "\n";
129     }
130     mtor << "}\n";
131 #endif
132 }
133
134 Lookup const *
135 Paper_def::lookup_l()
136 {
137     assert( lookup_p_ );
138     return lookup_p_;
139 }
140
141 Global_translator*
142 Paper_def::get_global_translator_p() const
143 {
144     return  itrans_p_->get_group_engraver_p()->global_l();
145 }