lilypond-0.0.47
[lilypond.git] / lily / request.cc
blobd6bae873b7c047bd1ebc025d8edc0d792e983af4
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 "musicalrequest.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 void
18 Stem_req::do_print() const
20 Rhythmic_req::do_print();
21 mtor << "dir : " << dir_i_;
24 Stem_req::Stem_req(int s, int d)
25 : Rhythmic_req(s,d)
27 dir_i_ = 0;
30 /* ************** */
31 void Musical_req::do_print()const{}
32 void Request::do_print() const{}
34 /* *************** */
36 void
37 Request::print() const
39 mtor << name() << " {";
40 do_print();
41 mtor << "}\n";
46 void
47 Span_req::do_print() const
49 #ifndef NPRINT
50 mtor << spantype ;
51 #endif
54 Request::Request()
56 elt_l_ = 0;
57 defined_ch_c_l_ = 0;
59 Request::Request(Request const&src)
61 elt_l_ = 0;
62 defined_ch_c_l_ = src.defined_ch_c_l_;
64 /* *************** */
65 Spacing_req::Spacing_req()
67 next = 0;
68 distance = 0;
69 strength = 0;
71 void
72 Spacing_req::do_print()const
74 #ifndef NPRINT
75 mtor << "next " << next << "dist " << distance << "strength\n";
76 #endif
79 void
80 Blank_req::do_print()const
82 Spacing_req::do_print();
84 /* *************** */
85 Melodic_req::Melodic_req()
87 notename_i_ = 0;
88 octave_i_ = 0;
89 accidental_i_ = 0;
90 forceacc_b_ = false;
93 void
94 Melodic_req::do_print() const
96 mtor << "notename: " << notename_i_ << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
99 int
100 Melodic_req::height() const
102 return notename_i_ + octave_i_*7;
106 should be settable from input to allow "viola"-mode
108 static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 };
111 Melodic_req::pitch() const
113 return pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
116 Plet_req::Plet_req()
118 type_c_ = ']';
119 dur_i_ = 1;
120 type_i_ = 1;
123 void
124 Plet_req::do_print() const
126 mtor << "plet: " << type_c_ << ": " << dur_i_ << "/" << type_i_;
129 /* *************** */
131 Rhythmic_req::compare(const Rhythmic_req &r1, const Rhythmic_req &r2)
133 return sign(r1.duration() - r2.duration());
135 Rhythmic_req::Rhythmic_req(int b, int d)
137 plet_factor = 1;
138 balltype = b;
139 dots = d;
142 Rhythmic_req::Rhythmic_req()
144 plet_factor = 1;
145 balltype = 1;
146 dots = 0;
149 void
150 Rhythmic_req::do_print() const
152 mtor << "ball: " << balltype ;
153 int d =dots;
154 while (d--)
155 mtor << '.';
157 mtor<<", plet factor"<<plet_factor<<"\n";
161 Moment
162 Rhythmic_req::duration() const {
163 return wholes(balltype,dots)*plet_factor;
165 /* *************** */
167 Lyric_req::Lyric_req(Text_def* def_p)
168 :Text_req(0, def_p)
170 def_p->align_i_ = 0; // centre
171 dir_i_ = -1; // lyrics below (invisible) staff
174 void
175 Lyric_req::do_print() const
177 Rhythmic_req::do_print();
178 Text_req::do_print();
180 /* *************** */
181 void
182 Note_req::do_print() const
184 Melodic_req::do_print();
185 Rhythmic_req::do_print();
187 /* *************** */
188 void
189 Rest_req::do_print() const
191 Rhythmic_req::do_print();
194 /* *************** */
195 Beam_req::Beam_req()
197 nplet = 0;
200 void Beam_req::do_print()const{}
201 /* *************** */
202 void Slur_req::do_print()const{}
203 /* *************** */
205 Span_req:: compare(const Span_req &r1, const Span_req &r2)
207 return r1.spantype - r2.spantype;
210 Span_req::Span_req()
212 spantype = NOSPAN;
215 /* *************** */
216 Script_req::Script_req(int d , Script_def*def)
218 dir_i_ = d;
219 scriptdef_p_ = def;
223 Script_req::compare(const Script_req &d1, const Script_req &d2)
225 return d1.dir_i_ == d2.dir_i_ &&
226 d1.scriptdef_p_->compare(*d2.scriptdef_p_);
229 Script_req::Script_req(Script_req const &s)
230 : Request( s )
232 dir_i_ = s.dir_i_;
233 scriptdef_p_ = new Script_def(*s.scriptdef_p_);
236 void
237 Script_req::do_print() const
239 mtor << " dir " << dir_i_ ;
240 scriptdef_p_->print();
244 Script_req::~Script_req()
246 delete scriptdef_p_;
248 /* *************** */
250 Text_req:: compare(const Text_req &r1, const Text_req &r2)
252 bool b1 = (r1.dir_i_ == r2.dir_i_);
253 bool b2 = (r1.tdef_p_ ->compare(*r2.tdef_p_));
254 return b1 && b2;
256 Text_req::~Text_req()
258 delete tdef_p_;
259 tdef_p_ = 0;
262 Text_req::Text_req(Text_req const& src)
264 tdef_p_ = new Text_def(*src.tdef_p_);
265 dir_i_ = src.dir_i_;
268 Text_req::Text_req(int dir_i, Text_def* tdef_p)
270 dir_i_ = dir_i;
271 tdef_p_ = tdef_p;
274 void
275 Text_req::do_print() const
277 mtor << " dir " << dir_i_ ;
278 tdef_p_->print();
281 /* *************** */
283 Moment
284 Skip_req::duration() const
286 return duration_;
289 void
290 Skip_req::do_print() const
292 mtor << "duration: " << duration();
295 Voice *
296 Request::voice_l()
298 if (!elt_l_)
299 return 0;
300 else
301 return (Voice*)elt_l_->voice_l_;
303 /* *************** */
305 void
306 Subtle_req::do_print() const
308 mtor << " subtime " << subtime_;
311 void
312 Dynamic_req::do_print() const
314 Subtle_req::do_print();
317 void
318 Absolute_dynamic_req::do_print() const
320 Dynamic_req::do_print();
321 mtor << " loudness_" <<loudness_;
324 String
325 Dynamic_req::loudness_str(Loudness l)
327 switch (l) {
328 case FFF: return "fff";
329 case FF: return "ff";
330 case F: return "f";
331 case MF: return "mf";
332 case MP: return "mp";
333 case P: return "p";
334 case PP: return "pp";
335 case PPP: return "ppp";
337 assert(false);
338 return "";
341 Absolute_dynamic_req::Absolute_dynamic_req()
343 loudness_ = MF;