lilypond-0.0.4
[lilypond.git] / note.cc
blobc51e3c33af8fa767164c51a388d1c31372d9e684
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"
9 int default_duration = 4;
11 void
12 parse_duration(const char *a, int &j, int &intdur, int &dots)
14 String durstr;
15 while (isdigit(a[j]))
17 durstr += a[j++];
20 dots=0;
22 while (a[j] == '.')
24 j++;
25 dots++;
27 intdur = (durstr.len()) ?
28 durstr.value():default_duration;
31 mtor << "dur " << intdur << "dots " << dots<<eol;
35 void
36 parse_pitch( const char *a, int &j, int &oct, bool & overide_acc,
37 int & large, int & small)
39 // octave
40 oct =0;
42 while (1)
44 if (a[j] == '\'')
45 oct ++;
46 else if (a[j] == '`')
47 oct --;
48 else
49 break;
50 j++;
54 mtor << "oct " << oct;
56 // accidental
57 overide_acc = false;
59 if (a[j] == '!')
61 overide_acc = true;
62 j++;
66 mtor << "ov " << overide_acc;
68 // notename.
69 String nm;
70 while (isalpha(a[j]))
72 nm += a[j++];
74 if (isupper(nm[0]))
76 oct--;
77 nm.lower();
81 lookup_notename(large,small,nm);
82 mtor << "int "<< large <<" "<<small<<" ";
86 Voice_element *
87 get_note_element(String pitch, String durstr)
89 Voice_element*v = new Voice_element;
90 int i=0;
92 int dur, dots;
93 parse_duration(durstr, i, dur, dots);
94 i=0;
96 Note_req * rq = new Note_req( v);
98 int oct, pit, acc;
99 bool forceacc;
100 parse_pitch(pitch, i, oct, forceacc, pit, acc);
102 rq->octave = oct;
103 rq->accidental = acc;
104 rq->forceacc = forceacc;
105 rq->balltype = dur;
106 rq->dots = dots;
109 v->add(rq);
110 return v;
113 Voice_element *
114 get_rest_element(String type, String durstr)
116 Voice_element*v = new Voice_element;
117 int i=0;
119 int dur, dots;
120 parse_duration(durstr, i, dur, dots);
121 i=0;
123 Rest_req * rq = new Rest_req(v);
125 rq->balltype = dur;
126 rq->dots = dots;
128 v->add(rq);
129 return v;