music-transcription 0.17.1 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/hip.rb +4 -4
- data/examples/missed_connection.rb +3 -3
- data/examples/song1.rb +6 -6
- data/examples/song2.rb +3 -3
- data/lib/music-transcription.rb +8 -2
- data/lib/music-transcription/model/change.rb +9 -3
- data/lib/music-transcription/model/measure_score.rb +62 -0
- data/lib/music-transcription/model/meter.rb +5 -1
- data/lib/music-transcription/model/note.rb +4 -1
- data/lib/music-transcription/model/note_score.rb +60 -0
- data/lib/music-transcription/model/part.rb +4 -1
- data/lib/music-transcription/model/program.rb +5 -2
- data/lib/music-transcription/model/tempo.rb +13 -23
- data/lib/music-transcription/packing/measure_score_packing.rb +34 -0
- data/lib/music-transcription/packing/{score_packing.rb → note_score_packing.rb} +12 -21
- data/lib/music-transcription/packing/part_packing.rb +1 -1
- data/lib/music-transcription/packing/program_packing.rb +1 -1
- data/lib/music-transcription/parsing/convenience_methods.rb +37 -58
- data/lib/music-transcription/parsing/numbers/nonnegative_float_parsing.rb +172 -59
- data/lib/music-transcription/parsing/numbers/nonnegative_float_parsing.treetop +13 -1
- data/lib/music-transcription/parsing/numbers/positive_float_parsing.rb +505 -0
- data/lib/music-transcription/parsing/numbers/positive_float_parsing.treetop +35 -0
- data/lib/music-transcription/parsing/numbers/positive_integer_parsing.rb +2 -0
- data/lib/music-transcription/parsing/numbers/positive_integer_parsing.treetop +2 -0
- data/lib/music-transcription/parsing/numbers/positive_rational_parsing.rb +86 -0
- data/lib/music-transcription/parsing/numbers/positive_rational_parsing.treetop +21 -0
- data/lib/music-transcription/parsing/parseable.rb +32 -0
- data/lib/music-transcription/parsing/tempo_parsing.rb +396 -0
- data/lib/music-transcription/parsing/tempo_parsing.treetop +49 -0
- data/lib/music-transcription/validatable.rb +5 -18
- data/lib/music-transcription/version.rb +1 -1
- data/spec/model/measure_score_spec.rb +85 -0
- data/spec/model/note_score_spec.rb +68 -0
- data/spec/model/tempo_spec.rb +15 -15
- data/spec/packing/{score_packing_spec.rb → measure_score_packing_spec.rb} +13 -7
- data/spec/packing/note_score_packing_spec.rb +100 -0
- data/spec/packing/part_packing_spec.rb +1 -1
- data/spec/parsing/convenience_methods_spec.rb +80 -81
- data/spec/parsing/numbers/nonnegative_float_spec.rb +19 -2
- data/spec/parsing/numbers/positive_float_spec.rb +28 -0
- data/spec/parsing/numbers/positive_integer_spec.rb +13 -2
- data/spec/parsing/numbers/positive_rational_spec.rb +28 -0
- data/spec/parsing/tempo_parsing_spec.rb +21 -0
- metadata +27 -8
- data/lib/music-transcription/model/score.rb +0 -68
- data/spec/model/score_spec.rb +0 -69
@@ -0,0 +1,505 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
module Music
|
5
|
+
module Transcription
|
6
|
+
module Parsing
|
7
|
+
|
8
|
+
module PositiveFloat
|
9
|
+
include Treetop::Runtime
|
10
|
+
|
11
|
+
def root
|
12
|
+
@root ||= :positive_float
|
13
|
+
end
|
14
|
+
|
15
|
+
module PositiveFloat0
|
16
|
+
def to_f
|
17
|
+
text_value.to_f
|
18
|
+
end
|
19
|
+
|
20
|
+
alias :to_num :to_f
|
21
|
+
end
|
22
|
+
|
23
|
+
def _nt_positive_float
|
24
|
+
start_index = index
|
25
|
+
if node_cache[:positive_float].has_key?(index)
|
26
|
+
cached = node_cache[:positive_float][index]
|
27
|
+
if cached
|
28
|
+
node_cache[:positive_float][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
29
|
+
@index = cached.interval.end
|
30
|
+
end
|
31
|
+
return cached
|
32
|
+
end
|
33
|
+
|
34
|
+
i0 = index
|
35
|
+
r1 = _nt_float1
|
36
|
+
if r1
|
37
|
+
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
38
|
+
r0 = r1
|
39
|
+
r0.extend(PositiveFloat0)
|
40
|
+
else
|
41
|
+
r2 = _nt_float2
|
42
|
+
if r2
|
43
|
+
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
44
|
+
r0 = r2
|
45
|
+
r0.extend(PositiveFloat0)
|
46
|
+
else
|
47
|
+
r3 = _nt_float3
|
48
|
+
if r3
|
49
|
+
r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
|
50
|
+
r0 = r3
|
51
|
+
r0.extend(PositiveFloat0)
|
52
|
+
else
|
53
|
+
@index = i0
|
54
|
+
r0 = nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
node_cache[:positive_float][start_index] = r0
|
60
|
+
|
61
|
+
r0
|
62
|
+
end
|
63
|
+
|
64
|
+
module Float10
|
65
|
+
def exponent
|
66
|
+
elements[3]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def _nt_float1
|
71
|
+
start_index = index
|
72
|
+
if node_cache[:float1].has_key?(index)
|
73
|
+
cached = node_cache[:float1][index]
|
74
|
+
if cached
|
75
|
+
node_cache[:float1][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
76
|
+
@index = cached.interval.end
|
77
|
+
end
|
78
|
+
return cached
|
79
|
+
end
|
80
|
+
|
81
|
+
i0, s0 = index, []
|
82
|
+
s1, i1 = [], index
|
83
|
+
loop do
|
84
|
+
if has_terminal?(@regexps[gr = '\A[0]'] ||= Regexp.new(gr), :regexp, index)
|
85
|
+
r2 = true
|
86
|
+
@index += 1
|
87
|
+
else
|
88
|
+
terminal_parse_failure('[0]')
|
89
|
+
r2 = nil
|
90
|
+
end
|
91
|
+
if r2
|
92
|
+
s1 << r2
|
93
|
+
else
|
94
|
+
break
|
95
|
+
end
|
96
|
+
end
|
97
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
98
|
+
s0 << r1
|
99
|
+
if r1
|
100
|
+
s3, i3 = [], index
|
101
|
+
loop do
|
102
|
+
if has_terminal?(@regexps[gr = '\A[1-9]'] ||= Regexp.new(gr), :regexp, index)
|
103
|
+
r4 = true
|
104
|
+
@index += 1
|
105
|
+
else
|
106
|
+
terminal_parse_failure('[1-9]')
|
107
|
+
r4 = nil
|
108
|
+
end
|
109
|
+
if r4
|
110
|
+
s3 << r4
|
111
|
+
else
|
112
|
+
break
|
113
|
+
end
|
114
|
+
end
|
115
|
+
if s3.empty?
|
116
|
+
@index = i3
|
117
|
+
r3 = nil
|
118
|
+
else
|
119
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
120
|
+
end
|
121
|
+
s0 << r3
|
122
|
+
if r3
|
123
|
+
s5, i5 = [], index
|
124
|
+
loop do
|
125
|
+
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
126
|
+
r6 = true
|
127
|
+
@index += 1
|
128
|
+
else
|
129
|
+
terminal_parse_failure('[0-9]')
|
130
|
+
r6 = nil
|
131
|
+
end
|
132
|
+
if r6
|
133
|
+
s5 << r6
|
134
|
+
else
|
135
|
+
break
|
136
|
+
end
|
137
|
+
end
|
138
|
+
r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
|
139
|
+
s0 << r5
|
140
|
+
if r5
|
141
|
+
r7 = _nt_exponent
|
142
|
+
s0 << r7
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
if s0.last
|
147
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
148
|
+
r0.extend(Float10)
|
149
|
+
else
|
150
|
+
@index = i0
|
151
|
+
r0 = nil
|
152
|
+
end
|
153
|
+
|
154
|
+
node_cache[:float1][start_index] = r0
|
155
|
+
|
156
|
+
r0
|
157
|
+
end
|
158
|
+
|
159
|
+
module Float20
|
160
|
+
end
|
161
|
+
|
162
|
+
def _nt_float2
|
163
|
+
start_index = index
|
164
|
+
if node_cache[:float2].has_key?(index)
|
165
|
+
cached = node_cache[:float2][index]
|
166
|
+
if cached
|
167
|
+
node_cache[:float2][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
168
|
+
@index = cached.interval.end
|
169
|
+
end
|
170
|
+
return cached
|
171
|
+
end
|
172
|
+
|
173
|
+
i0, s0 = index, []
|
174
|
+
s1, i1 = [], index
|
175
|
+
loop do
|
176
|
+
if has_terminal?(@regexps[gr = '\A[0]'] ||= Regexp.new(gr), :regexp, index)
|
177
|
+
r2 = true
|
178
|
+
@index += 1
|
179
|
+
else
|
180
|
+
terminal_parse_failure('[0]')
|
181
|
+
r2 = nil
|
182
|
+
end
|
183
|
+
if r2
|
184
|
+
s1 << r2
|
185
|
+
else
|
186
|
+
break
|
187
|
+
end
|
188
|
+
end
|
189
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
190
|
+
s0 << r1
|
191
|
+
if r1
|
192
|
+
s3, i3 = [], index
|
193
|
+
loop do
|
194
|
+
if has_terminal?(@regexps[gr = '\A[1-9]'] ||= Regexp.new(gr), :regexp, index)
|
195
|
+
r4 = true
|
196
|
+
@index += 1
|
197
|
+
else
|
198
|
+
terminal_parse_failure('[1-9]')
|
199
|
+
r4 = nil
|
200
|
+
end
|
201
|
+
if r4
|
202
|
+
s3 << r4
|
203
|
+
else
|
204
|
+
break
|
205
|
+
end
|
206
|
+
end
|
207
|
+
if s3.empty?
|
208
|
+
@index = i3
|
209
|
+
r3 = nil
|
210
|
+
else
|
211
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
212
|
+
end
|
213
|
+
s0 << r3
|
214
|
+
if r3
|
215
|
+
s5, i5 = [], index
|
216
|
+
loop do
|
217
|
+
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
218
|
+
r6 = true
|
219
|
+
@index += 1
|
220
|
+
else
|
221
|
+
terminal_parse_failure('[0-9]')
|
222
|
+
r6 = nil
|
223
|
+
end
|
224
|
+
if r6
|
225
|
+
s5 << r6
|
226
|
+
else
|
227
|
+
break
|
228
|
+
end
|
229
|
+
end
|
230
|
+
r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
|
231
|
+
s0 << r5
|
232
|
+
if r5
|
233
|
+
if has_terminal?(@regexps[gr = '\A[.]'] ||= Regexp.new(gr), :regexp, index)
|
234
|
+
r7 = true
|
235
|
+
@index += 1
|
236
|
+
else
|
237
|
+
terminal_parse_failure('[.]')
|
238
|
+
r7 = nil
|
239
|
+
end
|
240
|
+
s0 << r7
|
241
|
+
if r7
|
242
|
+
s8, i8 = [], index
|
243
|
+
loop do
|
244
|
+
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
245
|
+
r9 = true
|
246
|
+
@index += 1
|
247
|
+
else
|
248
|
+
terminal_parse_failure('[0-9]')
|
249
|
+
r9 = nil
|
250
|
+
end
|
251
|
+
if r9
|
252
|
+
s8 << r9
|
253
|
+
else
|
254
|
+
break
|
255
|
+
end
|
256
|
+
end
|
257
|
+
if s8.empty?
|
258
|
+
@index = i8
|
259
|
+
r8 = nil
|
260
|
+
else
|
261
|
+
r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
|
262
|
+
end
|
263
|
+
s0 << r8
|
264
|
+
if r8
|
265
|
+
r11 = _nt_exponent
|
266
|
+
if r11
|
267
|
+
r10 = r11
|
268
|
+
else
|
269
|
+
r10 = instantiate_node(SyntaxNode,input, index...index)
|
270
|
+
end
|
271
|
+
s0 << r10
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
if s0.last
|
278
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
279
|
+
r0.extend(Float20)
|
280
|
+
else
|
281
|
+
@index = i0
|
282
|
+
r0 = nil
|
283
|
+
end
|
284
|
+
|
285
|
+
node_cache[:float2][start_index] = r0
|
286
|
+
|
287
|
+
r0
|
288
|
+
end
|
289
|
+
|
290
|
+
module Float30
|
291
|
+
end
|
292
|
+
|
293
|
+
def _nt_float3
|
294
|
+
start_index = index
|
295
|
+
if node_cache[:float3].has_key?(index)
|
296
|
+
cached = node_cache[:float3][index]
|
297
|
+
if cached
|
298
|
+
node_cache[:float3][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
299
|
+
@index = cached.interval.end
|
300
|
+
end
|
301
|
+
return cached
|
302
|
+
end
|
303
|
+
|
304
|
+
i0, s0 = index, []
|
305
|
+
s1, i1 = [], index
|
306
|
+
loop do
|
307
|
+
if has_terminal?(@regexps[gr = '\A[0]'] ||= Regexp.new(gr), :regexp, index)
|
308
|
+
r2 = true
|
309
|
+
@index += 1
|
310
|
+
else
|
311
|
+
terminal_parse_failure('[0]')
|
312
|
+
r2 = nil
|
313
|
+
end
|
314
|
+
if r2
|
315
|
+
s1 << r2
|
316
|
+
else
|
317
|
+
break
|
318
|
+
end
|
319
|
+
end
|
320
|
+
if s1.empty?
|
321
|
+
@index = i1
|
322
|
+
r1 = nil
|
323
|
+
else
|
324
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
325
|
+
end
|
326
|
+
s0 << r1
|
327
|
+
if r1
|
328
|
+
if has_terminal?(@regexps[gr = '\A[.]'] ||= Regexp.new(gr), :regexp, index)
|
329
|
+
r3 = true
|
330
|
+
@index += 1
|
331
|
+
else
|
332
|
+
terminal_parse_failure('[.]')
|
333
|
+
r3 = nil
|
334
|
+
end
|
335
|
+
s0 << r3
|
336
|
+
if r3
|
337
|
+
s4, i4 = [], index
|
338
|
+
loop do
|
339
|
+
if has_terminal?(@regexps[gr = '\A[0]'] ||= Regexp.new(gr), :regexp, index)
|
340
|
+
r5 = true
|
341
|
+
@index += 1
|
342
|
+
else
|
343
|
+
terminal_parse_failure('[0]')
|
344
|
+
r5 = nil
|
345
|
+
end
|
346
|
+
if r5
|
347
|
+
s4 << r5
|
348
|
+
else
|
349
|
+
break
|
350
|
+
end
|
351
|
+
end
|
352
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
353
|
+
s0 << r4
|
354
|
+
if r4
|
355
|
+
s6, i6 = [], index
|
356
|
+
loop do
|
357
|
+
if has_terminal?(@regexps[gr = '\A[1-9]'] ||= Regexp.new(gr), :regexp, index)
|
358
|
+
r7 = true
|
359
|
+
@index += 1
|
360
|
+
else
|
361
|
+
terminal_parse_failure('[1-9]')
|
362
|
+
r7 = nil
|
363
|
+
end
|
364
|
+
if r7
|
365
|
+
s6 << r7
|
366
|
+
else
|
367
|
+
break
|
368
|
+
end
|
369
|
+
end
|
370
|
+
if s6.empty?
|
371
|
+
@index = i6
|
372
|
+
r6 = nil
|
373
|
+
else
|
374
|
+
r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
|
375
|
+
end
|
376
|
+
s0 << r6
|
377
|
+
if r6
|
378
|
+
s8, i8 = [], index
|
379
|
+
loop do
|
380
|
+
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
381
|
+
r9 = true
|
382
|
+
@index += 1
|
383
|
+
else
|
384
|
+
terminal_parse_failure('[0-9]')
|
385
|
+
r9 = nil
|
386
|
+
end
|
387
|
+
if r9
|
388
|
+
s8 << r9
|
389
|
+
else
|
390
|
+
break
|
391
|
+
end
|
392
|
+
end
|
393
|
+
r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
|
394
|
+
s0 << r8
|
395
|
+
if r8
|
396
|
+
r11 = _nt_exponent
|
397
|
+
if r11
|
398
|
+
r10 = r11
|
399
|
+
else
|
400
|
+
r10 = instantiate_node(SyntaxNode,input, index...index)
|
401
|
+
end
|
402
|
+
s0 << r10
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|
408
|
+
if s0.last
|
409
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
410
|
+
r0.extend(Float30)
|
411
|
+
else
|
412
|
+
@index = i0
|
413
|
+
r0 = nil
|
414
|
+
end
|
415
|
+
|
416
|
+
node_cache[:float3][start_index] = r0
|
417
|
+
|
418
|
+
r0
|
419
|
+
end
|
420
|
+
|
421
|
+
module Exponent0
|
422
|
+
end
|
423
|
+
|
424
|
+
def _nt_exponent
|
425
|
+
start_index = index
|
426
|
+
if node_cache[:exponent].has_key?(index)
|
427
|
+
cached = node_cache[:exponent][index]
|
428
|
+
if cached
|
429
|
+
node_cache[:exponent][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
430
|
+
@index = cached.interval.end
|
431
|
+
end
|
432
|
+
return cached
|
433
|
+
end
|
434
|
+
|
435
|
+
i0, s0 = index, []
|
436
|
+
if (match_len = has_terminal?("e", false, index))
|
437
|
+
r1 = true
|
438
|
+
@index += match_len
|
439
|
+
else
|
440
|
+
terminal_parse_failure("e")
|
441
|
+
r1 = nil
|
442
|
+
end
|
443
|
+
s0 << r1
|
444
|
+
if r1
|
445
|
+
if has_terminal?(@regexps[gr = '\A[+-]'] ||= Regexp.new(gr), :regexp, index)
|
446
|
+
r3 = true
|
447
|
+
@index += 1
|
448
|
+
else
|
449
|
+
terminal_parse_failure('[+-]')
|
450
|
+
r3 = nil
|
451
|
+
end
|
452
|
+
if r3
|
453
|
+
r2 = r3
|
454
|
+
else
|
455
|
+
r2 = instantiate_node(SyntaxNode,input, index...index)
|
456
|
+
end
|
457
|
+
s0 << r2
|
458
|
+
if r2
|
459
|
+
s4, i4 = [], index
|
460
|
+
loop do
|
461
|
+
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
462
|
+
r5 = true
|
463
|
+
@index += 1
|
464
|
+
else
|
465
|
+
terminal_parse_failure('[0-9]')
|
466
|
+
r5 = nil
|
467
|
+
end
|
468
|
+
if r5
|
469
|
+
s4 << r5
|
470
|
+
else
|
471
|
+
break
|
472
|
+
end
|
473
|
+
end
|
474
|
+
if s4.empty?
|
475
|
+
@index = i4
|
476
|
+
r4 = nil
|
477
|
+
else
|
478
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
479
|
+
end
|
480
|
+
s0 << r4
|
481
|
+
end
|
482
|
+
end
|
483
|
+
if s0.last
|
484
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
485
|
+
r0.extend(Exponent0)
|
486
|
+
else
|
487
|
+
@index = i0
|
488
|
+
r0 = nil
|
489
|
+
end
|
490
|
+
|
491
|
+
node_cache[:exponent][start_index] = r0
|
492
|
+
|
493
|
+
r0
|
494
|
+
end
|
495
|
+
|
496
|
+
end
|
497
|
+
|
498
|
+
class PositiveFloatParser < Treetop::Runtime::CompiledParser
|
499
|
+
include PositiveFloat
|
500
|
+
end
|
501
|
+
|
502
|
+
|
503
|
+
end
|
504
|
+
end
|
505
|
+
end
|