]> git.donarmstrong.com Git - lilypond.git/blob - lily/note.cc
release: 0.0.42.pre3
[lilypond.git] / lily / note.cc
1 /*
2   could use cleanup
3  */
4 #include <ctype.h>
5 #include "lexer.hh"
6 #include "string.hh"
7 #include "real.hh"
8 #include "debug.hh"
9 #include "musical-request.hh"
10 #include "command-request.hh"
11 #include "voice.hh"
12
13 #include "identifier.hh"
14 #include "varray.hh"
15 #include "text-def.hh"
16 #include "parseconstruct.hh"
17 #include "input-music.hh"
18 #include "voice-element.hh"
19 Moment
20 Lexer_prefs::plet_mom()
21 {
22     return Moment(default_plet_dur, default_plet_type);
23 }
24 Lexer_prefs::Lexer_prefs()
25 {
26     default_duration = 4, default_dots=0, default_octave_i_=0;
27     default_plet_type = 1, default_plet_dur = 1;
28     textstyle_str_="roman";             // in lexer?
29     
30     last_duration_mode = false;
31 }
32
33 void
34 Lexer_prefs::set_duration_mode(String s)
35 {
36     s = s.upper_str();
37     last_duration_mode = (s== "LAST");
38 }
39
40 void
41 Lexer_prefs::set_last_duration(int n)
42 {
43     if (last_duration_mode)
44         default_duration = n;
45 }
46
47 /* triplet is '2/3' */
48 void 
49 Lexer_prefs::set_plet(int num,int den)
50 {
51     assert(num >0&& den>0);
52     default_plet_dur = num;
53     default_plet_type = den;
54 }
55
56 Text_def*
57 get_text(String s) return t;
58 {
59     t= new Text_def;
60     t->text_str_= s;
61     t->style_str_ = lexer->prefs.textstyle_str_;
62     t->defined_ch_c_l_ = defined_ch_c_l;
63     return t;
64 }
65 Voice_element *
66 get_note_element(Note_req *rq, int * duration )
67 {
68     Voice_element*v = new Voice_element;
69     v->defined_ch_c_l_ = defined_ch_c_l;
70     
71     int dur = duration[0];
72     int dots = duration[1];
73
74     if (dur >= 2) {
75         Stem_req * stem_req_p = new Stem_req(dur,dots);
76         stem_req_p->plet_factor = lexer->prefs.plet_mom();
77         
78         stem_req_p->defined_ch_c_l_ = defined_ch_c_l;
79         v->add(stem_req_p);
80     }
81     
82     if ( !defined_ch_c_l )
83         defined_ch_c_l = lexer->here_ch_c_l();
84
85     rq->balltype = dur;
86     rq->dots = dots;
87     rq->plet_factor = lexer->prefs.plet_mom();
88
89     rq->defined_ch_c_l_ = defined_ch_c_l;
90
91     v->add(rq);
92
93     return v;
94 }
95
96 Voice_element*
97 get_word_element(Text_def* tdef_p, int* duration)
98 {
99     Voice_element* velt_p = new Voice_element;
100     velt_p->defined_ch_c_l_ = defined_ch_c_l;
101     
102     int dur = duration[0];
103     int dots=duration[1];
104     
105     tdef_p->defined_ch_c_l_ = defined_ch_c_l;
106
107     Lyric_req* lreq_p = new Lyric_req(tdef_p);
108
109     lreq_p->balltype = dur;
110     lreq_p->dots = dots;
111     lreq_p->plet_factor = lexer->prefs.plet_mom();
112     lreq_p->print();
113     lreq_p->defined_ch_c_l_ = defined_ch_c_l;
114
115     velt_p->add(lreq_p);
116
117     return velt_p;
118 }
119
120 Voice_element *
121 get_rest_element(String,  int * duration )
122 {    
123     Voice_element* velt_p = new Voice_element;
124     velt_p->defined_ch_c_l_ = defined_ch_c_l;
125
126     Rest_req * rest_req_p = new Rest_req;
127     rest_req_p->plet_factor = lexer->prefs.plet_mom();
128     rest_req_p->balltype = duration[0];
129     rest_req_p->dots = duration[1];    
130     rest_req_p->print();
131     rest_req_p->defined_ch_c_l_ = defined_ch_c_l;
132
133     velt_p->add(rest_req_p);
134
135     return velt_p;
136 }
137
138 void
139 Lexer_prefs::get_default_duration(int *p)
140 {
141     *p++ = default_duration;
142     *p = default_dots;
143 }
144
145 void
146 Lexer_prefs::set_default_duration(int *p)
147 {
148      default_duration = *p++;
149      default_dots = *p++;
150 }
151
152 Request*
153 get_plet_request( char c, int dur_i, int type_i )
154 {
155     Plet_req* plet_req_p = new Plet_req;
156     plet_req_p->dur_i_ = dur_i;
157     plet_req_p->type_i_ = type_i;
158     plet_req_p->type_c_ = c;
159     return plet_req_p;
160 }
161
162 Request*
163 get_request(char c)
164 {
165     Request* req_p=0;
166     switch (c) {
167     case '|':
168         req_p = new Barcheck_req;
169         break;
170
171     case '[':
172     case ']':
173     {
174         Beam_req*b = new Beam_req;
175         int p_i=lexer->prefs.default_plet_type ;
176         if (p_i!= 1)
177             b->nplet = p_i;
178         req_p = b;
179     }
180         break;
181
182
183     case ')':
184     case '(':
185         req_p = new Slur_req;
186         break;
187     default:
188         assert(false);
189         break;
190     }
191     
192     switch (c) {
193     case '(':
194     case '[':
195         req_p->span()->spantype = Span_req::START;
196         break;
197     case ')':
198     case ']':
199         req_p->span()->spantype = Span_req::STOP;
200         break;
201         
202     default:
203         break;
204     }
205
206     req_p->defined_ch_c_l_ = req_defined_ch_c_l;
207     return req_p;
208 }
209
210 void
211 add_requests(Voice_element *v, Array<Request*> &req)
212 {
213     for (int i = 0; i < req.size(); i++) {
214         v->add(req[i]);
215     }
216     req.set_size(0);
217 }
218
219 Script_def*
220 get_scriptdef(char c)
221 {
222     String s;
223     switch (c) {
224     case '^' : s = "marcato";
225         break;
226     case  '+' : s = "stopped";
227         break;
228     case '-' : s = "tenuto";
229         break;
230     case  '|':  s = "staccatissimo";
231         break;
232     case  'o' : s = "";
233         break;
234     case '>' : s = "accent";
235         break;
236     case  'v' : s = ""; 
237         break;
238     case  '.' : s = "staccato";
239         break;
240     }
241     return lexer->lookup_identifier(s)->script(1);
242 }
243
244 Request*
245 get_script_req(int d , Script_def*def)
246 {
247     Script_req* script_req_p = new Script_req(d, def);
248     return script_req_p;
249 }
250
251 Request*
252 get_text_req(int d , Text_def*def)
253 {
254     Text_req* text_req_p = new Text_req(d, def);
255     return text_req_p;
256 }
257
258 Request*
259 get_stemdir_req(int d)
260 {
261     Group_feature_req * gfreq_p = new Group_feature_req;
262     gfreq_p->stemdir_i_ =d; 
263     return gfreq_p;
264 }
265
266 Request*
267 get_grouping_req(Array<int> i_arr)
268 {
269     Measure_grouping_req * mr_p = new Measure_grouping_req;
270     for (int i=0; i <i_arr.size(); ) {
271         mr_p->beat_i_arr_.push(i_arr[i++]);
272         mr_p->elt_length_arr_.push(Moment(1, i_arr[i++]));
273     }
274     return mr_p;
275 }