Module: Music::Transcription::Parsing::Pitch

Includes:
NonnegativeInteger, Treetop::Runtime
Included in:
Link, Note, PitchParser
Defined in:
lib/music-transcription/parsing/pitch_parsing.rb

Defined Under Namespace

Modules: Cent0, Cent1, LetterA0, LetterB0, LetterC0, LetterD0, LetterE0, LetterF0, LetterG0, Octave0, Octave1, Pitch0

Instance Method Summary collapse

Methods included from NonnegativeInteger

#_nt_nonnegative_integer

Instance Method Details

#_nt_centObject



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
# File 'lib/music-transcription/parsing/pitch_parsing.rb', line 138

def _nt_cent
  start_index = index
  if node_cache[:cent].has_key?(index)
    cached = node_cache[:cent][index]
    if cached
      node_cache[:cent][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0, s0 = index, []
  if has_terminal?(@regexps[gr = '\A[+-]'] ||= Regexp.new(gr), :regexp, index)
    r1 = true
    @index += 1
  else
    terminal_parse_failure('[+-]')
    r1 = nil
  end
  s0 << r1
  if r1
    r2 = _nt_nonnegative_integer
    s0 << r2
  end
  if s0.last
    r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
    r0.extend(Cent0)
    r0.extend(Cent1)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:cent][start_index] = r0

  r0
end

#_nt_letter_aObject



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/music-transcription/parsing/pitch_parsing.rb', line 242

