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