flower-1.0.2
[lilypond.git] / note.cc
blob538f26a28e62bdee35cda6c7f1950d1325b564b4
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;
30 if (debug_flags & DEBUGTOKEN)
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++;
53 if (debug_flags & DEBUGTOKEN) mtor << "oct " << oct;
55 // accidental
56 overide_acc = false;
58 if (a[j] == '!')
60 overide_acc = true;
61 j++;
64 if (debug_flags & DEBUGTOKEN)
65 mtor << "ov " << overide_acc;
67 // notename.
68 String nm;
69 while (isalpha(a[j]))
71 nm += a[j++];
73 if (isupper(nm[0]))
75 oct--;
76 nm.lower();
80 lookup_notename(large,small,nm);
81 if (debug_flags & DEBUGTOKEN)
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;