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