Class: EDL::TimewarpMatcher

Inherits:
Matcher
  • Object
show all
Defined in:
lib/edl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Matcher

#matches?

Constructor Details

#initialize(fps) ⇒ TimewarpMatcher

Returns a new instance of TimewarpMatcher.



210
211
212
213
# File 'lib/edl.rb', line 210

def initialize(fps)
  @fps = fps
  @regexp = /M2(\s+)(\w+)(\s+)(\-?\d+\.\d+)(\s+)(\d{1,2}):(\d{1,2}):(\d{1,2}):(\d{1,2})/
end

Instance Attribute Details

#fpsObject (readonly)

Returns the value of attribute fps.



208
209
210
# File 'lib/edl.rb', line 208

def fps
  @fps
end

Instance Method Details

#apply(stack, line) ⇒ Object



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/edl.rb', line 215

def apply(stack, line)
  matches = line.scan(@regexp).flatten.map(&:strip).reject { |e| e.nil? || e.empty? }

  from_reel = matches.shift
  fps = matches.shift

  begin
    # FIXME
    tw_start_source_tc = Parser.timecode_from_line_elements(matches, @fps)
  rescue Timecode::Error => e
    raise ApplyError.new("Invalid TC in timewarp (#{e})", line)
  end

  evt_with_tw = stack.reverse.find { |e| e.src_start_tc == tw_start_source_tc && e.reel == from_reel }

  if evt_with_tw
    tw = Timewarp.new
    tw.actual_framerate = fps.to_f
    tw.clip = evt_with_tw
    evt_with_tw.timewarp = tw
  else
    raise ApplyError.new('Cannot find event marked by timewarp', line)
  end
end