Module: Castaway::Production::ClassMethods

Includes:
Times
Included in:
Castaway::Production
Defined in:
lib/castaway/production/class_methods.rb

Instance Method Summary collapse

Methods included from Times

#_parse_numeric_time, #_parse_time, #_parse_timespec_time

Instance Method Details

#finish(finish) ⇒ Object

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



110
111
112
# File 'lib/castaway/production/class_methods.rb', line 110

def finish(finish)
  scene(nil) { start finish }
end

#from_script(file) ⇒ Object

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.



137
138
139
140
141
142
143
144
145
# 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) ⇒ Object

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



96
97
98
# File 'lib/castaway/production/class_methods.rb', line 96

def output(path)
  @output_path = path
end

#output_pathObject

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.



72
73
74
# File 'lib/castaway/production/class_methods.rb', line 72

def output_path
  @output_path ||= 'build'
end

#pointer(path, options = {}) ⇒ Object

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.



123
124
125
126
# File 'lib/castaway/production/class_methods.rb', line 123

def pointer(path, options = {})
  id = options[:id] || :default
  pointers[id] = [path, options]
end

#pointersObject

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



130
131
132
# File 'lib/castaway/production/class_methods.rb', line 130

def pointers
  @pointers ||= {}
end

#resource(name) ⇒ Object

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`.

Raises:

  • (Errno::ENOENT)


85
86
87
88
89
90
91
92
# 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) ⇒ Object

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



78
79
80
# File 'lib/castaway/production/class_methods.rb', line 78

def resource_path(path)
  resource_paths << path
end

#resource_pathsObject

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.



65
66
67
# File 'lib/castaway/production/class_methods.rb', line 65

def resource_paths
  @resource_paths ||= %w( sounds images )
end

#scene(name, &block) ⇒ Object

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)



104
105
106
# File 'lib/castaway/production/class_methods.rb', line 104

def scene(name, &block)
  scenes << [name, block]
end

#scenesObject

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



10
11
12
# File 'lib/castaway/production/class_methods.rb', line 10

def scenes
  @scenes ||= []
end

#soundclip(id, value = nil, &block) ⇒ Object

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


35
36
37
38
39
40
41
# 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

#soundclipsObject

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



16
17
18
# File 'lib/castaway/production/class_methods.rb', line 16

def soundclips
  @soundclips ||= {}
end

#soundtrack(&block) ⇒ Object

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


54
55
56
57
58
59
60
# File 'lib/castaway/production/class_methods.rb', line 54

def soundtrack(&block)
  if block
    @soundtrack = block
  else
    @soundtrack
  end
end

#time(value) ⇒ Object

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



116
117
118
# File 'lib/castaway/production/class_methods.rb', line 116

def time(value)
  _parse_time(value)
end