]> git.donarmstrong.com Git - lilypond.git/blob - lily/musical-request.cc
release: 0.0.42.pre3
[lilypond.git] / lily / musical-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 "musical-request.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 #ifndef NPRINT
40     mtor << name() << " {";
41     do_print();
42     mtor << "}\n";
43 #endif
44 }
45      
46
47
48 void
49 Span_req::do_print() const    
50 {
51 #ifndef NPRINT
52     mtor  << spantype ;
53 #endif
54 }
55
56 Request::Request()
57 {
58     elt_l_ = 0;
59     defined_ch_c_l_ = 0;
60 }
61 Request::Request(Request const&src)
62 {
63     elt_l_ = 0;
64     defined_ch_c_l_ = src.defined_ch_c_l_;
65 }
66 /* *************** */
67 Spacing_req::Spacing_req()
68 {
69     next = 0;
70     distance = 0;
71     strength = 0;
72 }
73 void
74 Spacing_req::do_print()const
75 {
76 #ifndef NPRINT
77     mtor << "next " << next << "dist " << distance << "strength\n";
78 #endif
79 }
80
81 void
82 Blank_req::do_print()const
83 {
84     Spacing_req::do_print();
85 }
86 /* *************** */
87 Melodic_req::Melodic_req()
88 {
89     notename_i_ = 0;
90     octave_i_ = 0;
91     accidental_i_ = 0;
92 }
93
94 void
95 Melodic_req::do_print() const
96 {
97 #ifndef NPRINT
98         mtor << "notename: " << notename_i_ << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
99 #endif
100 }
101
102 int
103 Melodic_req::height() const
104 {
105     return  notename_i_ + octave_i_*7;
106 }
107
108 /*
109  should be settable from input to allow "viola"-mode
110  */
111 static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 };       
112
113 int
114 Melodic_req::pitch() const
115 {
116     return  pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
117 }
118
119 Plet_req::Plet_req()
120 {
121     type_c_ = ']';
122     dur_i_ = 1;
123     type_i_ = 1;
124 }
125
126 void
127 Plet_req::do_print() const
128 {
129 #ifndef NPRINT
130     mtor << "plet: " << type_c_ << ": " << dur_i_ << "/" << type_i_;
131 #endif
132 }
133
134 /* *************** */
135 int
136 Rhythmic_req::compare(Rhythmic_req const &r1, Rhythmic_req const &r2)
137 {
138     return sign(r1.duration() - r2.duration());
139 }
140 Rhythmic_req::Rhythmic_req(int b, int d)
141 {
142     plet_factor = 1;
143     balltype = b;
144     dots = d;
145 }
146
147 Rhythmic_req::Rhythmic_req()
148 {
149     plet_factor = 1;
150     balltype = 1;
151     dots = 0;
152 }
153
154 void
155 Rhythmic_req::do_print() const
156 {
157 #ifndef NPRINT
158     mtor << "ball: " << balltype ;
159     int d =dots;
160     while (d--)
161         mtor << '.';
162     
163     mtor<<", plet factor"<<plet_factor<<"\n";
164 #endif
165 }
166
167
168 Moment
169 Rhythmic_req::duration() const {    
170     return wholes(balltype,dots)*plet_factor;
171 }
172 /* *************** */
173
174 Lyric_req::Lyric_req(Text_def* def_p)
175     :Text_req(0, def_p)
176 {
177     def_p->align_i_ = 0;        // centre
178     dir_i_ = -1;                // lyrics below (invisible) staff
179 }
180
181 void
182 Lyric_req::do_print() const
183 {    
184     Rhythmic_req::do_print();
185     Text_req::do_print();
186 }
187
188 /* *************** */
189 Note_req::Note_req()
190 {
191     forceacc_b_ = false;
192 }
193 void
194 Note_req::do_print() const
195 {
196 #ifndef NPRINT
197     mtor << " forceacc_b_ " << forceacc_b_ << '\n';
198     Melodic_req::do_print();
199     Rhythmic_req::do_print();
200 #endif
201 }
202 /* *************** */
203 void
204 Rest_req::do_print() const
205 {
206         Rhythmic_req::do_print();
207 }
208
209 /* *************** */
210 Beam_req::Beam_req()
211 {
212     nplet = 0;
213 }
214
215 void Beam_req::do_print()const{}
216 /* *************** */
217 void Slur_req::do_print()const{}
218 /* *************** */
219 int
220 Span_req:: compare(Span_req const &r1, Span_req const &r2)
221 {
222      return r1.spantype - r2.spantype;
223 }
224
225 Span_req::Span_req()
226 {
227     spantype = NOSPAN;
228 }
229
230 /* *************** */
231 Script_req::Script_req(int d , Script_def*def)
232 {
233     dir_i_ = d;
234     scriptdef_p_ = def;
235 }
236
237 int
238 Script_req::compare(Script_req const &d1, Script_req const &d2)
239 {
240     return d1.dir_i_ == d2.dir_i_ &&
241         d1.scriptdef_p_->compare(*d2.scriptdef_p_);
242 }
243
244 Script_req::Script_req(Script_req const &s)
245     : Request( s )
246 {
247     dir_i_ = s.dir_i_;
248     scriptdef_p_ = new Script_def(*s.scriptdef_p_);
249 }
250
251 void
252 Script_req::do_print() const
253 {
254     mtor << " dir " << dir_i_ ;
255     scriptdef_p_->print();
256 }
257
258
259 Script_req::~Script_req()
260 {
261     delete scriptdef_p_;
262 }
263 /* *************** */
264 int
265 Text_req:: compare(Text_req const &r1, Text_req const &r2)
266 {
267     bool b1 = (r1.dir_i_ == r2.dir_i_);
268     bool b2 = (r1.tdef_p_ ->compare(*r2.tdef_p_));
269     return b1 && b2;
270 }
271 Text_req::~Text_req()
272 {
273     delete tdef_p_;
274     tdef_p_ = 0;
275 }
276
277 Text_req::Text_req(Text_req const& src)
278 {
279     tdef_p_ = new Text_def(*src.tdef_p_);
280     dir_i_ = src.dir_i_;
281 }
282
283 Text_req::Text_req(int dir_i, Text_def* tdef_p) 
284 {
285     dir_i_ = dir_i;
286     tdef_p_ = tdef_p;
287 }
288
289 void
290 Text_req::do_print() const
291 {
292 #ifndef NPRINT
293
294     mtor << " dir " << dir_i_ ;
295     tdef_p_->print();
296 #endif
297 }
298
299 /* *************** */
300
301 Moment
302 Skip_req::duration() const
303 {
304     return duration_;
305 }
306
307 void
308 Skip_req::do_print() const
309 {
310 #ifndef NPRINT
311
312     mtor << "duration: " << duration();
313 #endif
314 }
315
316 Voice *
317 Request::voice_l()
318 {
319     if (!elt_l_)
320         return 0;
321     else
322         return (Voice*)elt_l_->voice_l_;
323 }
324 /* *************** */
325
326 void
327 Subtle_req::do_print() const
328 {
329 #ifndef NPRINT
330         mtor << " subtime " <<  subtime_;
331 #endif
332 }
333
334 void
335 Dynamic_req::do_print() const
336 {
337     Subtle_req::do_print();
338 }
339
340 void
341 Absolute_dynamic_req::do_print() const
342 {
343     Dynamic_req::do_print();
344     mtor << " loudness_" <<loudness_;
345 }
346
347 String
348 Dynamic_req::loudness_str(Loudness l) 
349 {
350     switch (l) {
351     case FFF: return "fff";
352     case FF: return "ff";
353     case F: return "f";
354     case MF: return "mf";
355     case MP: return "mp";
356     case P: return "p";
357     case PP: return "pp";
358     case PPP: return "ppp";
359     }
360     assert(false);
361     return "";
362 }
363
364 Absolute_dynamic_req::Absolute_dynamic_req()
365 {
366     loudness_ = MF;
367 }
368
369
370 Span_dynamic_req::Span_dynamic_req()
371 {
372     dynamic_dir_i_  = 0;
373 }
374
375 void
376 Span_dynamic_req::do_print()const
377 {
378 #ifndef NPRINT
379     Span_req::do_print();
380     mtor << "louder/louder: " <<dynamic_dir_i_;
381 #endif
382 }