osc-ruby 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b6e50d421b58c68e16b4d82d132f25e15b0338b
4
+ data.tar.gz: 8875e8b6aa9cf1af663291b248c5708695ed1448
5
+ SHA512:
6
+ metadata.gz: c814bfa20121cb7a835159546c858b9f6d3370c6158e067c17df7ceeb379608c98242375ef5b776488cd35efe4c7df1a25b3439c2a97c01eed7799be7daf15c8
7
+ data.tar.gz: 576b0fcabd35b30da9cdfad8477d788ddec610fc455b796a4322483a1b3917a3f26f332e8536cc0b6dd534a3ea2c6b63b75a5cb5f22e1262944e309aed16c091
data/Rakefile CHANGED
@@ -4,11 +4,11 @@ task :default => :spec
4
4
 
5
5
  RSpec::Core::RakeTask.new do |t|
6
6
  t.rcov = false
7
- t.rspec_opts = ["--colour"]
7
+ t.rspec_opts = ["--colour", "--format", "documentation"]
8
8
  end
9
9
 
10
10
  require 'rdoc/task'
11
- Rake::RDocTask.new do |rdoc|
11
+ RDoc::Task.new do |rdoc|
12
12
  if File.exist?('VERSION')
13
13
  version = File.read('VERSION')
14
14
  else
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -10,7 +10,7 @@ require 'osc-ruby/em_server'
10
10
  @client = OSC::Client.new( 'localhost', 3333 )
11
11
 
12
12
  @server.add_method '/greeting' do | message |
13
- puts message.to_a
13
+ puts "#{message.ip_address}:#{message.ip_port} -- #{message.address} -- #{message.to_a}"
14
14
  end
15
15
 
16
16
  Thread.new do
@@ -2,43 +2,48 @@ module OSC
2
2
  class AddressPattern
3
3
  def initialize( pattern )
4
4
  @pattern = pattern
5
-
5
+
6
6
  generate_regex_from_pattern
7
7
  end
8
-
8
+
9
9
  def match?( address )
10
10
  !!(@re.nil? || @re.match( address ))
11
11
  end
12
-
13
- private
12
+
13
+ private
14
14
  def generate_regex_from_pattern
15
15
  case @pattern
16
16
  when NIL; @re = @pattern
17
17
  when Regexp; @re = @pattern
18
18
  when String
19
-
19
+
20
20
  # i'm unsure what this does
21
21
  # @pattern.gsub!(/[.^(|)]/, '\\1')
22
-
22
+
23
23
  # handles osc single char wildcard matching
24
24
  @pattern.gsub!(/\?/, '[^/]')
25
-
25
+
26
+ # handles ** - used in creating osc routers
27
+ # TODO: turns out the OSC 1.1 spec says that we shoudl use "//"
28
+ # this will be implemented in the next major release of this gem
29
+ #@pattern.gsub!(/\*\*/, '.*' )
30
+
26
31
  # handles osc * - 0 or more matching
27
- @pattern.gsub!(/\*/, '[^/]*')
28
-
32
+ @pattern.gsub!(/\*[^\*]/, '[^/]*')
33
+
29
34
  # handles [!] matching
