osc-ruby 0.6.3 → 0.7.0
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.
- data/LICENSE +19 -0
- data/Rakefile +24 -16
- data/VERSION +1 -0
- data/lib/osc-ruby/em_server.rb +1 -1
- data/lib/osc-ruby/server.rb +35 -35
- metadata +22 -14
- data/README.rdoc +0 -72
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2009 Colin Harris
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -23,23 +23,31 @@ Rake::RDocTask.new do |rdoc|
|
|
23
23
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
24
24
|
end
|
25
25
|
|
26
|
+
require 'rake/packagetask'
|
27
|
+
require 'rake/gempackagetask'
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
39
|
-
end
|
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
40
|
|
41
|
-
|
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
|
42
46
|
|
43
|
-
|
44
|
-
|
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
|
45
53
|
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.7.0
|
data/lib/osc-ruby/em_server.rb
CHANGED
data/lib/osc-ruby/server.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
module OSC
|
2
2
|
class Server
|
3
3
|
|
4
|
-
def initialize(port)
|
4
|
+
def initialize( port )
|
5
5
|
@socket = UDPSocket.new
|
6
|
-
@socket.bind('', port)
|
7
|
-
@
|
6
|
+
@socket.bind( '', port )
|
7
|
+
@matchers = []
|
8
8
|
@queue = Queue.new
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def run
|
12
12
|
start_dispatcher
|
13
|
-
|
13
|
+
|
14
14
|
start_detector
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def stop
|
18
18
|
@socket.close
|
19
19
|
end
|
20
20
|
|
21
|
-
def add_method(address_pattern, &proc)
|
21
|
+
def add_method( address_pattern, &proc )
|
22
22
|
matcher = AddressPattern.new( address_pattern )
|
23
|
-
|
24
|
-
@
|
23
|
+
|
24
|
+
@matchers << [matcher, proc]
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
@@ -33,7 +33,7 @@ private
|
|
33
33
|
Thread.main.raise $!
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def start_dispatcher
|
38
38
|
Thread.fork do
|
39
39
|
begin
|
@@ -44,14 +44,6 @@ private
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def sendmesg(mesg)
|
48
|
-
@cb.each do |matcher, obj|
|
49
|
-
if matcher.match?( mesg.address )
|
50
|
-
obj.call( mesg )
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
47
|
def dispatcher
|
56
48
|
loop do
|
57
49
|
mesg = @queue.pop
|
@@ -59,33 +51,41 @@ private
|
|
59
51
|
end
|
60
52
|
end
|
61
53
|
|
62
|
-
def detector
|
63
|
-
loop do
|
64
|
-
pa, network = @socket.recvfrom(16384)
|
65
|
-
begin
|
66
|
-
|
67
|
-
OSCPacket.messages_from_network(pa).each do |x|
|
68
|
-
@queue.push(x)
|
69
|
-
end
|
70
|
-
|
71
|
-
rescue EOFError
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
54
|
def dispatch_message( message )
|
77
55
|
diff = ( message.time || 0 ) - Time.now.to_ntp
|
78
|
-
|
56
|
+
|
79
57
|
if diff <= 0
|
80
58
|
sendmesg( message)
|
81
59
|
else # spawn a thread to wait until it's time
|
82
60
|
Thread.fork do
|
83
|
-
sleep(diff)
|
84
|
-
sendmesg(mesg)
|
61
|
+
sleep( diff )
|
62
|
+
sendmesg( mesg )
|
85
63
|
Thread.exit
|
86
64
|
end
|
87
65
|
end
|
88
66
|
end
|
89
67
|
|
68
|
+
def sendmesg(mesg)
|
69
|
+
@matchers.each do |matcher, proc|
|
70
|
+
if matcher.match?( mesg.address )
|
71
|
+
proc.call( mesg )
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def detector
|
77
|
+
loop do
|
78
|
+
osc_data, network = @socket.recvfrom( 16384 )
|
79
|
+
begin
|
80
|
+
|
81
|
+
OSCPacket.messages_from_network( osc_data ).each do |message|
|
82
|
+
@queue.push(message)
|
83
|
+
end
|
84
|
+
|
85
|
+
rescue EOFError
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
90
|
end
|
91
91
|
end
|
metadata
CHANGED
@@ -1,31 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osc-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 7
|
8
|
+
- 0
|
9
|
+
version: 0.7.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
|
-
-
|
12
|
+
- Colin Harris
|
8
13
|
autorequire:
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-08-15 00:00:00 -05:00
|
13
18
|
default_executable:
|
14
19
|
dependencies: []
|
15
20
|
|
16
|
-
description:
|
21
|
+
description: This OSC gem originally created by Tadayoshi Funaba has been updated for ruby 1.9/JRuby compatibility
|
17
22
|
email: qzzzq1@gmail.com
|
18
23
|
executables: []
|
19
24
|
|
20
25
|
extensions: []
|
21
26
|
|
22
|
-
extra_rdoc_files:
|
23
|
-
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
24
29
|
files:
|
25
30
|
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- LICENSE
|
26
33
|
- examples/classic_server.rb
|
27
34
|
- examples/event_machine_server.rb
|
28
|
-
- lib/osc-ruby.rb
|
29
35
|
- lib/osc-ruby/address_pattern.rb
|
30
36
|
- lib/osc-ruby/bundle.rb
|
31
37
|
- lib/osc-ruby/client.rb
|
@@ -38,35 +44,37 @@ files:
|
|
38
44
|
- lib/osc-ruby/osc_packet.rb
|
39
45
|
- lib/osc-ruby/osc_types.rb
|
40
46
|
- lib/osc-ruby/server.rb
|
41
|
-
-
|
47
|
+
- lib/osc-ruby.rb
|
42
48
|
has_rdoc: true
|
43
49
|
homepage: http://github.com/aberant/osc-ruby
|
44
50
|
licenses: []
|
45
51
|
|
46
52
|
post_install_message:
|
47
|
-
rdoc_options:
|
48
|
-
|
53
|
+
rdoc_options: []
|
54
|
+
|
49
55
|
require_paths:
|
50
56
|
- lib
|
51
57
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
58
|
requirements:
|
53
59
|
- - ">="
|
54
60
|
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 0
|
55
63
|
version: "0"
|
56
|
-
version:
|
57
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
65
|
requirements:
|
59
66
|
- - ">="
|
60
67
|
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 0
|
61
70
|
version: "0"
|
62
|
-
version:
|
63
71
|
requirements: []
|
64
72
|
|
65
73
|
rubyforge_project:
|
66
|
-
rubygems_version: 1.3.
|
74
|
+
rubygems_version: 1.3.6
|
67
75
|
signing_key:
|
68
76
|
specification_version: 3
|
69
|
-
summary:
|
77
|
+
summary: a ruby client for the OSC protocol
|
70
78
|
test_files:
|
71
79
|
- spec/builders/message_builder.rb
|
72
80
|
- spec/spec_helper.rb
|
data/README.rdoc
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
= An OSC client for Ruby
|
2
|
-
|
3
|
-
http://opensoundcontrol.org/
|
4
|
-
|
5
|
-
== Description
|
6
|
-
|
7
|
-
This OSC gem originally created by Tadayoshi Funaba has been updated for ruby 1.9 compatibility. I've made a point to make this code as expressive as possible and provide a test suite for confident hacking. It also should be flexible enough to support most crazy ideas.
|
8
|
-
|
9
|
-
Compatible with ruby 1.8, 1.9, and jruby
|
10
|
-
|
11
|
-
== Install
|
12
|
-
|
13
|
-
sudo gem install osc-ruby
|
14
|
-
|
15
|
-
for the EMServer, you will need EventMachine
|
16
|
-
|
17
|
-
sudo gem install eventmachine
|
18
|
-
|
19
|
-
== Event Machine example
|
20
|
-
|
21
|
-
# compatible with ruby 1.8, 1.9, and jruby
|
22
|
-
require 'rubygems'
|
23
|
-
require 'osc-ruby'
|
24
|
-
require 'osc-ruby/em_server'
|
25
|
-
|
26
|
-
@server = OSC::EMServer.new( 3333 )
|
27
|
-
@client = OSC::Client.new( 'localhost', 3333 )
|
28
|
-
|
29
|
-
@server.add_method '/greeting' do | message |
|
30
|
-
puts message.to_a
|
31
|
-
end
|
32
|
-
|
33
|
-
Thread.new do
|
34
|
-
@server.run
|
35
|
-
end
|
36
|
-
|
37
|
-
@client.send( OSC::Message.new( "/greeting" , "hullo!" ))
|
38
|
-
|
39
|
-
sleep( 3 )
|
40
|
-
|
41
|
-
== Classic example
|
42
|
-
|
43
|
-
# compatible with ruby 1.8
|
44
|
-
require 'rubygems'
|
45
|
-
require 'osc-ruby'
|
46
|
-
|
47
|
-
|
48
|
-
@server = OSC::Server.new( 3333 )
|
49
|
-
@client = OSC::Client.new( 'localhost', 3333 )
|
50
|
-
|
51
|
-
@server.add_method '/greeting' do | message |
|
52
|
-
puts message.inspect
|
53
|
-
end
|
54
|
-
|
55
|
-
Thread.new do
|
56
|
-
@server.run
|
57
|
-
end
|
58
|
-
|
59
|
-
@client.send( OSC::Message.new( "/greeting", "hullo!" ))
|
60
|
-
|
61
|
-
sleep( 3 )
|
62
|
-
|
63
|
-
|
64
|
-
== Credits
|
65
|
-
|
66
|
-
Originally created by...
|
67
|
-
|
68
|
-
Tadayoshi Funaba
|
69
|
-
|
70
|
-
http://www.funaba.org/en/
|
71
|
-
|
72
|
-
thx also to Toby Tripp and Obtiva
|