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