30
35
  @pattern.gsub!(/\[!/, '[^')
31
-
36
+
32
37
  # handles {} matching
33
38
  @pattern.gsub!(/\{/, '(')
34
39
  @pattern.gsub!(/,/, '|')
35
40
  @pattern.gsub!(/\}/, ')')
36
-
37
-
41
+
42
+
38
43
  # keeps from matching before the begining of the pattern
39
44
  @pattern.gsub!(/\A/, '\A')
40
-
41
- # keeps from matching beyond the end,
45
+
46
+ # keeps from matching beyond the end,
42
47
  # eg. pattern /hi does not match /hidden
43
48
  @pattern.gsub!(/\z/, '\z')
44
49
 
@@ -1,7 +1,7 @@
1
1
  module OSC
2
2
  class NetworkPacket
3
3
  def initialize(str)
4
- @str, @index = str, 0
4
+ @str, @index = str.force_encoding("BINARY"), 0
5
5
  end
6
6
 
7
7
  def to_s
@@ -9,15 +9,15 @@ module OSC
9
9
  osc = new( string )
10
10
 
11
11
  if osc.bundle?
12
- bundle = osc.get_string
12
+ osc.get_string #=> bundle
13
13
  time = osc.get_timestamp
14
14
 
15
15
  osc.get_bundle_messages.each do | message |
16
16
  msg = decode_simple_message( time, OSCPacket.new( message ) )
17
17
  if ip_info
18
18
  # Append info for the ip address
19
- msg.ip_address = ip_info[1].to_s + "." + ip_info[2].to_s + "." + ip_info[3].to_s + "." + ip_info[4].to_s
20
- msg.ip_port = ip_info[0]
19
+ msg.ip_port = ip_info.shift
20
+ msg.ip_address = ip_info.join(".")
21
21
  end
22
22
  messages << msg
23
23
  end
@@ -26,8 +26,8 @@ module OSC
26
26
  msg = decode_simple_message( time, osc )
27
27
  if ip_info
28
28
  # Append info for the ip address
29
- msg.ip_address = ip_info[1].to_s + "." + ip_info[2].to_s + "." + ip_info[3].to_s + "." + ip_info[4].to_s
30
- msg.ip_port = ip_info[0]
29
+ msg.ip_port = ip_info.shift
30
+ msg.ip_address = ip_info.join(".")
31
31
  end
32
32
  messages << msg
33
33
  end
@@ -72,6 +72,7 @@ module OSC
72
72
  end
73
73
 
74
74
  def get_timestamp
75
+ #TODO: refactor this so a mortal can figure it out
75
76
  t1 = @packet.getn(4).unpack('N')[0]
76
77
  t2 = @packet.getn(4).unpack('N')[0]
77
78
  @packet.skip_padding
@@ -123,8 +124,7 @@ module OSC
123
124
  end
124
125
 
125
126
  def string_delemeter
126
- # ruby 1.9 has multicharacter support
127
- RUBY_VERSION.include?( '1.9' ) ? "\x00" : 0
127
+ "\x00"
128
128
  end
129
129
  end
130
130
  end
@@ -1,23 +1,23 @@
1
1
  require File.join( File.dirname( __FILE__ ), "osc_argument" )
2
2
 
3
- module OSC
3
+ module OSC
4
4
  class OSCInt32 < OSCArgument
5
5
  def tag() 'i' end
6
- def encode() [@val].pack('N') end
6
+ def encode() [@val].pack('N').force_encoding("BINARY") end
7
7
  end
8
8
 
9
9
  class OSCFloat32 < OSCArgument
10
10
  def tag() 'f' end
11
- def encode() [@val].pack('g') end # fake - why fake?
11
+ def encode() [@val].pack('g').force_encoding("BINARY") end
12
12
  end
13
13
 
14
14
  class OSCString < OSCArgument
15
15
  def tag() 's' end
16
- def encode() padding(@val.sub(/\000.*\z/, '') + "\000") end
16
+ def encode() padding(@val.sub(/\000.*\z/, '') + "\000").force_encoding("BINARY") end
17
17
  end
18
18
 
19
19
  class OSCBlob < OSCArgument
20
20
  def tag() 'b' end
21
- def encode() padding([@val.size].pack('N') + @val) end
21
+ def encode() padding([@val.size].pack('N') + @val).force_encoding("BINARY") end
22
22
  end
23
23
  end
@@ -1,36 +1,47 @@
1
1
  require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
2
2
 
3
3
  describe OSC::AddressPattern do
4
+ # it "..." do
5
+ # ap = OSC::AddressPattern.new("/bob/test/**")
6
+
7
+ # ap.match?("/bob/test/monkey").should be_true
8
+ # ap.match?("/bob/test/monkey/shine/rainy/day").should be_true
9
+
10
+ # ap.match?("/bob/test").should be_false
11
+ # ap.match?("/bob").should be_false
12
+
13
+ # end
14
+
4
15
  it "should match anything if the pattern is nil" do
5
16
  ap = OSC::AddressPattern.new( nil )
6
-
17
+
7
18
  ap.match?( "/some/nonsense").should be_true
8
19
  ap.match?( "/completely.different").should be_true
9
20
  end
10
-
21
+
11
22
  it "should match based on a regex" do
12
23
  ap = OSC::AddressPattern.new( /hi/ )
13
-
24
+
14
25
  ap.match?( '/hi' ).should be_true
15
26
  ap.match?( '/hidden' ).should be_true
16
-
27
+
17
28
  ap.match?( '/bye' ).should be_false
18
- end
19
-
29
+ end
30
+
20
31
  it "should return a regex if the pattern is a string" do
21
32
  ap = OSC::AddressPattern.new( "/hi" )
22
-
33
+
23
34
  ap.match?('/hi').should be_true
24
-
35
+
25
36
  ap.match?(' /hi').should be_false
26
37
  ap.match?('/ahi').should be_false
27
38
  ap.match?( '/hidden' ).should be_false
28
39
  ap.match?( '/bye' ).should be_false
29
40
  end
30
-
41
+
31
42
  it "should match with question mark" do
32
43
  ap = OSC::AddressPattern.new( "/h?l" )
33
-
44
+
34
45
  ap.match?('/hal').should be_true
35
46
  ap.match?('/hel').should be_true
36
47
  ap.match?('/hil').should be_true
@@ -38,20 +49,20 @@ describe OSC::AddressPattern do
38
49
  ap.match?('/hul').should be_true
39
50
  ap.match?('/hub').should be_false
40
51
  end
41
-
52
+
42
53
  it "should match with *" do
43
54
  ap = OSC::AddressPattern.new( "/believ*d" )
44
-
55
+
45
56
  ap.match?('/believd').should be_true
46
57
  ap.match?('/believed').should be_true
47
58
  ap.match?('/believeeed').should be_true
48
59
  ap.match?('/believaeeeioud').should be_true
49
60
  ap.match?('/believaeeeioud').should be_true
50
61
  end
51
-
62
+
52
63
  it "should match with []" do
53
64
  ap = OSC::AddressPattern.new( "/believ[aeiou]d" )
54
-
65
+
55
66
  ap.match?('/believad').should be_true
56
67
  ap.match?('/believed').should be_true
57
68
  ap.match?('/believid').should be_true
@@ -59,10 +70,10 @@ describe OSC::AddressPattern do
59
70
  ap.match?('/believud').should be_true
60
71
  ap.match?('/believkd').should be_false
61
72
  end
62
-
73
+
63
74
  it "should match with [!]" do
64
75
  ap = OSC::AddressPattern.new( "/believ[!aeiou]d" )
65
-
76
+
66
77
  ap.match?('/believad').should be_false
67
78
  ap.match?('/believed').should be_false
68
79
  ap.match?('/believid').should be_false
@@ -71,13 +82,13 @@ describe OSC::AddressPattern do
71
82
  ap.match?('/believkd').should be_true
72
83
  ap.match?('/believzd').should be_true
73
84
  end
74
-
85
+
75
86
  it "should match with {}" do
76
87
  ap = OSC::AddressPattern.new( "/{hi,bye}" )
77
-
88
+
78
89
  ap.match?('/hi').should be_true
79
90
  ap.match?('/bye').should be_true
80
91
  ap.match?('/greetings').should be_false
81
92
  end
82
-
93
+
83
94
  end
@@ -8,28 +8,28 @@ describe MessageBuilder do
8
8
 
9
9
  it "encodes just the address" do
10
10
  mesg = @builder.with_address("/hi")
11
- mesg.build.encode.should == "/hi\000,\000\000\000"
11
+ mesg.build.encode.should == binary_string("/hi\000,\000\000\000")
12
12
  end
13
13
 
14
14
  it "encodes single int values" do
15
15
  mesg = @builder.with_address("/hi").
16
16
  with_int(33)
17
17
 
18
- mesg.build.encode.should == "/hi\000,i\000\000\000\000\000!"
18
+ mesg.build.encode.should == binary_string("/hi\000,i\000\000\000\000\000!")
19
19
  end
20
20
 
21
21
  it "encodes single string values" do
22
22
  mesg = @builder.with_address("/hi").
23
23
  with_string("hello")
24
24
 
25
- mesg.build.encode.should == "/hi\000,s\000\000hello\000\000\000"
25
+ mesg.build.encode.should == binary_string("/hi\000,s\000\000hello\000\000\000")
26
26
  end
27
27
 
28
28
  it "encodes single float values" do
29
29
  mesg = @builder.with_address("/hi").
30
30
  with_float(3.14159)
31
31
 
32
- mesg.build.encode.should == "/hi\000,f\000\000@I\017\320"
32
+ mesg.build.encode.should == binary_string("/hi\000,f\000\000@I\017\320")
33
33
  end
34
34
 
35
35
  it "encodes multiple floats" do
@@ -40,4 +40,7 @@ describe MessageBuilder do
40
40
  mesg.build.encode.should == [47, 104, 105, 0, 44, 102, 102, 0, 64, 73, 15, 208, 64, 144, 0, 0].pack("C*")
41
41
  end
42
42
 
43
+ def binary_string(string)
44
+ string.force_encoding("BINARY")
45
+ end
43
46
  end
@@ -37,6 +37,23 @@ describe OSC::Message do
37
37
  end
38
38
  end
39
39
 
40
+ describe "message output encoding" do
41
+ it "integer arguments output binary/ascii string" do
42
+ m = OSC::Message.new( "/hi", 42 ).encode
43
+ m.encoding.to_s.should == "ASCII-8BIT"
44
+ end
45
+
46
+ it "string arguments output binary/ascii string" do
47
+ m = OSC::Message.new( "/hi", "42" ).encode
48
+ m.encoding.to_s.should == "ASCII-8BIT"
49
+ end
50
+
51
+ it "float arguments output binary/ascii string" do
52
+ m = OSC::Message.new( "/hi", 3.14159 ).encode
53
+ m.encoding.to_s.should == "ASCII-8BIT"
54
+ end
55
+ end
56
+
40
57
  describe "more interesting traits" do
41
58
  before :each do
42
59
  @builder = MessageBuilder.new
@@ -46,8 +63,6 @@ describe OSC::Message do
46
63
  @message = @builder.build
47
64
  end
48
65
 
49
-
50
-
51
66
  it "should know equality" do
52
67
  @message2 = @builder.build
53
68
 
@@ -30,4 +30,8 @@ describe OSC::NetworkPacket do
30
30
  it "should be able to get a number of characters from the stream" do
31
31
  @simple.getn(3).should == "abc"
32
32
  end
33
+
34
+ it "outputs characters with ASCII/BINARY encoding" do
35
+ @simple.getc.encoding.to_s.should == "ASCII-8BIT"
36
+ end
33
37
  end
@@ -44,7 +44,7 @@ describe OSC::OSCPacket do
44
44
  msg.first.to_a.should == [@first_int, @second_int]
45
45
  end
46
46
 
47
- it "shold decode address with float arg" do
47
+ it "should decode address with float arg" do
48
48
  sent_msg = @builder.with_float( @first_float ).build
49
49
 
50
50
  msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
@@ -53,7 +53,7 @@ describe OSC::OSCPacket do
53
53
  end
54
54
 
55
55
 
56
- it "shold decode address with two float args" do
56
+ it "should decode address with two float args" do
57
57
  sent_msg = @builder.with_float( @first_float ).with_float( @second_float).build
58
58
 
59
59
  msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
metadata CHANGED
@@ -1,18 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osc-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Colin Harris
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-28 00:00:00.000000000 Z
13
- dependencies: []
11
+ date: 2013-05-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
14
27
  description: This OSC gem originally created by Tadayoshi Funaba has been updated
15
- for ruby 1.9/JRuby compatibility
28
+ for ruby 2.0/1.9/JRuby compatibility
16
29
  email: qzzzq1@gmail.com
17
30
  executables: []
18
31
  extensions: []
@@ -21,10 +34,7 @@ files:
21
34
  - Rakefile
22
35
  - VERSION
23
36
  - LICENSE
24
- - examples/classic_server.rb
25
- - examples/classic_server_ip_info.rb
26
37
  - examples/event_machine_server.rb
27
- - examples/ip_info.rb
28
38
  - lib/osc-ruby/address_pattern.rb
29
39
  - lib/osc-ruby/bundle.rb
30
40
  - lib/osc-ruby/client.rb
@@ -51,27 +61,26 @@ files:
51
61
  - spec/unit/osc_types_spec.rb
52
62
  homepage: http://github.com/aberant/osc-ruby
53
63
  licenses: []
64
+ metadata: {}
54
65
  post_install_message:
55
66
  rdoc_options: []
56
67
  require_paths:
57
68
  - lib
58
69
  required_ruby_version: !ruby/object:Gem::Requirement
59
- none: false
60
70
  requirements:
61
- - - ! '>='
71
+ - - '>='
62
72
  - !ruby/object:Gem::Version
63
73
  version: '0'
64
74
  required_rubygems_version: !ruby/object:Gem::Requirement
65
- none: false
66
75
  requirements:
67
- - - ! '>='
76
+ - - '>='
68
77
  - !ruby/object:Gem::Version
69
78
  version: '0'
70
79
  requirements: []
71
80
  rubyforge_project:
72
- rubygems_version: 1.8.24
81
+ rubygems_version: 2.0.3
73
82
  signing_key:
74
- specification_version: 3
83
+ specification_version: 4
75
84
  summary: a ruby client for the OSC protocol
76
85
  test_files:
77
86
  - spec/builders/message_builder.rb
@@ -1,18 +0,0 @@
1
- # compatible with ruby 1.8
2
- $:.unshift File.join( File.dirname( __FILE__ ), '..', 'lib')
3
- require 'osc-ruby'
4
-
5
- @server = OSC::Server.new( 3333 )
6
- @client = OSC::Client.new( 'localhost', 3333 )
7
-
8
- @server.add_method '/greeting' do | message |
9
- puts message.to_a
10
- end
11
-
12
- Thread.new do
13
- @server.run
14
- end
15
-
16
- @client.send( OSC::Message.new( "/greeting", "hullo!" ))
17
-
18
- sleep( 3 )
@@ -1,18 +0,0 @@
1
- # compatible with ruby 1.8
2
- $:.unshift File.join( File.dirname( __FILE__ ), '..', 'lib')
3
- require 'osc-ruby'
4
-
5
- @server = OSC::Server.new( 3333 )
6
- @client = OSC::Client.new( 'localhost', 3333 )
7
-
8
- @server.add_method '/greeting' do | message |
9
- puts message.ip_address + ":" + message.ip_port.to_s + " -- " + message.address + " -- " + message.to_a.to_s
10
- end
11
-
12
- Thread.new do
13
- @server.run
14
- end
15
-
16
- @client.send( OSC::Message.new( "/greeting", "hullo!" ))
17
-
18
- sleep( 3 )
data/examples/ip_info.rb DELETED
@@ -1,22 +0,0 @@
1
- # compatible with ruby 1.8, 1.9, and jruby
2
- $:.unshift File.join( File.dirname( __FILE__ ), '..', 'lib')
3
- require 'osc-ruby'
4
-
5
- require 'rubygems'
6
- require 'eventmachine'
7
- require 'osc-ruby/em_server'
8
-
9
- @server = OSC::EMServer.new( 3333 )
10
- @client = OSC::Client.new( 'localhost', 3333 )
11
-
12
- @server.add_method '/greeting' do | message |
13
- puts message.ip_address + ":" + message.ip_port.to_s + " -- " + message.address + " -- " + message.to_a.to_s
14
- end
15
-
16
- Thread.new do
17
- @server.run
18
- end
19
-
20
- @client.send( OSC::Message.new( "/greeting" , "hullo!" ))
21
-
22
- sleep( 3 )