maca-Scruby 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/README.rdoc +26 -0
  2. data/Rakefile +10 -0
  3. data/Scruby.gemspec +36 -0
  4. data/bin/live_session.rb +12 -0
  5. data/changes +1 -0
  6. data/lib/live/session.rb +144 -0
  7. data/lib/scruby.rb +60 -0
  8. data/lib/scruby/audio/control_name.rb +29 -0
  9. data/lib/scruby/audio/env.rb +97 -0
  10. data/lib/scruby/audio/node.rb +20 -0
  11. data/lib/scruby/audio/server.rb +112 -0
  12. data/lib/scruby/audio/synth.rb +15 -0
  13. data/lib/scruby/audio/synthdef.rb +114 -0
  14. data/lib/scruby/audio/ugens/env_gen.rb +18 -0
  15. data/lib/scruby/audio/ugens/in_out.rb +43 -0
  16. data/lib/scruby/audio/ugens/multi_out_ugens.rb +48 -0
  17. data/lib/scruby/audio/ugens/operation_indices.yaml +92 -0
  18. data/lib/scruby/audio/ugens/operation_ugens.rb +64 -0
  19. data/lib/scruby/audio/ugens/ugen.rb +154 -0
  20. data/lib/scruby/audio/ugens/ugen_defs.yaml +3421 -0
  21. data/lib/scruby/audio/ugens/ugen_operations.rb +44 -0
  22. data/lib/scruby/audio/ugens/ugens.rb +34 -0
  23. data/lib/scruby/control/metro.rb +6 -0
  24. data/lib/scruby/extensions.rb +109 -0
  25. data/lib/scruby/typed_array.rb +64 -0
  26. data/spec/audio/env_gen_specs.rb +25 -0
  27. data/spec/audio/in_out_spec.rb +107 -0
  28. data/spec/audio/integration_spec.rb +106 -0
  29. data/spec/audio/lib_spec.rb +14 -0
  30. data/spec/audio/multiout_ugen_spec.rb +112 -0
  31. data/spec/audio/node_spec.rb +60 -0
  32. data/spec/audio/operation_ugens_spec.rb +189 -0
  33. data/spec/audio/server_spec.rb +68 -0
  34. data/spec/audio/synth_spec.rb +46 -0
  35. data/spec/audio/synthdef_spec.rb +275 -0
  36. data/spec/audio/ugen_operations_spec.rb +146 -0
  37. data/spec/audio/ugen_spec.rb +333 -0
  38. data/spec/audio/ugens_spec.rb +61 -0
  39. data/spec/env_spec.rb +64 -0
  40. data/spec/extensions_spec.rb +133 -0
  41. data/spec/helper.rb +11 -0
  42. data/spec/typed_array_spec.rb +95 -0
  43. metadata +129 -0
