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