lib/music-transcription/parsing/meter_parsing.rb in music-transcription-0.11.0 vs lib/music-transcription/parsing/meter_parsing.rb in music-transcription-0.13.0

- old
+ new

@@ -12,32 +12,64 @@ @root ||= :meter end include PositiveInteger - module Meter0 + def _nt_meter + start_index = index + if node_cache[:meter].has_key?(index) + cached = node_cache[:meter][index] + if cached + node_cache[:meter][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true + @index = cached.interval.end + end + return cached + end + + i0 = index + r1 = _nt_meter1 + if r1 + r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true + r0 = r1 + else + r2 = _nt_meter2 + if r2 + r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true + r0 = r2 + else + @index = i0 + r0 = nil + end + end + + node_cache[:meter][start_index] = r0 + + r0 + end + + module Meter10 def bpm elements[0] end def bd elements[2] end end - module Meter1 + module Meter11 def to_meter Music::Transcription::Meter.new(bpm.to_i, Rational(1,bd.to_i)) end end - def _nt_meter + def _nt_meter1 start_index = index - if node_cache[:meter].has_key?(index) - cached = node_cache[:meter][index] + if node_cache[:meter1].has_key?(index) + cached = node_cache[:meter1][index] if cached - node_cache[:meter][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true + node_cache[:meter1][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true @index = cached.interval.end end return cached end @@ -58,17 +90,93 @@ s0 << r3 end end if s0.last r0 = instantiate_node(SyntaxNode,input, i0...index, s0) - r0.extend(Meter0) - r0.extend(Meter1) + r0.extend(Meter10) + r0.extend(Meter11) else @index = i0 r0 = nil end - node_cache[:meter][start_index] = r0 + node_cache[:meter1][start_index] = r0 + + r0 + end + + module Meter20 + def bpm + elements[0] + end + + def num + elements[2] + end + + def den + elements[4] + end + end + + module Meter21 + def to_meter + Music::Transcription::Meter.new(bpm.to_i, Rational(num.to_i,den.to_i)) + end + end + + def _nt_meter2 + start_index = index + if node_cache[:meter2].has_key?(index) + cached = node_cache[:meter2][index] + if cached + node_cache[:meter2][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true + @index = cached.interval.end + end + return cached + end + + i0, s0 = index, [] + r1 = _nt_positive_integer + s0 << r1 + if r1 + if (match_len = has_terminal?("*", false, index)) + r2 = true + @index += match_len + else + terminal_parse_failure("*") + r2 = nil + end + s0 << r2 + if r2 + r3 = _nt_positive_integer + s0 << r3 + if r3 + if (match_len = has_terminal?("/", false, index)) + r4 = true + @index += match_len + else + terminal_parse_failure("/") + r4 = nil + end + s0 << r4 + if r4 + r5 = _nt_positive_integer + s0 << r5 + end + end + end + end + if s0.last + r0 = instantiate_node(SyntaxNode,input, i0...index, s0) + r0.extend(Meter20) + r0.extend(Meter21) + else + @index = i0 + r0 = nil + end + + node_cache[:meter2][start_index] = r0 r0 end end \ No newline at end of file