osc-ruby 0.7.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -35
- data/VERSION +1 -1
- data/examples/classic_server_ip_info.rb +18 -0
- data/examples/ip_info.rb +22 -0
- data/lib/osc-ruby/em_server.rb +2 -1
- data/lib/osc-ruby/message.rb +2 -0
- data/lib/osc-ruby/osc_packet.rb +15 -3
- data/lib/osc-ruby/server.rb +4 -3
- data/spec/spec_helper.rb +1 -2
- data/spec/unit/osc_simple_packets_spec.rb +40 -40
- metadata +37 -39
data/Rakefile
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
require '
|
1
|
+
require 'rspec/core/rake_task'
|
2
2
|
|
3
3
|
task :default => :spec
|
4
4
|
|
5
|
-
|
6
|
-
t.libs << 'lib'
|
7
|
-
t.warning = false
|
5
|
+
RSpec::Core::RakeTask.new do |t|
|
8
6
|
t.rcov = false
|
9
|
-
t.
|
7
|
+
t.rspec_opts = ["--colour"]
|
10
8
|
end
|
11
9
|
|
12
|
-
require '
|
10
|
+
require 'rdoc/task'
|
13
11
|
Rake::RDocTask.new do |rdoc|
|
14
12
|
if File.exist?('VERSION')
|
15
13
|
version = File.read('VERSION')
|
@@ -22,32 +20,3 @@ Rake::RDocTask.new do |rdoc|
|
|
22
20
|
rdoc.rdoc_files.include('README*')
|
23
21
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
24
22
|
end
|
25
|
-
|
26
|
-
require 'rake/packagetask'
|
27
|
-
require 'rake/gempackagetask'
|
28
|
-
|
29
|
-
### Task: gem
|
30
|
-
gemspec = Gem::Specification.new do |gem|
|
31
|
-
gem.name = "osc-ruby"
|
32
|
-
gem.version = File.read('VERSION')
|
33
|
-
|
34
|
-
gem.summary = "a ruby client for the OSC protocol"
|
35
|
-
gem.description = "This OSC gem originally created by Tadayoshi Funaba has been updated for ruby 1.9/JRuby compatibility"
|
36
|
-
|
37
|
-
gem.authors = "Colin Harris"
|
38
|
-
gem.email = "qzzzq1@gmail.com"
|
39
|
-
gem.homepage = "http://github.com/aberant/osc-ruby"
|
40
|
-
|
41
|
-
gem.has_rdoc = true
|
42
|
-
|
43
|
-
gem.files = FileList['Rakefile', 'VERSION', 'LICENSE', 'examples/**/*', 'lib/**/*'].to_a
|
44
|
-
gem.test_files = FileList['spec/**/*.rb']
|
45
|
-
end
|
46
|
-
|
47
|
-
Rake::GemPackageTask.new( gemspec ) do |task|
|
48
|
-
task.gem_spec = gemspec
|
49
|
-
task.need_tar = false
|
50
|
-
task.need_tar_gz = true
|
51
|
-
task.need_tar_bz2 = true
|
52
|
-
task.need_zip = true
|
53
|
-
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0
|
@@ -0,0 +1,18 @@
|
|
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
ADDED
@@ -0,0 +1,22 @@
|
|
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 )
|
data/lib/osc-ruby/em_server.rb
CHANGED
@@ -5,7 +5,8 @@ module OSC
|
|
5
5
|
|
6
6
|
class Connection < EventMachine::Connection
|
7
7
|
def receive_data data
|
8
|
-
|
8
|
+
ip_info = get_peername[2,6].unpack "nC4"
|
9
|
+
Channel << OSC::OSCPacket.messages_from_network( data, ip_info )
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
data/lib/osc-ruby/message.rb
CHANGED
data/lib/osc-ruby/osc_packet.rb
CHANGED
@@ -4,7 +4,7 @@ require 'ostruct'
|
|
4
4
|
module OSC
|
5
5
|
class OSCPacket
|
6
6
|
|
7
|
-
def self.messages_from_network( string )
|
7
|
+
def self.messages_from_network( string, ip_info=nil )
|
8
8
|
messages = []
|
9
9
|
osc = new( string )
|
10
10
|
|
@@ -13,11 +13,23 @@ module OSC
|
|
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
|
+
if ip_info
|
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]
|
21
|
+
end
|
22
|
+
messages << msg
|
17
23
|
end
|
18
24
|
|
19
25
|
else
|
20
|
-
|
26
|
+
msg = decode_simple_message( time, osc )
|
27
|
+
if ip_info
|
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]
|
31
|
+
end
|
32
|
+
messages << msg
|
21
33
|
end
|
22
34
|
|
23
35
|
return messages
|
data/lib/osc-ruby/server.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module OSC
|
2
2
|
class Server
|
3
|
-
|
4
3
|
def initialize( port )
|
5
4
|
@socket = UDPSocket.new
|
6
5
|
@socket.bind( '', port )
|
@@ -77,8 +76,10 @@ private
|
|
77
76
|
loop do
|
78
77
|
osc_data, network = @socket.recvfrom( 16384 )
|
79
78
|
begin
|
80
|
-
|
81
|
-
|
79
|
+
ip_info = Array.new
|
80
|
+
ip_info << network[1]
|
81
|
+
ip_info.concat(network[2].split('.'))
|
82
|
+
OSCPacket.messages_from_network( osc_data, ip_info ).each do |message|
|
82
83
|
@queue.push(message)
|
83
84
|
end
|
84
85
|
|
data/spec/spec_helper.rb
CHANGED
@@ -6,102 +6,102 @@ describe OSC::OSCPacket do
|
|
6
6
|
@address = "/hi"
|
7
7
|
@first_int = 42
|
8
8
|
@second_int = 33
|
9
|
-
|
9
|
+
|
10
10
|
@first_float = 42.01
|
11
11
|
@second_float = 33.01
|
12
|
-
|
12
|
+
|
13
13
|
@first_string = "greetings"
|
14
14
|
@second_string = "how are you?"
|
15
|
-
|
15
|
+
|
16
16
|
@first_blob = "this is a fake blob"
|
17
17
|
@second_blob = "tis another fake blob"
|
18
|
-
|
18
|
+
|
19
19
|
@builder = MessageBuilder.new
|
20
20
|
@builder.with_address( @address )
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
it "should decode the address of a simple message from the network data" do
|
24
24
|
sent_msg = @builder.build
|
25
|
-
|
25
|
+
|
26
26
|
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
|
27
|
-
|
27
|
+
|
28
28
|
msg.first.address.should == @address
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
it "should decode the int arg of a simple message from the network data" do
|
32
32
|
sent_msg = @builder.with_int( @first_int ).build
|
33
|
-
|
33
|
+
|
34
34
|
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
|
35
|
-
|
35
|
+
|
36
36
|
msg.first.to_a.should == [@first_int]
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it "should decode two int args" do
|
40
40
|
sent_msg = @builder.with_int( @first_int ).with_int( @second_int ).build
|
41
|
-
|
41
|
+
|
42
42
|
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
|
43
|
-
|
43
|
+
|
44
44
|
msg.first.to_a.should == [@first_int, @second_int]
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
it "shold 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 )
|
51
|
-
|
52
|
-
msg.first.to_a[0].should
|
51
|
+
|
52
|
+
msg.first.to_a[0].should be_within( 0.001 ).of( @first_float )
|
53
53
|
end
|
54
|
-
|
55
|
-
|
54
|
+
|
55
|
+
|
56
56
|
it "shold 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 )
|
60
|
-
|
60
|
+
|
61
61
|
args = msg.first.to_a
|
62
|
-
args.first.should
|
63
|
-
args[1].should
|
62
|
+
args.first.should be_within( 0.001 ).of( @first_float )
|
63
|
+
args[1].should be_within( 0.001 ).of( @second_float )
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
it "should decode address with string arg" do
|
67
67
|
sent_msg = @builder.with_string( @first_string ).build
|
68
|
-
|
68
|
+
|
69
69
|
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
|
70
|
-
|
70
|
+
|
71
71
|
msg.first.to_a.should == [@first_string]
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
it "should decode address with multiple string args" do
|
75
75
|
sent_msg = @builder.with_string( @first_string ).with_string( @second_string).build
|
76
76
|
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
|
77
|
-
|
77
|
+
|
78
78
|
args = msg.first.to_a
|
79
|
-
args[0].should
|
80
|
-
args[1].should
|
79
|
+
args[0].should eql @first_string
|
80
|
+
args[1].should eql @second_string
|
81
81
|
end
|
82
|
-
|
83
|
-
|
82
|
+
|
83
|
+
|
84
84
|
it "should decode messages with three different types of args" do
|
85
85
|
sent_msg = @builder.with_int( @first_int ).
|
86
86
|
with_float( @second_float ).
|
87
87
|
with_string( @first_string ).
|
88
88
|
build
|
89
|
-
|
89
|
+
|
90
90
|
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
|
91
|
-
|
91
|
+
|
92
92
|
args = msg.first.to_a
|
93
|
-
|
93
|
+
|
94
94
|
args[0].should eql( @first_int )
|
95
|
-
args[1].should
|
95
|
+
args[1].should be_within( 0.001 ).of( @second_float )
|
96
96
|
args[2].should eql( @first_string )
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
it "should decode messages with blobs" do
|
100
100
|
sent_msg = @builder.with_blob( @first_blob ).build
|
101
|
-
|
102
|
-
|
101
|
+
|
102
|
+
|
103
103
|
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
|
104
|
-
|
104
|
+
|
105
105
|
args = msg.first.to_a
|
106
106
|
args.first.should eql( @first_blob )
|
107
107
|
end
|
metadata
CHANGED
@@ -1,37 +1,30 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: osc-ruby
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 7
|
8
|
-
- 0
|
9
|
-
version: 0.7.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Colin Harris
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2010-08-15 00:00:00 -05:00
|
18
|
-
default_executable:
|
12
|
+
date: 2012-10-28 00:00:00.000000000 Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
|
-
|
14
|
+
description: This OSC gem originally created by Tadayoshi Funaba has been updated
|
15
|
+
for ruby 1.9/JRuby compatibility
|
22
16
|
email: qzzzq1@gmail.com
|
23
17
|
executables: []
|
24
|
-
|
25
18
|
extensions: []
|
26
|
-
|
27
19
|
extra_rdoc_files: []
|
28
|
-
|
29
|
-
files:
|
20
|
+
files:
|
30
21
|
- Rakefile
|
31
22
|
- VERSION
|
32
23
|
- LICENSE
|
33
24
|
- examples/classic_server.rb
|
25
|
+
- examples/classic_server_ip_info.rb
|
34
26
|
- examples/event_machine_server.rb
|
27
|
+
- examples/ip_info.rb
|
35
28
|
- lib/osc-ruby/address_pattern.rb
|
36
29
|
- lib/osc-ruby/bundle.rb
|
37
30
|
- lib/osc-ruby/client.rb
|
@@ -45,37 +38,42 @@ files:
|
|
45
38
|
- lib/osc-ruby/osc_types.rb
|
46
39
|
- lib/osc-ruby/server.rb
|
47
40
|
- lib/osc-ruby.rb
|
48
|
-
|
41
|
+
- spec/builders/message_builder.rb
|
42
|
+
- spec/spec_helper.rb
|
43
|
+
- spec/unit/address_pattern_spec.rb
|
44
|
+
- spec/unit/message_builder_spec.rb
|
45
|
+
- spec/unit/message_bundle_spec.rb
|
46
|
+
- spec/unit/message_spec.rb
|
47
|
+
- spec/unit/network_packet_spec.rb
|
48
|
+
- spec/unit/osc_argument_spec.rb
|
49
|
+
- spec/unit/osc_complex_packets_spec.rb
|
50
|
+
- spec/unit/osc_simple_packets_spec.rb
|
51
|
+
- spec/unit/osc_types_spec.rb
|
49
52
|
homepage: http://github.com/aberant/osc-ruby
|
50
53
|
licenses: []
|
51
|
-
|
52
54
|
post_install_message:
|
53
55
|
rdoc_options: []
|
54
|
-
|
55
|
-
require_paths:
|
56
|
+
require_paths:
|
56
57
|
- lib
|
57
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
requirements:
|
66
|
-
- -
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
|
69
|
-
- 0
|
70
|
-
version: "0"
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
71
70
|
requirements: []
|
72
|
-
|
73
71
|
rubyforge_project:
|
74
|
-
rubygems_version: 1.
|
72
|
+
rubygems_version: 1.8.24
|
75
73
|
signing_key:
|
76
74
|
specification_version: 3
|
77
75
|
summary: a ruby client for the OSC protocol
|
78
|
-
test_files:
|
76
|
+
test_files:
|
79
77
|
- spec/builders/message_builder.rb
|
80
78
|
- spec/spec_helper.rb
|
81
79
|
- spec/unit/address_pattern_spec.rb
|