flame_timewarp_extractor 0.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +8 -0
- data/Manifest.txt +1 -1
- data/{README.txt → README.rdoc} +1 -2
- data/Rakefile +2 -1
- data/bin/flametwextract +0 -1
- data/lib/flame_timewarp_extractor.rb +19 -63
- data/test/test_twextract.rb +38 -11
- metadata +14 -15
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/{README.txt → README.rdoc}
RENAMED
data/Rakefile
CHANGED
@@ -4,8 +4,9 @@ require 'rubygems'
|
|
4
4
|
require 'hoe'
|
5
5
|
|
6
6
|
Hoe.spec 'flame_timewarp_extractor' do | s |
|
7
|
+
s.readme_file = 'README.rdoc'
|
7
8
|
s.developer('Julik', 'me@julik.nl')
|
8
|
-
s.extra_deps = {"
|
9
|
+
s.extra_deps = {"flame_channel_parser" => ">=1.1.1"}
|
9
10
|
end
|
10
11
|
|
11
12
|
# vim: syntax=ruby
|
data/bin/flametwextract
CHANGED
@@ -1,79 +1,35 @@
|
|
1
1
|
require "rubygems"
|
2
|
-
require "
|
2
|
+
require "flame_channel_parser"
|
3
3
|
|
4
4
|
class FlameTimewarpExtractor
|
5
5
|
|
6
|
-
VERSION = "
|
7
|
-
|
8
|
-
class Output
|
9
|
-
def initialize(io, first_f, last_f)
|
10
|
-
@io, @first, @last = io, first_f, last_f
|
11
|
-
end
|
12
|
-
attr_reader :output_header, :output_tail
|
13
|
-
def write_kf(to_f, from_f)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Import < Tracksperanto::Import::FlameStabilizer
|
18
|
-
def initialize
|
19
|
-
@progress_block = nil
|
20
|
-
end
|
21
|
-
|
22
|
-
def channel_is_useful?(name)
|
23
|
-
true
|
24
|
-
end
|
25
|
-
|
26
|
-
def extract_channels(from_io)
|
27
|
-
extract_channels_from_stream(from_io)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class OutputChan < Output
|
32
|
-
def write_kf(to_f, from_f)
|
33
|
-
@io.puts("%d\t%.5f" % [to_f, from_f])
|
34
|
-
end
|
35
|
-
end
|
6
|
+
VERSION = "1.1.0"
|
36
7
|
|
37
8
|
CHANNELS = %( Timing/Timing Frame )
|
38
9
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
10
|
+
# Pass the path to the Kronos or Timewarp setup here and you will get the timewarp curve on STDOUT
|
11
|
+
def extract(path, to_io = $stdout)
|
12
|
+
File.open(path) do | f |
|
13
|
+
channels = FlameChannelParser.parse(f)
|
14
|
+
|
15
|
+
timing_channel = channels.find{|c| CHANNELS.include?(c.name) }
|
16
|
+
raise "No timing channel found in this setup" unless timing_channel
|
17
|
+
|
18
|
+
write_channel(timing_channel, to_io)
|
19
|
+
end
|
46
20
|
end
|
47
21
|
|
48
22
|
private
|
49
23
|
|
50
|
-
def write_channel(
|
24
|
+
def write_channel(channel, to_io)
|
25
|
+
interpolator = FlameChannelParser::Interpolator.new(channel)
|
26
|
+
|
27
|
+
from_frame = interpolator.first_defined_frame
|
28
|
+
to_frame = interpolator.last_defined_frame
|
51
29
|
|
52
|
-
|
53
|
-
|
54
|
-
last_at, last_value = nil, nil
|
55
|
-
ch.each do | at, value |
|
56
|
-
last_at, last_value = lerp(last_at, last_value, at, value) do | interp_at, interp_value |
|
57
|
-
o.write_kf(interp_at, interp_value)
|
58
|
-
end
|
30
|
+
(from_frame..to_frame).each do | frame |
|
31
|
+
to_io.puts("%d\t%.5f" % [frame, interpolator.sample_at(frame)])
|
59
32
|
end
|
60
|
-
o.output_tail
|
61
33
|
end
|
62
34
|
|
63
|
-
# Do a simple linear interpolxion. The function will yield
|
64
|
-
# the interim X and Y, one tuple per whole value between the set points,
|
65
|
-
# and return the last tuple (so you can return-assign from it in a loop)
|
66
|
-
def lerp(last_x, last_y, x, y) #:yields: interp_x, interp_y
|
67
|
-
if last_x.nil?
|
68
|
-
yield(x, y)
|
69
|
-
else
|
70
|
-
gap_size = x - last_x
|
71
|
-
increment = (y.to_f - last_y) / gap_size.to_f
|
72
|
-
(1..gap_size).each do | index |
|
73
|
-
yield(last_x + index, last_y + (increment * index))
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
return [x, y]
|
78
|
-
end
|
79
35
|
end
|
data/test/test_twextract.rb
CHANGED
@@ -3,17 +3,44 @@ require "flame_timewarp_extractor"
|
|
3
3
|
require "stringio"
|
4
4
|
|
5
5
|
class TestTwextract < Test::Unit::TestCase
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
def test_parse_with_basic_baked_setup
|
7
|
+
io = StringIO.new
|
8
|
+
FlameTimewarpExtractor.new.extract(File.dirname(__FILE__) + "/samples/TW_015_010_v01_Baked.timewarp", io)
|
9
|
+
|
10
|
+
compare_outputs(File.read(File.dirname(__FILE__) + "/samples/output.txt"), io.string)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_parse_with_interpolated_setup
|
14
|
+
interpolated_io = StringIO.new
|
15
|
+
baked_io = StringIO.new
|
16
|
+
|
17
|
+
FlameTimewarpExtractor.new.extract(File.dirname(__FILE__) + "/samples/TW_016_010_v01.timewarp", interpolated_io)
|
18
|
+
FlameTimewarpExtractor.new.extract(File.dirname(__FILE__) + "/samples/TW_016_010_v01_Baked.timewarp", baked_io)
|
15
19
|
|
16
|
-
|
17
|
-
|
20
|
+
compare_outputs(baked_io.string, interpolated_io.string)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
D = 0.1
|
25
|
+
|
26
|
+
def compare_outputs(ref, out)
|
27
|
+
ref = ref.split("\n")
|
28
|
+
out = out.split("\n")
|
29
|
+
|
30
|
+
puts ref
|
31
|
+
puts out
|
32
|
+
|
33
|
+
ref.zip(out).each_with_index do | (reference_line, output_line), lineno |
|
34
|
+
assert_not_nil output_line, "at #{lineno} the output should not be shorter than the reference"
|
35
|
+
assert_not_nil reference_line, "at #{lineno} the output should not be longer than the reference"
|
36
|
+
|
37
|
+
from_f, from_d = reference_line.strip.split
|
38
|
+
to_f, to_d = output_line.strip.split
|
39
|
+
|
40
|
+
assert_equal from_f, to_f, "at #{lineno} the line should have the same frame"
|
41
|
+
|
42
|
+
assert_in_delta from_d.to_f, to_d.to_f, D, "At frame #{to_f}"
|
43
|
+
end
|
18
44
|
end
|
45
|
+
|
19
46
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flame_timewarp_extractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
7
9
|
- 0
|
8
|
-
|
9
|
-
- 2
|
10
|
-
version: 0.0.2
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Julik
|
@@ -15,23 +15,23 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-05-17 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: flame_channel_parser
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 17
|
30
30
|
segments:
|
31
31
|
- 1
|
32
|
-
-
|
33
|
-
-
|
34
|
-
version: 1.
|
32
|
+
- 1
|
33
|
+
- 1
|
34
|
+
version: 1.1.1
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
version: 2.9.1
|
51
51
|
type: :development
|
52
52
|
version_requirements: *id002
|
53
|
-
description: Extract timewarp channels from Flame setup files
|
53
|
+
description: Extract timewarp channels from Flame setup files into a simple list of "to-frame" to "from-frame" mappings.
|
54
54
|
email:
|
55
55
|
- me@julik.nl
|
56
56
|
executables:
|
@@ -60,11 +60,10 @@ extensions: []
|
|
60
60
|
extra_rdoc_files:
|
61
61
|
- History.txt
|
62
62
|
- Manifest.txt
|
63
|
-
- README.txt
|
64
63
|
files:
|
65
64
|
- History.txt
|
66
65
|
- Manifest.txt
|
67
|
-
- README.
|
66
|
+
- README.rdoc
|
68
67
|
- Rakefile
|
69
68
|
- bin/flametwextract
|
70
69
|
- lib/flame_timewarp_extractor.rb
|
@@ -79,7 +78,7 @@ licenses: []
|
|
79
78
|
post_install_message:
|
80
79
|
rdoc_options:
|
81
80
|
- --main
|
82
|
-
- README.
|
81
|
+
- README.rdoc
|
83
82
|
require_paths:
|
84
83
|
- lib
|
85
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -106,6 +105,6 @@ rubyforge_project: flame_timewarp_extractor
|
|
106
105
|
rubygems_version: 1.4.1
|
107
106
|
signing_key:
|
108
107
|
specification_version: 3
|
109
|
-
summary: Extract timewarp channels from Flame setup files
|
108
|
+
summary: Extract timewarp channels from Flame setup files into a simple list of "to-frame" to "from-frame" mappings.
|
110
109
|
test_files:
|
111
110
|
- test/test_twextract.rb
|