lilypond-0.1.35
[lilypond.git] / src / request.cc
blobecfe68c881a3470d4504b08c3cc5f9a15d1b5371
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 mtor << "next " << next << "dist " << distance << "strength\n";
77 void
78 Blank_req::do_print()const
80 Spacing_req::do_print();
82 /* *************** */
83 Melodic_req::Melodic_req()
85 notename_i_ = 0;
86 octave_i_ = 0;
87 accidental_i_ = 0;
88 forceacc_b_ = false;
91 void
92 Melodic_req::do_print() const
94 mtor << "notename: " << notename_i_ << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
97 int
98 Melodic_req::height() const
100 return notename_i_ + octave_i_*7;
104 should be settable from input to allow "viola"-mode
106 static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 };
109 Melodic_req::pitch() const
111 return pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
114 Plet_req::Plet_req()
116 type_c_ = ']';
117 dur_i_ = 1;
118 type_i_ = 1;
121 void
122 Plet_req::do_print() const
124 mtor << "plet: " << type_c_ << ": " << dur_i_ << "/" << type_i_;
127 /* *************** */
129 Rhythmic_req::compare(const Rhythmic_req &r1, const Rhythmic_req &r2)
131 return sign(r1.duration() - r2.duration());
133 Rhythmic_req::Rhythmic_req(int b, int d)
135 plet_factor = 1;
136 balltype = b;
137 dots = d;
140 Rhythmic_req::Rhythmic_req()
142 plet_factor = 1;
143 balltype = 1;
144 dots = 0;
147 void
148 Rhythmic_req::do_print() const
150 mtor << "ball: " << balltype ;
151 int d =dots;
152 while (d--)
153 mtor << '.';
155 mtor<<", plet factor"<<plet_factor<<"\n";
159 Moment
160 Rhythmic_req::duration() const {
161 return wholes(balltype,dots)*plet_factor;
163 /* *************** */
165 Lyric_req::Lyric_req(Text_def* def_p)
166 :Text_req(0, def_p)
168 def_p->align_i_ = 0; // centre
169 dir_i_ = -1; // lyrics below (invisible) staff
172 void
173 Lyric_req::do_print() const
175 Rhythmic_req::do_print();
176 Text_req::do_print();
178 /* *************** */
179 void
180 Note_req::do_print() const
182 Melodic_req::do_print();
183 Rhythmic_req::do_print();
185 /* *************** */
186 void
187 Rest_req::do_print() const
189 Rhythmic_req::do_print();
192 /* *************** */
193 Beam_req::Beam_req()
195 nplet = 0;
198 void Beam_req::do_print()const{}
199 /* *************** */
200 void Slur_req::do_print()const{}
201 /* *************** */
203 Span_req:: compare(const Span_req &r1, const Span_req &r2)
205 return r1.spantype - r2.spantype;
208 Span_req::Span_req()
210 spantype = NOSPAN;
213 /* *************** */
214 Script_req::Script_req(int d , Script_def*def)
216 dir_i_ = d;
217 scriptdef_p_ = def;
221 Script_req::compare(const Script_req &d1, const Script_req &d2)
223 return d1.dir_i_ == d2.dir_i_ &&
224 d1.scriptdef_p_->compare(*d2.scriptdef_p_);
227 Script_req::Script_req(Script_req const &s)
228 : Request( s )
230 dir_i_ = s.dir_i_;
231 scriptdef_p_ = new Script_def(*s.scriptdef_p_);
234 void
235 Script_req::do_print() const
237 mtor << " dir " << dir_i_ ;
238 scriptdef_p_->print();
242 Script_req::~Script_req()
244 delete scriptdef_p_;
246 /* *************** */
248 Text_req:: compare(const Text_req &r1, const Text_req &r2)
250 bool b1 = (r1.dir_i_ == r2.dir_i_);
251 bool b2 = (r1.tdef_p_ ->compare(*r2.tdef_p_));
252 return b1 && b2;
254 Text_req::~Text_req()
256 delete tdef_p_;
257 tdef_p_ = 0;
260 Text_req::Text_req(Text_req const& src)
262 tdef_p_ = new Text_def(*src.tdef_p_);
263 dir_i_ = src.dir_i_;
266 Text_req::Text_req(int dir_i, Text_def* tdef_p)
268 dir_i_ = dir_i;
269 tdef_p_ = tdef_p;
272 void
273 Text_req::do_print() const
275 mtor << " dir " << dir_i_ ;
276 tdef_p_->print();
279 /* *************** */
281 Moment
282 Skip_req::duration() const
284 return duration_;
287 void
288 Skip_req::do_print() const
290 mtor << "duration: " << duration();
293 Voice *
294 Request::voice_l()
296 if (!elt_l_)
297 return 0;
298 else
299 return (Voice*)elt_l_->voice_l_;