]> git.donarmstrong.com Git - lilypond.git/blob - note.cc
release: 0.0.6
[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 void 
36 parse_pitch( const char *a, int &j, int &oct, bool & overide_acc,
37              int & large, int & small)
38 {
39     // octave
40     oct =0;
41     
42     while (1) 
43         {       
44         if (a[j] == '\'')
45             oct ++;
46         else    if (a[j] == '`')
47             oct --;
48         else
49             break;
50         j++;
51         
52         }
53
54         mtor << "oct " << oct;
55         
56     // accidental
57     overide_acc = false;
58     
59     if (a[j] == '!')
60         {       
61         overide_acc = true;
62         j++;
63         }
64
65     
66     // notename.
67     String nm;
68     while (isalpha(a[j])) 
69         {
70         nm += a[j++];
71         }
72     if (isupper(nm[0]))
73         {
74         oct--;  
75         nm.lower();
76         }
77         
78
79     lookup_notename(large,small,nm);
80     mtor << "override: " << overide_acc;    
81     mtor << "pitch "<< large <<", "<<small<<"\n";    
82 }
83
84
85 Voice_element *
86 get_note_element(String pitch, String durstr)
87 {
88     Voice_element*v = new Voice_element;
89     int i=0;
90     
91     int dur, dots;
92     parse_duration(durstr, i, dur, dots);
93     i=0;
94
95     Note_req * rq = new Note_req( v);
96
97     int oct, pit, acc;
98     bool forceacc;
99     parse_pitch(pitch, i, oct, forceacc, pit, acc);
100     char nm =  pit + 'c';
101     if (nm > 'g')
102         nm += 'a' - 'h';
103     rq->name =nm;
104     
105     rq->octave = oct;
106     rq->accidental = acc;
107     rq->forceacc = forceacc;
108     rq->balltype = dur;
109     rq->dots = dots;
110     
111     rq->print();
112
113     v->add(rq);
114     return v;
115 }
116
117 Voice_element *
118 get_rest_element(String, String durstr)
119 {    
120     Voice_element*v = new Voice_element;
121     int i=0;
122     
123     int dur, dots;
124     parse_duration(durstr, i, dur, dots);
125     i=0;
126
127     Rest_req * rq = new Rest_req(v);
128   
129     rq->balltype = dur;
130     rq->dots = dots;    
131     rq->print();
132     v->add(rq);
133     return v;
134 }