]> git.donarmstrong.com Git - lilypond.git/blob - lily/musical-request.cc
release: 0.0.59
[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 void
131 Melodic_req::do_print() const
132 {
133 #ifndef NPRINT
134         mtor << "notename: " << notename_i_ << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
135 #endif
136 }
137
138 int
139 Melodic_req::height() const
140 {
141     return  notename_i_ + octave_i_*7;
142 }
143
144 /*
145  should be settable from input to allow "viola"-mode
146  */
147 static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 };       
148
149 int
150 Melodic_req::pitch() const
151 {
152     return  pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
153 }
154
155 Plet_req::Plet_req()
156 {
157     type_c_ = ']';
158     dur_i_ = 1;
159     type_i_ = 1;
160 }
161
162 IMPLEMENT_STATIC_NAME(Plet_req);
163
164 void
165 Plet_req::do_print() const
166 {
167 #ifndef NPRINT
168     mtor << "plet: " << type_c_ << ": " << dur_i_ << "/" << type_i_;
169 #endif
170 }
171
172 /* *************** */
173 int
174 Rhythmic_req::compare(Rhythmic_req const &r1, Rhythmic_req const &r2)
175 {
176     return sign(r1.duration() - r2.duration());
177 }
178
179 void
180 Rhythmic_req::set_duration(Duration d)
181 {
182     duration_ = d;
183 }
184
185 Rhythmic_req::Rhythmic_req()
186 {
187 }
188
189 IMPLEMENT_STATIC_NAME(Rhythmic_req);
190
191 void
192 Rhythmic_req::do_print() const
193 {
194 #ifndef NPRINT
195     mtor << "duration { " <<duration_.str() << "}";
196 #endif
197 }
198
199
200 Moment
201 Rhythmic_req::duration() const {    
202     return duration_.length();
203 }
204 /* *************** */
205
206 Lyric_req::Lyric_req(Text_def* def_p)
207     :Text_req(0, def_p)
208 {
209     def_p->align_i_ = 0;        // centre
210     dir_i_ = -1;                // lyrics below (invisible) staff
211 }
212
213 IMPLEMENT_STATIC_NAME(Lyric_req);
214
215 void
216 Lyric_req::do_print() const
217 {    
218     Rhythmic_req::do_print();
219     Text_req::do_print();
220 }
221
222 /* *************** */
223 Note_req::Note_req()
224 {
225     forceacc_b_ = false;
226 }
227 IMPLEMENT_STATIC_NAME(Note_req);
228
229 void
230 Note_req::do_print() const
231 {
232 #ifndef NPRINT
233     Melodic_req::do_print();
234     if (forceacc_b_) {
235         mtor << " force accidental\n";
236     }
237     Rhythmic_req::do_print();
238 #endif
239 }
240 /* *************** */
241 IMPLEMENT_STATIC_NAME(Rest_req);
242
243 void
244 Rest_req::do_print() const
245 {
246         Rhythmic_req::do_print();
247 }
248
249 /* *************** */
250 Beam_req::Beam_req()
251 {
252     nplet = 0;
253 }
254 IMPLEMENT_STATIC_NAME(Beam_req);
255 void
256 Beam_req::do_print()const{}
257 /* *************** */
258 IMPLEMENT_STATIC_NAME(Slur_req);
259 void
260 Slur_req::do_print()const{}
261 /* *************** */
262 int
263 Span_req:: compare(Span_req const &r1, Span_req const &r2)
264 {
265      return r1.spantype - r2.spantype;
266 }
267
268 Span_req::Span_req()
269 {
270     spantype = NOSPAN;
271 }
272
273 /* *************** */
274 Script_req::Script_req(int d , Script_def*def)
275 {
276     dir_i_ = d;
277     scriptdef_p_ = def;
278 }
279
280 int
281 Script_req::compare(Script_req const &d1, Script_req const &d2)
282 {
283     return d1.dir_i_ == d2.dir_i_ &&
284         d1.scriptdef_p_->compare(*d2.scriptdef_p_);
285 }
286
287 Script_req::Script_req(Script_req const &s)
288     : Request( s )
289 {
290     dir_i_ = s.dir_i_;
291     scriptdef_p_ = new Script_def(*s.scriptdef_p_);
292 }
293
294 IMPLEMENT_STATIC_NAME(Script_req);
295
296 void
297 Script_req::do_print() const
298 {
299     mtor << " dir " << dir_i_ ;
300     scriptdef_p_->print();
301 }
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_ ->compare(*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);