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