fast_osc 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/ext/fast_osc/fast_osc_wrapper.c +40 -14
- data/lib/fast_osc/version.rb +1 -3
- data/lib/fast_osc.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b61fec8aa9b7da4919beb24194add024e7fc96ed
|
4
|
+
data.tar.gz: f3b8f4387da0d02161f4d173b60de999c9851948
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6f8997f138ca1d6a78c3d686cbd24fcd9b29638dae90d817becd9f2a97ced738eb2f33025c5f6a86a0ece2abad5794ffa640bb690a8d92a0850108f8c1fb7cf
|
7
|
+
data.tar.gz: 58723176381c238b7591c82e1ff43f24ae4cb829311b862f03639236d16e47c65bbf914b26e1986ef494d45b799e88f688d680385dd761fb049ecf321ab61094
|
data/README.md
CHANGED
@@ -65,19 +65,19 @@ I'll include a better test in the repo in time.
|
|
65
65
|
## Usage
|
66
66
|
|
67
67
|
```
|
68
|
-
>> FastOsc.
|
68
|
+
>> FastOsc.encode_single_message("/foo", ["baz", 1, 2.0])
|
69
69
|
=> "/foo\x00\x00\x00\x00,sif\x00\x00\x00\x00baz\x00\x00\x00\x00\x01@\x00\x00\x00"
|
70
70
|
>> res = _
|
71
|
-
>> FastOsc.
|
72
|
-
=> ["baz", 1, 2.0]
|
71
|
+
>> FastOsc.decode_single_message(res)
|
72
|
+
=> ["/foo", ["baz", 1, 2.0]]
|
73
|
+
>> FastOsc.encode_single_bundle(Time.now.to_i, "/foo", ["baz", 1, 2.0])
|
74
|
+
=> "#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"
|
73
75
|
```
|
74
76
|
|
75
77
|
## Still todo
|
76
78
|
|
77
79
|
* Implement more types
|
78
|
-
* return address with `deserialize` (doh!)
|
79
80
|
* add tests at the Ruby level (rtosc C code is already tested)
|
80
|
-
* figure out build process
|
81
81
|
|
82
82
|
## Development notes
|
83
83
|
|
@@ -10,8 +10,9 @@ VALUE FastOsc = Qnil;
|
|
10
10
|
// when this file is loaded, and the second is the actual business logic we're
|
11
11
|
// implementing.
|
12
12
|
void Init_fast_osc();
|
13
|
-
VALUE
|
14
|
-
VALUE
|
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);
|
15
16
|
|
16
17
|
// Initial setup function, takes no arguments and returns nothing. Some API
|
17
18
|
// notes:
|
@@ -27,15 +28,24 @@ VALUE method_fast_osc_serialize(VALUE self, VALUE address, VALUE args);
|
|
27
28
|
//
|
28
29
|
void Init_fast_osc() {
|
29
30
|
FastOsc = rb_define_module("FastOsc");
|
30
|
-
rb_define_singleton_method(FastOsc, "
|
31
|
-
rb_define_singleton_method(FastOsc, "
|
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
34
|
}
|
33
35
|
|
34
|
-
|
36
|
+
const char *rtosc_path(const char *msg)
|
37
|
+
{
|
38
|
+
return msg;
|
39
|
+
}
|
40
|
+
|
41
|
+
VALUE method_fast_osc_decode_single_message(VALUE self, VALUE msg) {
|
35
42
|
rtosc_arg_itr_t itr;
|
36
43
|
char* data = StringValuePtr(msg);
|
37
44
|
itr = rtosc_itr_begin(data);
|
38
45
|
VALUE output = rb_ary_new();
|
46
|
+
VALUE args_output = rb_ary_new();
|
47
|
+
|
48
|
+
VALUE path = rb_str_new2(rtosc_path(data));
|
39
49
|
|
40
50
|
rtosc_arg_val_t next_val;
|
41
51
|
|
@@ -46,38 +56,40 @@ VALUE method_fast_osc_deserialize(VALUE self, VALUE msg) {
|
|
46
56
|
switch(next_val.type) {
|
47
57
|
case 'i' :
|
48
58
|
// INT2FIX() for integers within 31bits.
|
49
|
-
rb_ary_push(
|
59
|
+
rb_ary_push(args_output, INT2FIX(next_val.val.i));
|
50
60
|
break;
|
51
61
|
case 'f' :
|
52
|
-
rb_ary_push(
|
62
|
+
rb_ary_push(args_output, rb_float_new(next_val.val.f));
|
53
63
|
break;
|
54
64
|
case 's' :
|
55
|
-
rb_ary_push(
|
65
|
+
rb_ary_push(args_output, rb_str_new2(next_val.val.s));
|
56
66
|
break;
|
57
67
|
case 'b' :
|
58
|
-
rb_ary_push(
|
68
|
+
rb_ary_push(args_output, rb_str_new((const char*)next_val.val.b.data, next_val.val.b.len));
|
59
69
|
break;
|
60
70
|
case 'h' :
|
61
71
|
// INT2NUM() for arbitrary sized integers
|
62
|
-
rb_ary_push(
|
72
|
+
rb_ary_push(args_output, INT2NUM(next_val.val.h));
|
63
73
|
break;
|
64
74
|
case 't' :
|
65
75
|
// OSC time tag
|
66
76
|
// not implemented
|
67
77
|
break;
|
68
78
|
case 'd' :
|
69
|
-
rb_ary_push(
|
79
|
+
rb_ary_push(args_output, rb_float_new(next_val.val.d));
|
70
80
|
break;
|
71
81
|
case 'S' :
|
72
|
-
rb_ary_push(
|
82
|
+
rb_ary_push(args_output, ID2SYM(rb_intern(next_val.val.s)));
|
73
83
|
break;
|
74
84
|
case 'c' :
|
75
|
-
rb_ary_push(
|
85
|
+
rb_ary_push(args_output, rb_str_concat(rb_str_new2(""), INT2FIX(next_val.val.i)));
|
76
86
|
break;
|
77
87
|
}
|
78
88
|
|
79
89
|
}
|
80
90
|
|
91
|
+
rb_ary_push(output, path);
|
92
|
+
rb_ary_push(output, args_output);
|
81
93
|
return output;
|
82
94
|
}
|
83
95
|
|
@@ -86,7 +98,7 @@ int buffer_size_for_ruby_string(VALUE rstring) {
|
|
86
98
|
return (int)((str_bytesize + sizeof(int) - 1) & ~(sizeof(int) - 1));
|
87
99
|
}
|
88
100
|
|
89
|
-
VALUE
|
101
|
+
VALUE method_fast_osc_encode_single_message(VALUE self, VALUE address, VALUE args) {
|
90
102
|
char* c_address = StringValueCStr(address);
|
91
103
|
|
92
104
|
int no_of_args = NUM2INT(LONG2NUM(RARRAY_LEN(args)));
|
@@ -153,3 +165,17 @@ VALUE method_fast_osc_serialize(VALUE self, VALUE address, VALUE args) {
|
|
153
165
|
|
154
166
|
return output;
|
155
167
|
}
|
168
|
+
|
169
|
+
VALUE method_fast_osc_encode_single_bundle(VALUE self, VALUE timestamp, VALUE address, VALUE args) {
|
170
|
+
VALUE message = method_fast_osc_encode_single_message(self, address, args);
|
171
|
+
int bufsize = buffer_size_for_ruby_string(message) + 16;
|
172
|
+
int no_of_elems = 1;
|
173
|
+
uint64_t tt = FIX2LONG(timestamp);
|
174
|
+
char output_buffer[bufsize];
|
175
|
+
|
176
|
+
int len = rtosc_bundle(output_buffer, bufsize, tt, no_of_elems, StringValuePtr(message));
|
177
|
+
|
178
|
+
VALUE output = rb_str_new(output_buffer, len);
|
179
|
+
|
180
|
+
return output;
|
181
|
+
}
|
data/lib/fast_osc/version.rb
CHANGED
data/lib/fast_osc.rb
CHANGED
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.
|
4
|
+
version: 0.0.5
|
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-
|
11
|
+
date: 2016-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|