@@ -0,0 +1,14 @@
1
+ require File.join( File.expand_path(File.dirname(__FILE__)), '..',"helper")
2
+ require "named_arguments"
3
+ require 'osc'
4
+
5
+ require "#{SCRUBY_DIR}/../scruby"
6
+
7
+ describe 'Lib' do
8
+
9
+ it "should instantiate and encode" do
10
+ expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 4, 104, 101, 108, 112, 0, 2, 67, -36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 2, 0, 0, 0, 3, 0, 0, 2, 0, 0 ].pack('C*')
11
+ SynthDef.new(:help){ (SinOsc.ar() + SinOsc.ar()) * SinOsc.ar() }.encode.should == expected
12
+ end
13
+
14
+ end
@@ -0,0 +1,112 @@
1
+ require File.join( File.expand_path(File.dirname(__FILE__)), '..',"helper")
2
+
3
+ require "#{SCRUBY_DIR}/audio/ugens/ugen_operations"
4
+ require "#{SCRUBY_DIR}/audio/ugens/ugen"
5
+ require "#{SCRUBY_DIR}/extensions"
6
+ require "#{SCRUBY_DIR}/audio/ugens/multi_out_ugens"
7
+
8
+ include Scruby
9
+ include Audio
10
+ include Ugens
11
+
12
+ describe MultiOutUgen do
13
+ before do
14
+ sdef = mock( 'sdef', :children => [] )
15
+ Ugen.should_receive( :synthdef ).and_return( sdef )
16
+ @proxies = MultiOutUgen.new( :audio, 1, 2, 3 )
17
+ @multi = sdef.children.first
18
+ end
19
+
20
+ it "should return an array of channels" do
21
+ @proxies.should be_instance_of( Array )
22
+ @proxies.should == [1,2,3]
23
+ end
24
+
25
+ it "should be instace of Control" do
26
+ @multi.should be_instance_of( MultiOutUgen )
27
+ end
28
+
29
+ it do
30
+ @multi.rate.should == :audio
31
+ end
32
+
33
+ it do
34
+ @multi.channels.should == [1,2,3]
35
+ end
36
+
37
+ it do
38
+ @multi.inputs.should == []
39
+ end
40
+ end
41
+
42
+ describe Control do
43
+ before do
44
+ sdef = mock( 'sdef', :children => [] )
45
+ Ugen.stub!( :synthdef ).and_return( sdef )
46
+
47
+ @proxy = mock('proxy', :instance_of_proxy? => true)
48
+ OutputProxy.stub!( :new ).and_return( @proxy )
49
+
50
+ @names = Array.new( rand(7) + 3 ){ |i| mock('name', :rate => :audio, :valid_ugen_input? => true) }
51
+ @proxies = Control.new( :audio, *@names )
52
+ @control = sdef.children.first
53
+ end
54
+
55
+ it "should return an array of proxies" do
56
+ @proxies.should be_instance_of( Array )
57
+ @proxies.should have( @names.size ).proxies
58
+ end
59
+
60
+ it "should set channels" do
61
+ @control.should be_instance_of( Control )
62
+ @control.channels.should == @names.map{ @proxy }
63
+ end
64
+
65
+ it "should be added to synthdef" do
66
+ Ugen.should_receive( :synthdef )
67
+ Control.new( :audio, [])
68
+ end
69
+
70
+ it "should instantiate with #and_proxies_from" do
71
+ Control.should_receive(:new).with( :audio, *@names )
72
+ Control.and_proxies_from( @names )
73
+ end
74
+
75
+ it "should have index" do
76
+ @control.index.should == 0
77
+ end
78
+
79
+ end
80
+
81
+ describe OutputProxy do
82
+
83
+ before do
84
+ @sdef = mock( 'sdef', :children => [] )
85
+ Ugen.stub!( :synthdef ).and_return( @sdef )
86
+
87
+ @source = mock('source', :index => 0, :valid_ugen_input? => true )
88
+ @name = mock('control name', :valid_ugen_input? => true)
89
+ @output_index = mock('output_idex', :valid_ugen_input? => true)
90
+
91
+ @names = [mock('name', :rate => :audio, :valid_ugen_input? => true)]
92
+
93
+ end
94
+
95
+ it "should receive index from control" do
96
+ Control.and_proxies_from( @names ).first.index.should == 0
97
+ @sdef.children.first.index.should == 0
98
+ end
99
+
100
+ it "should have empty inputs" do
101
+ OutputProxy.new( :audio, @source, @output_index, @name ).inputs.should == []
102
+ end
103
+
104
+
105
+ it "should not be added to synthdef" do
106
+ Ugen.should_not_receive( :synthdef )
107
+ OutputProxy.new( :audio, @source, @output_index, @name )
108
+ end
109
+
110
+ end
111
+
112
+
@@ -0,0 +1,60 @@
1
+ require File.join( File.expand_path(File.dirname(__FILE__)), '..',"helper")
2
+ require 'yaml'
3
+ require 'named_arguments'
4
+
5
+
6
+ require "#{SCRUBY_DIR}/typed_array"
7
+ require "#{SCRUBY_DIR}/audio/node"
8
+ include Scruby
9
+
10
+
11
+
12
+
13
+ describe Node do
14
+ before :all do
15
+ @server = mock('server')
16
+ Server = mock('Server' )
17
+ end
18
+
19
+ before do
20
+ Node.reset!
21
+ Server.stub!(:all).and_return([@server])
22
+ end
23
+
24
+ it "should have incremental uniq id" do
25
+ 10.times do |i|
26
+ Node.new( 'nodo' ).id.should == 2001 + i
27
+ end
28
+ end
29
+
30
+ it "should reset" do
31
+ Node.new( 'nodo' ).id.should == 2001
32
+ end
33
+
34
+ describe 'instantiation' do
35
+
36
+ it "should have a name" do
37
+ Node.new('nodo').name.should == 'nodo'
38
+ end
39
+
40
+ it "should not accept non servers" do
41
+ lambda{ Node.new('nodo', 1,2) }.should raise_error(TypeError)
42
+ lambda{ Node.new('nodo', [1,2]) }.should raise_error(TypeError)
43
+ end
44
+
45
+ it "should accept a server and have a TypedArray of Servers" do
46
+ @server.should_receive(:instance_of?).exactly(:twice).and_return(true)
47
+ n = Node.new( 'nodo', @server )
48
+ n.servers.should == [@server]
49
+ n = Node.new( 'nodo', [@server] )
50
+ n.servers.should == [@server]
51
+ end
52
+
53
+ it "should have default servers if no server is passed" do
54
+ n = Node.new( 'nodo' )
55
+ n.servers.should == [@server]
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -0,0 +1,189 @@
1
+ require File.join( File.expand_path(File.dirname(__FILE__)), '..',"helper")
2
+ require 'yaml'
3
+
4
+ require "#{SCRUBY_DIR}/audio/ugens/ugen_operations"
5
+ require "#{SCRUBY_DIR}/audio/ugens/ugen"
6
+ require "#{SCRUBY_DIR}/extensions"
7
+ require "#{SCRUBY_DIR}/audio/ugens/operation_ugens"
8
+
9
+ include Scruby
10
+ include Audio
11
+ include Ugens
12
+ include OperationUgens
13
+
14
+ describe UnaryOpUgen do
15
+ RATES = [ :scalar, :demand, :control, :audio ]
16
+
17
+ before do
18
+ @scalar = mock( 'ugen', :rate => :scalar, :valid_ugen_input? => true )
19
+ @demand = mock( 'ugen', :rate => :demand, :valid_ugen_input? => true )
20
+ @control = mock( 'ugen', :rate => :control, :valid_ugen_input? => true )
21
+ @audio = mock( 'ugen', :rate => :audio, :valid_ugen_input? => true )
22
+ end
23
+
24
+ describe UnaryOpUgen do
25
+
26
+ before do
27
+ @op = UnaryOpUgen.new( :neg, @audio )
28
+ end
29
+
30
+ it "should return special index" do
31
+ UnaryOpUgen.new( :neg, @audio ).special_index.should == 0
32
+ UnaryOpUgen.new( :bitNot, @audio ).special_index.should == 4
33
+ UnaryOpUgen.new( :abs, @audio ).special_index.should == 5
34
+ UnaryOpUgen.new( :asFloat, @audio ).special_index.should == 6
35
+ end
36
+
37
+ it "should accept just one input" do
38
+ lambda{ UnaryOpUgen.new(:neg, @audio, @demand) }.should raise_error( ArgumentError )
39
+ end
40
+
41
+ it "should just accept defined operators" # do
42
+ # lambda{ UnaryOpUgen.new(:not_operator, @audio) }.should raise_error( ArgumentError )
43
+ # end
44
+
45
+ it "should get max rate" do
46
+ UnaryOpUgen.send(:get_rate, @scalar, @demand ).should == :demand
47
+ UnaryOpUgen.send(:get_rate, @scalar, @demand, @audio ).should == :audio
48
+ UnaryOpUgen.send(:get_rate, @scalar, [@demand, [@control, @audio]] ).should == :audio
49
+ end
50
+
51
+ it do
52
+ UnaryOpUgen.new(:neg, @audio).should be_instance_of(UnaryOpUgen)
53
+ end
54
+
55
+ it "should set rate" do
56
+ UnaryOpUgen.new(:neg, @audio).rate.should == :audio
57
+ UnaryOpUgen.new(:neg, @scalar).rate.should == :scalar
58
+ end
59
+
60
+ it "should set operator" do
61
+ UnaryOpUgen.new(:neg, @audio).operator.should == :neg
62
+ end
63
+ end
64
+
65
+ describe BinaryOpUGen do
66
+
67
+ before do
68
+ @arg_array = [@audio, [@scalar, @audio, [@demand, [@control, @demand]]] ]
69
+ @op_arr = BinaryOpUGen.new(:+, @audio, @arg_array )
70
+ end
71
+
72
+ it "should return special index" do
73
+ BinaryOpUGen.new( :+, @audio, @audio ).special_index.should eql(0)
74
+ BinaryOpUGen.new( :-, @audio, @audio ).special_index.should eql(1)
75
+ BinaryOpUGen.new( :*, @audio, @audio ).special_index.should eql(2)
76
+ BinaryOpUGen.new( :/, @audio, @audio ).special_index.should eql(4)
77
+ end
78
+
79
+ it "should accept exactly two inputs" do
80
+ lambda{ BinaryOpUGen.new(:+, @audio) }.should raise_error( ArgumentError )
81
+ lambda{ BinaryOpUGen.new(:+, @audio, @demand, @demand) }.should raise_error( ArgumentError )
82
+ end
83
+
84
+ it "should have correct inputs and operator when two inputs" do
85
+ arr = BinaryOpUGen.new( :+, @audio, @demand )
86
+ arr.inputs.should == [@audio, @demand]
87
+ arr.operator.should == :+
88
+ arr.rate.should == :audio
89
+ end
90
+
91
+ it "should accept array as input" do
92
+ BinaryOpUGen.new(:+, @audio, [@audio, @scalar] ).should be_instance_of(Array)
93
+ end
94
+
95
+ it "should return an array of UnaryOpUgens" do
96
+ @op_arr.flatten.map { |op| op.should be_instance_of(BinaryOpUGen) }
97
+ end
98
+
99
+ it "should set rate for all operations" do
100
+ @op_arr.flatten.map { |op| op.rate.should eql(:audio) }
101
+ end
102
+
103
+ it "should set operator for all operations" do
104
+ @op_arr.flatten.map { |op| op.operator.should eql(:+) }
105
+ end
106
+
107
+ it "should set correct inputs when provided an array" do
108
+ arr = BinaryOpUGen.new(:+, @control, [@audio, @scalar] )
109
+ arr.first.inputs.should == [@control, @audio]
110
+ arr.last.inputs.should == [@control, @scalar]
111
+ end
112
+
113
+ it "should create the correct number of operations" do
114
+ @op_arr.flatten.size.should eql( @arg_array.flatten.size )
115
+ end
116
+
117
+ it "should replicate the array passed" do
118
+ last = lambda do |i|
119
+ if i.instance_of?( BinaryOpUGen)
120
+ i.inputs.first.should == @audio
121
+ i.inputs.last
122
+ else
123
+ i.map{ |e| last.call(e) }
124
+ end
125
+ end
126
+ last.call(@op_arr).should == @arg_array
127
+ end
128
+
129
+ it "should accept numbers as inputs" do
130
+ arr = BinaryOpUGen.new(:+, @control, [100, 200.0] )
131
+ arr.first.inputs.should == [@control, 100]
132
+ arr.last.inputs.should == [@control, 200.0]
133
+ BinaryOpUGen.new(:+, 100, @control ).inputs.should == [100, @control]
134
+ end
135
+
136
+ it "should accept array as input" do
137
+ arr = BinaryOpUGen.new(:+, [@audio, @scalar], @control )
138
+ arr.first.inputs.should == [@audio, @control]
139
+ arr.last.inputs.should == [@scalar, @control]
140
+ end
141
+ end
142
+
143
+ describe MulAdd do
144
+ it do
145
+ MulAdd.new( @audio, 0.5, 0.5 ).should be_instance_of(MulAdd)
146
+ end
147
+
148
+ it do
149
+ MulAdd.new( @audio, 0.5, 0.5 ).rate.should == :audio
150
+ end
151
+
152
+ it do
153
+ MulAdd.new( @audio, 0.5, 0.5 ).inputs.should == [@audio, 0.5, 0.5]
154
+ end
155
+
156
+ it "should not be instance of MulAdd" do
157
+ unary_op = mock('neg')
158
+ mult = mock('mult')
159
+ minus = mock('minus')
160
+ plus = mock('plus')
161
+
162
+ @audio.should_receive( :neg ).and_return( unary_op )
163
+ @audio.should_receive( :* ).and_return( mult )
164
+ add = mock( '0.5', :- => minus, :zero? => false )
165
+ @audio.should_receive( :+ ).and_return( plus )
166
+
167
+ MulAdd.new( @audio, 0, 0.5 ).should be_instance_of( Float )
168
+ MulAdd.new( @audio, 1, 0 ).should == @audio
169
+ MulAdd.new( @audio, -1, 0 ).should == unary_op
170
+ MulAdd.new( @audio, 0.5, 0 ).should == mult
171
+ MulAdd.new( @audio, -1, add ).should == minus
172
+ MulAdd.new( @audio, 1, 0.5 ).should == plus
173
+ end
174
+
175
+ it "should accept ugens" do
176
+ MulAdd.new( @audio, @audio, 1 ).should be_instance_of(MulAdd)
177
+ MulAdd.new( @audio, @audio, @scalar ).should be_instance_of(MulAdd)
178
+
179
+ bin_op_ugen = mock('binary op ugen')
180
+ @audio.stub!( :* ).and_return( bin_op_ugen )
181
+ MulAdd.new( @audio, @audio, 0 ).should == bin_op_ugen
182
+ end
183
+
184
+ it "should accept array"
185
+
186
+ end
187
+
188
+ end
189
+
@@ -0,0 +1,68 @@
1
+ require File.join( File.expand_path(File.dirname(__FILE__)), '..',"helper")
2
+ require 'yaml'
3
+ require 'tempfile'
4
+
5
+ require 'named_arguments'
6
+ require 'osc'
7
+ require "#{SCRUBY_DIR}/audio/server"
8
+
9
+ include Scruby
10
+ include Audio
11
+
12
+
13
+ describe Server, 'instantiation and booting' do
14
+
15
+ before do
16
+ @server = Server.new
17
+ end
18
+
19
+ it "should not rise scynth not found error" do
20
+ File.stub!( :exists ).and_return( true )
21
+ lambda{ @server = Server.new; @server.boot; @server.stop }.should_not raise_error(Server::SCError)
22
+ end
23
+
24
+ it "should not reboot" do
25
+ @server.boot
26
+ Thread.should_not_receive(:new)
27
+ @server.boot
28
+ @server.stop
29
+ end
30
+
31
+ it "should raise scsynth not found error" do
32
+ Server.sc_path = '/Applications/SuperCollider/not_scsynth'
33
+ lambda{ @server = Server.new; @server.boot }.should raise_error(Server::SCError)
34
+ end
35
+
36
+ it "should add self to a list of servers" do
37
+ s = Server.new
38
+ Server.all.should include(s)
39
+ end
40
+
41
+ describe 'sending OSC' do
42
+
43
+ before :all do
44
+ Server.sc_path = '/Applications/SuperCollider/scsynth'
45
+
46
+ encoded = "SCgf\000\000\000\001\000\001\003out\000\002C\334\000\000\000\000\000\000\000\000\000\000\000\002\006SinOsc\002\000\002\000\001\000\000\377\377\000\000\377\377\000\001\002\003Out\002\000\002\000\000\000\000\377\377\000\001\000\000\000\000\000\000"
47
+ @sdef = mock('sdef', :encode => encoded)
48
+
49
+ @server = Server.new
50
+ # @server.boot
51
+ end
52
+
53
+ after do
54
+ # @server.stop
55
+ end
56
+
57
+ it "should send message" # do
58
+ # @server.send_synth_def( @sdef )
59
+ #
60
+ # # blob = [OSC::Blob.new( @sdef.encode ), 0]
61
+ #
62
+ # end
63
+
64
+
65
+
66
+ end
67
+ end
68
+