lilypond-0.0.47
[lilypond.git] / lily / musical-request.cc
blob1ba4fd7801d1306efb1d05b8969528fa5198b736
1 /*
2 request.cc -- implement all musical requests.
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
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"
17 IMPLEMENT_STATIC_NAME(Stem_req);
18 void
19 Stem_req::do_print() const
21 #ifndef NPRINT
22 Rhythmic_req::do_print();
23 mtor << "dir : " << dir_i_;
24 #endif
27 Stem_req::Stem_req()
29 dir_i_ = 0;
32 /* ************** */
33 IMPLEMENT_STATIC_NAME(Musical_req);
34 void
35 Musical_req::do_print()const{}
37 IMPLEMENT_STATIC_NAME(Request);
39 void Request::do_print() const{}
41 /* *************** */
43 void
44 Request::print() const
46 #ifndef NPRINT
47 mtor << name() << " {";
48 do_print();
49 mtor << "}\n";
50 #endif
55 IMPLEMENT_STATIC_NAME(Span_req);
57 void
58 Span_req::do_print() const
60 #ifndef NPRINT
61 mtor << spantype ;
62 #endif
65 Request::Request()
67 elt_l_ = 0;
69 Request::Request(Request const&src)
70 :Input(src)
72 elt_l_ = 0;
74 /* *************** */
75 Spacing_req::Spacing_req()
77 next = 0;
78 distance = 0;
79 strength = 0;
81 IMPLEMENT_STATIC_NAME(Spacing_req);
83 void
84 Spacing_req::do_print()const
86 #ifndef NPRINT
87 mtor << "next " << next << "dist " << distance << "strength\n";
88 #endif
91 IMPLEMENT_STATIC_NAME(Blank_req);
93 void
94 Blank_req::do_print()const
96 Spacing_req::do_print();
98 /* *************** */
99 Melodic_req::Melodic_req()
101 notename_i_ = 0;
102 octave_i_ = 0;
103 accidental_i_ = 0;
106 void
107 Melodic_req::transpose(Melodic_req const & delta)
109 octave_i_ += delta.octave_i_;
110 notename_i_ += delta.notename_i_;
111 while (notename_i_ >= 7 ) {
112 notename_i_ -= 7;
113 octave_i_ ++;
115 accidental_i_ += delta.accidental_i_;
116 if (abs(accidental_i_) > 2) {
117 delta.warning("transposition makes accidental larger than 2");
121 IMPLEMENT_STATIC_NAME(Melodic_req);
123 void
124 Melodic_req::do_print() const
126 #ifndef NPRINT
127 mtor << "notename: " << notename_i_ << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
128 #endif
132 Melodic_req::height() const
134 return notename_i_ + octave_i_*7;
138 should be settable from input to allow "viola"-mode
140 static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 };
143 Melodic_req::pitch() const
145 return pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
148 Plet_req::Plet_req()
150 type_c_ = ']';
151 dur_i_ = 1;
152 type_i_ = 1;
155 IMPLEMENT_STATIC_NAME(Plet_req);
157 void
158 Plet_req::do_print() const
160 #ifndef NPRINT
161 mtor << "plet: " << type_c_ << ": " << dur_i_ << "/" << type_i_;
162 #endif
165 /* *************** */
167 Rhythmic_req::compare(Rhythmic_req const &r1, Rhythmic_req const &r2)
169 return sign(r1.duration() - r2.duration());
172 void
173 Rhythmic_req::set_duration(Duration d)
175 duration_ = d;
178 Rhythmic_req::Rhythmic_req()
182 IMPLEMENT_STATIC_NAME(Rhythmic_req);
184 void
185 Rhythmic_req::do_print() const
187 #ifndef NPRINT
188 mtor << "duration { " <<duration_.str() << "}";
189 #endif
193 Moment
194 Rhythmic_req::duration() const {
195 return duration_.length();
197 /* *************** */
199 Lyric_req::Lyric_req(Text_def* def_p)
200 :Text_req(0, def_p)
202 def_p->align_i_ = 0; // centre
203 dir_i_ = -1; // lyrics below (invisible) staff
206 IMPLEMENT_STATIC_NAME(Lyric_req);
208 void
209 Lyric_req::do_print() const
211 Rhythmic_req::do_print();
212 Text_req::do_print();
215 /* *************** */
216 Note_req::Note_req()
218 forceacc_b_ = false;
220 IMPLEMENT_STATIC_NAME(Note_req);
222 void
223 Note_req::do_print() const
225 #ifndef NPRINT
226 Melodic_req::do_print();
227 if (forceacc_b_) {
228 mtor << " force accidental\n";
230 Rhythmic_req::do_print();
231 #endif
233 /* *************** */
234 IMPLEMENT_STATIC_NAME(Rest_req);
236 void
237 Rest_req::do_print() const
239 Rhythmic_req::do_print();
242 /* *************** */
243 Beam_req::Beam_req()
245 nplet = 0;
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 /* *************** */
256 Span_req:: compare(Span_req const &r1, Span_req const &r2)
258 return r1.spantype - r2.spantype;
261 Span_req::Span_req()
263 spantype = NOSPAN;
266 /* *************** */
267 Script_req::Script_req(int d , Script_def*def)
269 dir_i_ = d;
270 scriptdef_p_ = def;
274 Script_req::compare(Script_req const &d1, Script_req const &d2)
276 return d1.dir_i_ == d2.dir_i_ &&
277 d1.scriptdef_p_->compare(*d2.scriptdef_p_);
280 Script_req::Script_req(Script_req const &s)
281 : Request( s )
283 dir_i_ = s.dir_i_;
284 scriptdef_p_ = new Script_def(*s.scriptdef_p_);
287 IMPLEMENT_STATIC_NAME(Script_req);
289 void
290 Script_req::do_print() const
292 mtor << " dir " << dir_i_ ;
293 scriptdef_p_->print();
297 Script_req::~Script_req()
299 delete scriptdef_p_;
301 /* *************** */
303 Text_req:: compare(Text_req const &r1, Text_req const &r2)
305 bool b1 = (r1.dir_i_ == r2.dir_i_);
306 bool b2 = (r1.tdef_p_ ->compare(*r2.tdef_p_));
307 return b1 && b2;
309 Text_req::~Text_req()
311 delete tdef_p_;
312 tdef_p_ = 0;
315 Text_req::Text_req(Text_req const& src)
317 tdef_p_ = new Text_def(*src.tdef_p_);
318 dir_i_ = src.dir_i_;
321 Text_req::Text_req(int dir_i, Text_def* tdef_p)
323 dir_i_ = dir_i;
324 tdef_p_ = tdef_p;
327 IMPLEMENT_STATIC_NAME(Text_req);
329 void
330 Text_req::do_print() const
332 #ifndef NPRINT
334 mtor << " dir " << dir_i_ ;
335 tdef_p_->print();
336 #endif
339 /* *************** */
341 Moment
342 Skip_req::duration() const
344 return duration_;
347 IMPLEMENT_STATIC_NAME(Skip_req);
349 void
350 Skip_req::do_print() const
352 #ifndef NPRINT
354 mtor << "duration: " << duration();
355 #endif
358 Voice *
359 Request::voice_l()
361 if (!elt_l_)
362 return 0;
363 else
364 return (Voice*)elt_l_->voice_C_;
366 /* *************** */
368 IMPLEMENT_STATIC_NAME(Subtle_req);
370 void
371 Subtle_req::do_print() const
373 #ifndef NPRINT
374 mtor << " subtime " << subtime_;
375 #endif
378 IMPLEMENT_STATIC_NAME(Dynamic_req);
380 void
381 Dynamic_req::do_print() const
383 Subtle_req::do_print();
386 IMPLEMENT_STATIC_NAME(Absolute_dynamic_req);
388 void
389 Absolute_dynamic_req::do_print() const
391 Dynamic_req::do_print();
392 mtor << " loudness " <<loudness_;
395 String
396 Dynamic_req::loudness_str(Loudness l)
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";
408 assert(false);
409 return "";
412 Absolute_dynamic_req::Absolute_dynamic_req()
414 loudness_ = MF;
418 Span_dynamic_req::Span_dynamic_req()
420 dynamic_dir_i_ = 0;
423 IMPLEMENT_STATIC_NAME(Span_dynamic_req);
425 void
426 Span_dynamic_req::do_print()const
428 #ifndef NPRINT
429 Span_req::do_print();
430 mtor << "louder/louder: " <<dynamic_dir_i_;
431 #endif