fast_osc 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b61fec8aa9b7da4919beb24194add024e7fc96ed
4
- data.tar.gz: f3b8f4387da0d02161f4d173b60de999c9851948
3
+ metadata.gz: f284e9a9b81cb84245fbf2d9a1c7631fb670696d
4
+ data.tar.gz: 40f36cc032625bc34a9bd4811127fe0d1cae7c49
5
5
  SHA512:
6
- metadata.gz: d6f8997f138ca1d6a78c3d686cbd24fcd9b29638dae90d817becd9f2a97ced738eb2f33025c5f6a86a0ece2abad5794ffa640bb690a8d92a0850108f8c1fb7cf
7
- data.tar.gz: 58723176381c238b7591c82e1ff43f24ae4cb829311b862f03639236d16e47c65bbf914b26e1986ef494d45b799e88f688d680385dd761fb049ecf321ab61094
6
+ metadata.gz: 9ca15f55e91996ed3435a378985667afe7ffe31156d257873a2d26c68cc5eb295845d025b21339233a7068abc27fc19da2f5e7e1527eb9f54bff6c77d21e1fde
7
+ data.tar.gz: 3ae9debfc8cfc11bb415ffe052c7346e161bef20e3abd1add9466d174401ebd240fe2ca7deef3f649a7d8cb63169e24fc190865a396c198a404b454d7dcd3edb
data/README.md CHANGED
@@ -18,8 +18,6 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install fast_osc
20
20
 
21
- This will only work on a mac at the moment as that's what the `librtosc.a` was compiled on.
22
-
23
21
  ## Is it fast?
24
22
 
25
23
  Let's see...
@@ -74,10 +72,22 @@ I'll include a better test in the repo in time.
74
72
  => "#bundle\x00\x00\x00\x00\x00W*1\x7F\x00\x00\x00\x1C/foo\x00\x00\x00\x00,sif\x00\x00\x00\x00baz\x00\x00\x00\x00\x01@\x00\x00\x00"
