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