scruby 0.2.7

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.
Files changed (69) hide show
  1. data/.gitignore +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +53 -0
  5. data/README.rdoc +65 -0
  6. data/Rakefile +10 -0
  7. data/TODO.markdown +3 -0
  8. data/examples/example.rb +73 -0
  9. data/lib/scruby/buffer.rb +153 -0
  10. data/lib/scruby/bus.rb +67 -0
  11. data/lib/scruby/control_name.rb +29 -0
  12. data/lib/scruby/core_ext/array.rb +44 -0
  13. data/lib/scruby/core_ext/delegator_array.rb +44 -0
  14. data/lib/scruby/core_ext/fixnum.rb +8 -0
  15. data/lib/scruby/core_ext/numeric.rb +25 -0
  16. data/lib/scruby/core_ext/object.rb +23 -0
  17. data/lib/scruby/core_ext/proc.rb +11 -0
  18. data/lib/scruby/core_ext/string.rb +5 -0
  19. data/lib/scruby/core_ext/symbol.rb +5 -0
  20. data/lib/scruby/core_ext/typed_array.rb +54 -0
  21. data/lib/scruby/env.rb +93 -0
  22. data/lib/scruby/group.rb +24 -0
  23. data/lib/scruby/node.rb +102 -0
  24. data/lib/scruby/server.rb +182 -0
  25. data/lib/scruby/synth.rb +50 -0
  26. data/lib/scruby/synthdef.rb +109 -0
  27. data/lib/scruby/ticker.rb +92 -0
  28. data/lib/scruby/ugens/buffer_read_write.rb +98 -0
  29. data/lib/scruby/ugens/demand.rb +9 -0
  30. data/lib/scruby/ugens/disk_in_out.rb +33 -0
  31. data/lib/scruby/ugens/env_gen.rb +38 -0
  32. data/lib/scruby/ugens/in_out.rb +46 -0
  33. data/lib/scruby/ugens/multi_out.rb +53 -0
  34. data/lib/scruby/ugens/operation_indices.yaml +92 -0
  35. data/lib/scruby/ugens/operation_ugens.rb +63 -0
  36. data/lib/scruby/ugens/panner.rb +137 -0
  37. data/lib/scruby/ugens/ugen.rb +173 -0
  38. data/lib/scruby/ugens/ugen_defs.yaml +3123 -0
  39. data/lib/scruby/ugens/ugen_operations.rb +57 -0
  40. data/lib/scruby/ugens/ugens.rb +95 -0
  41. data/lib/scruby/version.rb +3 -0
  42. data/lib/scruby.rb +65 -0
  43. data/scruby.gemspec +27 -0
  44. data/spec/buffer_read_write_spec.rb +333 -0
  45. data/spec/buffer_spec.rb +199 -0
  46. data/spec/bus_spec.rb +184 -0
  47. data/spec/core_ext/core_ext_spec.rb +120 -0
  48. data/spec/core_ext/delegator_array_spec.rb +144 -0
  49. data/spec/core_ext/typed_array_spec.rb +95 -0
  50. data/spec/demand_spec.rb +81 -0
  51. data/spec/disk_in_out_spec.rb +138 -0
  52. data/spec/env_gen_spec.rb +23 -0
  53. data/spec/env_spec.rb +73 -0
  54. data/spec/group_spec.rb +71 -0
  55. data/spec/helper.rb +20 -0
  56. data/spec/in_out_spec.rb +127 -0
  57. data/spec/integration_spec.rb +88 -0
  58. data/spec/multiout_ugen_spec.rb +86 -0
  59. data/spec/node_spec.rb +112 -0
  60. data/spec/operation_ugens_spec.rb +196 -0
  61. data/spec/panner_spec.rb +271 -0
  62. data/spec/server.rb +12 -0
  63. data/spec/server_spec.rb +198 -0
  64. data/spec/synth_spec.rb +103 -0
  65. data/spec/synthdef_spec.rb +267 -0
  66. data/spec/ugen_operations_spec.rb +100 -0
  67. data/spec/ugen_spec.rb +356 -0
  68. data/spec/ugens_spec.rb +65 -0
  69. metadata +207 -0
