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