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/buffer_spec.rb
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + "/helper"
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
require 'arguments'
|
5
|
+
require 'tempfile'
|
6
|
+
|
7
|
+
require "scruby/buffer"
|
8
|
+
require "scruby/bus"
|
9
|
+
require "scruby/server"
|
10
|
+
require File.join( File.expand_path(File.dirname(__FILE__)), "server")
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
include Scruby
|
15
|
+
|
16
|
+
|
17
|
+
describe Buffer do
|
18
|
+
describe "messaging" do
|
19
|
+
before :all do
|
20
|
+
@server = Server.new
|
21
|
+
@server.boot
|
22
|
+
@server.send "/dumpOSC", 3
|
23
|
+
sleep 0.05
|
24
|
+
end
|
25
|
+
|
26
|
+
after :all do
|
27
|
+
@server.quit
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'Buffer.read' do
|
31
|
+
before do
|
32
|
+
@buffer = Buffer.read @server, "sounds/a11wlk01-44_1.aiff"
|
33
|
+
sleep 0.005
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should instantiate and send /b_allocRead message" do
|
37
|
+
@buffer.should be_a(Buffer)
|
38
|
+
@server.output.should =~ %r{\[ "/b_allocRead", #{ @buffer.buffnum }, "/.+/Scruby/sounds/a11wlk01-44_1.aiff", 0, -1, DATA\[20\] \]}
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should allow passing a completion message"
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'Buffer.allocate' do
|
45
|
+
before do
|
46
|
+
@buffer = Buffer.allocate @server, 44100 * 8.0, 2
|
47
|
+
sleep 0.005
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should call allocate and send /b_alloc message" do
|
51
|
+
@buffer.should be_a(Buffer)
|
52
|
+
@server.output.should =~ %r{\[ "/b_alloc", #{ @buffer.buffnum }, 352800, 2, 0 \]}
|
53
|
+
@server.output.should =~ /69 00 00 00 00 00 00 00 00 44 ac 48 00 00 00 02/
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should allow passing a completion message"
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'Buffer.cueSoundFile' do
|
60
|
+
before do
|
61
|
+
@buffer = Buffer.cue_sound_file @server, "/sounds/a11wlk01-44_1.aiff", 0, 1
|
62
|
+
sleep 0.005
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should send /b_alloc message and instantiate" do
|
66
|
+
@buffer.should be_a(Buffer)
|
67
|
+
@server.output.should =~ %r{\[ "/b_alloc", #{ @buffer.buffnum }, 32768, 1, DATA\[72\] \]}
|
68
|
+
@server.output.should =~ /6e 64 73 2f 61 31 31 77 6c 6b 30 31 2d 34 34 5f/
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should allow passing a completion message"
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#free' do
|
75
|
+
before do
|
76
|
+
@buffer = Buffer.allocate @server, 44100 * 10.0, 2
|
77
|
+
@buffer2 = Buffer.allocate @server, 44100 * 10.0, 2
|
78
|
+
@bnum = @buffer2.buffnum
|
79
|
+
@buffer2.free
|
80
|
+
sleep 0.005
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should remove itself from the server @buffers array and send free message" do
|
84
|
+
@buffer2.buffnum.should be_nil
|
85
|
+
@server.output.should =~ %r{\[ "/b_free", #{ @bnum }, 0 \]}
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should allow passing a completion message"
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
describe 'Buffer.alloc_consecutive' do
|
93
|
+
before do
|
94
|
+
@buffers = Buffer.alloc_consecutive 8, @server, 4096, 2
|
95
|
+
sleep 0.005
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should send alloc message for each Buffer and instantiate" do
|
99
|
+
@buffers.should have(8).buffers
|
100
|
+
@buffers.each do |buff|
|
101
|
+
@server.output.should =~ %r{\[ "/b_alloc", #{ buff.buffnum }, 4096, 2, 0 \]}
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should allow passing a message"
|
106
|
+
end
|
107
|
+
|
108
|
+
describe 'Buffer.read_channel' do
|
109
|
+
before do
|
110
|
+
@buffer = Buffer.read_channel @server, "sounds/SinedPink.aiff", :channels => [0]
|
111
|
+
sleep 0.005
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should allocate and send /b_allocReadChannel message" do
|
115
|
+
@buffer.should be_a(Buffer)
|
116
|
+
@server.output.should =~ %r{\[ "/b_allocReadChannel", #{ @buffer.buffnum }, "/.+/Scruby/sounds/SinedPink.aiff", 0, -1, 0, DATA\[20\] \]}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe '#read' do
|
121
|
+
before do
|
122
|
+
@buffer = Buffer.allocate( @server, 44100 * 10.0, 2 ).read( "sounds/robot.aiff" )
|
123
|
+
sleep 0.005
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should send message" do
|
127
|
+
@buffer.should be_a(Buffer)
|
128
|
+
@server.output.should =~ %r{\[ "/b_read", #{ @buffer.buffnum }, "/.+/Scruby/sounds/robot.aiff", 0, -1, 0, 0, DATA\[20\] \]}
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should allow passing a completion message"
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#close' do
|
135
|
+
before do
|
136
|
+
@buffer = Buffer.read( @server, "sounds/a11wlk01-44_1.aiff" ).close
|
137
|
+
sleep 0.005
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should send message" do
|
141
|
+
@buffer.should be_a(Buffer)
|
142
|
+
@server.output.should =~ %r{\[ "/b_close", #{ @buffer.buffnum }, 0 \]}
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should allow passing a completion message"
|
146
|
+
end
|
147
|
+
|
148
|
+
describe '#zero' do
|
149
|
+
before do
|
150
|
+
@buffer = Buffer.read( @server, "sounds/a11wlk01-44_1.aiff" ).zero
|
151
|
+
sleep 0.005
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should send message" do
|
155
|
+
@buffer.should be_a(Buffer)
|
156
|
+
@server.output.should =~ %r{\[ "/b_zero", #{ @buffer.buffnum }, 0 \]}
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should allow passing a completion message"
|
160
|
+
end
|
161
|
+
|
162
|
+
describe '#cue_sound_file' do
|
163
|
+
before do
|
164
|
+
@buffer = Buffer.allocate( @server, 44100, 2 ).cue_sound_file( "sounds/robot.aiff" )
|
165
|
+
sleep 0.005
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should send message" do
|
169
|
+
@buffer.should be_a(Buffer)
|
170
|
+
@server.output.should =~ %r{\[ "/b_read", #{ @buffer.buffnum }, "/.+/Scruby/sounds/robot.aiff", 0, 44100, 0, 1, 0 \]}
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should allow passing a completion message"
|
174
|
+
end
|
175
|
+
|
176
|
+
describe '#write' do
|
177
|
+
before do
|
178
|
+
@buffer = Buffer.allocate( @server, 44100 * 10.0, 2 ).write(
|
179
|
+
"sounds/test.aiff", "aiff", "int16", 0, 0, true
|
180
|
+
);
|
181
|
+
sleep 0.005
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should send message" do
|
185
|
+
@buffer.should be_a(Buffer)
|
186
|
+
@server.output.should =~ %r{\[ "/b_write", #{ @buffer.buffnum }, "/.+/Scruby/sounds/test.aiff", "aiff", "int16", 0, 0, 1, 0 \]}
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should have a default path" do
|
190
|
+
@server.flush
|
191
|
+
buffer = Buffer.allocate( @server, 44100 * 10.0, 2 ).write( nil, "aiff", "int16", 0, 0, true );
|
192
|
+
sleep 0.005
|
193
|
+
@server.output.should =~ %r{\[ "/b_write", #{ buffer.buffnum }, "/.+/Scruby/\d\d\d\d.+\.aiff", "aiff", "int16", 0, 0, 1, 0 \]}
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should allow passing a completion message"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
data/spec/bus_spec.rb
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + "/helper"
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
require "scruby/core_ext/numeric"
|
6
|
+
require "scruby/bus"
|
7
|
+
require "scruby/server"
|
8
|
+
require File.join( File.expand_path(File.dirname(__FILE__)), "server")
|
9
|
+
|
10
|
+
include Scruby
|
11
|
+
|
12
|
+
|
13
|
+
describe Bus do
|
14
|
+
describe 'instantiation' do
|
15
|
+
before do
|
16
|
+
@server = Server.new
|
17
|
+
@audio = Bus.audio @server
|
18
|
+
@control = Bus.control @server
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be a bus" do
|
22
|
+
@audio.should be_a(Bus)
|
23
|
+
@control.should be_a(Bus)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not instantiate with new" do
|
27
|
+
lambda { Bus.new @server, :control, 1 }.should raise_error(NoMethodError)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should set server" do
|
31
|
+
@audio.server.should == @server
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should set audio rate" do
|
35
|
+
@audio.rate.should == :audio
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should set control rate" do
|
39
|
+
Bus.control(@server).rate.should == :control
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should allocate in server on instantiation and have index" do
|
43
|
+
@server.audio_buses.should include(@audio)
|
44
|
+
@server.control_buses.should include(@control)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should have index" do
|
48
|
+
@audio.index.should == 16
|
49
|
+
@control.index.should == 0
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should free and null index" do
|
53
|
+
@audio.free
|
54
|
+
@server.audio_buses.should_not include(@audio)
|
55
|
+
@audio.index.should == nil
|
56
|
+
@control.free
|
57
|
+
@server.audio_buses.should_not include(@control)
|
58
|
+
@control.index.should == nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return as map if control" do
|
62
|
+
@control.to_map.should == "c0"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should raise error if calling to_map on an audio bus" do
|
66
|
+
lambda { @audio.to_map }.should raise_error(SCError)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should print usefull information with to_s"
|
70
|
+
|
71
|
+
it "should be hardware out" do
|
72
|
+
@server.audio_buses[0].should be_audio_out
|
73
|
+
@audio.should_not be_audio_out
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'multichannel' do
|
77
|
+
before do
|
78
|
+
@server = Server.new
|
79
|
+
@audio = Bus.audio @server, 4
|
80
|
+
@control = Bus.control @server, 4
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should allocate consecutive when passing more than one channel for audio" do
|
84
|
+
@audio.index.should == 16
|
85
|
+
buses = @server.audio_buses
|
86
|
+
buses[16..-1].should have(4).elements
|
87
|
+
Bus.audio(@server).index.should == 20
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should allocate consecutive when passing more than one channel for control" do
|
91
|
+
@control.index.should == 0
|
92
|
+
@server.control_buses.should have(4).elements
|
93
|
+
Bus.control(@server).index.should == 4
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should set the number of channels" do
|
97
|
+
@audio.channels.should == 4
|
98
|
+
@control.channels.should == 4
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should depend on a main bus" do
|
102
|
+
@server.audio_buses[16].main_bus.should == @audio #main bus
|
103
|
+
@server.audio_buses[17].main_bus.should == @audio #main bus
|
104
|
+
@server.control_buses[0].main_bus.should == @control #main bus
|
105
|
+
@server.control_buses[1].main_bus.should == @control #main bus
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "messaging" do
|
111
|
+
before :all do
|
112
|
+
@server = Server.new
|
113
|
+
@server.boot
|
114
|
+
@server.send "/dumpOSC", 3
|
115
|
+
@bus = Bus.control @server, 4
|
116
|
+
sleep 0.05
|
117
|
+
end
|
118
|
+
|
119
|
+
after :all do
|
120
|
+
@server.quit
|
121
|
+
end
|
122
|
+
|
123
|
+
before do
|
124
|
+
@server.flush
|
125
|
+
end
|
126
|
+
|
127
|
+
describe 'set' do
|
128
|
+
it "should send set message with one value" do
|
129
|
+
@bus.set 101
|
130
|
+
sleep 0.01
|
131
|
+
@server.output.should =~ %r{\[ "/c_set", #{ @bus.index }, 101 \]}
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should accept value list and send set with them" do
|
135
|
+
@bus.set 101, 202
|
136
|
+
sleep 0.01
|
137
|
+
@server.output.should =~ %r{\[ "/c_set", #{ @bus.index }, 101, #{ @bus.index + 1}, 202 \]}
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should accept an array and send set with them" do
|
141
|
+
@bus.set [101, 202]
|
142
|
+
sleep 0.01
|
143
|
+
@server.output.should =~ %r{\[ "/c_set", #{ @bus.index }, 101, #{ @bus.index + 1}, 202 \]}
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should warn but not set if trying to set more values than channels" do
|
147
|
+
@bus.should_receive(:warn).with("You tried to set 5 values for bus #{ @bus.index } that only has 4 channels, extra values are ignored.")
|
148
|
+
@bus.set 101, 202, 303, 404, 505
|
149
|
+
sleep 0.01
|
150
|
+
@server.output.should =~ %r{\[ "/c_set", #{ @bus.index }, 101, #{ @bus.index + 1}, 202, #{ @bus.index + 2}, 303, #{ @bus.index + 3}, 404 \]}
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe 'set' do
|
155
|
+
it "should send fill just one channel" do
|
156
|
+
@bus.fill 101, 1
|
157
|
+
sleep 0.01
|
158
|
+
@server.output.should =~ %r{\[ "/c_fill", #{ @bus.index }, 1, 101 \]}
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should fill all channels" do
|
162
|
+
@bus.fill 101
|
163
|
+
sleep 0.01
|
164
|
+
@server.output.should =~ %r{\[ "/c_fill", #{ @bus.index }, 4, 101 \]}
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should raise error if trying to fill more than assigned channels" do
|
168
|
+
@bus.should_receive(:warn).with("You tried to set 5 values for bus #{ @bus.index } that only has 4 channels, extra values are ignored.")
|
169
|
+
@bus.fill 101, 5
|
170
|
+
sleep 0.01
|
171
|
+
@server.output.should =~ %r{\[ "/c_fill", #{ @bus.index }, 4, 101 \]}
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe 'get' do
|
176
|
+
it "should send get message with one value"
|
177
|
+
it "should send get message for various channels"
|
178
|
+
it "should accept an array and send set with them"
|
179
|
+
it "should raise error if trying to set more values than channels"
|
180
|
+
it "should actually get the response from the server"
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + "/../helper"
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
describe Numeric do
|
6
|
+
before :all do
|
7
|
+
@bin_op = mock 'binop'
|
8
|
+
::BinaryOpUGen = mock 'BinaryOpUGen', :new => @bin_on
|
9
|
+
@ugen = mock 'ugen'
|
10
|
+
::Ugen = mock 'Ugen', :new => @ugen
|
11
|
+
end
|
12
|
+
|
13
|
+
it "shoud have an scalar rate" do
|
14
|
+
1.rate.should == :scalar
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have an scalar rate" do
|
18
|
+
100.0.rate.should == :scalar
|
19
|
+
end
|
20
|
+
|
21
|
+
it "sum as usual" do
|
22
|
+
(100 + 100).should == 200
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should #collect_constants" do
|
26
|
+
1.send( :collect_constants ).should == 1
|
27
|
+
1.5.send( :collect_constants ).should == 1.5
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should spec #input_specs" do
|
31
|
+
synthdef = mock('synthdef', :constants => [200.0,1,3, 400.0] )
|
32
|
+
200.0.send( :input_specs, synthdef ).should == [-1,0]
|
33
|
+
3.send( :input_specs, synthdef ).should == [-1,2]
|
34
|
+
400.0.send( :input_specs, synthdef ).should == [-1,3]
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should spec encode"
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
describe Proc do
|
42
|
+
describe "#arguments" do
|
43
|
+
|
44
|
+
it do
|
45
|
+
Proc.new{}.should respond_to( :arguments )
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should get empty array if proc has no args" do
|
49
|
+
Proc.new{}.arguments.should eql( [] )
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should get one argument name" do
|
53
|
+
Proc.new{ |arg| }.arguments.should eql( [ :arg ] )
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should get arg names with several args" do
|
57
|
+
Proc.new{ |arg, arg2, arg3| }.arguments.should eql( [ :arg, :arg2, :arg3 ] )
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe Array, "monkey patches" do
|
63
|
+
describe "#collect_with_index" do
|
64
|
+
it do
|
65
|
+
[].should respond_to( :collect_with_index )
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should return an array the same size as the original" do
|
69
|
+
[1,2,3,4].collect_with_index{ nil }.should have( 4 ).items
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should collect_with_index" do
|
73
|
+
array = %w(a, b, c, d)
|
74
|
+
array.collect_with_index{ |element, index| [index, element] }.should eql( [0,1,2,3].zip( array ) )
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should wrap and zip" do
|
78
|
+
[:a,:b,:c].wrap_and_zip([1]).flatten.should == [:a,1,:b,1,:c,1]
|
79
|
+
[0.5, 0.5].wrap_and_zip([3],[5]).flatten.should == [0.5,3,5,0.5,3,5]
|
80
|
+
[0.01, 1.0].wrap_and_zip([-4.0],[5]).flatten.should == [0.01, -4.0, 5, 1.0, -4.0, 5]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#wrap_to" do
|
85
|
+
it do
|
86
|
+
Array.new.should respond_to( :wrap_to )
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should wrap_to!" do
|
90
|
+
[1,2].wrap_to!(4).should == [1,2,1,2]
|
91
|
+
end
|
92
|
+
|
93
|
+
it do
|
94
|
+
Array.new.should respond_to( :wrap_to )
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should return self if the passed size is the same as self.size" do
|
98
|
+
a = [1,2,3,4]
|
99
|
+
a.wrap_to( 4 ).should == a
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should sum with Ugen"
|
104
|
+
it "should collect constants"
|
105
|
+
end
|
106
|
+
|
107
|
+
describe String do
|
108
|
+
it "should encode" do
|
109
|
+
"SinOsc".encode.should == [6, 83, 105, 110, 79, 115, 99].pack('C*')
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should encode large strings" do
|
113
|
+
'set arguments cn.argNum << this is the size of controlNames when controlName was added'.encode.should ==
|
114
|
+
[86, 115, 101, 116, 32, 97, 114, 103, 117, 109, 101, 110, 116, 115, 32, 99, 110, 46, 97, 114, 103, 78, 117, 109, 32, 60, 60, 32, 116, 104, 105, 115, 32, 105, 115, 32, 116, 104, 101, 32, 115, 105, 122, 101, 32, 111, 102, 32, 99, 111, 110, 116, 114, 111, 108, 78, 97, 109, 101, 115, 32, 119, 104, 101, 110, 32, 99, 111, 110, 116, 114, 111, 108, 78, 97, 109, 101, 32, 119, 97, 115, 32, 97, 100, 100, 101, 100].pack('C*')
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + "/../helper"
|
2
|
+
|
3
|
+
require "scruby/core_ext/array"
|
4
|
+
require "scruby/core_ext/delegator_array"
|
5
|
+
require "scruby/env"
|
6
|
+
require "scruby/control_name"
|
7
|
+
require "scruby/ugens/ugen"
|
8
|
+
require "scruby/ugens/ugens"
|
9
|
+
require "scruby/ugens/ugen_operations"
|
10
|
+
require "scruby/ugens/operation_ugens"
|
11
|
+
|
12
|
+
include Scruby
|
13
|
+
include Ugens
|
14
|
+
|
15
|
+
class MockUgen < Ugen
|
16
|
+
class << self; public :new; end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
class SinOsc < Ugen
|
21
|
+
class << self
|
22
|
+
def ar freq = 440.0, phase = 0.0 #not interested in muladd by now
|
23
|
+
new :audio, freq, phase
|
24
|
+
end
|
25
|
+
|
26
|
+
def kr freq = 440.0, phase = 0.0
|
27
|
+
new :control, freq, phase
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Mocks
|
33
|
+
class ControlName; end
|
34
|
+
class Env; end
|
35
|
+
|
36
|
+
describe DelegatorArray do
|
37
|
+
|
38
|
+
it "should have 'literal' notation" do
|
39
|
+
d(1,2).should == [1,2]
|
40
|
+
d(1,2).should be_instance_of(DelegatorArray)
|
41
|
+
d([1,2]).should == d(1,2)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should allow nil" do
|
45
|
+
d(nil)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return DelegatorArray" do
|
49
|
+
sig = SinOsc.ar([100, [100, 100]])
|
50
|
+
sig.should be_a(DelegatorArray)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should convet to_da" do
|
54
|
+
[].to_da.should be_a(DelegatorArray)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should pass missing method" do
|
58
|
+
d(1,2).to_f.should == d(1.0,2.0)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return a DelegatorArray for muladd" do
|
62
|
+
SinOsc.ar(100).muladd(1, 0.5).should be_a(BinaryOpUGen)
|
63
|
+
SinOsc.ar([100, [100, 100]]).muladd(0.5, 0.5).should be_a(DelegatorArray)
|
64
|
+
# SinOsc.ar([100, [100, 100]]).muladd(1, 0.5).should be_a(DelegatorArray)
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
it "should pass method missing" do
|
69
|
+
d(1,2,3).to_i.should == [1.0, 2.0, 3.0]
|
70
|
+
end
|
71
|
+
|
72
|
+
shared_examples_for 'aritmetic operand' do
|
73
|
+
before do
|
74
|
+
@numeric_op = eval %{ d(1,2) #{ @op } 3.0 }
|
75
|
+
@array_op = eval %{ d(1,2) #{ @op } d(1.0, 2.0) }
|
76
|
+
@asim_array_op1 = eval %{ d(1,2,3) #{ @op } d(1.0, 2.0) }
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should do operation" do
|
80
|
+
@numeric_op.should == @numeric_op
|
81
|
+
@numeric_op.should be_a(DelegatorArray)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should do operation with array of the same size" do
|
85
|
+
@array_op.should == @array_result
|
86
|
+
@array_op.should be_a(DelegatorArray)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should do operation with array of diferent size (left bigger)" do
|
90
|
+
@asim_array_op1.should == @asim_result1
|
91
|
+
@asim_array_op1.should be_a(DelegatorArray)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should blow passing nil" do
|
95
|
+
lambda { d(1,2,3,nil) + 1 }.should raise_error(NoMethodError)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should blow pass nil" do
|
99
|
+
actual = eval %{ d(1,2,3) #{ @op } MockUgen.new(:audio, 2)}
|
100
|
+
expected = BinaryOpUGen.new(@op.to_sym, [1,2,3], MockUgen.new(:audio, 2) )
|
101
|
+
actual.should == expected
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should allow passing an MockUgen Array" do
|
105
|
+
eval %{ SinOsc.ar([100, [100, 100]]) #{@op} SinOsc.ar }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "should override sum" do
|
110
|
+
before do
|
111
|
+
@op = '+'
|
112
|
+
@array_result = d(1+1.0, 2+2.0)
|
113
|
+
@asim_result1 = d(1+1.0, 2+2.0, 3)
|
114
|
+
end
|
115
|
+
it_should_behave_like 'aritmetic operand'
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "should override subs" do
|
119
|
+
before do
|
120
|
+
@op = '-'
|
121
|
+
@array_result = d(1-1.0, 2-2.0)
|
122
|
+
@asim_result1 = d(1-1.0, 2-2.0, 3)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "should override mult" do
|
127
|
+
before do
|
128
|
+
@op = '*'
|
129
|
+
@array_result = d(1*1.0, 2*2.0)
|
130
|
+
@asim_result1 = d(1*1.0, 2*2.0, 3)
|
131
|
+
end
|
132
|
+
it_should_behave_like 'aritmetic operand'
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "should override div" do
|
136
|
+
before do
|
137
|
+
@op = '/'
|
138
|
+
@array_result = d(1/1.0, 2/2.0)
|
139
|
+
@asim_result1 = d(1/1.0, 2/2.0, 3)
|
140
|
+
end
|
141
|
+
it_should_behave_like 'aritmetic operand'
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|