]> git.donarmstrong.com Git - lilypond.git/blob - request.cc
fd032fcfd813ddb6f07199e2d820b87baecc52b8
[lilypond.git] / request.cc
1 #include "request.hh"
2 #include "debug.hh"
3
4 #define VIRTUALCONS(T,R) R *T::clone() const { return  new T(*this); } struct T
5 #define RCONS(T) VIRTUALCONS(T, Request)
6
7 RCONS(Rest_req);
8 RCONS(Rhythmic_req);
9 RCONS(Stem_req);
10 RCONS(Note_req);
11
12
13 void
14 Request::print() const    
15 {
16 #ifndef NPRINT
17     mtor << "Req{ unknown }\n";
18 #endif
19 }
20
21 Request::Request(Voice_element*v)
22 {
23     elt = v;
24 }
25
26 Note_req::Note_req(Voice_element*v)
27     : Rhythmic_req(v)
28 {
29     name = 'c';
30     octave = 0;
31     accidental = 0;
32     forceacc = false;
33 }
34
35 int
36 Note_req::height() const
37 {
38     int s = name -'c';
39     if (s < 0)
40         s+=7;
41     return  s + octave*7;
42 }
43
44 /****************************************************************/
45 Rhythmic_req::Rhythmic_req(Voice_element*v)
46      :Request(v)
47 {
48     balltype = 1;
49     dots = 0;
50 }
51 void
52 Rhythmic_req::print() const
53 {
54     mtor << "rhythmic: " << balltype ;
55     int d =dots;
56     while (d--)
57         mtor << '.';
58     mtor<<"\n";
59 }
60 void
61 Note_req::print() const
62 {
63     mtor << "note: " << name << " oct: "<< octave;
64     Rhythmic_req::print();
65 }
66
67 Request::Request()
68 {
69     elt = 0;
70 }
71
72 void
73 Rest_req::print() const
74 {
75     mtor << "rest, " ;
76     Rhythmic_req::print();
77 }
78
79 Real
80 wholes(int dur, int dots)
81 {
82     Real f = 1.0/Real(dur);
83     Real delta = f;
84
85     while (dots--) {
86         delta /= 2.0;
87         f += delta;
88     }
89     return f;    
90 }
91
92 Real
93 Rhythmic_req::duration() const {    
94     return wholes( balltype,dots);
95 }
96