]> git.donarmstrong.com Git - lilypond.git/blob - lily/musical-request.cc
release: 0.0.67
[lilypond.git] / lily / musical-request.cc
1 /*
2   request.cc -- implement all musical requests.
3
4   source file of the GNU 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 /* *************** */
168 int
169 Rhythmic_req::compare(Rhythmic_req const &r1, Rhythmic_req const &r2)
170 {
171     return sign(r1.duration() - r2.duration());
172 }
173
174 void
175 Rhythmic_req::set_duration(Duration d)
176 {
177     duration_ = d;
178 }
179
180 Rhythmic_req::Rhythmic_req()
181 {
182 }
183
184 IMPLEMENT_STATIC_NAME(Rhythmic_req);
185
186 void
187 Rhythmic_req::do_print() const
188 {
189 #ifndef NPRINT
190     mtor << "duration { " <<duration_.str() << "}";
191 #endif
192 }
193
194
195 Moment
196 Rhythmic_req::duration() const {    
197     return duration_.length();
198 }
199 /* *************** */
200
201 Lyric_req::Lyric_req(Text_def* def_p)
202     :Text_req(0, def_p)
203 {
204     def_p->align_i_ = 0;        // centre
205     dir_i_ = -1;                // lyrics below (invisible) staff
206 }
207
208 IMPLEMENT_STATIC_NAME(Lyric_req);
209
210 void
211 Lyric_req::do_print() const
212 {    
213     Rhythmic_req::do_print();
214     Text_req::do_print();
215 }
216
217 /* *************** */
218 Note_req::Note_req()
219 {
220     forceacc_b_ = false;
221 }
222 IMPLEMENT_STATIC_NAME(Note_req);
223
224 void
225 Note_req::do_print() const
226 {
227 #ifndef NPRINT
228     Melodic_req::do_print();
229     if (forceacc_b_) {
230         mtor << " force accidental\n";
231     }
232     Rhythmic_req::do_print();
233 #endif
234 }
235 /* *************** */
236 IMPLEMENT_STATIC_NAME(Rest_req);
237
238 void
239 Rest_req::do_print() const
240 {
241         Rhythmic_req::do_print();
242 }
243
244 /* *************** */
245 Beam_req::Beam_req()
246 {
247     nplet = 0;
248 }
249 IMPLEMENT_STATIC_NAME(Beam_req);
250 void
251 Beam_req::do_print()const{}
252 /* *************** */
253 IMPLEMENT_STATIC_NAME(Slur_req);
254 void
255 Slur_req::do_print()const{}
256 /* *************** */
257 int
258 Span_req:: compare(Span_req const &r1, Span_req const &r2)
259 {
260      return r1.spantype - r2.spantype;
261 }
262
263 Span_req::Span_req()
264 {
265     spantype = NOSPAN;
266 }
267
268 /* *************** */
269 Script_req::Script_req(Script_req const&s)
270 {
271     dir_i_ = s.dir_i_;
272     scriptdef_p_ = s.scriptdef_p_ ? s.scriptdef_p_->clone() : 0;
273 }
274
275 int
276 Script_req::compare(Script_req const &d1, Script_req const &d2)
277 {
278     return d1.dir_i_ == d2.dir_i_ &&
279         d1.scriptdef_p_->equal_b(*d2.scriptdef_p_);
280 }
281
282 Script_req::Script_req()
283 {
284     dir_i_ = 0;
285     scriptdef_p_ = 0;
286 }
287
288 IMPLEMENT_STATIC_NAME(Script_req);
289
290 void
291 Script_req::do_print() const
292 {
293     mtor << " dir " << dir_i_ ;
294     scriptdef_p_->print();
295 }
296
297 void
298 Musical_script_req::do_print() const
299 {}
300
301 IMPLEMENT_STATIC_NAME(Musical_script_req);
302
303
304 Script_req::~Script_req()
305 {
306     delete scriptdef_p_;
307 }
308 /* *************** */
309 int
310 Text_req:: compare(Text_req const &r1, Text_req const &r2)
311 {
312     bool b1 = (r1.dir_i_ == r2.dir_i_);
313     bool b2 = (r1.tdef_p_ ->equal_b(*r2.tdef_p_));
314     return b1 && b2;
315 }
316 Text_req::~Text_req()
317 {
318     delete tdef_p_;
319     tdef_p_ = 0;
320 }
321
322 Text_req::Text_req(Text_req const& src)
323 {
324     tdef_p_ = new Text_def(*src.tdef_p_);
325     dir_i_ = src.dir_i_;
326 }
327
328 Text_req::Text_req(int dir_i, Text_def* tdef_p) 
329 {
330     dir_i_ = dir_i;
331     tdef_p_ = tdef_p;
332 }
333
334 IMPLEMENT_STATIC_NAME(Text_req);
335
336 void
337 Text_req::do_print() const
338 {
339 #ifndef NPRINT
340
341     mtor << " dir " << dir_i_ ;
342     tdef_p_->print();
343 #endif
344 }
345
346 /* *************** */
347
348 Moment
349 Skip_req::duration() const
350 {
351     return duration_;
352 }
353
354 IMPLEMENT_STATIC_NAME(Skip_req);
355
356 void
357 Skip_req::do_print() const
358 {
359 #ifndef NPRINT
360
361     mtor << "duration: " << duration();
362 #endif
363 }
364
365 Voice *
366 Request::voice_l()
367 {
368     if (!elt_l_)
369         return 0;
370     else
371         return (Voice*)elt_l_->voice_C_;
372 }
373 /* *************** */
374
375 IMPLEMENT_STATIC_NAME(Subtle_req);
376
377 void
378 Subtle_req::do_print() const
379 {
380 #ifndef NPRINT
381         mtor << " subtime " <<  subtime_;
382 #endif
383 }
384
385 IMPLEMENT_STATIC_NAME(Dynamic_req);
386
387 void
388 Dynamic_req::do_print() const
389 {
390     Subtle_req::do_print();
391 }
392
393 IMPLEMENT_STATIC_NAME(Absolute_dynamic_req);
394
395 void
396 Absolute_dynamic_req::do_print() const
397 {
398     Dynamic_req::do_print();
399     mtor << " loudness " <<loudness_;
400 }
401
402 String
403 Dynamic_req::loudness_str(Loudness l) 
404 {
405     switch (l) {
406     case FFF: return "fff";
407     case FF: return "ff";
408     case F: return "f";
409     case MF: return "mf";
410     case MP: return "mp";
411     case P: return "p";
412     case PP: return "pp";
413     case PPP: return "ppp";
414     }
415     assert(false);
416     return "";
417 }
418
419 Absolute_dynamic_req::Absolute_dynamic_req()
420 {
421     loudness_ = MF;
422 }
423
424
425 Span_dynamic_req::Span_dynamic_req()
426 {
427     dynamic_dir_i_  = 0;
428 }
429
430 IMPLEMENT_STATIC_NAME(Span_dynamic_req);
431
432 void
433 Span_dynamic_req::do_print()const
434 {
435 #ifndef NPRINT
436     Span_req::do_print();
437     mtor << "louder/louder: " <<dynamic_dir_i_;
438 #endif
439 }
440
441 IMPLEMENT_STATIC_NAME(Tie_req);
442
443