summaryrefslogtreecommitdiff
path: root/src/note.cc
blob: 0041bb723879d68c5bdb9d793b18cf40b901cc1d (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#include <ctype.h>

#include "string.hh"
#include "real.hh"
#include "debug.hh"
#include "request.hh"
#include "voice.hh"
#include "notename.hh"
#include "vray.hh"

int default_duration = 4, default_dots=0, default_octave=0;

void
parse_duration(const char *a, int &j, int &intdur, int &dots)
{    
    String durstr;    
    while (isdigit(a[j])) 
	{
	durstr += a[j++];
	}

    dots=default_dots;
    
    while (a[j] == '.') 
	{
	j++;
	dots++;
	}
    
    intdur = (durstr.len()) ?
	durstr.value():default_duration;

    mtor << "dur " << intdur << "dots " << dots<<eol;
}



void 
parse_pitch( const char *a, int &j, int &oct, bool & overide_acc,
	     int & large, int & small)
{
    // octave
    oct =default_octave;
    
    while (1) 
	{	
	if (a[j] == '\'')
	    oct ++;
	else if (a[j] == '`')
	    oct --;
	else
	    break;
	j++;
	
	}

	mtor << "oct " << oct;
	
    // accidental
    overide_acc = false;
    
    if (a[j] == '!')
	{	
	overide_acc = true;
	j++;
	}

    
    // notename.
    String nm;
    while (isalpha(a[j])) 
	{
	nm += a[j++];
	}
    if (isupper(nm[0]))
	{
	oct--;	
	nm.lower();
	}
        

    lookup_notename(large,small,nm);
    mtor << "override: " << overide_acc;    
    mtor << "pitch "<< large <<", "<<small<<"\n";    
}


Voice_element *
get_note_element(String pitch, String durstr)
{
    Voice_element*v = new Voice_element;
    int i=0;
    
    int dur, dots;
    parse_duration(durstr, i, dur, dots);
    i=0;

    Note_req * rq = new Note_req;

    if (dur >= 2) {
	Stem_req * st = new Stem_req(dur);
	v->add(st);
    }
    
    int oct, pit, acc;
    bool forceacc;
    parse_pitch(pitch, i, oct, forceacc, pit, acc);
    char nm =  pit + 'c';
    if (nm > 'g')
	nm += 'a' - 'h';
    rq->name =nm;
    
    rq->octave = oct;
    rq->accidental = acc;
    rq->forceacc = forceacc;
    rq->balltype = dur;
    rq->dots = dots;
    
    rq->print();

    v->add(rq);

    return v;
}

Voice_element *
get_rest_element(String, String durstr)
{    
    Voice_element*v = new Voice_element;
    int i=0;
    
    int dur, dots;
    parse_duration(durstr, i, dur, dots);
    i=0;

    Rest_req * rq = new Rest_req;
  
    rq->balltype = dur;
    rq->dots = dots;    
    rq->print();
    v->add(rq);

    return v;
}

void
set_default_duration(String d)
{
    int i=0;
    parse_duration(d, i, default_duration, default_dots);
}


void
set_default_pitch(String d)
{
    int i=0;
    bool b;
    int l,s;
    parse_pitch(d, i, default_octave, b, l,s);
}

Request*
get_request(char c)
{
    Request* ret=0;
    switch (c) {
    case '[':
    case ']':
	ret = new Beam_req;
	break;

    case ')':
    case '(':
	ret = new Slur_req;
	break;
    default:
	assert(false);
	break;
    }
    
    switch (c) {
    case '(':
    case '[':
	ret->span()->spantype = Span_req::START;
	break;
    case ')':
    case ']':
	ret->span()->spantype = Span_req::STOP;
	break;
    default:
	assert(false);
	break;
    }

    return ret;
}

void
add_requests(Voice_element *v, svec<Request*> &req)
{
    for (int i = 0; i < req.sz(); i++) {
	v->add(req[i]);
    }
    req.set_size(0);
}