fast_osc 0.0.6 → 0.0.7

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: f284e9a9b81cb84245fbf2d9a1c7631fb670696d
4
- data.tar.gz: 40f36cc032625bc34a9bd4811127fe0d1cae7c49
3
+ metadata.gz: e928fde0a4bf601705f34f29aab9f788d2044cf9
4
+ data.tar.gz: 9ea87039d5da0efa5edb45e600ee985c5caee1df
5
5
  SHA512:
6
- metadata.gz: 9ca15f55e91996ed3435a378985667afe7ffe31156d257873a2d26c68cc5eb295845d025b21339233a7068abc27fc19da2f5e7e1527eb9f54bff6c77d21e1fde
7
- data.tar.gz: 3ae9debfc8cfc11bb415ffe052c7346e161bef20e3abd1add9466d174401ebd240fe2ca7deef3f649a7d8cb63169e24fc190865a396c198a404b454d7dcd3edb
6
+ metadata.gz: 44b41b3ccf0c5aa9d35c0b586bb2e4df93710ecf7ac58a5c747c29f669bf510ebc8cb1a5438fd687344133a0185931de0b9027e829f4c1d09ff9ae853fa04b75
7
+ data.tar.gz: c7556261e6f6ac3895f86b4c0f5cb190eddef9b7ff3d7dfbe7ba44acf773cc8707a1b8a5b5540d47d9f0ac79dc38d424fb3c9de846a3365c88c4df855812ab0e
@@ -11,8 +11,8 @@ VALUE FastOsc = Qnil;
11
11
  // implementing.
12
12
  void Init_fast_osc();
13
13
  VALUE method_fast_osc_decode_single_message(VALUE self, VALUE msg);
14
- VALUE method_fast_osc_encode_single_message(VALUE self, VALUE address, VALUE args);
15
- VALUE method_fast_osc_encode_single_bundle(VALUE self, VALUE timestamp, VALUE address, VALUE args);
14
+ VALUE method_fast_osc_encode_single_message(int argc, VALUE* argv, VALUE self);
15
+ VALUE method_fast_osc_encode_single_bundle(int argc, VALUE* argv, VALUE self);
16
16
 
17
17
  // Initial setup function, takes no arguments and returns nothing. Some API
18
18
  // notes:
