fast_osc 0.0.7 → 0.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e928fde0a4bf601705f34f29aab9f788d2044cf9
4
- data.tar.gz: 9ea87039d5da0efa5edb45e600ee985c5caee1df
3
+ metadata.gz: 268fcf3a70da8309727ef032b0434db61b8e6e23
4
+ data.tar.gz: 3df91b74cce13e82a908aadcd9f951bbb2ff39ce
5
5
  SHA512:
6
- metadata.gz: 44b41b3ccf0c5aa9d35c0b586bb2e4df93710ecf7ac58a5c747c29f669bf510ebc8cb1a5438fd687344133a0185931de0b9027e829f4c1d09ff9ae853fa04b75
7
- data.tar.gz: c7556261e6f6ac3895f86b4c0f5cb190eddef9b7ff3d7dfbe7ba44acf773cc8707a1b8a5b5540d47d9f0ac79dc38d424fb3c9de846a3365c88c4df855812ab0e
6
+ metadata.gz: 68be3a880de29bfe9e0d4870389cb75bb8f3c92a4dc174bb0ffe918ff5545525d9d08fa42d71aaa7f579ae37de49821aa48b7ad147a731fc780292f01752f426
7
+ data.tar.gz: 97ad3ab5853cbfa9424a16611e4c0a2a15198fdccbff61de897543f534cacc30d10401fad8be3044eeda41174ce4feaf9ea01bcf38e74182aa3b72f6e2d99704
@@ -118,7 +118,7 @@ VALUE method_fast_osc_encode_single_message(int argc, VALUE* argv, VALUE self) {
118
118
  int no_of_args = NUM2INT(LONG2NUM(RARRAY_LEN(args)));
119
119
  int i;
120
120
  int max_buffer_size = 0;
121
- VALUE current_arg;
121
+ VALUE current_arg, strval;
122
122
 
123
123
  //output tags and args list
124
124
  VALUE tagstring = rb_str_new2(""); //rtosc will handle comma
@@ -154,6 +154,16 @@ VALUE method_fast_osc_encode_single_message(int argc, VALUE* argv, VALUE self) {
154
154
  rb_str_concat(tagstring, rb_str_new2("s"));
155
155
  output_args[i].s = StringValueCStr(current_arg);
156
156
  break;
157
+ case T_SYMBOL:
158
+ // now align to 4 byte boundary for sizing output buffer
159
+ strval = rb_sym_to_s(current_arg);
160
+ max_buffer_size += buffer_size_for_ruby_string(strval);
161
+
162
+ // encode as a string because not all implementation understand S as
163
+ // alternative string tag
164
+ rb_str_concat(tagstring, rb_str_new2("s"));
165
+ output_args[i].s = StringValueCStr(strval);
166
+ break;
157
167
  }
158
168
  }
159
169
 
@@ -200,9 +210,12 @@ uint64_t ruby_time_to_osc_timetag(VALUE rubytime) {
200
210
  // convert Time object to ntp
201
211
  floattime = JAN_1970 + NUM2DBL(rb_funcall(rubytime, rb_intern("to_f"), 0));
202
212
 
203
- sec = NUM2UINT(DBL2NUM(floattime));
204
- frac = (int)(fmod(floattime, 1.0) * 4294967296); // * (2 ** 32)
213
+ sec = floor(floattime);
214
+ frac = (uint32_t)(fmod(floattime, 1.0) * 4294967296); // * (2 ** 32)
215
+ /* printf("\nsec: %04x\n", sec); */
216
+ /* printf("\nfrac: %04x\n", frac); */
205
217
  timetag = (uint64_t)((uint64_t)sec << 32 | (uint64_t)frac);
218
+ /* printf("\ntimetag: %08llx\n", timetag); */
206
219
  break;
207
220
  }
208
221
 
@@ -1,3 +1,3 @@
1
1
  module FastOsc
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -5,7 +5,7 @@ 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
11
  @msg0 = OSC::Message.new(@path).encode
@@ -64,4 +64,31 @@ class FastOscTest < Minitest::Test
64
64
 
65
65
  assert_equal bundle1, bundle2
66
66
  end
67
+
68
+ def test_that_it_encodes_and_decodes_messages_with_symbols
69
+ path = "/s_new"
70
+ args = ["sonic-pi-basic_mixer", 10, 0, 2, :amp, 1, :amp_slide, 0.1, :amp_slide_shape, 1, :amp_slide_curve, 0, "in_bus", 12, "amp", 0.3 , "out_bus", 10]
71
+ outpath, outargs = FastOsc.decode_single_message(FastOsc.encode_single_message(path, args))
72
+
73
+ assert_equal path, outpath
74
+ # normalize symbols to strings, round floats to 5 places
75
+ assert_equal args.map {|x| x.is_a?(Symbol) ? x.to_s : x}, outargs.map {|x| x.is_a?(Float) ? x.round(5) : x }
76
+ end
77
+
78
+ def test_that_encoded_timestamps_line_up
79
+ # this test is a bit convoluted but I found that fractional
80
+ # seconds weren't working when I plugged this into Sonic Pi
81
+ # This test ensures that the timestamp encoding matches to
82
+ # at least a tolerance of 0.001 seconds which should catch any
83
+ # major issues.
84
+ start = Time.at(1463234577.4387462) - 1.0
85
+ # assert_in_delta is 0.001 by default
86
+ assert_in_delta 1.25, Time.at(OSC::OSCPacket.messages_from_network(FastOsc.encode_single_bundle(1463234577.688746, "/foo", []), []).first.time - 2208988800) - start
87
+ assert_in_delta 1.5, Time.at(OSC::OSCPacket.messages_from_network(FastOsc.encode_single_bundle(1463234577.9387462, "/foo", []), []).first.time - 2208988800) - start
88
+ assert_in_delta 1.75, Time.at(OSC::OSCPacket.messages_from_network(FastOsc.encode_single_bundle(1463234578.188746, "/foo", []), []).first.time - 2208988800) - start
89
+ assert_in_delta 2.0, Time.at(OSC::OSCPacket.messages_from_network(FastOsc.encode_single_bundle(1463234578.4387462, "/foo", []), []).first.time - 2208988800) - start
90
+ assert_in_delta 2.25, Time.at(OSC::OSCPacket.messages_from_network(FastOsc.encode_single_bundle(1463234578.688746, "/foo", []), []).first.time - 2208988800) - start
91
+ assert_in_delta 2.5, Time.at(OSC::OSCPacket.messages_from_network(FastOsc.encode_single_bundle(1463234578.9387462, "/foo", []), []).first.time - 2208988800) - start
92
+ assert_in_delta 2.75, Time.at(OSC::OSCPacket.messages_from_network(FastOsc.encode_single_bundle(1463234579.188746, "/foo", []), []).first.time - 2208988800) - start
93
+ end
67
94
  end
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.7
4
+ version: 0.0.9
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-12 00:00:00.000000000 Z
11
+ date: 2016-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler