]> git.donarmstrong.com Git - lilypond.git/blob - lily/request.cc
release: 0.0.39-1
[lilypond.git] / lily / request.cc
1 /*
2   request.cc -- implement all musical requests.
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "musicalrequest.hh"
10 #include "misc.hh"
11 #include "debug.hh"
12 #include "script-def.hh"
13 #include "text-def.hh"
14 #include "voice.hh"
15 #include "voice-element.hh"
16
17 void
18 Stem_req::do_print() const
19 {
20     Rhythmic_req::do_print();
21     mtor << "dir : " << dir_i_;
22 }
23
24 Stem_req::Stem_req(int s, int d)
25     : Rhythmic_req(s,d)
26 {
27     dir_i_ = 0;
28 }
29
30 /* ************** */
31 void Musical_req::do_print()const{}
32 void Request::do_print() const{}
33
34 /* *************** */
35
36 void
37 Request::print() const
38 {
39     mtor << name() << " {";
40     do_print();
41     mtor << "}\n";
42 }
43      
44
45
46 void
47 Span_req::do_print() const    
48 {
49 #ifndef NPRINT
50     mtor  << spantype ;
51 #endif
52 }
53
54 Request::Request()
55 {
56     elt_l_ = 0;
57     defined_ch_c_l_ = 0;
58 }
59 Request::Request(Request const&src)
60 {
61     elt_l_ = 0;
62     defined_ch_c_l_ = src.defined_ch_c_l_;
63 }
64 /* *************** */
65 Spacing_req::Spacing_req()
66 {
67     next = 0;
68     distance = 0;
69     strength = 0;
70 }
71 void
72 Spacing_req::do_print()const
73 {
74     mtor << "next " << next << "dist " << distance << "strength\n";
75 }
76
77 void
78 Blank_req::do_print()const
79 {
80     Spacing_req::do_print();
81 }
82 /* *************** */
83 Melodic_req::Melodic_req()
84 {
85     notename_i_ = 0;
86     octave_i_ = 0;
87     accidental_i_ = 0;
88     forceacc_b_ = false;
89 }
90
91 void
92 Melodic_req::do_print() const
93 {
94     mtor << "notename: " << notename_i_ << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
95 }
96
97 int
98 Melodic_req::height() const
99 {
100     return  notename_i_ + octave_i_*7;
101 }
102
103 /*
104  should be settable from input to allow "viola"-mode
105  */
106 static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 };       
107
108 int
109 Melodic_req::pitch() const
110 {
111     return  pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
112 }
113
114 Plet_req::Plet_req()
115 {
116     type_c_ = ']';
117     dur_i_ = 1;
118     type_i_ = 1;
119 }
120
121 void
122 Plet_req::do_print() const
123 {
124     mtor << "plet: " << type_c_ << ": " << dur_i_ << "/" << type_i_;
125 }
126
127 /* *************** */
128 int
129 Rhythmic_req::compare(const Rhythmic_req &r1, const Rhythmic_req &r2)
130 {
131     return sign(r1.duration() - r2.duration());
132 }
133 Rhythmic_req::Rhythmic_req(int b, int d)
134 {
135     plet_factor = 1;
136     balltype = b;
137     dots = d;
138 }
139
140 Rhythmic_req::Rhythmic_req()
141 {
142     plet_factor = 1;
143     balltype = 1;
144     dots = 0;
145 }
146
147 void
148 Rhythmic_req::do_print() const
149 {
150     mtor << "ball: " << balltype ;
151     int d =dots;
152     while (d--)
153         mtor << '.';
154     
155     mtor<<", plet factor"<<plet_factor<<"\n";
156 }
157
158
159 Moment
160 Rhythmic_req::duration() const {    
161     return wholes(balltype,dots)*plet_factor;
162 }
163 /* *************** */
164
165 Lyric_req::Lyric_req(Text_def* def_p)
166     :Text_req(0, def_p)
167 {
168     def_p->align_i_ = 0;        // centre
169     dir_i_ = -1;                // lyrics below (invisible) staff
170 }
171
172 void
173 Lyric_req::do_print() const
174 {    
175     Rhythmic_req::do_print();
176     Text_req::do_print();
177 }
178 /* *************** */
179 void
180 Note_req::do_print() const
181 {
182     Melodic_req::do_print();
183     Rhythmic_req::do_print();
184 }
185 /* *************** */
186 void
187 Rest_req::do_print() const
188 {
189         Rhythmic_req::do_print();
190 }
191
192 /* *************** */
193 Beam_req::Beam_req()
194 {
195     nplet = 0;
196 }
197
198 void Beam_req::do_print()const{}
199 /* *************** */
200 void Slur_req::do_print()const{}
201 /* *************** */
202 int
203 Span_req:: compare(const Span_req &r1, const Span_req &r2)
204 {
205      return r1.spantype - r2.spantype;
206 }
207
208 Span_req::Span_req()
209 {
210     spantype = NOSPAN;
211 }
212
213 /* *************** */
214 Script_req::Script_req(int d , Script_def*def)
215 {
216     dir_i_ = d;
217     scriptdef_p_ = def;
218 }
219
220 int
221 Script_req::compare(const Script_req &d1, const Script_req &d2)
222 {
223     return d1.dir_i_ == d2.dir_i_ &&
224         d1.scriptdef_p_->compare(*d2.scriptdef_p_);
225 }
226
227 Script_req::Script_req(Script_req const &s)
228     : Request( s )
229 {
230     dir_i_ = s.dir_i_;
231     scriptdef_p_ = new Script_def(*s.scriptdef_p_);
232 }
233
234 void
235 Script_req::do_print() const
236 {
237     mtor << " dir " << dir_i_ ;
238     scriptdef_p_->print();
239 }
240
241
242 Script_req::~Script_req()
243 {
244     delete scriptdef_p_;
245 }
246 /* *************** */
247 int
248 Text_req:: compare(const Text_req &r1, const Text_req &r2)
249 {
250     bool b1 = (r1.dir_i_ == r2.dir_i_);
251     bool b2 = (r1.tdef_p_ ->compare(*r2.tdef_p_));
252     return b1 && b2;
253 }
254 Text_req::~Text_req()
255 {
256     delete tdef_p_;
257     tdef_p_ = 0;
258 }
259
260 Text_req::Text_req(Text_req const& src)
261 {
262     tdef_p_ = new Text_def(*src.tdef_p_);
263     dir_i_ = src.dir_i_;
264 }
265
266 Text_req::Text_req(int dir_i, Text_def* tdef_p) 
267 {
268     dir_i_ = dir_i;
269     tdef_p_ = tdef_p;
270 }
271
272 void
273 Text_req::do_print() const
274 {
275     mtor << " dir " << dir_i_ ;
276     tdef_p_->print();
277 }
278
279 /* *************** */
280
281 Moment
282 Skip_req::duration() const
283 {
284     return duration_;
285 }
286
287 void
288 Skip_req::do_print() const
289 {
290     mtor << "duration: " << duration();
291 }
292
293 Voice *
294 Request::voice_l()
295 {
296     if (!elt_l_)
297         return 0;
298     else
299         return (Voice*)elt_l_->voice_l_;
300 }