]> git.donarmstrong.com Git - lilypond.git/blob - note.cc
release: 0.0.8
[lilypond.git] / note.cc
1 #include <ctype.h>
2 #include "string.hh"
3 #include "real.hh"
4 #include "debug.hh"
5 #include "request.hh"
6 #include "voice.hh"
7 #include "notename.hh"
8
9 int default_duration = 4;
10
11 void
12 parse_duration(const char *a, int &j, int &intdur, int &dots)
13 {    
14     String durstr;    
15     while (isdigit(a[j])) 
16         {
17         durstr += a[j++];
18         }
19
20     dots=0;
21     
22     while (a[j] == '.') 
23         {
24         j++;
25         dots++;
26         }
27     intdur = (durstr.len()) ?
28         durstr.value():default_duration;
29
30
31     mtor << "dur " << intdur << "dots " << dots<<eol;
32 }
33
34
35
36 void 
37 parse_pitch( const char *a, int &j, int &oct, bool & overide_acc,
38              int & large, int & small)
39 {
40     // octave
41     oct =0;
42     
43     while (1) 
44         {       
45         if (a[j] == '\'')
46             oct ++;
47         else    if (a[j] == '`')
48             oct --;
49         else
50             break;
51         j++;
52         
53         }
54
55         mtor << "oct " << oct;
56         
57     // accidental
58     overide_acc = false;
59     
60     if (a[j] == '!')
61         {       
62         overide_acc = true;
63         j++;
64         }
65
66     
67     // notename.
68     String nm;
69     while (isalpha(a[j])) 
70         {
71         nm += a[j++];
72         }
73     if (isupper(nm[0]))
74         {
75         oct--;  
76         nm.lower();
77         }
78         
79
80     lookup_notename(large,small,nm);
81     mtor << "override: " << overide_acc;    
82     mtor << "pitch "<< large <<", "<<small<<"\n";    
83 }
84
85
86 Voice_element *
87 get_note_element(String pitch, String durstr)
88 {
89     Voice_element*v = new Voice_element;
90     int i=0;
91     
92     int dur, dots;
93     parse_duration(durstr, i, dur, dots);
94     i=0;
95
96     Note_req * rq = new Note_req( v);
97
98     if (dur >= 2) {
99         Stem_req * st = new Stem_req(v, dur);
100         v->add(st);
101     }
102     
103     int oct, pit, acc;
104     bool forceacc;
105     parse_pitch(pitch, i, oct, forceacc, pit, acc);
106     char nm =  pit + 'c';
107     if (nm > 'g')
108         nm += 'a' - 'h';
109     rq->name =nm;
110     
111     rq->octave = oct;
112     rq->accidental = acc;
113     rq->forceacc = forceacc;
114     rq->balltype = dur;
115     rq->dots = dots;
116     
117     rq->print();
118
119     v->add(rq);
120
121     return v;
122 }
123
124 Voice_element *
125 get_rest_element(String, String durstr)
126 {    
127     Voice_element*v = new Voice_element;
128     int i=0;
129     
130     int dur, dots;
131     parse_duration(durstr, i, dur, dots);
132     i=0;
133
134     Rest_req * rq = new Rest_req(v);
135   
136     rq->balltype = dur;
137     rq->dots = dots;    
138     rq->print();
139     v->add(rq);
140     return v;
141 }