micro-osc 0.0.1
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 +13 -0
- data/README.rdoc +74 -0
- data/lib/micro-osc.rb +45 -0
- data/lib/micro-osc/context.rb +59 -0
- data/lib/micro-osc/shorthand.rb +22 -0
- data/lib/micro-osc/state.rb +58 -0
- data/lib/osc.rb +15 -0
- data/test/helper.rb +17 -0
- data/test/test_context.rb +51 -0
- metadata +87 -0
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2011-2012 Ari Russo
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.rdoc
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
= MicroOSC
|
2
|
+
|
3
|
+
A Ruby DSL for OSC
|
4
|
+
|
5
|
+
== Features
|
6
|
+
|
7
|
+
* Works with MRI and JRuby
|
8
|
+
* Network resources are invisible to the user even when shared or multiplexed
|
9
|
+
* Includes shortcuts for common tasks associated with OSC such as translating numeric values from one range to another
|
10
|
+
* Network discoverable using {Zeroconf}[http://en.wikipedia.org/wiki/Zero_configuration_networking]
|
11
|
+
|
12
|
+
== Requirements
|
13
|
+
|
14
|
+
Ruby (MRI) 1.9.2+ or JRuby (in 1.9 mode)
|
15
|
+
|
16
|
+
{eventmachine}[http://github.com/eventmachine/eventmachine] (version 0.12.8 recommended for MRI)
|
17
|
+
|
18
|
+
{osc-access}[http://github.com/arirusso/osc-access]
|
19
|
+
|
20
|
+
{osc-ruby}[http://github.com/aberant/osc-ruby]
|
21
|
+
|
22
|
+
(These should install automatically with the gem)
|
23
|
+
|
24
|
+
For Zeroconf support, {dnssd}[http://github.com/tenderlove/dnssd] is required.
|
25
|
+
|
26
|
+
== Installation
|
27
|
+
|
28
|
+
gem install micro-osc
|
29
|
+
|
30
|
+
== Usage
|
31
|
+
|
32
|
+
The following are two MicroOSC programs; the first will receive OSC messages and the second will send one. Run them in two separate windows and they will talk to each other.
|
33
|
+
|
34
|
+
Here's the receiver...
|
35
|
+
|
36
|
+
require "osc"
|
37
|
+
|
38
|
+
OSC.using(:input_port => 8000) do
|
39
|
+
|
40
|
+
receive("/greeting") { |val| p "received #{val}" }
|
41
|
+
|
42
|
+
p "Ready to receive OSC messages on port(s) #{input_ports.join(', ')}..."
|
43
|
+
|
44
|
+
wait_for_input
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
When you run this, You should see confirmation that the program is running "Ready to receive OSC..." in your Ruby console.
|
49
|
+
|
50
|
+
Next, in another window run this the client program:
|
51
|
+
|
52
|
+
require "osc"
|
53
|
+
|
54
|
+
OSC.using(:output => { :host => "localhost", :port => 8000 }) do
|
55
|
+
|
56
|
+
out "/greeting", "hullo!"
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
After running it, flip back to the first receiver program and see "received hullo!", confirming that these two programs could reach each other.
|
61
|
+
|
62
|
+
Note that a single MicroOSC block can act as a client and receiver, both sending and receiving OSC ({see here...}[http://github.com/arirusso/micro-osc/blob/master/examples/duplex.rb])
|
63
|
+
|
64
|
+
These examples and more are available {here}[http://github.com/arirusso/micro-osc/tree/master/examples]
|
65
|
+
|
66
|
+
== Other Documentation
|
67
|
+
|
68
|
+
* {rdoc}[http://rubydoc.info/github/arirusso/micro-osc]
|
69
|
+
|
70
|
+
== License
|
71
|
+
|
72
|
+
Licensed under Apache 2.0, See the file LICENSE
|
73
|
+
|
74
|
+
Copyright © 2011-2012 Ari Russo
|
data/lib/micro-osc.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# MicroOSC
|
4
|
+
# A Ruby DSL for OSC
|
5
|
+
# (c)2011 Ari Russo and licensed under the Apache 2.0 License
|
6
|
+
#
|
7
|
+
|
8
|
+
# libs
|
9
|
+
require "forwardable"
|
10
|
+
require "osc-access"
|
11
|
+
|
12
|
+
# modules
|
13
|
+
|
14
|
+
# classes
|
15
|
+
require "micro-osc/context"
|
16
|
+
require "micro-osc/state"
|
17
|
+
|
18
|
+
module MicroOSC
|
19
|
+
|
20
|
+
VERSION = "0.0.1"
|
21
|
+
|
22
|
+
def self.message(options = {}, &block)
|
23
|
+
MicroOSC::Context.new(options, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
class << self
|
27
|
+
alias_method :using, :message
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
# define this module again to avoid overwriting another OSC module
|
33
|
+
module OSC
|
34
|
+
|
35
|
+
def self.message(*a, &block)
|
36
|
+
MicroOSC.using(*a, &block)
|
37
|
+
end
|
38
|
+
|
39
|
+
class << self
|
40
|
+
alias_method :using, :message
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
require "micro-osc/shorthand"
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
|
4
|
+
module MicroOSC
|
5
|
+
|
6
|
+
class Context
|
7
|
+
|
8
|
+
include OSCAccessible
|
9
|
+
|
10
|
+
extend Forwardable
|
11
|
+
|
12
|
+
attr_reader :state
|
13
|
+
|
14
|
+
def_delegator :state, :output_cache, :cache
|
15
|
+
|
16
|
+
alias_method :output, :osc_send
|
17
|
+
alias_method :receive, :osc_receive
|
18
|
+
|
19
|
+
def initialize(options = {}, &block)
|
20
|
+
@state = State.new
|
21
|
+
osc_start(options.merge({}))
|
22
|
+
edit(&block) if block_given?
|
23
|
+
end
|
24
|
+
|
25
|
+
# open a block for editing/live coding in this Context
|
26
|
+
def edit(&block)
|
27
|
+
self.instance_eval(&block)
|
28
|
+
end
|
29
|
+
|
30
|
+
def receive(pattern, options = {}, &block)
|
31
|
+
osc_receive(pattern, options) { |target_obj, val| yield(val) }
|
32
|
+
sleep(0.01)
|
33
|
+
end
|
34
|
+
|
35
|
+
# repeat the last command
|
36
|
+
def repeat
|
37
|
+
self.send(@state.last_command[:method], *@state.last_command[:args]) unless @state.last_command.nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
# shortcut to an array of port numbers
|
41
|
+
def input_ports
|
42
|
+
@osc_receiver.servers.keys
|
43
|
+
end
|
44
|
+
|
45
|
+
def method_missing(m, *a, &b)
|
46
|
+
outp = nil
|
47
|
+
options = a.last.kind_of?(Hash) ? a.last : {}
|
48
|
+
do_output = options[:output] || true
|
49
|
+
outp = super
|
50
|
+
@state.record(m, a, b, outp)
|
51
|
+
end
|
52
|
+
|
53
|
+
def join(options = {})
|
54
|
+
osc_join(options)
|
55
|
+
end
|
56
|
+
alias_method :wait_for_input, :join
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
|
4
|
+
module MicroOSC
|
5
|
+
|
6
|
+
alias l loop
|
7
|
+
|
8
|
+
class << self
|
9
|
+
alias_method :m, :message
|
10
|
+
end
|
11
|
+
|
12
|
+
class Context
|
13
|
+
alias_method :o, :output
|
14
|
+
alias_method :out, :output
|
15
|
+
alias_method :r, :repeat
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def O(*a, &block)
|
21
|
+
OSC.message(*a, &block)
|
22
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
module MicroOSC
|
4
|
+
|
5
|
+
class State
|
6
|
+
|
7
|
+
Default = {
|
8
|
+
:channel => 0,
|
9
|
+
:octave => 2,
|
10
|
+
:velocity => 100
|
11
|
+
}
|
12
|
+
|
13
|
+
attr_accessor :auto_output,
|
14
|
+
:pattern,
|
15
|
+
:super_sticky
|
16
|
+
|
17
|
+
attr_reader :last_command,
|
18
|
+
:output_cache
|
19
|
+
|
20
|
+
def initialize(options = {})
|
21
|
+
@auto_output = true
|
22
|
+
@last_command = nil
|
23
|
+
@super_sticky = false
|
24
|
+
|
25
|
+
@channel = options[:channel] || Default[:channel]
|
26
|
+
@velocity = options[:velocity] || Default[:velocity]
|
27
|
+
@octave = options[:octave] || Default[:octave]
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def record(m, a, b, outp)
|
32
|
+
ts = now
|
33
|
+
@output_cache << { :message => outp, :timestamp => ts }
|
34
|
+
@last_command = { :method => m, :args => a, :block => b, :timestamp => ts }
|
35
|
+
end
|
36
|
+
|
37
|
+
def toggle_super_sticky
|
38
|
+
@super_sticky = !@super_sticky
|
39
|
+
end
|
40
|
+
|
41
|
+
def toggle_auto_output
|
42
|
+
@auto_output = !@auto_output
|
43
|
+
end
|
44
|
+
|
45
|
+
def message_properties(opts, *props)
|
46
|
+
output = {}
|
47
|
+
props.each do |prop|
|
48
|
+
output[prop] = opts[prop]
|
49
|
+
self.send("#{prop.to_s}=", output[prop]) if !output[prop].nil? && (self.send(prop).nil? || @super_sticky)
|
50
|
+
output[prop] ||= self.send(prop.to_s)
|
51
|
+
end
|
52
|
+
output
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/lib/osc.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# micromidi
|
4
|
+
# A Ruby DSL for OSC
|
5
|
+
#
|
6
|
+
# (c)2011 Ari Russo
|
7
|
+
# licensed under the Apache 2.0 License
|
8
|
+
#
|
9
|
+
|
10
|
+
# the purpose of this file is just to allow both
|
11
|
+
# <em>require "micro-osc"</em>
|
12
|
+
# and
|
13
|
+
# <em>require "osc"</em>
|
14
|
+
|
15
|
+
require 'micro-osc'
|
data/test/helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
dir = File.dirname(File.expand_path(__FILE__))
|
4
|
+
$LOAD_PATH.unshift dir + '/../lib'
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
require 'micro-osc'
|
8
|
+
|
9
|
+
module TestHelper
|
10
|
+
|
11
|
+
$port_counter = 8000
|
12
|
+
|
13
|
+
def self.next_port
|
14
|
+
$port_counter += 1
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
class ContextTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include MicroOSC
|
8
|
+
include TestHelper
|
9
|
+
|
10
|
+
def test_output
|
11
|
+
sleep(0.5)
|
12
|
+
received = nil
|
13
|
+
port = TestHelper.next_port
|
14
|
+
|
15
|
+
server = OSC::EMServer.new(port)
|
16
|
+
server.add_method("/test_output") do |message|
|
17
|
+
received = message.args[0]
|
18
|
+
end
|
19
|
+
Thread.new { server.run }
|
20
|
+
|
21
|
+
sleep(0.5)
|
22
|
+
|
23
|
+
OSC.using(:output => { :port => port, :host => "localhost" }) do
|
24
|
+
output("/test_output", "hi friend")
|
25
|
+
end
|
26
|
+
|
27
|
+
sleep(0.5)
|
28
|
+
|
29
|
+
assert_equal("hi friend", received)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_input
|
33
|
+
sleep(0.5)
|
34
|
+
received = nil
|
35
|
+
port = TestHelper.next_port
|
36
|
+
|
37
|
+
OSC.using(:input_port => port) do
|
38
|
+
receive("/test_input") do |val|
|
39
|
+
received = val
|
40
|
+
end
|
41
|
+
end
|
42
|
+
sleep(0.5)
|
43
|
+
|
44
|
+
client = OSC::Client.new("localhost", port)
|
45
|
+
client.send( OSC::Message.new( "/test_input", "hullo from test_input!"))
|
46
|
+
sleep(0.5)
|
47
|
+
|
48
|
+
assert_equal("hullo from test_input!", received)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: micro-osc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ari Russo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-17 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: eventmachine
|
16
|
+
requirement: &70257285738520 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70257285738520
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: osc-access
|
27
|
+
requirement: &70257285769300 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70257285769300
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: osc-ruby
|
38
|
+
requirement: &70257285768880 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70257285768880
|
47
|
+
description: A Ruby DSL for OSC
|
48
|
+
email:
|
49
|
+
- ari.russo@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- lib/micro-osc/context.rb
|
55
|
+
- lib/micro-osc/shorthand.rb
|
56
|
+
- lib/micro-osc/state.rb
|
57
|
+
- lib/micro-osc.rb
|
58
|
+
- lib/osc.rb
|
59
|
+
- test/helper.rb
|
60
|
+
- test/test_context.rb
|
61
|
+
- LICENSE
|
62
|
+
- README.rdoc
|
63
|
+
homepage: http://github.com/arirusso/micro-osc
|
64
|
+
licenses: []
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.3.6
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project: osc-access
|
83
|
+
rubygems_version: 1.8.17
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: A Ruby DSL for OSC
|
87
|
+
test_files: []
|