]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
release: 0.0.72pre
[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
18
19 void
20 Paper_def::set_var(String s, Real r)
21 {
22    real_vars_p_->elem(s) = r;
23 }
24
25 Real
26 Paper_def::get_var(String s)const
27 {
28     if(! real_vars_p_->elt_b(s))
29         error ( "unknown paper variable `"  + s+"'");
30     return real_vars_p_->elem(s);
31 }
32
33 Real
34 Paper_def::linewidth_f() const
35 {
36     return get_var("linewidth");
37 }
38
39 Real
40 Paper_def::duration_to_dist(Moment d)
41 {
42     if (!d)
43         return 0;
44     
45     return get_var("unitspace")  * pow(get_var("geometric"), log_2(d));
46 }
47
48
49 Paper_def::Paper_def()
50 {
51     lookup_p_ = 0;
52     real_vars_p_ = new Assoc<String,Real>;
53     outfile_str_ = "lelie.tex";
54 }
55
56 Paper_def::~Paper_def()
57 {
58     delete real_vars_p_;
59     delete lookup_p_;
60 }
61
62 Paper_def::Paper_def(Paper_def const&s)
63 {
64     lookup_p_ = s.lookup_p_? new Lookup(*s.lookup_p_) : 0;
65     lookup_p_->paper_l_ = this;
66     real_vars_p_ = new Assoc<String,Real> (*s.real_vars_p_);
67     outfile_str_ = s.outfile_str_;
68 }
69
70 void
71 Paper_def::set(Lookup*l)
72 {
73     assert(l != lookup_p_);
74     delete lookup_p_;
75     lookup_p_ = l;
76     lookup_p_->paper_l_ = this;
77 }
78
79 Real
80 Paper_def::interline_f() const
81 {
82     return get_var("interline");
83 }
84
85
86 Real
87 Paper_def::rule_thickness()const
88 {
89     return get_var("rule_thickness");
90 }
91
92 Real
93 Paper_def::interbeam_f() const
94 {
95     return get_var("interbeam");
96 }
97 Real
98 Paper_def::internote_f() const
99 {
100     return interline_f() / 2; 
101 }
102
103 Real
104 Paper_def::note_width()const
105 {
106     return get_var("notewidth");
107 }
108
109 void
110 Paper_def::print() const
111 {
112 #ifndef NPRINT
113     mtor << "Paper {";
114     mtor << "out: " <<outfile_str_;
115     lookup_p_->print();
116     mtor << "}\n";
117 #endif
118 }
119 Lookup const *
120 Paper_def::lookup_l()
121 {
122     assert( lookup_p_ );
123     return lookup_p_;
124 }