class MovieMasher::Layer

base for all layers

Public Class Methods

new(input, job_input) click to toggle source
# File lib/graph.rb, line 132
def initialize(input, job_input)
  @input = input
  @job_input = job_input # will be different than input if we're in a mash
  raise('no input') unless input
  @range = input[:range]
  @chains = []
  initialize_chains
end

Public Instance Methods

initialize_chains() click to toggle source
# File lib/graph.rb, line 140
def initialize_chains
  if @input[:merger]
    @input[:merger][:dimensions] ||= @input[:dimensions]
    @merger_chain =
      if 'com.moviemasher.merger.blend' == @input[:merger][:id]
        ChainBlend.new(@input[:merger], @job_input, @input)
      else
        ChainModule.new(@input[:merger], @job_input, @input)
      end
  else
    @merger_chain = ChainOverlay.new(@job_input)
  end
  if @input[:scaler]
    @input[:scaler][:dimensions] ||= @input[:dimensions]
    @scaler_chain = ChainModule.new(@input[:scaler], @job_input, @input)
  else
    @scaler_chain = ChainScaler.new(@input, @job_input)
  end
  @effects_chain = ChainEffects.new(@input, @job_input)
  @chains << @scaler_chain
  @chains << @effects_chain
end
inputs() click to toggle source
# File lib/graph.rb, line 162
def inputs
  []
end
layer_command(scope) click to toggle source
# File lib/graph.rb, line 165
def layer_command(scope)
  layer_scope(scope)
  __join_commands(@chains.map { |chain| chain.chain_command(scope) })
end
layer_scope(scope) click to toggle source
# File lib/graph.rb, line 169
def layer_scope(scope)
  __raise_unless(@input[:length], "no input length #{@input}")
  scope[:mm_duration] = @input[:length]
  scope[:mm_t] = "(t/#{scope[:mm_duration]})"
  if @input[:dimensions]
    scope[:overlay_w], scope[:overlay_h] = @input[:dimensions].split('x')
  end
end
merger_command(scope, label, i) click to toggle source
# File lib/graph.rb, line 177
def merger_command(scope, label, i)
  merge_cmd = @merger_chain.chain_command(scope)
  __raise_if_empty(merge_cmd, "merger produced nothing #{self}")
  "#{@merger_chain.chain_labels(label, i)}#{merge_cmd}"
end
range() click to toggle source
# File lib/graph.rb, line 182
def range
  (@input ? @input[:range] : nil)
end
trim_command(render_range) click to toggle source
# File lib/graph.rb, line 185
def trim_command(render_range)
  input_range = range
  # puts "command_range_trim #{input_range}"
  cmd = ''
  if render_range && input_range && !input_range.equals?(render_range)
    range_start = render_range.start_seconds
    range_end = render_range.end_seconds
    input_start = input_range.start_seconds
    input_end = input_range.end_seconds
    if range_start > input_start || range_end < input_end
      dur = __coerce_if_numeric(render_range.length_seconds)
      cmd += ",trim=duration=#{dur}"
      if range_start > input_start
        start = FloatUtil.precision(range_start - input_start)
        start = __coerce_if_numeric(start)
        cmd += ":start=#{start}"
      end
      cmd += ',setpts=expr=PTS-STARTPTS'
    end
  end
  cmd
end