]> git.donarmstrong.com Git - lilypond.git/blob - lily/request.cc
release: 0.0.40
[lilypond.git] / lily / 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 "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"
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     mtor << name() << " {";
40     do_print();
41     mtor << "}\n";
42 }
43      
44
45
46 void
47 Span_req::do_print() const    
48 {
49 #ifndef NPRINT
50     mtor  << spantype ;
51 #endif
52 }
53
54 Request::Request()
55 {
56     elt_l_ = 0;
57     defined_ch_c_l_ = 0;
58 }
59 Request::Request(Request const&src)
60 {
61     elt_l_ = 0;
62     defined_ch_c_l_ = src.defined_ch_c_l_;
63 }
64 /* *************** */
65 Spacing_req::Spacing_req()
66 {
67     next = 0;
68     distance = 0;
69     strength = 0;
70 }
71 void
72 Spacing_req::do_print()const
73 {
74 #ifndef NPRINT
75     mtor << "next " << next << "dist " << distance << "strength\n";
76 #endif
77 }
78
79 void
80 Blank_req::do_print()const
81 {
82     Spacing_req::do_print();
83 }
84 /* *************** */
85 Melodic_req::Melodic_req()
86 {
87     notename_i_ = 0;
88     octave_i_ = 0;
89     accidental_i_ = 0;
90     forceacc_b_ = false;
91 }
92
93 void
94 Melodic_req::do_print() const
95 {
96     mtor << "notename: " << notename_i_ << " acc: " <<accidental_i_<<" oct: "<< octave_i_;
97 }
98
99 int
100 Melodic_req::height() const
101 {
102     return  notename_i_ + octave_i_*7;
103 }
104
105 /*
106  should be settable from input to allow "viola"-mode
107  */
108 static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 };       
109
110 int
111 Melodic_req::pitch() const
112 {
113     return  pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12;
114 }
115
116 Plet_req::Plet_req()
117 {
118     type_c_ = ']';
119     dur_i_ = 1;
120     type_i_ = 1;
121 }
122
123 void
124 Plet_req::do_print() const
125 {
126     mtor << "plet: " << type_c_ << ": " << dur_i_ << "/" << type_i_;
127 }
128
129 /* *************** */
130 int
131 Rhythmic_req::compare(const Rhythmic_req &r1, const Rhythmic_req &r2)
132 {
133     return sign(r1.duration() - r2.duration());
134 }
135 Rhythmic_req::Rhythmic_req(int b, int d)
136 {
137     plet_factor = 1;
138     balltype = b;
139     dots = d;
140 }
141
142 Rhythmic_req::Rhythmic_req()
143 {
144     plet_factor = 1;
145     balltype = 1;
146     dots = 0;
147 }
148
149 void
150 Rhythmic_req::do_print() const
151 {
152     mtor << "ball: " << balltype ;
153     int d =dots;
154     while (d--)
155         mtor << '.';
156     
157     mtor<<", plet factor"<<plet_factor<<"\n";
158 }
159
160
161 Moment
162 Rhythmic_req::duration() const {    
163     return wholes(balltype,dots)*plet_factor;
164 }
165 /* *************** */
166
167 Lyric_req::Lyric_req(Text_def* def_p)
168     :Text_req(0, def_p)
169 {
170     def_p->align_i_ = 0;        // centre
171     dir_i_ = -1;                // lyrics below (invisible) staff
172 }
173
174 void
175 Lyric_req::do_print() const
176 {    
177     Rhythmic_req::do_print();
178     Text_req::do_print();
179 }
180 /* *************** */
181 void
182 Note_req::do_print() const
183 {
184     Melodic_req::do_print();
185     Rhythmic_req::do_print();
186 }
187 /* *************** */
188 void
189 Rest_req::do_print() const
190 {
191         Rhythmic_req::do_print();
192 }
193
194 /* *************** */
195 Beam_req::Beam_req()
196 {
197     nplet = 0;
198 }
199
200 void Beam_req::do_print()const{}
201 /* *************** */
202 void Slur_req::do_print()const{}
203 /* *************** */
204 int
205 Span_req:: compare(const Span_req &r1, const Span_req &r2)
206 {
207      return r1.spantype - r2.spantype;
208 }
209
210 Span_req::Span_req()
211 {
212     spantype = NOSPAN;
213 }
214
215 /* *************** */
216 Script_req::Script_req(int d , Script_def*def)
217 {
218     dir_i_ = d;
219     scriptdef_p_ = def;
220 }
221
222 int
223 Script_req::compare(const Script_req &d1, const Script_req &d2)
224 {
225     return d1.dir_i_ == d2.dir_i_ &&
226         d1.scriptdef_p_->compare(*d2.scriptdef_p_);
227 }
228
229 Script_req::Script_req(Script_req const &s)
230     : Request( s )
231 {
232     dir_i_ = s.dir_i_;
233     scriptdef_p_ = new Script_def(*s.scriptdef_p_);
234 }
235
236 void
237 Script_req::do_print() const
238 {
239     mtor << " dir " << dir_i_ ;
240     scriptdef_p_->print();
241 }
242
243
244 Script_req::~Script_req()
245 {
246     delete scriptdef_p_;
247 }
248 /* *************** */
249 int
250 Text_req:: compare(const Text_req &r1, const Text_req &r2)
251 {
252     bool b1 = (r1.dir_i_ == r2.dir_i_);
253     bool b2 = (r1.tdef_p_ ->compare(*r2.tdef_p_));
254     return b1 && b2;
255 }
256 Text_req::~Text_req()
257 {
258     delete tdef_p_;
259     tdef_p_ = 0;
260 }
261
262 Text_req::Text_req(Text_req const& src)
263 {
264     tdef_p_ = new Text_def(*src.tdef_p_);
265     dir_i_ = src.dir_i_;
266 }
267
268 Text_req::Text_req(int dir_i, Text_def* tdef_p) 
269 {
270     dir_i_ = dir_i;
271     tdef_p_ = tdef_p;
272 }
273
274 void
275 Text_req::do_print() const
276 {
277     mtor << " dir " << dir_i_ ;
278     tdef_p_->print();
279 }
280
281 /* *************** */
282
283 Moment
284 Skip_req::duration() const
285 {
286     return duration_;
287 }
288
289 void
290 Skip_req::do_print() const
291 {
292     mtor << "duration: " << duration();
293 }
294
295 Voice *
296 Request::voice_l()
297 {
298     if (!elt_l_)
299         return 0;
300     else
301         return (Voice*)elt_l_->voice_l_;
302 }
303 /* *************** */
304
305 void
306 Subtle_req::do_print() const
307 {
308     mtor << " subtime " <<  subtime_;
309 }
310
311 void
312 Dynamic_req::do_print() const
313 {
314     Subtle_req::do_print();
315 }
316
317 void
318 Absolute_dynamic_req::do_print() const
319 {
320     Dynamic_req::do_print();
321     mtor << " loudness_" <<loudness_;
322 }
323
324 String
325 Dynamic_req::loudness_str(Loudness l) 
326 {
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";
336     }
337     assert(false);
338     return "";
339 }
340
341 Absolute_dynamic_req::Absolute_dynamic_req()
342 {
343     loudness_ = MF;
344 }