scruby 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +53 -0
- data/README.rdoc +65 -0
- data/Rakefile +10 -0
- data/TODO.markdown +3 -0
- data/examples/example.rb +73 -0
- data/lib/scruby/buffer.rb +153 -0
- data/lib/scruby/bus.rb +67 -0
- data/lib/scruby/control_name.rb +29 -0
- data/lib/scruby/core_ext/array.rb +44 -0
- data/lib/scruby/core_ext/delegator_array.rb +44 -0
- data/lib/scruby/core_ext/fixnum.rb +8 -0
- data/lib/scruby/core_ext/numeric.rb +25 -0
- data/lib/scruby/core_ext/object.rb +23 -0
- data/lib/scruby/core_ext/proc.rb +11 -0
- data/lib/scruby/core_ext/string.rb +5 -0
- data/lib/scruby/core_ext/symbol.rb +5 -0
- data/lib/scruby/core_ext/typed_array.rb +54 -0
- data/lib/scruby/env.rb +93 -0
- data/lib/scruby/group.rb +24 -0
- data/lib/scruby/node.rb +102 -0
- data/lib/scruby/server.rb +182 -0
- data/lib/scruby/synth.rb +50 -0
- data/lib/scruby/synthdef.rb +109 -0
- data/lib/scruby/ticker.rb +92 -0
- data/lib/scruby/ugens/buffer_read_write.rb +98 -0
- data/lib/scruby/ugens/demand.rb +9 -0
- data/lib/scruby/ugens/disk_in_out.rb +33 -0
- data/lib/scruby/ugens/env_gen.rb +38 -0
- data/lib/scruby/ugens/in_out.rb +46 -0
- data/lib/scruby/ugens/multi_out.rb +53 -0
- data/lib/scruby/ugens/operation_indices.yaml +92 -0
- data/lib/scruby/ugens/operation_ugens.rb +63 -0
- data/lib/scruby/ugens/panner.rb +137 -0
- data/lib/scruby/ugens/ugen.rb +173 -0
- data/lib/scruby/ugens/ugen_defs.yaml +3123 -0
- data/lib/scruby/ugens/ugen_operations.rb +57 -0
- data/lib/scruby/ugens/ugens.rb +95 -0
- data/lib/scruby/version.rb +3 -0
- data/lib/scruby.rb +65 -0
- data/scruby.gemspec +27 -0
- data/spec/buffer_read_write_spec.rb +333 -0
- data/spec/buffer_spec.rb +199 -0
- data/spec/bus_spec.rb +184 -0
- data/spec/core_ext/core_ext_spec.rb +120 -0
- data/spec/core_ext/delegator_array_spec.rb +144 -0
- data/spec/core_ext/typed_array_spec.rb +95 -0
- data/spec/demand_spec.rb +81 -0
- data/spec/disk_in_out_spec.rb +138 -0
- data/spec/env_gen_spec.rb +23 -0
- data/spec/env_spec.rb +73 -0
- data/spec/group_spec.rb +71 -0
- data/spec/helper.rb +20 -0
- data/spec/in_out_spec.rb +127 -0
- data/spec/integration_spec.rb +88 -0
- data/spec/multiout_ugen_spec.rb +86 -0
- data/spec/node_spec.rb +112 -0
- data/spec/operation_ugens_spec.rb +196 -0
- data/spec/panner_spec.rb +271 -0
- data/spec/server.rb +12 -0
- data/spec/server_spec.rb +198 -0
- data/spec/synth_spec.rb +103 -0
- data/spec/synthdef_spec.rb +267 -0
- data/spec/ugen_operations_spec.rb +100 -0
- data/spec/ugen_spec.rb +356 -0
- data/spec/ugens_spec.rb +65 -0
- metadata +207 -0
data/spec/panner_spec.rb
ADDED
@@ -0,0 +1,271 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + "/helper"
|
2
|
+
|
3
|
+
require "scruby/core_ext/delegator_array"
|
4
|
+
require "scruby/control_name"
|
5
|
+
require "scruby/env"
|
6
|
+
require "scruby/ugens/ugen"
|
7
|
+
require "scruby/ugens/ugen_operations"
|
8
|
+
require "scruby/ugens/multi_out"
|
9
|
+
require "scruby/ugens/ugens"
|
10
|
+
require "scruby/ugens/panner"
|
11
|
+
|
12
|
+
include Scruby
|
13
|
+
include Ugens
|
14
|
+
|
15
|
+
class MockUgen < Ugen
|
16
|
+
class << self; public :new; end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'Panner' do
|
20
|
+
shared_examples_for 'Panner' do
|
21
|
+
before do
|
22
|
+
@pan = @class.send @method, *@params
|
23
|
+
@inputs ||= @params
|
24
|
+
@instance = @pan.first.source
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should output a DelegatorArray" do
|
28
|
+
@pan.should be_a(DelegatorArray)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have correct rate" do
|
32
|
+
@instance.rate.should == @rate
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return an array of output proxies" do
|
36
|
+
@pan.should be_a(Array)
|
37
|
+
@pan.should have(@channels).proxies
|
38
|
+
@pan.each_with_index do |proxy, i|
|
39
|
+
proxy.source.should be_a(@class)
|
40
|
+
proxy.should be_a(OutputProxy)
|
41
|
+
proxy.output_index.should == i
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should set inputs" do
|
46
|
+
@instance.inputs.should == @inputs
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should accept control rate inputs unless rate is audio"
|
50
|
+
end
|
51
|
+
|
52
|
+
shared_examples_for 'Panner with control rate' do
|
53
|
+
before do
|
54
|
+
@method = :kr
|
55
|
+
@rate = :control
|
56
|
+
end
|
57
|
+
it_should_behave_like 'Panner'
|
58
|
+
end
|
59
|
+
|
60
|
+
shared_examples_for 'Panner with audio rate' do
|
61
|
+
before do
|
62
|
+
@method = :ar
|
63
|
+
@rate = :audio
|
64
|
+
end
|
65
|
+
it_should_behave_like 'Panner'
|
66
|
+
|
67
|
+
it "should just accept audio inputs if rate is audio" # do
|
68
|
+
# lambda { @class.new( :audio, MockUgen.new(:control) ) }.should raise_error(ArgumentError)
|
69
|
+
# end
|
70
|
+
end
|
71
|
+
|
72
|
+
shared_examples_for 'Panner with array as input' do
|
73
|
+
it "should have n channels" do
|
74
|
+
@arrayed.should have(@ugens.size).proxies
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should have array as channel" do
|
78
|
+
@arrayed.each { |a| a.should have(@channels).proxies }
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should have the same source class" do
|
82
|
+
@arrayed.flatten.source.uniq.should have(@ugens.size).elements
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
shared_examples_for 'Multi input panner' do
|
87
|
+
describe "two ugens as input" do
|
88
|
+
before do
|
89
|
+
@params[0] = @ugens = [@ugen] * 2
|
90
|
+
@arrayed = @class.ar *@params
|
91
|
+
end
|
92
|
+
it_should_behave_like 'Panner with array as input'
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "four ugens as input" do
|
96
|
+
before do
|
97
|
+
@params[0] = @ugens = [@ugen] * 4
|
98
|
+
@arrayed = @class.ar *@params
|
99
|
+
# p @arrayed.first.first.source.output_specs
|
100
|
+
end
|
101
|
+
it_should_behave_like 'Panner with array as input'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe Pan2 do
|
106
|
+
before do
|
107
|
+
@class = Pan2
|
108
|
+
@ugen = MockUgen.new :audio, 1, 2
|
109
|
+
@params = @ugen, 0.5, 1.0
|
110
|
+
@channels = 2
|
111
|
+
end
|
112
|
+
it_should_behave_like 'Panner with audio rate'
|
113
|
+
it_should_behave_like 'Panner with control rate'
|
114
|
+
it_should_behave_like 'Multi input panner'
|
115
|
+
|
116
|
+
|
117
|
+
it "should have keyword args" do
|
118
|
+
@class.ar( @ugen, :level => 2.0 ).first.source.inputs.should == [@ugen, 0.0, 2.0]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe LinPan2 do
|
123
|
+
before do
|
124
|
+
@class = LinPan2
|
125
|
+
@ugen = MockUgen.new :audio, 1, 2
|
126
|
+
@params = @ugen, 0.5, 1.0
|
127
|
+
@channels = 2
|
128
|
+
end
|
129
|
+
it_should_behave_like 'Panner with audio rate'
|
130
|
+
it_should_behave_like 'Panner with control rate'
|
131
|
+
it_should_behave_like 'Multi input panner'
|
132
|
+
|
133
|
+
it "should have keyword args" do
|
134
|
+
@class.ar( @ugen, :level => 2.0 ).first.source.inputs.should == [@ugen, 0.0, 2.0]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe Pan4 do
|
139
|
+
before do
|
140
|
+
@class = Pan4
|
141
|
+
@ugen = MockUgen.new :audio, 1, 2
|
142
|
+
@params = @ugen, 0.5, 0.5, 1.0
|
143
|
+
@channels = 4
|
144
|
+
end
|
145
|
+
it_should_behave_like 'Panner with audio rate'
|
146
|
+
it_should_behave_like 'Panner with control rate'
|
147
|
+
it_should_behave_like 'Multi input panner'
|
148
|
+
|
149
|
+
it "should have keyword args" do
|
150
|
+
@class.ar( @ugen, :level => 2.0 ).first.source.inputs.should == [@ugen, 0.0, 0.0, 2.0]
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe Balance2 do
|
155
|
+
before do
|
156
|
+
@class = Balance2
|
157
|
+
@ugen = MockUgen.new :audio, 1, 2
|
158
|
+
@ugen2 = MockUgen.new :audio, 2, 4
|
159
|
+
@params = @ugen, @ugen2, 0.5, 1.0
|
160
|
+
@channels = 2
|
161
|
+
end
|
162
|
+
it_should_behave_like 'Panner with audio rate'
|
163
|
+
it_should_behave_like 'Panner with control rate'
|
164
|
+
it_should_behave_like 'Multi input panner'
|
165
|
+
|
166
|
+
it "should have keyword args" do
|
167
|
+
@class.ar( @ugen, @ugen2 , :level => 2.0 ).first.source.inputs.should == [@ugen, @ugen2 , 0.0, 2.0]
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe Rotate2 do
|
172
|
+
before do
|
173
|
+
@class = Rotate2
|
174
|
+
@ugen = MockUgen.new :audio, 1, 2
|
175
|
+
@ugen2 = MockUgen.new :audio, 2, 4
|
176
|
+
@params = @ugen, @ugen2, 0.5
|
177
|
+
@channels = 2
|
178
|
+
end
|
179
|
+
it_should_behave_like 'Panner with audio rate'
|
180
|
+
it_should_behave_like 'Panner with control rate'
|
181
|
+
it_should_behave_like 'Multi input panner'
|
182
|
+
|
183
|
+
# it "should have keyword args" do
|
184
|
+
# @class.ar( @ugen, @ugen2 , :level => 2.0 ).first.source.inputs.should == [@ugen, @ugen2 , 0.0, 2.0]
|
185
|
+
# end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe PanB do
|
189
|
+
before do
|
190
|
+
@class = PanB
|
191
|
+
@ugen = MockUgen.new :audio, 1, 2
|
192
|
+
@params = @ugen, 0.5, 0.5, 1.0
|
193
|
+
@channels = 4
|
194
|
+
end
|
195
|
+
it_should_behave_like 'Panner with audio rate'
|
196
|
+
it_should_behave_like 'Panner with control rate'
|
197
|
+
it_should_behave_like 'Multi input panner'
|
198
|
+
|
199
|
+
# it "should have keyword args" do
|
200
|
+
# @class.ar( @ugen, @ugen2 , :level => 2.0 ).first.source.inputs.should == [@ugen, @ugen2 , 0.0, 2.0]
|
201
|
+
# end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe PanB2 do
|
205
|
+
before do
|
206
|
+
@class = PanB2
|
207
|
+
@ugen = MockUgen.new :audio, 1, 2
|
208
|
+
@params = @ugen, 0.5, 1.0
|
209
|
+
@channels = 3
|
210
|
+
end
|
211
|
+
it_should_behave_like 'Panner with audio rate'
|
212
|
+
it_should_behave_like 'Panner with control rate'
|
213
|
+
it_should_behave_like 'Multi input panner'
|
214
|
+
|
215
|
+
# it "should have keyword args" do
|
216
|
+
# @class.ar( @ugen, @ugen2 , :level => 2.0 ).first.source.inputs.should == [@ugen, @ugen2 , 0.0, 2.0]
|
217
|
+
# end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe BiPanB2 do
|
221
|
+
before do
|
222
|
+
@class = BiPanB2
|
223
|
+
@ugen2 = MockUgen.new(:audio, 2, 4)
|
224
|
+
@ugen = MockUgen.new :audio, 1, 2
|
225
|
+
@params = @ugen, @ugen2, 0.5, 0.5
|
226
|
+
@channels = 3
|
227
|
+
end
|
228
|
+
it_should_behave_like 'Panner with audio rate'
|
229
|
+
it_should_behave_like 'Panner with control rate'
|
230
|
+
it_should_behave_like 'Multi input panner'
|
231
|
+
|
232
|
+
# it "should have keyword args" do
|
233
|
+
# @class.ar( @ugen, @ugen2 , :level => 2.0 ).first.source.inputs.should == [@ugen, @ugen2 , 0.0, 2.0]
|
234
|
+
# end
|
235
|
+
end
|
236
|
+
|
237
|
+
describe DecodeB2, 'five channels' do
|
238
|
+
before do
|
239
|
+
@class = DecodeB2
|
240
|
+
@params = 5, 0.5, 0.5, 0.5, 0.5
|
241
|
+
@inputs = 0.5, 0.5, 0.5, 0.5
|
242
|
+
@channels = 5
|
243
|
+
end
|
244
|
+
it_should_behave_like 'Panner with audio rate'
|
245
|
+
it_should_behave_like 'Panner with control rate'
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
describe DecodeB2, 'seven channels' do
|
250
|
+
before do
|
251
|
+
@class = DecodeB2
|
252
|
+
@params = 7, 0.5, 0.5, 0.5, 0.5
|
253
|
+
@inputs = 0.5, 0.5, 0.5, 0.5
|
254
|
+
@channels = 7
|
255
|
+
end
|
256
|
+
it_should_behave_like 'Panner with audio rate'
|
257
|
+
it_should_behave_like 'Panner with control rate'
|
258
|
+
end
|
259
|
+
|
260
|
+
describe PanAz, 'five channels' do
|
261
|
+
before do
|
262
|
+
@class = PanAz
|
263
|
+
@ugen = MockUgen.new(:audio, 1, 2)
|
264
|
+
@params = 5, @ugen, 0.5, 0.5, 0.5, 0.5
|
265
|
+
@inputs = @ugen, 0.5, 0.5, 0.5, 0.5
|
266
|
+
@channels = 5
|
267
|
+
end
|
268
|
+
it_should_behave_like 'Panner with audio rate'
|
269
|
+
it_should_behave_like 'Panner with control rate'
|
270
|
+
end
|
271
|
+
end
|
data/spec/server.rb
ADDED
data/spec/server_spec.rb
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + "/helper"
|
2
|
+
|
3
|
+
require 'arguments'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'scruby/node'
|
6
|
+
require 'scruby/core_ext/array'
|
7
|
+
require 'scruby/core_ext/typed_array'
|
8
|
+
require 'scruby/bus'
|
9
|
+
require "scruby/server"
|
10
|
+
|
11
|
+
include Scruby
|
12
|
+
|
13
|
+
module Mocks
|
14
|
+
class Bus; end
|
15
|
+
class Buffer; end
|
16
|
+
end
|
17
|
+
|
18
|
+
Thread.abort_on_exception = true
|
19
|
+
|
20
|
+
class Scruby::Server
|
21
|
+
attr_reader :output
|
22
|
+
|
23
|
+
def puts string
|
24
|
+
@output ||= ""
|
25
|
+
@output << string
|
26
|
+
string
|
27
|
+
end
|
28
|
+
|
29
|
+
def flush
|
30
|
+
@output = ''
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Scruby::Buffer
|
35
|
+
def == other
|
36
|
+
self.class == other.class
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe Message do
|
41
|
+
it "should encode array as Message Blob" do
|
42
|
+
m = Message.new "/b_allocRead", 1, "path", 1, -1, ["/b_query", 1]
|
43
|
+
m.encode.should == "/b_allocRead\000\000\000\000,isiib\000\000\000\000\000\001path\000\000\000\000\000\000\000\001\377\377\377\377\000\000\000\024/b_query\000\000\000\000,i\000\000\000\000\000\001"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe Server do
|
48
|
+
|
49
|
+
describe "booting" do
|
50
|
+
before do
|
51
|
+
@server = Server.new
|
52
|
+
end
|
53
|
+
|
54
|
+
after do
|
55
|
+
@server.quit
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should not rise scynth not found error" do
|
59
|
+
lambda{ @server.boot }.should_not raise_error(Server::SCError)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not reboot" do
|
63
|
+
@server.boot
|
64
|
+
Thread.should_not_receive(:new)
|
65
|
+
@server.boot
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should remove server from server list" do
|
69
|
+
@server.boot
|
70
|
+
@server.quit
|
71
|
+
Server.all.should be_empty
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should raise scsynth not found error" do
|
75
|
+
lambda{ @server = Server.new(:path => '/not_scsynth'); @server.boot }.should raise_error(Server::SCError)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should add self to a list of servers" do
|
79
|
+
s = Server.new
|
80
|
+
Server.all.should include(s)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'sending OSC' do
|
85
|
+
before :all do
|
86
|
+
@server = Server.new
|
87
|
+
@server.boot
|
88
|
+
@server.send "/dumpOSC", 3
|
89
|
+
sleep 0.05
|
90
|
+
end
|
91
|
+
|
92
|
+
after :all do
|
93
|
+
@server.quit
|
94
|
+
end
|
95
|
+
|
96
|
+
before do
|
97
|
+
@server.flush
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should send dump" do
|
101
|
+
@server.send "/dumpOSC", 1
|
102
|
+
sleep 0.1
|
103
|
+
@server.output.should =~ %r{/dumpOSC}
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should send synthdef" do
|
107
|
+
sdef = mock 'sdef', :encode => [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 4, 104, 111, 108, 97, 0, 2, 67, -36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 0, 0 ].pack('C*')
|
108
|
+
@server.send_synth_def sdef
|
109
|
+
sleep 0.1
|
110
|
+
@server.output.should =~ %r{\[ "#bundle", 1, \n\s*\[ "/d_recv", DATA\[56\], 0 \]\n\]}
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should send synthdef2" do
|
114
|
+
sdef = mock 'sdef', :encode => [83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 3, 114, 101, 99, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 6, 98, 117, 102, 110, 117, 109, 0, 0, 0, 3, 7, 67, 111, 110, 116, 114, 111, 108, 1, 0, 0, 0, 1, 0, 0, 1, 2, 73, 110, 2, 0, 1, 0, 2, 0, 0, 255, 255, 0, 0, 2, 2, 7, 68, 105, 115, 107, 79, 117, 116, 2, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0].pack('C*')
|
115
|
+
@server.send_synth_def sdef
|
116
|
+
sleep 0.1
|
117
|
+
@server.output.should =~ %r{\[ "#bundle", 1, \n\s*\[ "/d_recv", DATA\[100\], 0 \]\n\]}
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
shared_examples_for 'allocator' do
|
122
|
+
it "should allow less than @max_size elements" do
|
123
|
+
@server.__send__( :allocate, @kind, (1..@allowed_elements).map{ @class.new } )
|
124
|
+
@server.__send__(@kind).size.should == @max_size
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should not allow more than @max_size elements" do
|
128
|
+
lambda { @server.__send__( :allocate, @kind, (1..@max_size+1).map{ @class.new } ) }.should raise_error(SCError)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should try to allocate lowest nil slot" do
|
132
|
+
@server.__send__(@kind).concat([nil, nil, @class.new, nil, nil, nil, @class.new])
|
133
|
+
@server.__send__ :allocate, @kind, buffer = @class.new
|
134
|
+
@server.__send__(@kind).index(buffer).should == @index_start
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should allocate various elements in available contiguous indices" do
|
138
|
+
@server.__send__(@kind).concat([nil, nil, @class.new, nil, nil, nil, @class.new])
|
139
|
+
@server.__send__ :allocate, @kind, @class.new, @class.new, @class.new
|
140
|
+
elements = @server.__send__(@kind)[@max_size-@allowed_elements..-1].compact
|
141
|
+
elements.should have(5).elements
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should allocate by appending various elements" do
|
145
|
+
@server.__send__(@kind).concat([nil, nil, @class.new, nil, nil, nil, @class.new])
|
146
|
+
@server.__send__ :allocate, @kind, @class.new, @class.new, @class.new, @class.new
|
147
|
+
elements = @server.__send__(@kind)[@max_size-@allowed_elements..-1].compact
|
148
|
+
elements.should have(6).elements
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should not surpass the max buffer limit" do
|
152
|
+
@server.__send__( :allocate, @kind, (1..@allowed_elements-2).map{ |i| @class.new if i % 2 == 0 } )
|
153
|
+
lambda { @server.__send__ :allocate, @kind, @class.new, @class.new, @class.new }.should raise_error
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should allocate by appending" do
|
157
|
+
@server.__send__( :allocate, @kind, (1..@allowed_elements-3).map{ |i| @class.new if i % 2 == 0 } )
|
158
|
+
@server.__send__ :allocate, @kind, @class.new, @class.new, @class.new
|
159
|
+
@server.__send__(@kind).size.should == @max_size
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe 'buffers allocation' do
|
164
|
+
before do
|
165
|
+
@server = Server.new
|
166
|
+
@kind = :buffers
|
167
|
+
@class = ::Mocks::Buffer
|
168
|
+
@allowed_elements = @max_size = 1024
|
169
|
+
@index_start = 0
|
170
|
+
end
|
171
|
+
it_should_behave_like 'allocator'
|
172
|
+
end
|
173
|
+
|
174
|
+
describe 'control_buses allocation' do
|
175
|
+
before do
|
176
|
+
@server = Server.new
|
177
|
+
@kind = :control_buses
|
178
|
+
@class = ::Mocks::Bus
|
179
|
+
@allowed_elements = @max_size = 4096
|
180
|
+
@index_start = 0
|
181
|
+
end
|
182
|
+
it_should_behave_like 'allocator'
|
183
|
+
end
|
184
|
+
|
185
|
+
describe 'audio_buses allocation' do
|
186
|
+
before do
|
187
|
+
@server = Server.new
|
188
|
+
@kind = :audio_buses
|
189
|
+
@class = ::Mocks::Bus
|
190
|
+
@allowed_elements = 112
|
191
|
+
@max_size = 128
|
192
|
+
@index_start = 16
|
193
|
+
end
|
194
|
+
it_should_behave_like 'allocator'
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
|
data/spec/synth_spec.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + "/helper"
|
2
|
+
|
3
|
+
|
4
|
+
require "scruby/core_ext/typed_array"
|
5
|
+
require "scruby/node"
|
6
|
+
require "scruby/bus"
|
7
|
+
require "scruby/group"
|
8
|
+
require "scruby/synth"
|
9
|
+
require "scruby/server"
|
10
|
+
require File.join( File.expand_path(File.dirname(__FILE__)), "server")
|
11
|
+
|
12
|
+
include Scruby
|
13
|
+
|
14
|
+
describe Synth do
|
15
|
+
|
16
|
+
before :all do
|
17
|
+
Server.clear
|
18
|
+
@server = Server.new
|
19
|
+
@server.boot
|
20
|
+
@server.send "/dumpOSC", 3
|
21
|
+
sleep 0.05
|
22
|
+
end
|
23
|
+
|
24
|
+
after :all do
|
25
|
+
@server.quit
|
26
|
+
sleep 1
|
27
|
+
end
|
28
|
+
|
29
|
+
before do
|
30
|
+
@server.flush
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'instantiation with node target' do
|
34
|
+
before do
|
35
|
+
Node.reset!
|
36
|
+
@target = Node.new( (0..3).map{ Server.new } )
|
37
|
+
@synth = Synth.new :synth, {:attack => 10}, @target
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should initialize" do
|
41
|
+
@synth.name.should == 'synth'
|
42
|
+
@synth.servers.should == @target.servers
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should initialize not passing servers and have default servers" do
|
46
|
+
s = Synth.new( 'synth' )
|
47
|
+
s.servers.should == Server.all
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'instantiaton messaging' do
|
52
|
+
it "should send /s_new message" do
|
53
|
+
synth = Synth.new :synth, :attack => 10
|
54
|
+
sleep 0.05
|
55
|
+
@server.output.should =~ %r{\[ "/s_new", "#{ synth.name }", #{ synth.id }, 0, 1, "attack", 10 \]}
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should send set message and return self" do
|
59
|
+
synth = Synth.new :synth, :attack => 10
|
60
|
+
synth.set( :attack => 20 ).should be_a(Synth)
|
61
|
+
sleep 0.05
|
62
|
+
@server.output.should =~ %r{\[ "/n_set", #{ synth.id }, "attack", 20 \]}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'Default Group' do
|
67
|
+
it "should send after message" do
|
68
|
+
synth = Synth.after nil, :synth, :attack => 10
|
69
|
+
synth.should be_a(Synth)
|
70
|
+
sleep 0.05
|
71
|
+
@server.output.should =~ %r{\[ "/s_new", "#{ synth.name }", #{ synth.id }, 3, 1, "attack", 10 \]}
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should send before message" do
|
75
|
+
synth = Synth.before nil, :synth, :attack => 10
|
76
|
+
synth.should be_a(Synth)
|
77
|
+
sleep 0.05
|
78
|
+
@server.output.should =~ %r{\[ "/s_new", "#{ synth.name }", #{ synth.id }, 2, 1, "attack", 10 \]}
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should send head message" do
|
82
|
+
synth = Synth.head nil, :synth, :attack => 10
|
83
|
+
synth.should be_a(Synth)
|
84
|
+
sleep 0.05
|
85
|
+
@server.output.should =~ %r{\[ "/s_new", "#{ synth.name }", #{ synth.id }, 0, 1, "attack", 10 \]}
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should send tail message" do
|
89
|
+
synth = Synth.tail nil, :synth, :attack => 10
|
90
|
+
synth.should be_a(Synth)
|
91
|
+
sleep 0.05
|
92
|
+
@server.output.should =~ %r{\[ "/s_new", "#{ synth.name }", #{ synth.id }, 1, 1, "attack", 10 \]}
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should send replace message" do
|
96
|
+
synth = Synth.replace nil, :synth, :attack => 10
|
97
|
+
synth.should be_a(Synth)
|
98
|
+
sleep 0.05
|
99
|
+
@server.output.should =~ %r{\[ "/s_new", "#{ synth.name }", #{ synth.id }, 4, 1, "attack", 10 \]}
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|