module Castaway::Production::ClassMethods

Public Instance Methods

finish(finish) click to toggle source

Declares the end-time of the production. If this is not set, your final scene will likely be truncated.

# File lib/castaway/production/class_methods.rb, line 110
def finish(finish)
  scene(nil) { start finish }
end
from_script(file) click to toggle source

Treats the given `file` as a Castaway script, and evaluates it in the context of a new, anonymous subclass of Castaway::Production. This new subclass is returned.

# File lib/castaway/production/class_methods.rb, line 137
def from_script(file)
  Class.new(self) do
    class_eval File.read(file), file
  end
rescue Exception => e
  puts "#{e.class} (#{e.message})"
  puts e.backtrace
  abort
end
output(path) click to toggle source

Declares the directory to be used for storing intermediate media, like frames and audio. (See output_path)

# File lib/castaway/production/class_methods.rb, line 96
def output(path)
  @output_path = path
end
output_path() click to toggle source

Returns the output path to be used for generated files, like frames and intermediate audio. It defaults to 'build'. See the output method for how to set this value.

# File lib/castaway/production/class_methods.rb, line 72
def output_path
  @output_path ||= 'build'
end
pointer(path, options = {}) click to toggle source

Declares a pointer using the image at the given `path`. If an `:id` option is given, it will be used to identify the pointer. Otherwise, it will use the default identifier. See Castaway::Scene.

# File lib/castaway/production/class_methods.rb, line 123
def pointer(path, options = {})
  id = options[:id] || :default
  pointers[id] = [path, options]
end
pointers() click to toggle source

Returns a Hash of pointer declarations, mapping ids to path/option data.

# File lib/castaway/production/class_methods.rb, line 130
def pointers
  @pointers ||= {}
end
resource(name) click to toggle source

Looks for a file with the given name in the defined resource paths (see resource_paths). Returns the path to the file if it is found in one of the paths, otherwise raises `Errno::ENOENT`.

# File lib/castaway/production/class_methods.rb, line 85
def resource(name)
  resource_paths.each do |path|
    full = File.join(path, name)
    return full if File.exist?(full)
  end

  raise Errno::ENOENT, "no such resource #{name} found"
end
resource_path(path) click to toggle source

Adds the given path to the list of paths that will be searched by Castaway for resources. (See resource_paths)

# File lib/castaway/production/class_methods.rb, line 78
def resource_path(path)
  resource_paths << path
end
resource_paths() click to toggle source

Returns a list of paths that will be searched for resources. By default, the searched paths are 'sounds' and 'images'. See the resource method for how to add paths to this list.

# File lib/castaway/production/class_methods.rb, line 65
def resource_paths
  @resource_paths ||= %w( sounds images )
end
scene(name, &block) click to toggle source

Declares a new scene with the given name. Although it is not required that all scenes have unique names, it is recommended. The given block is invoked, without arguments, when the scene is constructed. (See Castaway::Scene)

# File lib/castaway/production/class_methods.rb, line 104
def scene(name, &block)
  scenes << [name, block]
end
scenes() click to toggle source

Returns an Array of Castaway::Scene objects corresponding to the scenes that have been defined.

# File lib/castaway/production/class_methods.rb, line 10
def scenes
  @scenes ||= []
end
soundclip(id, value = nil, &block) click to toggle source

Declare a new soundclip with the given `id`. If a `value` is given, it is expected to be a path to a sound file. For example:

soundclip :narration, resource('narration.mp3')

If a block is given, it is expected to accept a single parameter (a Chaussettes::Clip instance), and configure the soundclip on that instance.

soundclip :theme do |clip|
  clip.in resource('theme.mp3')
  clip.chain.
    trim(0, 15).     # grab the first 15s of the clip
    fade(0.5, 0, 5)  # fade in 0.5s, and then out 5s at the end
end
# File lib/castaway/production/class_methods.rb, line 35
def soundclip(id, value = nil, &block)
  if value.nil? && !block
    soundclips[id]
  else
    soundclips[id] = value || block
  end
end
soundclips() click to toggle source

Returns a Hash, mapping ids to either direct values (path names), or blocks (which are intended to configure a soundclip).

# File lib/castaway/production/class_methods.rb, line 16
def soundclips
  @soundclips ||= {}
end
soundtrack(&block) click to toggle source

Declare the soundtrack for the production. Every production may have zero or one soundtracks. The block you provide here should accept a single parameter–a `Chausettes::Clip` instance–which must be populated with the desired audio for the production.

soundtrack do |clip|
  clip.in(
    duck(soundclip(:theme),
         clip: soundclip[:narration], at: 3)
  )
end
# File lib/castaway/production/class_methods.rb, line 54
def soundtrack(&block)
  if block
    @soundtrack = block
  else
    @soundtrack
  end
end
time(value) click to toggle source

Parses the given value into a float representing a number of seconds. See Castaway::Times.

# File lib/castaway/production/class_methods.rb, line 116
def time(value)
  _parse_time(value)
end