]> git.donarmstrong.com Git - lilypond.git/blob - lily/musical-request.cc
release: 0.0.45
[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     defined_ch_C_ = 0;
69 }
70 Request::Request(Request const&src)
71 {
72     elt_l_ = 0;
73     defined_ch_C_ = src.defined_ch_C_;
74 }
75 /* *************** */
76 Spacing_req::Spacing_req()
77 {
78     next = 0;
79     distance = 0;
80     strength = 0;
81 }
82 IMPLEMENT_STATIC_NAME(Spacing_req);
83
84 void
85 Spacing_req::do_print()const
86 {
87 #ifndef NPRINT
88     mtor << "next " << next << "dist " << distance << "strength\n";
89 #endif
90 }
91
92 IMPLEMENT_STATIC_NAME(Blank_req);
93
94 void
95 Blank_req::do_print()const
96 {
97     Spacing_req::do_print();
98 }
99 /* *************** */
100 Melodic_req::Melodic_req()
101 {
102     notename_i_ = 0;
103     octave_i_ = 0;
104     accidental_i_ = 0;
105 }
106
107 void
108 Melodic_req::transpose(Melodic_req const & delta)
109 {
110     octave_i_ += delta.octave_i_;
111     notename_i_ += delta.notename_i_;
112     while  (notename_i_ >= 7 ) {
113         notename_i_ -= 7;
114         octave_i_ ++;
115     }
116     accidental_i_ += delta.accidental_i_;
117     if (abs(accidental_i_) > 2) {
118         warning("transposition makes accidental larger than 2", 
119                 delta.defined_ch_C_);
120     }
121 }
122
123 IMPLEMENT_STATIC_NAME(Melodic_req);
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 Plet_req::Plet_req()
151 {
152     type_c_ = ']';
153     dur_i_ = 1;
154     type_i_ = 1;
155 }
156
157 IMPLEMENT_STATIC_NAME(Plet_req);
158
159 void
160 Plet_req::do_print() const
161 {
162 #ifndef NPRINT
163     mtor << "plet: " << type_c_ << ": " << dur_i_ << "/" << type_i_;
164 #endif
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(int d , Script_def*def)
270 {
271     dir_i_ = d;
272     scriptdef_p_ = def;
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_->compare(*d2.scriptdef_p_);
280 }
281
282 Script_req::Script_req(Script_req const &s)
283     : Request( s )
284 {
285     dir_i_ = s.dir_i_;
286     scriptdef_p_ = new Script_def(*s.scriptdef_p_);
287 }
288
289 IMPLEMENT_STATIC_NAME(Script_req);
290
291 void
292 Script_req::do_print() const
293 {
294     mtor << " dir " << dir_i_ ;
295     scriptdef_p_->print();
296 }
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_ ->compare(*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
331 void
332 Text_req::do_print() const
333 {
334 #ifndef NPRINT
335
336     mtor << " dir " << dir_i_ ;
337     tdef_p_->print();
338 #endif
339 }
340
341 /* *************** */
342
343 Moment
344 Skip_req::duration() const
345 {
346     return duration_;
347 }
348
349 IMPLEMENT_STATIC_NAME(Skip_req);
350
351 void
352 Skip_req::do_print() const
353 {
354 #ifndef NPRINT
355
356     mtor << "duration: " << duration();
357 #endif
358 }
359
360 Voice *
361 Request::voice_l()
362 {
363     if (!elt_l_)
364         return 0;
365     else
366         return (Voice*)elt_l_->voice_l_;
367 }
368 /* *************** */
369
370 IMPLEMENT_STATIC_NAME(Subtle_req);
371
372 void
373 Subtle_req::do_print() const
374 {
375 #ifndef NPRINT
376         mtor << " subtime " <<  subtime_;
377 #endif
378 }
379
380 IMPLEMENT_STATIC_NAME(Dynamic_req);
381
382 void
383 Dynamic_req::do_print() const
384 {
385     Subtle_req::do_print();
386 }
387
388 IMPLEMENT_STATIC_NAME(Absolute_dynamic_req);
389
390 void
391 Absolute_dynamic_req::do_print() const
392 {
393     Dynamic_req::do_print();
394     mtor << " loudness " <<loudness_;
395 }
396
397 String
398 Dynamic_req::loudness_str(Loudness l) 
399 {
400     switch (l) {
401     case FFF: return "fff";
402     case FF: return "ff";
403     case F: return "f";
404     case MF: return "mf";
405     case MP: return "mp";
406     case P: return "p";
407     case PP: return "pp";
408     case PPP: return "ppp";
409     }
410     assert(false);
411     return "";
412 }
413
414 Absolute_dynamic_req::Absolute_dynamic_req()
415 {
416     loudness_ = MF;
417 }
418
419
420 Span_dynamic_req::Span_dynamic_req()
421 {
422     dynamic_dir_i_  = 0;
423 }
424
425 IMPLEMENT_STATIC_NAME(Span_dynamic_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 }