def _nt_letter_a
  start_index = index
  if node_cache[:letter_a].has_key?(index)
    cached = node_cache[:letter_a][index]
    if cached
      node_cache[:letter_a][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  if has_terminal?(@regexps[gr = '\A[Aa]'] ||= Regexp.new(gr), :regexp, index)
    r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
    r0.extend(LetterA0)
    @index += 1
  else
    terminal_parse_failure('[Aa]')
    r0 = nil
  end

  node_cache[:letter_a][start_index] = r0

  r0
end

#_nt_letter_bObject



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/music-transcription/parsing/pitch_parsing.rb', line 271

def _nt_letter_b
  start_index = index
  if node_cache[:letter_b].has_key?(index)
    cached = node_cache[:letter_b][index]
    if cached
      node_cache[:letter_b][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  if has_terminal?(@regexps[gr = '\A[Bb]'] ||= Regexp.new(gr), :regexp, index)
    r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
    r0.extend(LetterB0)
    @index += 1
  else
    terminal_parse_failure('[Bb]')
    r0 = nil
  end

  node_cache[:letter_b][start_index] = r0

  r0
end

#_nt_letter_cObject



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/music-transcription/parsing/pitch_parsing.rb', line 300

def _nt_letter_c
  start_index = index
  if node_cache[:letter_c].has_key?(index)
    cached = node_cache[:letter_c][index]
    if cached
      node_cache[:letter_c][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  if has_terminal?(@regexps[gr = '\A[Cc]'] ||= Regexp.new(gr), :regexp, index)
    r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
    r0.extend(LetterC0)
    @index += 1
  else
    terminal_parse_failure('[Cc]')
    r0 = nil
  end

  node_cache[:letter_c][start_index] = r0

  r0
end

#_nt_letter_dObject



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/music-transcription/parsing/pitch_parsing.rb', line 329

def _nt_letter_d
  start_index = index
  if node_cache[:letter_d].has_key?(index)
    cached = node_cache[:letter_d][index]
    if cached
      node_cache[:letter_d][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  if has_terminal?(@regexps[gr = '\A[Dd]'] ||= Regexp.new(gr), :regexp, index)
    r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
    r0.extend(LetterD0)
    @index += 1
  else
    terminal_parse_failure('[Dd]')
    r0 = nil
  end

  node_cache[:letter_d][start_index] = r0

  r0
end

#_nt_letter_eObject



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/music-transcription/parsing/pitch_parsing.rb', line 358

def _nt_letter_e
  start_index = index
  if node_cache[:letter_e].has_key?(index)
    cached = node_cache[:letter_e][index]
    if cached
      node_cache[:letter_e][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  if has_terminal?(@regexps[gr = '\A[Ee]'] ||= Regexp.new(gr), :regexp, index)
    r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
    r0.extend(LetterE0)
    @index += 1
  else
    terminal_parse_failure('[Ee]')
    r0 = nil
  end

  node_cache[:letter_e][start_index] = r0

  r0
end

#_nt_letter_fObject



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/music-transcription/parsing/pitch_parsing.rb', line 387

def _nt_letter_f
  start_index = index
  if node_cache[:letter_f].has_key?(index)
    cached = node_cache[:letter_f][index]
    if cached
      node_cache[:letter_f][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  if has_terminal?(@regexps[gr = '\A[Ff]'] ||= Regexp.new(gr), :regexp, index)
    r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
    r0.extend(LetterF0)
    @index += 1
  else
    terminal_parse_failure('[Ff]')
    r0 = nil
  end

  node_cache[:letter_f][start_index] = r0

  r0
end

#_nt_letter_gObject



416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
# File 'lib/music-transcription/parsing/pitch_parsing.rb', line 416

def _nt_letter_g
  start_index = index
  if node_cache[:letter_g].has_key?(index)
    cached = node_cache[:letter_g][index]
    if cached
      node_cache[:letter_g][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  if has_terminal?(@regexps[gr = '\A[Gg]'] ||= Regexp.new(gr), :regexp, index)
    r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
    r0.extend(LetterG0)
    @index += 1
  else
    terminal_parse_failure('[Gg]')
    r0 = nil
  end

  node_cache[:letter_g][start_index] = r0

  r0
end

#_nt_octaveObject



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
# File 'lib/music-transcription/parsing/pitch_parsing.rb', line 100

def _nt_octave
  start_index = index
  if node_cache[:octave].has_key?(index)
    cached = node_cache[:octave][index]
    if cached
      node_cache[:octave][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0, s0 = index, []
  r1 = _nt_nonnegative_integer
  s0 << r1
  if s0.last
    r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
    r0.extend(Octave0)
    r0.extend(Octave1)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:octave][start_index] = r0

  r0
end

#_nt_pitchObject



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
# File 'lib/music-transcription/parsing/pitch_parsing.rb', line 35

def _nt_pitch
  start_index = index
  if node_cache[:pitch].has_key?(index)
    cached = node_cache[:pitch][index]
    if cached
      node_cache[:pitch][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0, s0 = index, []
  r1 = _nt_pitch_letter
  s0 << r1
  if r1
    if has_terminal?(@regexps[gr = '\A[#b]'] ||= Regexp.new(gr), :regexp, index)
      r3 = true
      @index += 1
    else
      terminal_parse_failure('[#b]')
      r3 = nil
    end
    if r3
      r2 = r3
    else
      r2 = instantiate_node(SyntaxNode,input, index...index)
    end
    s0 << r2
    if r2
      r4 = _nt_octave
      s0 << r4
      if r4
        r6 = _nt_cent
        if r6
          r5 = r6
        else
          r5 = instantiate_node(SyntaxNode,input, index...index)
        end
        s0 << r5
      end
    end
  end
  if s0.last
    r0 = instantiate_node(PitchNode,input, i0...index, s0)
    r0.extend(Pitch0)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:pitch][start_index] = r0

  r0
end

#_nt_pitch_letterObject



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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/music-transcription/parsing/pitch_parsing.rb', line 176

def _nt_pitch_letter
  start_index = index
  if node_cache[:pitch_letter].has_key?(index)
    cached = node_cache[:pitch_letter][index]
    if cached
      node_cache[:pitch_letter][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0 = index
  r1 = _nt_letter_a
  if r1
    r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
    r0 = r1
  else
    r2 = _nt_letter_b
    if r2
      r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
      r0 = r2
    else
      r3 = _nt_letter_c
      if r3
        r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
        r0 = r3
      else
        r4 = _nt_letter_d
        if r4
          r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
          r0 = r4
        else
          r5 = _nt_letter_e
          if r5
            r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
            r0 = r5
          else
            r6 = _nt_letter_f
            if r6
              r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
              r0 = r6
            else
              r7 = _nt_letter_g
              if r7
                r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
                r0 = r7
              else
                @index = i0
                r0 = nil
              end
            end
          end
        end
      end
    end
  end

  node_cache[:pitch_letter][start_index] = r0

  r0
end

#rootObject



11
12
13
# File 'lib/music-transcription/parsing/pitch_parsing.rb', line 11

def root
  @root ||= :pitch
end