lib/tickly/curve.rb in tickly-2.1.4 vs lib/tickly/curve.rb in tickly-2.1.5

- old
+ new

@@ -20,32 +20,42 @@ raise InvalidCurveError, "Curve expression contained no values" unless curve_expression[2] # Nuke7 sometimes produces curves where the command is a string literal # within quotes, and it contains a trailing space cmd = curve_expression[1].to_s.strip - raise InvalidCurveError, "Curve expression should start with a 'curve' command" unless cmd == 'curve' + raise InvalidCurveError, "Curve expression should start with a 'curve' command" unless cmd =~ /^curve/ + # Compute the curve increment or decrement. It looks like a modifier: + # "curve+5" means we have to add 5 to every value on the curve + xformer = lambda { |v| v} # Identity + if cmd =~ /^(curve)([+-])([\d\.]+)$/ + operator = $2[0..1] # Ensure only one character gets through + modifier = $3.to_f + xformer = lambda{|v| v.send(operator, modifier) } + end - expand_curve(curve_expression) + expand_curve(curve_expression, &xformer) end # Returns each defined keyframe as a pair of a frame number and a value def each(&blk) @tuples.each(&blk) end private - def expand_curve(curve_expression) + def expand_curve(curve_expression, &post_lambda) # Replace the closing curly brace with a curly brace with space so that it gets caught by split atoms = curve_expression[2..-1] # remove the :c curly designator and the "curve" keyword @tuples = [] - # Nuke saves curves very efficiently. x(keyframe_number) means that an uninterrupted sequence of values will start, - # after which values follow. When the curve is interrupted in some way a new x(keyframe_number) will signifu that we - # skip to that specified keyframe and the curve continues from there, in gap size defined by the last fragment. - # That is, x1 1 x3 2 3 4 will place 2, 3 and 4 at 2-frame increments. + # Nuke saves curves very efficiently. x(keyframe_number) means that an + # uninterrupted sequence of values will start, after which values follow. + # When the curve is interrupted in some way a new x(keyframe_number) will + # signify that we skip to that specified keyframe and the curve continues + # from there, in gap size defined by the last fragment. That is, + # x1 1 x3 2 3 4 will place 2, 3 and 4 at 2-frame increments. # Thanks to Michael Lester for explaining this. last_processed_keyframe = 1 intraframe_gap_size = 1 while atom = atoms.shift if atom =~ SECTION_START @@ -53,10 +63,10 @@ if @tuples.any? last_captured_frame = @tuples[-1][0] intraframe_gap_size = last_processed_keyframe - last_captured_frame end elsif atom =~ KEYFRAME - @tuples << [last_processed_keyframe, $1.to_f] + @tuples << [last_processed_keyframe, yield($1.to_f)] last_processed_keyframe += intraframe_gap_size end end end end \ No newline at end of file