patch 0.4.13
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 +7 -0
- data/LICENSE +13 -0
- data/README.md +176 -0
- data/bin/patchrb +40 -0
- data/lib/patch/config.rb +124 -0
- data/lib/patch/em_patch.rb +47 -0
- data/lib/patch/hub.rb +68 -0
- data/lib/patch/io/midi/action.rb +42 -0
- data/lib/patch/io/midi/input.rb +110 -0
- data/lib/patch/io/midi/message.rb +112 -0
- data/lib/patch/io/midi/output.rb +58 -0
- data/lib/patch/io/midi.rb +45 -0
- data/lib/patch/io/module.rb +35 -0
- data/lib/patch/io/osc/action.rb +43 -0
- data/lib/patch/io/osc/client.rb +60 -0
- data/lib/patch/io/osc/message.rb +109 -0
- data/lib/patch/io/osc/server.rb +159 -0
- data/lib/patch/io/osc.rb +43 -0
- data/lib/patch/io/websocket/node.rb +103 -0
- data/lib/patch/io/websocket/socket.rb +103 -0
- data/lib/patch/io/websocket.rb +27 -0
- data/lib/patch/io.rb +15 -0
- data/lib/patch/log.rb +97 -0
- data/lib/patch/message.rb +67 -0
- data/lib/patch/node/container.rb +69 -0
- data/lib/patch/node/map.rb +71 -0
- data/lib/patch/node.rb +10 -0
- data/lib/patch/patch.rb +59 -0
- data/lib/patch/report.rb +132 -0
- data/lib/patch/thread.rb +19 -0
- data/lib/patch.rb +42 -0
- data/test/config/nodes.yml +16 -0
- data/test/config/patches.yml +41 -0
- data/test/config_test.rb +216 -0
- data/test/helper.rb +20 -0
- data/test/hub_test.rb +49 -0
- data/test/io/midi/action_test.rb +82 -0
- data/test/io/midi/input_test.rb +130 -0
- data/test/io/midi/message_test.rb +54 -0
- data/test/io/midi/output_test.rb +44 -0
- data/test/io/midi_test.rb +94 -0
- data/test/io/module_test.rb +21 -0
- data/test/io/osc/action_test.rb +76 -0
- data/test/io/osc/client_test.rb +49 -0
- data/test/io/osc/message_test.rb +53 -0
- data/test/io/osc/server_test.rb +116 -0
- data/test/io/osc_test.rb +111 -0
- data/test/io/websocket/node_test.rb +96 -0
- data/test/io/websocket_test.rb +37 -0
- data/test/js/logger.js +67 -0
- data/test/js/message.js +62 -0
- data/test/js/qunit-1.18.0.js +3828 -0
- data/test/js/qunit.css +291 -0
- data/test/js/test.html +15 -0
- data/test/js/websocket.js +12 -0
- data/test/log_test.rb +96 -0
- data/test/message_test.rb +109 -0
- data/test/node/container_test.rb +104 -0
- data/test/node/map_test.rb +50 -0
- data/test/node_test.rb +14 -0
- data/test/patch_test.rb +57 -0
- data/test/report_test.rb +37 -0
- metadata +320 -0
@@ -0,0 +1,130 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class Patch::IO::MIDI::InputTest < Minitest::Test
|
4
|
+
|
5
|
+
context "Input" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
load_test_data
|
9
|
+
@nodes = Patch::Config.to_nodes(@nodes_path)
|
10
|
+
@patches = Patch::Config.to_patches(@nodes, @patches_path)
|
11
|
+
@input = @nodes.find_all_by_type(:midi).first
|
12
|
+
end
|
13
|
+
|
14
|
+
context "#initialize" do
|
15
|
+
|
16
|
+
should "have id" do
|
17
|
+
refute_nil @input.id
|
18
|
+
end
|
19
|
+
|
20
|
+
should "have midi input" do
|
21
|
+
refute_nil @input
|
22
|
+
end
|
23
|
+
|
24
|
+
should "initialize midi listener" do
|
25
|
+
refute_nil @input.instance_variable_get("@listener")
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
context "#start" do
|
31
|
+
|
32
|
+
setup do
|
33
|
+
::MIDIEye::Listener.any_instance.expects(:run)
|
34
|
+
end
|
35
|
+
|
36
|
+
teardown do
|
37
|
+
::MIDIEye::Listener.any_instance.unstub(:run)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "start listener" do
|
41
|
+
@input.start
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
context "#stop" do
|
47
|
+
|
48
|
+
setup do
|
49
|
+
refute @input.listener.running?
|
50
|
+
@input.start
|
51
|
+
assert @input.listener.running?
|
52
|
+
end
|
53
|
+
|
54
|
+
should "stop listener" do
|
55
|
+
assert @input.stop
|
56
|
+
sleep(0.5) # wait until listener thread is killed
|
57
|
+
refute @input.listener.running?
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
context "#handle_event_received" do
|
63
|
+
|
64
|
+
setup do
|
65
|
+
@message = MIDIMessage::ControlChange.new(0, 0x00, 0x30)
|
66
|
+
@patch = @patches.first
|
67
|
+
@scale = Object.new
|
68
|
+
@scale.expects(:from).once.returns(@scale)
|
69
|
+
@scale.expects(:to).once
|
70
|
+
end
|
71
|
+
|
72
|
+
teardown do
|
73
|
+
@scale.unstub(:from)
|
74
|
+
@scale.unstub(:to)
|
75
|
+
end
|
76
|
+
|
77
|
+
context "message value" do
|
78
|
+
|
79
|
+
setup do
|
80
|
+
Scale.expects(:transform).once.returns(@scale)
|
81
|
+
end
|
82
|
+
|
83
|
+
teardown do
|
84
|
+
Scale.unstub(:transform)
|
85
|
+
end
|
86
|
+
|
87
|
+
should "perform scaling on value" do
|
88
|
+
@result = @input.send(:handle_event_received, @patch, { :message => @message })
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
context "messages" do
|
94
|
+
|
95
|
+
should "return array of messages" do
|
96
|
+
@result = @input.send(:handle_event_received, @patch, { :message => @message })
|
97
|
+
refute_nil @result
|
98
|
+
assert_equal Array, @result.class
|
99
|
+
refute_empty @result
|
100
|
+
|
101
|
+
@result.each do |message|
|
102
|
+
assert_equal ::Patch::Message, message.class
|
103
|
+
assert_equal :test_patch, message.patch_name
|
104
|
+
refute_nil message.index
|
105
|
+
refute_nil message.value
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
should "yield array of messages" do
|
110
|
+
@input.send(:handle_event_received, @patch, { :message => @message }) do |hash|
|
111
|
+
@result = hash
|
112
|
+
refute_nil @result
|
113
|
+
assert_equal Array, @result.class
|
114
|
+
refute_empty @result
|
115
|
+
|
116
|
+
@result.each do |message|
|
117
|
+
assert_equal ::Patch::Message, message.class
|
118
|
+
assert_equal :test_patch, message.patch_name
|
119
|
+
refute_nil message.index
|
120
|
+
refute_nil message.value
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class Patch::IO::MIDI::MessageTest < Minitest::Test
|
4
|
+
|
5
|
+
|
6
|
+
context "Message" do
|
7
|
+
|
8
|
+
setup do
|
9
|
+
load_test_data
|
10
|
+
@nodes = Patch::Config.to_nodes(@nodes_path)
|
11
|
+
@patches = Patch::Config.to_patches(@nodes, @patches_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
context ".to_midi_messages" do
|
15
|
+
|
16
|
+
setup do
|
17
|
+
@message = Patch::Message.new(:index => 0, :patch_name => @patches.first.name, :value => 3.0)
|
18
|
+
@result = ::Patch::IO::MIDI::Message.to_midi_messages(@patches.first, @message)
|
19
|
+
end
|
20
|
+
|
21
|
+
should "have correct properties" do
|
22
|
+
refute_nil @result
|
23
|
+
refute_empty @result
|
24
|
+
message = @result.first
|
25
|
+
|
26
|
+
assert_equal ::MIDIMessage::ControlChange, message.class
|
27
|
+
assert_equal 0, message.index
|
28
|
+
assert_equal 75, message.value
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
context ".to_patch_messages" do
|
34
|
+
|
35
|
+
setup do
|
36
|
+
@message = MIDIMessage::ControlChange.new(0, 0, 127)
|
37
|
+
@result = ::Patch::IO::MIDI::Message.to_patch_messages(@patches.first, @message)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "have correct values" do
|
41
|
+
refute_nil @result
|
42
|
+
refute_empty @result
|
43
|
+
message = @result.first
|
44
|
+
|
45
|
+
assert_equal ::Patch::Message, message.class
|
46
|
+
assert_equal 0, message.index
|
47
|
+
assert_equal 5, message.value
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class Patch::IO::MIDI::OutputTest < Minitest::Test
|
4
|
+
|
5
|
+
context "Output" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
load_test_data
|
9
|
+
@nodes = Patch::Config.to_nodes(@nodes_path)
|
10
|
+
@patches = Patch::Config.to_patches(@nodes, @patches_path)
|
11
|
+
@patch = @patches.first
|
12
|
+
@output = ::Patch::IO::MIDI::Output.new(0, $>)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "#initialize" do
|
16
|
+
|
17
|
+
should "have id" do
|
18
|
+
refute_nil @output.id
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
context "#puts" do
|
24
|
+
|
25
|
+
setup do
|
26
|
+
@message = Patch::Message.new
|
27
|
+
@message.index = 0
|
28
|
+
@message.value = 100
|
29
|
+
@message.patch_name = @patch.name
|
30
|
+
@output.device.expects(:puts).once
|
31
|
+
end
|
32
|
+
|
33
|
+
teardown do
|
34
|
+
@output.device.unstub(:puts)
|
35
|
+
end
|
36
|
+
|
37
|
+
should "send midi message" do
|
38
|
+
@output.puts(@patch, @message)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class Patch::IO::MIDITest < Minitest::Test
|
4
|
+
|
5
|
+
context "MIDI" do
|
6
|
+
|
7
|
+
context "#get_direction_class" do
|
8
|
+
|
9
|
+
should "return input class" do
|
10
|
+
assert_equal Patch::IO::MIDI::Input, Patch::IO::MIDI.send(:get_direction_class, "input")
|
11
|
+
assert_equal Patch::IO::MIDI::Input, Patch::IO::MIDI.send(:get_direction_class, :input)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "return output class" do
|
15
|
+
assert_equal Patch::IO::MIDI::Output, Patch::IO::MIDI.send(:get_direction_class, "output")
|
16
|
+
assert_equal Patch::IO::MIDI::Output, Patch::IO::MIDI.send(:get_direction_class, :output)
|
17
|
+
end
|
18
|
+
|
19
|
+
should "return nil" do
|
20
|
+
assert_nil Patch::IO::MIDI.send(:get_direction_class, "blah")
|
21
|
+
assert_nil Patch::IO::MIDI.send(:get_direction_class, :blah)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
context "#new_from_config" do
|
27
|
+
|
28
|
+
context "input" do
|
29
|
+
|
30
|
+
setup do
|
31
|
+
@config = {
|
32
|
+
:id=>2,
|
33
|
+
:type=>"midi",
|
34
|
+
:direction=>"input",
|
35
|
+
:name=>"Apple Inc. IAC Driver"
|
36
|
+
}
|
37
|
+
@input = Patch::IO::MIDI.new_from_config(@config)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "be input" do
|
41
|
+
refute_nil @input
|
42
|
+
assert_equal Patch::IO::MIDI::Input, @input.class
|
43
|
+
end
|
44
|
+
|
45
|
+
should "have id" do
|
46
|
+
refute_nil @input.id
|
47
|
+
assert_equal 2, @input.id
|
48
|
+
end
|
49
|
+
|
50
|
+
should "have underlying midi input" do
|
51
|
+
refute_nil @input.device
|
52
|
+
assert_equal @config[:name], @input.device.name
|
53
|
+
end
|
54
|
+
|
55
|
+
should "initialize midi listener" do
|
56
|
+
refute_nil @input.instance_variable_get("@listener")
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
context "output" do
|
63
|
+
|
64
|
+
setup do
|
65
|
+
@config = {
|
66
|
+
:id=>3,
|
67
|
+
:type=>"midi",
|
68
|
+
:direction=>"output",
|
69
|
+
:name=>"Apple Inc. IAC Driver"
|
70
|
+
}
|
71
|
+
@output = ::Patch::IO::MIDI.new_from_config(@config)
|
72
|
+
end
|
73
|
+
|
74
|
+
should "be output" do
|
75
|
+
refute_nil @output
|
76
|
+
assert_equal Patch::IO::MIDI::Output, @output.class
|
77
|
+
end
|
78
|
+
|
79
|
+
should "have id" do
|
80
|
+
refute_nil @output.id
|
81
|
+
assert_equal 3, @output.id
|
82
|
+
end
|
83
|
+
|
84
|
+
should "have underlying midi output" do
|
85
|
+
refute_nil @output.device
|
86
|
+
assert_equal @config[:name], @output.device.name
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class Patch::IO::ModuleTest < Minitest::Test
|
4
|
+
|
5
|
+
context "Module" do
|
6
|
+
|
7
|
+
context ".all" do
|
8
|
+
|
9
|
+
should "contain modules" do
|
10
|
+
modules = Patch::IO::Module.all
|
11
|
+
refute_nil modules
|
12
|
+
refute_empty modules
|
13
|
+
assert modules.all? { |mod| mod.kind_of?(Module) }
|
14
|
+
assert modules.all? { |mod| mod.name.match(/\APatch\:\:IO/) }
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class Patch::IO::OSC::ActionTest < Minitest::Test
|
4
|
+
|
5
|
+
context "Action" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@actions = [
|
9
|
+
{
|
10
|
+
:name=>"Volume",
|
11
|
+
:key=>"volume",
|
12
|
+
:default=> {
|
13
|
+
:scale=>0..2.0
|
14
|
+
},
|
15
|
+
:midi => {
|
16
|
+
:channel=>4,
|
17
|
+
:index=>7
|
18
|
+
}
|
19
|
+
},
|
20
|
+
{
|
21
|
+
:name=>"Z Depth",
|
22
|
+
:key=>"zDepth",
|
23
|
+
:default=>{
|
24
|
+
:scale=>0..1000
|
25
|
+
},
|
26
|
+
:osc=>{
|
27
|
+
:address=>"\\A/1/faderA\\z",
|
28
|
+
:scale=> {
|
29
|
+
:osc=>0..1.0
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
]
|
34
|
+
end
|
35
|
+
|
36
|
+
context "#osc?" do
|
37
|
+
|
38
|
+
should "return true for actions with osc" do
|
39
|
+
assert Patch::IO::OSC::Action.osc?(@actions[1])
|
40
|
+
end
|
41
|
+
|
42
|
+
should "return false for actions without osc" do
|
43
|
+
refute Patch::IO::OSC::Action.osc?(@actions[0])
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
context "#osc_actions" do
|
49
|
+
|
50
|
+
should "return only osc actions" do
|
51
|
+
actions = Patch::IO::OSC::Action.osc_actions(@actions)
|
52
|
+
refute_nil actions
|
53
|
+
refute_empty actions
|
54
|
+
assert_equal 1, actions.size
|
55
|
+
assert_equal @actions[1], actions.first
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
context "#find_by_address" do
|
61
|
+
|
62
|
+
should "return action with address" do
|
63
|
+
addy = "/1/faderA"
|
64
|
+
action = Patch::IO::OSC::Action.find_by_address(@actions, addy)
|
65
|
+
refute_nil action
|
66
|
+
assert_match addy, action[:osc][:address]
|
67
|
+
end
|
68
|
+
|
69
|
+
should "return nil if not found" do
|
70
|
+
assert_nil Patch::IO::OSC::Action.find_by_address(@actions, "/1/faderZ")
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class Patch::IO::OSC::ClientTest < Minitest::Test
|
4
|
+
|
5
|
+
context "Client" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
load_test_data
|
9
|
+
@nodes = Patch::Config.to_nodes(@nodes_path)
|
10
|
+
@patches = Patch::Config.to_patches(@nodes, @patches_path)
|
11
|
+
@client = ::Patch::IO::OSC::Client.new("blah", 9000)
|
12
|
+
end
|
13
|
+
|
14
|
+
context "#puts" do
|
15
|
+
|
16
|
+
setup do
|
17
|
+
@resource = @client.instance_variable_get("@client")
|
18
|
+
@resource.expects(:send).once
|
19
|
+
end
|
20
|
+
|
21
|
+
context "osc message" do
|
22
|
+
|
23
|
+
setup do
|
24
|
+
@message = ::OSC::Message.new( "/1/rotaryA" , 0.5)
|
25
|
+
end
|
26
|
+
|
27
|
+
should "send message to underlying client" do
|
28
|
+
assert @client.puts(@patches.first, @message)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
context "patch message" do
|
34
|
+
|
35
|
+
setup do
|
36
|
+
@message = Patch::Message.new(:index => 0, :patch_name => @patches.first.name, :value => 5)
|
37
|
+
end
|
38
|
+
|
39
|
+
should "send message to underlying client" do
|
40
|
+
assert @client.puts(@patches.first, @message)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class Patch::IO::OSC::MessageTest < Minitest::Test
|
4
|
+
|
5
|
+
context "Message" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
load_test_data
|
9
|
+
@nodes = Patch::Config.to_nodes(@nodes_path)
|
10
|
+
@patches = Patch::Config.to_patches(@nodes, @patches_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
context ".to_osc_messages" do
|
14
|
+
|
15
|
+
setup do
|
16
|
+
@message = Patch::Message.new(:index => 0, :patch_name => @patches.first.name, :value => 5)
|
17
|
+
@result = ::Patch::IO::OSC::Message.to_osc_messages(@patches.first, @message)
|
18
|
+
end
|
19
|
+
|
20
|
+
should "have correct properties" do
|
21
|
+
refute_nil @result
|
22
|
+
refute_empty @result
|
23
|
+
message = @result.first
|
24
|
+
|
25
|
+
assert_equal ::OSC::Message, message.class
|
26
|
+
assert_equal "/1/rotaryA", message.address
|
27
|
+
assert_equal 1, message.to_a[0]
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
context ".to_patch_messages" do
|
33
|
+
|
34
|
+
setup do
|
35
|
+
@message = ::OSC::Message.new("/1/rotaryA", 1)
|
36
|
+
@result = ::Patch::IO::OSC::Message.to_patch_messages(@patches.first, @message)
|
37
|
+
end
|
38
|
+
|
39
|
+
should "have correct values" do
|
40
|
+
refute_nil @result
|
41
|
+
refute_empty @result
|
42
|
+
message = @result.first
|
43
|
+
|
44
|
+
assert_equal ::Patch::Message, message.class
|
45
|
+
assert_equal 0, message.index
|
46
|
+
assert_equal 5, message.value
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class Patch::IO::OSC::ServerTest < Minitest::Test
|
4
|
+
|
5
|
+
context "Server" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
load_test_data
|
9
|
+
@nodes = Patch::Config.to_nodes(@nodes_path)
|
10
|
+
@patches = Patch::Config.to_patches(@nodes, @patches_path)
|
11
|
+
@nodes = Patch::Config.to_nodes(@nodes_path)
|
12
|
+
@server = @nodes.find_all_by_type(:osc).first
|
13
|
+
@server.instance_variable_get("@server").stubs(:run).returns(:true)
|
14
|
+
end
|
15
|
+
|
16
|
+
teardown do
|
17
|
+
@server.instance_variable_get("@server").unstub(:run)
|
18
|
+
end
|
19
|
+
|
20
|
+
context "#initialize" do
|
21
|
+
|
22
|
+
should "have id" do
|
23
|
+
refute_nil @server.id
|
24
|
+
end
|
25
|
+
|
26
|
+
should "initialize client" do
|
27
|
+
refute_nil @server.instance_variable_get("@client")
|
28
|
+
end
|
29
|
+
|
30
|
+
should "initialize server" do
|
31
|
+
refute_nil @server.instance_variable_get("@server")
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
context "#handle_message_received" do
|
37
|
+
|
38
|
+
setup do
|
39
|
+
@client = @server.instance_variable_get("@client").instance_variable_get("@client")
|
40
|
+
@message = ::OSC::Message.new( "/1/rotaryA" , 0.5)
|
41
|
+
@patch = @patches.first
|
42
|
+
@client.expects(:send).once.with(@message)
|
43
|
+
@scale = Object.new
|
44
|
+
@scale.expects(:from).once.returns(@scale)
|
45
|
+
@scale.expects(:to).once
|
46
|
+
end
|
47
|
+
|
48
|
+
teardown do
|
49
|
+
@client.unstub(:send)
|
50
|
+
@scale.unstub(:from)
|
51
|
+
@scale.unstub(:to)
|
52
|
+
end
|
53
|
+
|
54
|
+
should "return array of messages" do
|
55
|
+
@results = @server.send(:handle_message_received, @patch, @message)
|
56
|
+
refute_nil @results
|
57
|
+
assert_equal Array, @results.class
|
58
|
+
refute_empty @results
|
59
|
+
|
60
|
+
@results.each do |message|
|
61
|
+
assert_equal Patch::Message, message.class
|
62
|
+
assert_equal :test_patch, message.patch_name
|
63
|
+
refute_nil message.index
|
64
|
+
refute_nil message.value
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
should "yield array of messages" do
|
69
|
+
@server.send(:handle_message_received, @patch, @message) do |messages|
|
70
|
+
@results = messages
|
71
|
+
refute_nil @results
|
72
|
+
assert_equal Array, @results.class
|
73
|
+
refute_empty @results
|
74
|
+
|
75
|
+
@results.each do |message|
|
76
|
+
assert_equal Patch::Message, message.class
|
77
|
+
assert_equal :test_patch, message.patch_name
|
78
|
+
refute_nil message.index
|
79
|
+
refute_nil message.value
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
should "scale value" do
|
85
|
+
@results = @server.send(:handle_message_received, @patch, @message)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "#start" do
|
90
|
+
|
91
|
+
should "start server" do
|
92
|
+
server = @server.instance_variable_get("@server")
|
93
|
+
server.expects(:run)
|
94
|
+
@server.start
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
context "#listen" do
|
100
|
+
|
101
|
+
setup do
|
102
|
+
@patch = @patches.first
|
103
|
+
end
|
104
|
+
|
105
|
+
should "bind addresses" do
|
106
|
+
resource = @server.instance_variable_get("@server")
|
107
|
+
osc_actions = Patch::IO::OSC::Action.osc_actions(@patch.actions)
|
108
|
+
resource.expects(:add_address).times(osc_actions.count)
|
109
|
+
assert @server.listen(@patch)
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|