lib/import/flame_stabilizer.rb in tracksperanto-2.6.1 vs lib/import/flame_stabilizer.rb in tracksperanto-2.6.2
- old
+ new
@@ -21,12 +21,10 @@
raise "A channel was nil" if channels.find{|e| e.nil? }
report_progress("Assembling tracker curves from channels")
scavenge_trackers_from_channels(channels, names) {|t| yield(t) }
- ensure
- channels.clear
end
private
def extract_width_and_height_from_stream(io)
w, h = nil, nil
@@ -44,32 +42,35 @@
return [w, h] if (w && h)
end
end
-
+
+ # We subclass the standard parser for a couple of reasons - we want to only parse the needed channels
+ # AND we want to provide progress reports
+ class StabilizerParser < FlameChannelParser::Parser
+ USEFUL_CHANNELS = %w( /shift/x /shift/y /ref/x /ref/y ).map(&Regexp.method(:new))
+
+ # This method tells the importer whether a channel that has been found in the source
+ # setup is needed. If that method returns ++false++ the channel will be discarded and not
+ # kept in memory. Should you need to write a module that scavenges other Flame animation channels
+ # inherit from this class and rewrite this method to either return +true+ always (then all the channels
+ # will be recovered) or to return +true+ only for channels that you actually need.
+ def channel_is_useful?(channel_name)
+ USEFUL_CHANNELS.any?{|e| channel_name =~ e }
+ end
+ end
+
def extract_channels_from_stream(io)
- channels = FlameChannelParser.parse(io)
+ parser = StabilizerParser.new(&method(:report_progress))
+ channels = parser.parse(io)
[channels, channels.map{|c| c.path }]
end
- USEFUL_CHANNELS = %w( /shift/x /shift/y /ref/x /ref/y ).map(&Regexp.method(:new))
-
- # This method tells the importer whether a channel that has been found in the source
- # setup is needed. If that method returns ++false++ the channel will be discarded and not
- # kept in memory. Should you need to write a module that scavenges other Flame animation channels
- # inherit from this class and rewrite this method to either return +true+ always (then all the channels
- # will be recovered) or to return +true+ only for channels that you actually need.
- def channel_is_useful?(channel_name)
- USEFUL_CHANNELS.any?{|e| channel_name =~ e }
- end
-
- REF_CHANNEL = "ref" # or "track" - sometimes works sometimes don't
-
def scavenge_trackers_from_channels(channels, names)
channels.each do |c|
- next unless c.name =~ /\/#{REF_CHANNEL}\/x/
+ next unless c.name =~ /\/ref\/x/
report_progress("Detected reference channel #{c.name}")
t = grab_tracker(channels, c, names)
yield(t) if t
@@ -85,10 +86,10 @@
report_progress("Extracting tracker #{t.name}")
# This takes a LONG time when we have alot of channels, we need a precache of
# some sort to do this
- ref_idx = names.index("#{t.name}/#{REF_CHANNEL}/y")
+ ref_idx = names.index("#{t.name}/ref/y")
shift_x_idx = names.index("#{t.name}/shift/x")
shift_y_idx = names.index("#{t.name}/shift/y")
track_y = channels[ref_idx]
shift_x = channels[shift_x_idx]
\ No newline at end of file