75
73
  ```
76
74
 
75
+ See the test suite for additional methods regarding bundles with timestamps. Bundles are only supported with a single message at present. A timestamp of `nil` is a special case meaning "immediately".
76
+
77
+ ## Running the test suite
78
+
79
+ ```
80
+ $ gem install minitest # or bundle install
81
+ $ rake clean && rake clobber && rake compile && rake test
82
+ ```
83
+
77
84
  ## Still todo
78
85
 
79
86
  * Implement more types
80
- * add tests at the Ruby level (rtosc C code is already tested)
87
+ * Bring benchmarks into the repo
88
+ * Implement multi message/nested bundles
89
+ * Documentation
90
+ * Travis
81
91
 
82
92
  ## Development notes
83
93
 
data/Rakefile CHANGED
@@ -1,5 +1,14 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ require "rake/testtask"
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
11
+
3
12
  require 'rake/extensiontask'
4
13
  spec = Gem::Specification.load('fast_osc.gemspec')
5
14
  Rake::ExtensionTask.new('fast_osc') do |ext|
@@ -166,11 +166,36 @@ VALUE method_fast_osc_encode_single_message(VALUE self, VALUE address, VALUE arg
166
166
  return output;
167
167
  }
168
168
 
169
- VALUE method_fast_osc_encode_single_bundle(VALUE self, VALUE timestamp, VALUE address, VALUE args) {
169
+ #define JAN_1970 2208988800.0 /* 2208988800 time from 1900 to 1970 in seconds */
170
+
171
+ uint64_t ruby_time_to_osc_timetag(VALUE rubytime) {
172
+ uint64_t timetag;
173
+ double floattime;
174
+ uint32_t sec;
175
+ uint32_t frac;
176
+
177
+ switch(TYPE(rubytime)) {
178
+ case T_NIL:
179
+ timetag = 1;
180
+ break;
181
+ default:
182
+ // convert Time object to ntp
183
+ floattime = JAN_1970 + NUM2DBL(rb_funcall(rubytime, rb_intern("to_f"), 0));
184
+
185
+ sec = NUM2UINT(DBL2NUM(floattime));
186
+ frac = (int)(fmod(floattime, 1.0) * 4294967296); // * (2 ** 32)
187
+ timetag = (uint64_t)((uint64_t)sec << 32 | (uint64_t)frac);
188
+ break;
189
+ }
190
+
191
+ return timetag;
192
+ }
193
+
194
+ VALUE method_fast_osc_encode_single_bundle(VALUE self, VALUE timetag, VALUE address, VALUE args) {
170
195
  VALUE message = method_fast_osc_encode_single_message(self, address, args);
171
196
  int bufsize = buffer_size_for_ruby_string(message) + 16;
172
197
  int no_of_elems = 1;
173
- uint64_t tt = FIX2LONG(timestamp);
198
+ uint64_t tt = ruby_time_to_osc_timetag(timetag);
174
199
  char output_buffer[bufsize];
175
200
 
176
201
  int len = rtosc_bundle(output_buffer, bufsize, tt, no_of_elems, StringValuePtr(message));
data/fast_osc.gemspec CHANGED
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.5"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rake-compiler"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+ spec.add_development_dependency "osc-ruby", "~> 1.1.1"
26
28
  end
@@ -1,3 +1,3 @@
1
1
  module FastOsc
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,59 @@
1
+ require 'test_helper'
2
+ require 'osc-ruby'
3
+ require 'date'
4
+
5
+ class FastOscTest < Minitest::Test
6
+ def setup
7
+ @path = "/thisisatest"
8
+ @args = [1, 2.0, "baz"]
9
+ @timestamp = Date.parse("1st Jan 1990").to_time
10
+
11
+ @msg1 = OSC::Message.new(@path, *@args).encode
12
+ @encoded_msg1 = @msg1.encode
13
+ end
14
+
15
+ def test_that_it_has_a_version_number
16
+ refute_nil ::FastOsc::VERSION
17
+ end
18
+
19
+ def test_that_it_encodes_a_single_message
20
+ msg = FastOsc.encode_single_message(@path, @args)
21
+
22
+ assert msg == @encoded_msg1
23
+ end
24
+
25
+ def test_that_it_decodes_a_single_message
26
+ path, args = FastOsc.decode_single_message(@encoded_msg1)
27
+
28
+ assert path == @path
29
+ assert args == @args
30
+ end
31
+
32
+ def test_that_it_encodes_a_single_bundle
33
+ bundle1 = OSC::Bundle.new(@timestamp, @msg1).encode
34
+ bundle2 = FastOsc.encode_single_bundle(@timestamp, @path, @args)
35
+
36
+ assert_equal bundle1, bundle2
37
+ end
38
+
39
+ def test_that_it_encodes_a_single_bundle_with_fractional_time
40
+ bundle1 = OSC::Bundle.new(@timestamp + 0.33, @msg1).encode
41
+ bundle2 = FastOsc.encode_single_bundle(@timestamp + 0.33, @path, @args)
42
+
43
+ assert_equal bundle1, bundle2
44
+ end
45
+
46
+ def test_that_it_encodes_a_single_bundle_with_fractional_time
47
+ bundle1 = OSC::Bundle.new(@timestamp + 0.3343215, @msg1).encode
48
+ bundle2 = FastOsc.encode_single_bundle(@timestamp + 0.3343215, @path, @args)
49
+
50
+ assert_equal bundle1, bundle2
51
+ end
52
+
53
+ def test_that_it_encodes_a_single_bundle_with_special_immediate_time
54
+ bundle1 = OSC::Bundle.new(nil, @msg1).encode
55
+ bundle2 = FastOsc.encode_single_bundle(nil, @path, @args)
56
+
57
+ assert_equal bundle1, bundle2
58
+ end
59
+ end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'fast_osc'
3
+
4
+ require 'minitest/autorun'
5
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_osc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xavier Riley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-04 00:00:00.000000000 Z
11
+ date: 2016-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: osc-ruby
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.1.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.1.1
55
83
  description: Serialize and deserialize Open Sound Control messages using rtosc
56
84
  email:
57
85
  - xavriley@hotmail.com
@@ -72,6 +100,8 @@ files:
72
100
  - fast_osc.gemspec
73
101
  - lib/fast_osc.rb
74
102
  - lib/fast_osc/version.rb
103
+ - test/fast_osc_test.rb
104
+ - test/test_helper.rb
75
105
  homepage: https://github.com/xavriley/fast_osc
76
106
  licenses:
77
107
  - MIT
@@ -97,4 +127,6 @@ rubygems_version: 2.4.6
97
127
  signing_key:
98
128
  specification_version: 4
99
129
  summary: Serialize and deserialize Open Sound Control messages
100
- test_files: []
130
+ test_files:
131
+ - test/fast_osc_test.rb
132
+ - test/test_helper.rb