@@ -29,8 +29,8 @@ VALUE method_fast_osc_encode_single_bundle(VALUE self, VALUE timestamp, VALUE ad
29
29
  void Init_fast_osc() {
30
30
  FastOsc = rb_define_module("FastOsc");
31
31
  rb_define_singleton_method(FastOsc, "decode_single_message", method_fast_osc_decode_single_message, 1);
32
- rb_define_singleton_method(FastOsc, "encode_single_message", method_fast_osc_encode_single_message, 2);
33
- rb_define_singleton_method(FastOsc, "encode_single_bundle", method_fast_osc_encode_single_bundle, 3);
32
+ rb_define_singleton_method(FastOsc, "encode_single_message", method_fast_osc_encode_single_message, -1);
33
+ rb_define_singleton_method(FastOsc, "encode_single_bundle", method_fast_osc_encode_single_bundle, -1);
34
34
  }
35
35
 
36
36
  const char *rtosc_path(const char *msg)
@@ -95,10 +95,24 @@ VALUE method_fast_osc_decode_single_message(VALUE self, VALUE msg) {
95
95
 
96
96
  int buffer_size_for_ruby_string(VALUE rstring) {
97
97
  int str_bytesize = FIX2INT(LONG2FIX(RSTRING_LEN(rstring)));
98
- return (int)((str_bytesize + sizeof(int) - 1) & ~(sizeof(int) - 1));
98
+ int bufsize = (int)((str_bytesize + sizeof(int) - 1) & ~(sizeof(int) - 1));
99
+ return (bufsize + 4) & ~3u;
99
100
  }
100
101
 
101
- VALUE method_fast_osc_encode_single_message(VALUE self, VALUE address, VALUE args) {
102
+ VALUE method_fast_osc_encode_single_message(int argc, VALUE* argv, VALUE self) {
103
+ VALUE address, args;
104
+
105
+ rb_scan_args(argc, argv, "11", &address, &args);
106
+
107
+ if (NIL_P(args)) args = rb_ary_new();
108
+
109
+ // Ruby C API only really allows methods that slurp in all the args
110
+ // Since we want the method to look like
111
+ //
112
+ // def encode_single_message(path, args=[])
113
+ //
114
+ // we need to muck around with the args option a bit
115
+ // VALUE* brings in args as a C array
102
116
  char* c_address = StringValueCStr(address);
103
117
 
104
118
  int no_of_args = NUM2INT(LONG2NUM(RARRAY_LEN(args)));
@@ -158,8 +172,12 @@ VALUE method_fast_osc_encode_single_message(VALUE self, VALUE address, VALUE arg
158
172
 
159
173
  char buffer[max_buffer_size];
160
174
 
161
-
162
- int len = rtosc_amessage(buffer, sizeof(buffer), c_address, StringValueCStr(tagstring), output_args);
175
+ int len;
176
+ if(RSTRING_LEN(tagstring)) {
177
+ len = rtosc_amessage(buffer, sizeof(buffer), c_address, StringValueCStr(tagstring), output_args);
178
+ } else {
179
+ len = rtosc_message(buffer, sizeof(buffer), c_address, "");
180
+ }
163
181
 
164
182
  VALUE output = rb_str_new(buffer, len);
165
183
 
@@ -191,8 +209,19 @@ uint64_t ruby_time_to_osc_timetag(VALUE rubytime) {
191
209
  return timetag;
192
210
  }
193
211
 
194
- VALUE method_fast_osc_encode_single_bundle(VALUE self, VALUE timetag, VALUE address, VALUE args) {
195
- VALUE message = method_fast_osc_encode_single_message(self, address, args);
212
+ VALUE method_fast_osc_encode_single_bundle(int argc, VALUE* argv, VALUE self) {
213
+ VALUE timetag, path, args;
214
+ rb_scan_args(argc, argv, "21", &timetag, &path, &args);
215
+
216
+ if (NIL_P(args)) args = rb_ary_new();
217
+
218
+ VALUE combined_args_holder = rb_ary_new();
219
+ rb_ary_push(combined_args_holder, path);
220
+ rb_ary_push(combined_args_holder, args);
221
+ VALUE* combined_path_and_args = RARRAY_PTR(combined_args_holder);
222
+
223
+ // There are always 2 args here - [path, [args...]]
224
+ VALUE message = method_fast_osc_encode_single_message(2, combined_path_and_args, self);
196
225
  int bufsize = buffer_size_for_ruby_string(message) + 16;
197
226
  int no_of_elems = 1;
198
227
  uint64_t tt = ruby_time_to_osc_timetag(timetag);
@@ -1,3 +1,3 @@
1
1
  module FastOsc
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -5,9 +5,11 @@ require 'date'
5
5
  class FastOscTest < Minitest::Test
6
6
  def setup
7
7
  @path = "/thisisatest"
8
- @args = [1, 2.0, "baz"]
8
+ @args = ["", 1, 2.0, "baz", ""]
9
9
  @timestamp = Date.parse("1st Jan 1990").to_time
10
10
 
11
+ @msg0 = OSC::Message.new(@path).encode
12
+ @encoded_msg0 = @msg0.encode
11
13
  @msg1 = OSC::Message.new(@path, *@args).encode
12
14
  @encoded_msg1 = @msg1.encode
13
15
  end
@@ -17,12 +19,25 @@ class FastOscTest < Minitest::Test
17
19
  end
18
20
 
19
21
  def test_that_it_encodes_a_single_message
22
+ msg = FastOsc.encode_single_message(@path)
23
+
24
+ assert_equal msg, @encoded_msg0
25
+ end
26
+
27
+ def test_that_it_decodes_a_single_message
28
+ path, args = FastOsc.decode_single_message(@encoded_msg0)
29
+
30
+ assert path == @path
31
+ assert args == []
32
+ end
33
+
34
+ def test_that_it_encodes_a_single_message_with_args
20
35
  msg = FastOsc.encode_single_message(@path, @args)
21
36
 
22
37
  assert msg == @encoded_msg1
23
38
  end
24
39
 
25
- def test_that_it_decodes_a_single_message
40
+ def test_that_it_decodes_a_single_message_with_args
26
41
  path, args = FastOsc.decode_single_message(@encoded_msg1)
27
42
 
28
43
  assert path == @path
@@ -36,13 +51,6 @@ class FastOscTest < Minitest::Test
36
51
  assert_equal bundle1, bundle2
37
52
  end
38
53
 
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
54
  def test_that_it_encodes_a_single_bundle_with_fractional_time
47
55
  bundle1 = OSC::Bundle.new(@timestamp + 0.3343215, @msg1).encode
48
56
  bundle2 = FastOsc.encode_single_bundle(@timestamp + 0.3343215, @path, @args)
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.6
4
+ version: 0.0.7
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-10 00:00:00.000000000 Z
11
+ date: 2016-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler