Skip to content
Browse files

changed outputs attribute for channels attribute in multiout ugen

  • Loading branch information...
1 parent a7ef557 commit 2b61957f961eda875e8b828b56d99955af8abdef @maca committed
View
3 README
@@ -0,0 +1,3 @@
+
+
+Ruby has operation precendence
View
26 lib/scruby/audio/ugens/in_out.rb
@@ -0,0 +1,26 @@
+module Scruby
+ module Audio
+ module Ugens
+
+ class In < MultiOutUgen
+ def self.ar( bus, num_channels = 1 )
+ new :audio, num_channels, bus
+ end
+
+ def self.kr( bus, num_channels = 1 )
+ new :control, num_channels, bus
+ end
+ end
+
+ class AbstractOut
+ end
+
+ class Out
+
+
+ end
+
+
+ end
+ end
+end
View
19 lib/scruby/audio/ugens/multi_out_ugens.rb
@@ -1,6 +1,7 @@
module Scruby
module Audio
module Ugens
+
class OutputProxy < Ugen
attr_reader :source, :control_name, :output_index
@@ -11,31 +12,23 @@ def initialize( rate, source, name, output_index )
end
def add_to_synthdef; end
-
end
class MultiOutUgen < Ugen
- attr_reader :channels, :outputs
- private
- attr_writer :channels, :outputs
-
+ private
+ attr_writer :channels
def output_specs
- outputs.collect{ |output| output.send :output_specs }.flatten
+ channels.collect{ |output| output.send :output_specs }.flatten
end
-
end
class Control < MultiOutUgen #:nodoc:
def self.and_proxies_from( names )
control = Control.new( names.first.rate )
- control.send :outputs=, names.collect_with_index { |name, index| OutputProxy.new( names.first.rate, control, name, index ) }
+ control.send :channels=, names.collect_with_index { |name, index| OutputProxy.new( names.first.rate, control, name, index ) }
end
-
- def initialize(rate, *inputs)
- super
- end
-
end
+
end
end
end
View
8 lib/scruby/audio/ugens/ugen.rb
@@ -2,7 +2,7 @@ module Scruby
module Audio
module Ugens
class Ugen
- attr_reader :inputs, :rate, :index, :special_index, :output_index, :outputs
+ attr_reader :inputs, :rate, :index, :special_index, :output_index, :channels
RATES = [ :scalar, :trigger, :demand, :control, :audio ]
E_RATES = [ :scalar, :control, :audio, :demand ]
@@ -15,7 +15,7 @@ def initialize( rate, *inputs)
@special_index ||= 0
@output_index ||= 0
- @outputs ||= [1]
+ @channels ||= [1]
@index = add_to_synthdef || 0
end
@@ -33,12 +33,12 @@ def ugen?
end
def encode
- self.class.to_s.split('::').last.encode + [E_RATES.index(rate)].pack('w') + [inputs.size, outputs.size, special_index, collect_input_specs].flatten.pack('n*') + output_specs.pack('w*')
+ self.class.to_s.split('::').last.encode + [E_RATES.index(rate)].pack('w') + [inputs.size, channels.size, special_index, collect_input_specs].flatten.pack('n*') + output_specs.pack('w*')
end
private
def synthdef
- @synthdef ||= self.class.synthdef
+ @synthdef ||= Ugen.synthdef
end
def add_to_synthdef #:nodoc:
View
47 spec/audio/in_out_spec.rb
@@ -0,0 +1,47 @@
+require File.join( File.expand_path(File.dirname(__FILE__)),"../helper")
+
+require "#{LIB_DIR}/audio/ugens/ugen_operations"
+require "#{LIB_DIR}/extensions"
+require "#{LIB_DIR}/audio/ugens/ugen"
+require "#{LIB_DIR}/audio/ugens/multi_out_ugens"
+require "#{LIB_DIR}/audio/ugens/in_out"
+
+
+require 'named_arguments'
+
+include Scruby
+include Audio
+include Ugens
+
+
+describe In do
+
+ it "respond to #kr and #ar "do
+ In.should respond_to(:kr)
+ In.should respond_to(:ar)
+ end
+
+ it "should instatiate with #ar" do
+ ar = In.ar(0, 2)
+ ar.should be_instance_of( In )
+ ar.rate.should == :audio
+ ar.inputs.should == [2,0]
+ end
+
+ it "should instatiate with #kr" do
+ kr = In.kr(0, 2)
+ kr.should be_instance_of( In )
+ kr.rate.should == :control
+ kr.inputs.should == [2,0]
+ end
+
+
+
+end
+
+describe AbstractOut do
+
+end
+
+describe Out do
+end
View
11 spec/audio/integration_spec.rb
@@ -14,16 +14,12 @@
require "#{LIB_DIR}/audio/synthdef"
require "#{LIB_DIR}/extensions"
-
-
include Scruby
include Audio
include Ugens
include OperationUgens
-
-
describe "synthdef examples" do
before do
@@ -43,4 +39,11 @@
@sdef.encode.should == @expected
end
+ it "should encode" do
+ 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*')
+ SynthDef.new(:help){ (SinOsc.ar() + SinOsc.ar()) * SinOsc.ar() }.encode.should == expected
+ end
+
+
+
end
View
12 spec/audio/multiout_ugen_spec.rb
@@ -12,9 +12,9 @@
describe MultiOutUgen do
- it "should respond to channels and outputs" do
+ it "should respond to channels and channels" do
+ # MultiOutUgen.new( :audio, 1 ).should respond_to(:channels)
MultiOutUgen.new( :audio, 1 ).should respond_to(:channels)
- MultiOutUgen.new( :audio, 1 ).should respond_to(:outputs)
end
end
@@ -23,7 +23,7 @@
before do
- @control = mock('control', :outputs= => nil)
+ @control = mock('control', :channels= => nil)
@names = Array.new( rand(7) + 3 ){ |i| mock('name', :rate => :control) }
Ugen.synthdef = nil
@proxy = mock('proxy', :instance_of_proxy? => true)
@@ -73,7 +73,7 @@
end
it "should instantiate output proxies with the right attributes" do
- @control = mock('control', :outputs= => nil)
+ @control = mock('control', :channels= => nil)
Control.stub!( :new ).and_return( @control )
@names.collect_with_index { |n, i| OutputProxy.should_receive(:new).with( :control, @control, n, i) }
Control.and_proxies_from( @names )
@@ -85,8 +85,8 @@
end
end
- it "should set outputs" do
- @control.should_receive( :outputs= )
+ it "should set channels" do
+ @control.should_receive( :channels= )
Control.stub!( :new ).and_return( @control )
Control.and_proxies_from( @names )
end
View
4 spec/audio/ugen_spec.rb
@@ -289,7 +289,7 @@ def kr( freq=440.0, phase=0.0 )
end
it "should encode have [1] as output index" do
- @sin.send(:outputs).should == [1]
+ @sin.send(:channels).should == [1]
end
it "should return input_specs" do
@@ -313,7 +313,7 @@ def kr( freq=440.0, phase=0.0 )
@sin.encode[0..7].should == @encoded[0..7]
end
- it "should encode cn, rt, inputs, outputs, special_index" do
+ it "should encode cn, rt, inputs, channels, special_index" do
@sin.encode[0..13].should == @encoded[0..13]
end

0 comments on commit 2b61957

Please sign in to comment.
Something went wrong with that request. Please try again.