@@ -0,0 +1,95 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + "/../helper"
2
+ require "scruby/core_ext/typed_array"
3
+
4
+ class Type
5
+ end
6
+
7
+ describe TypedArray do
8
+
9
+ before do
10
+ @t1 = Type.new
11
+ @t2 = Type.new
12
+ end
13
+
14
+ it "should initialize with attributes" do
15
+ objs = (0..3).map{ Type.new }
16
+ ta = TypedArray.new( Type, objs )
17
+ ta.type.should == Type
18
+ ta.should == objs
19
+ end
20
+
21
+ it "should instantiate with an array" do
22
+ objs = (0..3).map{ Type.new }
23
+ ta = TypedArray.new( Type, objs )
24
+ ta.should == objs
25
+ end
26
+
27
+ it "set type by instance" do
28
+ ta = TypedArray.new( Type.new )
29
+ ta.type.should == Type
30
+ end
31
+
32
+ it "should raise error if wrong type" do
33
+ lambda{ TypedArray.new(Type, 1) }.should raise_error(TypeError)
34
+ end
35
+
36
+ it "+ success" do
37
+ ta = TypedArray.new( Type )
38
+ o = Type.new
39
+ sum = ta + [o]
40
+ # sum.should be_instance_of(TypedArray)
41
+ sum.should == [o]
42
+ end
43
+
44
+ it "+ failure" do
45
+ lambda{ TypedArray.new(Type, Type.new) + [1] }.should raise_error(TypeError)
46
+ end
47
+
48
+ it "concat success" do
49
+ ta = TypedArray.new( Type, [@t1] )
50
+ ta.concat( [@t2] ).should == ta
51
+ ta.should == [@t1,@t2]
52
+ end
53
+
54
+ it "concat failure" do
55
+ lambda{ TypedArray.new(Type, Type.new).concat( 1 ) }.should raise_error(TypeError)
56
+ lambda{ TypedArray.new(Type, Type.new).concat( [1] ) }.should raise_error(TypeError)
57
+ end
58
+
59
+ it "<< success" do
60
+ ta = TypedArray.new(Type) << @t1
61
+ ta.should == [@t1]
62
+ end
63
+
64
+ it "<< failure" do
65
+ lambda{ TypedArray.new(Type, Type.new) << [1] }.should raise_error(TypeError)
66
+ end
67
+
68
+ it "[]= success" do
69
+ ta = TypedArray.new(Type)
70
+ ta[0]= @t1
71
+ ta[0].should == @t1
72
+ end
73
+
74
+ it "[]= failure" do
75
+ lambda{ TypedArray.new(Type, Type.new)[0]= 1 }.should raise_error(TypeError)
76
+ end
77
+
78
+ it "push success" do
79
+ ta = TypedArray.new(Type)
80
+ ta.push( @t1 )
81
+ ta.should == [@t1]
82
+ end
83
+
84
+ it "push failure" do
85
+ lambda{ TypedArray.new(Type, Type.new).push(1) }.should raise_error(TypeError)
86
+ end
87
+
88
+ it "should convert to array" do
89
+ ta = TypedArray.new(Type)
90
+ ta.to_a.should be_instance_of(Array)
91
+ end
92
+
93
+ end
94
+
95
+
@@ -0,0 +1,81 @@
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/demand"
11
+
12
+ include Scruby
13
+ include Ugens
14
+
15
+ class MockUgen < Ugen
16
+ class << self; public :new; end
17
+ end
18
+
19
+ describe Demand do
20
+ shared_examples_for 'Demand Ugen' do
21
+ before do
22
+ @prox = @splatted ? Demand.send( @method, *@ugens) : Demand.send( @method, @ugens)
23
+ @instance = @splatted ? @prox.source : @prox.first.source
24
+ end
25
+
26
+ it "should output proxies or single proxie" do
27
+ @splatted ? @prox.each{ |prox| prox.should be_a(OutputProxy) } : @prox.should( be_a(OutputProxy) )
28
+ end
29
+ end
30
+
31
+ shared_examples_for 'Demand with ar' do
32
+ before do
33
+ @method = :ar
34
+ end
35
+ it_should_behave_like 'Demand Ugen'
36
+ end
37
+
38
+ shared_examples_for 'Demand with kr' do
39
+ before do
40
+ @method = :ar
41
+ end
42
+ it_should_behave_like 'Demand Ugen'
43
+ end
44
+
45
+
46
+
47
+ describe 'Single channel splatted input' do
48
+ before do
49
+ @channels = 1
50
+ @ugens = [MockUgen.new(:audio, 1, 2)] * 4
51
+ @splatted = true
52
+ end
53
+
54
+ end
55
+
56
+ describe "Single channel array input" do
57
+ before do
58
+ @channels = 1
59
+ @ugens = [MockUgen.new(:audio, 1, 2)] * 4
60
+ @splatted = false
61
+ end
62
+
63
+ end
64
+
65
+ # describe "Two channel splatted input" do
66
+ # before do
67
+ # @channels = 2
68
+ # @splatted = false
69
+ # end
70
+ #
71
+ # end
72
+ #
73
+ # describe "Two channel array input" do
74
+ # before do
75
+ # @channels = 2
76
+ # @splatted = false
77
+ # end
78
+ #
79
+ # end
80
+
81
+ end
@@ -0,0 +1,138 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + "/helper"
2
+
3
+ require "scruby/core_ext/delegator_array"
4
+ require "scruby/core_ext/array"
5
+ require "scruby/control_name"
6
+ require "scruby/env"
7
+ require "scruby/synthdef"
8
+ require "scruby/ugens/ugen"
9
+ require "scruby/ugens/ugen_operations"
10
+ require "scruby/ugens/operation_ugens"
11
+ require "scruby/ugens/multi_out"
12
+ require "scruby/ugens/ugens"
13
+ require "scruby/ugens/disk_in_out"
14
+
15
+ include Scruby
16
+ include Ugens
17
+
18
+ class MockUgen < Ugen
19
+ class << self; public :new; end
20
+ end
21
+
22
+ describe 'IO ugens' do
23
+ describe DiskOut, 'one channel' do
24
+ before do
25
+ @sdef = SynthDef.new :out do |bufnum|
26
+ @out = DiskOut.ar bufnum, WhiteNoise.ar
27
+ end
28
+ end
29
+
30
+ it "should output zero" do
31
+ @out.should == 0.0
32
+ end
33
+
34
+ it "should encode correctly" do
35
+ expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 3, 111, 117, 116, 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, 10, 87, 104, 105, 116, 101, 78, 111, 105, 115, 101, 2, 0, 0, 0, 1, 0, 0, 2, 7, 68, 105, 115, 107, 79, 117, 116, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
36
+ @sdef.encode.should == expected.pack('C*')
37
+ end
38
+ end
39
+
40
+ describe DiskOut, 'two channel' do
41
+ before do
42
+ @sdef = SynthDef.new :out do |bufnum|
43
+ @out = DiskOut.ar bufnum, [WhiteNoise.ar, WhiteNoise.ar]
44
+ end
45
+ @sdef2 = SynthDef.new :out do |bufnum|
46
+ @out2 = DiskOut.ar bufnum, WhiteNoise.ar, WhiteNoise.ar
47
+ end
48
+ end
49
+
50
+ it "should output zero" do
51
+ @out.should == 0.0
52
+ end
53
+
54
+ it "should encode the same" do
55
+ @sdef.encode.should == @sdef2.encode
56
+ end
57
+
58
+ it "should encode correctly" do
59
+ expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 3, 111, 117, 116, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 6, 98, 117, 102, 110, 117, 109, 0, 0, 0, 4, 7, 67, 111, 110, 116, 114, 111, 108, 1, 0, 0, 0, 1, 0, 0, 1, 10, 87, 104, 105, 116, 101, 78, 111, 105, 115, 101, 2, 0, 0, 0, 1, 0, 0, 2, 10, 87, 104, 105, 116, 101, 78, 111, 105, 115, 101, 2, 0, 0, 0, 1, 0, 0, 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, 2, 0, 0, 0, 0 ]
60
+ @sdef.encode.should == expected.pack('C*')
61
+ end
62
+ end
63
+
64
+ shared_examples_for 'DiskIn' do
65
+ before do
66
+ @sdef = SynthDef.new :in do
67
+ @proxies = @class.send :ar, @channels, *@inputs
68
+ end
69
+ @instance = @proxies.first.source
70
+ end
71
+
72
+ it "should output a DelegatorArray" do
73
+ @proxies.should be_a(DelegatorArray)
74
+ end
75
+
76
+ it "should have correct rate" do
77
+ @instance.rate.should == :audio
78
+ end
79
+
80
+ it "should return an array of output proxies" do
81
+ @proxies.should have(@channels).proxies
82
+ @proxies.each_with_index do |proxy, i|
83
+ proxy.source.should be_a(@class)
84
+ proxy.should be_a(OutputProxy)
85
+ proxy.output_index.should == i
86
+ end
87
+ end
88
+
89
+ it "should set inputs" do
90
+ @instance.inputs.should == @inputs
91
+ end
92
+
93
+ it "should encode" do
94
+ @sdef.encode.should == @expected.pack('C*')
95
+ end
96
+ end
97
+
98
+ describe DiskIn, 'single channel' do
99
+ before do
100
+ @channels = 1
101
+ @inputs = 1, 0
102
+ @class = DiskIn
103
+ @expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 2, 105, 110, 0, 2, 63, -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 68, 105, 115, 107, 73, 110, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 0, 0 ]
104
+ end
105
+ it_should_behave_like 'DiskIn'
106
+ end
107
+
108
+ describe DiskIn, 'two channels' do
109
+ before do
110
+ @channels = 2
111
+ @inputs = 1, 0
112
+ @class = DiskIn
113
+ @expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 2, 105, 110, 0, 2, 63, -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 68, 105, 115, 107, 73, 110, 2, 0, 2, 0, 2, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 2, 0, 0 ]
114
+ end
115
+ it_should_behave_like 'DiskIn'
116
+ end
117
+
118
+ describe VDiskIn, 'single channel' do
119
+ before do
120
+ @channels = 1
121
+ @inputs = 1, 2, 3, 4
122
+ @class = VDiskIn
123
+ @expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 2, 105, 110, 0, 4, 63, -128, 0, 0, 64, 0, 0, 0, 64, 64, 0, 0, 64, -128, 0, 0, 0, 0, 0, 0, 0, 1, 7, 86, 68, 105, 115, 107, 73, 110, 2, 0, 4, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, -1, -1, 0, 2, -1, -1, 0, 3, 2, 0, 0 ]
124
+ end
125
+ it_should_behave_like 'DiskIn'
126
+ end
127
+
128
+ describe VDiskIn, 'two channels' do
129
+ before do
130
+ @channels = 2
131
+ @inputs = 1, 2, 3, 4
132
+ @class = VDiskIn
133
+ @expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 2, 105, 110, 0, 4, 63, -128, 0, 0, 64, 0, 0, 0, 64, 64, 0, 0, 64, -128, 0, 0, 0, 0, 0, 0, 0, 1, 7, 86, 68, 105, 115, 107, 73, 110, 2, 0, 4, 0, 2, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, -1, -1, 0, 2, -1, -1, 0, 3, 2, 2, 0, 0 ]
134
+ end
135
+ it_should_behave_like 'DiskIn'
136
+ end
137
+
138
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + "/helper"
2
+
3
+ require "scruby/control_name"
4
+ require "scruby/env"
5
+ require "scruby/ugens/ugen"
6
+ require "scruby/ugens/ugen_operations"
7
+ require "scruby/ugens/env_gen"
8
+
9
+ include Scruby
10
+ include Ugens
11
+
12
+ describe EnvGen do
13
+
14
+ it "should not instantiate with #new" do
15
+ lambda { EnvGen.new :audio, 1, 2 }.should raise_error
16
+ end
17
+
18
+ it "should have correct inputs" do
19
+ envgen = EnvGen.kr Env.adsr
20
+ envgen.rate.should == :control
21
+ envgen.inputs.should == [ 1, 1, 0, 1, 0, 0, 3, 2, -99, 1, 0.01, 5, -4, 0.5, 0.3, 5, -4, 0, 1, 5, -4 ].collect{ |i| i.to_f }
22
+ end
23
+ end
data/spec/env_spec.rb ADDED
@@ -0,0 +1,73 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + "/helper"
2
+
3
+ require "scruby/env"
4
+ require "scruby/control_name"
5
+ require "scruby/ugens/ugen"
6
+ require "scruby/ugens/ugen_operations"
7
+
8
+ class ControlName; end
9
+
10
+ include Scruby
11
+
12
+ describe Env do
13
+ it "Env.new [0,1,0], [0.5, 1]" do
14
+ env = Env.new [0,1,0], [0.5, 1]
15
+ env.times.should == [0.5, 1]
16
+ env.levels.should == [ 0, 1, 0 ]
17
+ env.shape_numbers.should == [1]
18
+ env.curve_values.should == [0]
19
+ end
20
+
21
+ it do
22
+ env = Env.new [0,1,0], [0.5, 1]
23
+ env.to_array.collect{ |i| i.to_f }.should == [ 0, 2, -99, -99, 1, 0.5, 1, 0, 0, 1, 1, 0 ].collect{ |i| i.to_f }
24
+ end
25
+
26
+ it do
27
+ Env.perc.should be_instance_of( Env )
28
+ end
29
+
30
+ it "#perc" do
31
+ perc = Env.perc
32
+ perc.to_array.collect{ |i| i.to_f }.should == [ 0, 2, -99, -99, 1, 0.01, 5, -4, 0, 1, 5, -4 ].collect{ |i| i.to_f }
33
+ end
34
+
35
+ it '#sine' do
36
+ env = Env.sine
37
+ env.to_array.collect{ |i| i.to_f }.should == [ 0, 2, -99, -99, 1, 0.5, 3, 0, 0, 0.5, 3, 0 ].collect{ |i| i.to_f }
38
+ end
39
+
40
+ it "#linen" do
41
+ env = Env.linen
42
+ env.to_array.collect{ |i| i.to_f }.should == [ 0, 3, -99, -99, 1, 0.01, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0 ].collect{ |i| i.to_f }
43
+ end
44
+
45
+ it "#triangle" do
46
+ env = Env.triangle
47
+ env.to_array.collect{ |i| i.to_f }.should == [ 0, 2, -99, -99, 1, 0.5, 1, 0, 0, 0.5, 1, 0 ].collect{ |i| i.to_f }
48
+ end
49
+
50
+ it "#cutoff" do
51
+ env = Env.cutoff
52
+ env.to_array.collect{ |i| i.to_f }.should == [ 1, 1, 0, -99, 0, 0.1, 1, 0 ].collect{ |i| i.to_f }
53
+ end
54
+
55
+ it "#dadsr" do
56
+ env = Env.dadsr
57
+ env.to_array.collect{ |i| i.to_f }.should == [ 0, 4, 3, -99, 0, 0.1, 5, -4, 1, 0.01, 5, -4, 0.5, 0.3, 5, -4, 0, 1, 5, -4 ].collect{ |i| i.to_f }
58
+ end
59
+
60
+ it "#dadsr" do
61
+ env = Env.adsr
62
+ env.to_array.collect{ |i| i.to_f }.should == [ 0, 3, 2, -99, 1, 0.01, 5, -4, 0.5, 0.3, 5, -4, 0, 1, 5, -4 ].collect{ |i| i.to_f }
63
+ end
64
+
65
+ describe 'Overriding defaults' do
66
+
67
+ it "#asr" do
68
+ Env.asr(2, 1, 2).to_array.should == [ 0, 2, 1, -99, 1, 2, 5, -4, 0, 2, 5, -4 ]
69
+ end
70
+
71
+ end
72
+
73
+ end
@@ -0,0 +1,71 @@
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/group"
7
+ require 'scruby/bus'
8
+
9
+ require 'scruby/server'
10
+ require File.join( File.expand_path(File.dirname(__FILE__)), "server")
11
+
12
+
13
+ include Scruby
14
+ class Bus; end # mock
15
+
16
+ describe Group do
17
+ before :all do
18
+ end
19
+
20
+ before do
21
+ Node.reset!
22
+ Server.stub!(:all).and_return([@server])
23
+ end
24
+
25
+ describe 'Server interaction' do
26
+ before :all do
27
+ @server = Server.new
28
+ @server.boot
29
+ @server.send "/dumpOSC", 3
30
+ sleep 0.05
31
+ end
32
+
33
+ after :all do
34
+ @server.quit
35
+ end
36
+
37
+ before do
38
+ @server.flush
39
+ @group = Group.new @server
40
+ @node = Node.new @server
41
+ end
42
+
43
+ describe 'position' do
44
+ end
45
+
46
+ it "should send free all message" do
47
+ @group.free_all.should be_a(Group)
48
+ sleep 0.05
49
+ @server.output.should =~ %r{\[ "/g_freeAll", #{ @group.id } \]}
50
+ end
51
+
52
+ it "should send deepFree message" do
53
+ @group.deep_free.should be_a(Group)
54
+ sleep 0.05
55
+ @server.output.should =~ %r{\[ "/g_deepFree", #{ @group.id } \]}
56
+ end
57
+
58
+ it "should send dump tree message" do
59
+ @group.dump_tree.should be_a(Group)
60
+ sleep 0.05
61
+ @server.output.should =~ %r{\[ "/g_dumpTree", #{ @group.id }, 0 \]}
62
+ @group.dump_tree true
63
+ sleep 0.05
64
+ @server.output.should =~ %r{\[ "/g_dumpTree", #{ @group.id }, 1 \]}
65
+ end
66
+
67
+ it "should send dump tree message with arg"
68
+ it "should query_tree"
69
+ end
70
+
71
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,20 @@
1
+ require "rubygems"
2
+ require "rspec"
3
+ require 'arguments'
4
+ require 'yaml'
5
+ require 'ruby-osc'
6
+
7
+ $:.unshift( File.dirname(__FILE__) + '/../lib' )
8
+
9
+ require "scruby/core_ext/object"
10
+ require "scruby/core_ext/array"
11
+ require "scruby/core_ext/numeric"
12
+ require "scruby/core_ext/fixnum"
13
+ require "scruby/core_ext/proc"
14
+ require "scruby/core_ext/string"
15
+ require "scruby/core_ext/symbol"
16
+
17
+
18
+
19
+
20
+
@@ -0,0 +1,127 @@
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/in_out"
10
+
11
+ include Scruby
12
+ include Ugens
13
+
14
+ class SinOsc < Ugen
15
+ #not interested in muladd
16
+ def self.ar freq = 440.0, phase = 0.0
17
+ new :audio, freq, phase
18
+ end
19
+ end
20
+
21
+ class MockUgen < Ugen
22
+ class << self; public :new; end
23
+ end
24
+
25
+ describe In do
26
+ before do
27
+ @sdef = mock( 'ugen', :children => [] )
28
+ Ugen.should_receive( :synthdef ).at_least( :once ).and_return( @sdef )
29
+
30
+ @proxy = mock('output proxy' )
31
+ @proxies = (1..10).map{ @proxy }
32
+ OutputProxy.stub!(:new).and_return( @proxy )
33
+
34
+ @ar = In.ar 3
35
+ end
36
+
37
+ it "respond to #kr and #ar" do
38
+ In.should respond_to(:kr)
39
+ In.should respond_to(:ar)
40
+ end
41
+
42
+ it "should spec #ar" do
43
+ @ar.should be_instance_of( DelegatorArray )
44
+ @ar.should have(1).proxy
45
+ @ar.first.should == @proxy
46
+ end
47
+
48
+ it "should have bus as input" do
49
+ @sdef.children.first.inputs.should == [3]
50
+ end
51
+
52
+ it "should have ten channels" do
53
+ In.ar(0, 10).should == @proxies
54
+ end
55
+
56
+ it "should describe passing arrays to initialize"
57
+
58
+ end
59
+
60
+
61
+ describe Out do
62
+ shared_examples_for 'Out' do
63
+ before do
64
+ @sdef = mock 'sdef', :children => [], :constants => [400, 0]
65
+ Ugen.should_receive( :synthdef ).at_least( :once ).and_return @sdef
66
+ end
67
+
68
+ it "should accept one ugen" do
69
+ @ugen1 = MockUgen.new :audio
70
+ @class.kr( 1, @ugen1 ).should == 0.0
71
+ @sdef.children.should have(2).ugens
72
+
73
+ out = @sdef.children.last
74
+ out.rate.should == :control
75
+ out.inputs.should == [1, @ugen1]
76
+ out.channels.should == []
77
+ end
78
+
79
+ it "should accept several inputs from array" do
80
+ @ugen1 = MockUgen.new :audio
81
+ @ugen2 = MockUgen.new :audio
82
+ @ugen3 = MockUgen.new :audio
83
+
84
+ @class.kr 1, [@ugen1, @ugen2, @ugen3]
85
+ @sdef.children.should have(4).ugens
86
+
87
+ out = @sdef.children.last
88
+ out.inputs.should == [1, @ugen1, @ugen2, @ugen3]
89
+ end
90
+
91
+ it "should accept several inputs" do
92
+ @ugen1 = MockUgen.new :audio
93
+ @ugen2 = MockUgen.new :audio
94
+ @ugen3 = MockUgen.new :audio
95
+
96
+ @class.kr 1, @ugen1, @ugen2, @ugen3
97
+ @sdef.children.should have(4).ugens
98
+
99
+ out = @sdef.children.last
100
+ out.inputs.should == [1, @ugen1, @ugen2, @ugen3]
101
+ end
102
+
103
+ it "should validate rate"
104
+ it "should substitute zero with silence"
105
+ it "should spec passing array on init"
106
+ end
107
+
108
+ describe Out do
109
+ before do
110
+ @class = Out
111
+ end
112
+ it_should_behave_like 'Out'
113
+ end
114
+
115
+ describe ReplaceOut do
116
+ before do
117
+ @class = Out
118
+ end
119
+ it_should_behave_like 'Out'
120
+ end
121
+ end
122
+
123
+
124
+
125
+
126
+
127
+