Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added Panner and subclasses, I think panning should work now

  • Loading branch information...
commit 8080ee0af1a13aa3f8c9a7f03c29055d1699495a 1 parent 6e4ca1b
@maca maca authored
View
6 lib/scruby/ugens/multi_out_ugens.rb
@@ -8,9 +8,7 @@ def initialize rate, source, output_index, name = nil
@source, @control_name, @output_index = source, name, output_index
end
- def index
- @source.index
- end
+ def index; @source.index; end
def add_to_synthdef; end
end
@@ -22,7 +20,7 @@ def initialize rate, *channels
end
def self.new rate, *args
- super.channels #returns the channels but gets instantiated
+ super.channels #returns the channels but gets instantiated, TODO: Maybe not a good idea
end
private
View
167 lib/scruby/ugens/pan.rb
@@ -0,0 +1,167 @@
+module Scruby
+ module Ugens
+
+ class Panner < MultiOutUgen
+ def initialize rate, inputs, channels
+ super rate, *(0...channels).map{ |i| OutputProxy.new(rate, self, i) }
+ @inputs = inputs
+ inputs.each do |i|
+ raise ArgumentError.new("input #{ i } has not audio rate.") unless i.rate == :audio if Ugen === i
+ end if rate == :audio
+ end
+ end
+
+ class Pan2 < Panner
+ def initialize rate, *inputs
+ super rate, inputs, 2
+ end
+
+ class << self
+ def ar input, pos = 0.0, level = 1.0
+ new :audio, input, pos, level
+ end
+
+ def kr input, pos = 0.0, level = 1.0
+ new :control, input, pos, level
+ end
+ named_args_for :ar, :kr
+ end
+ end
+
+ class LinPan2 < Pan2; end
+
+ class Pan4 < Panner
+ def initialize rate, *inputs
+ super rate, inputs, 4
+ end
+
+ class << self
+ def ar input, xpos = 0.0, ypos = 0.0, level = 1.0
+ new :audio, input, xpos, ypos, level
+ end
+
+ def kr input, xpos = 0.0, ypos = 0.0, level = 1.0
+ new :control, input, xpos, ypos, level
+ end
+
+ named_args_for :ar, :kr
+ end
+ end
+
+ class Balance2 < Panner
+ def initialize rate, *inputs
+ super rate, inputs, 2
+ end
+
+ class << self
+ def ar left, right, pos = 0.0, level = 1.0
+ new :audio, left, right, pos, level
+ end
+
+ def kr left, right, pos = 0.0, level = 1.0
+ new :control, left, right, pos, level
+ end
+ named_args_for :ar, :kr
+ end
+ end
+
+ class Rotate2 < Panner
+ def initialize rate, *inputs
+ super rate, inputs, 2
+ end
+
+ class << self
+ def ar x, y, pos = 0.0
+ new :audio, x, y, pos
+ end
+
+ def kr x, y, pos = 0.0
+ new :control, x, y, pos
+ end
+ end
+ end
+
+ class PanB < Panner
+ def initialize rate, *inputs
+ super rate, inputs, 4
+ end
+
+ class << self
+ def ar input, azimuth = 0, elevation = 0, gain = 1
+ new :audio, input, azimuth, elevation, gain
+ end
+
+ def kr input, azimuth = 0, elevation = 0, gain = 1
+ new :control, input, azimuth, elevation, gain
+ end
+ named_args_for :ar, :kr
+ end
+ end
+
+ class PanB2 < Panner
+ def initialize rate, *inputs
+ super rate, inputs, 3
+ end
+
+ class << self
+ def ar input, azimuth = 0, gain = 1
+ new :audio, input, azimuth, gain
+ end
+
+ def kr input, azimuth = 0, gain = 1
+ new :control, input, azimuth, gain
+ end
+ named_args_for :ar, :kr
+ end
+ end
+
+ class BiPanB2 < Panner
+ def initialize rate, *inputs
+ super rate, inputs, 3
+ end
+
+ class << self
+ def ar a, b, azimuth, gain = 1
+ new :audio, a, b, azimuth, gain
+ end
+
+ def kr a, b, azimuth, gain = 1
+ new :control, a, b, azimuth, gain
+ end
+ end
+ end
+
+ class DecodeB2 < Panner
+ def initialize rate, num_channels, *inputs
+ super rate, inputs, num_channels
+ end
+
+ class << self
+ def ar num_channels, w, x, y, orientation = 0.5
+ new :audio, num_channels, w, x, y, orientation
+ end
+
+ def kr num_channels, w, x, y, orientation = 0.5
+ new :control, num_channels, w, x, y, orientation
+ end
+ end
+ end
+
+ class PanAz < Panner
+ def initialize rate, num_channels, *inputs
+ super rate, inputs, num_channels
+ end
+
+ class << self
+ def ar num_channels, input, pos = 0.0, level = 1.0, width = 2.0, orientation = 0.5
+ new :audio, num_channels, input, pos, level, width, orientation
+ end
+
+ def kr num_channels, input, pos = 0.0, level = 1.0, width = 2.0, orientation = 0.5
+ new :control, num_channels, input, pos, level, width, orientation
+ end
+ end
+ end
+
+ end
+end
View
4 lib/scruby/ugens/ugen.rb
@@ -66,7 +66,7 @@ def initialize rate, *inputs
@special_index ||= 0
@output_index ||= 0
@channels ||= [1]
- @index = add_to_synthdef || 0
+ @index = add_to_synthdef || 0
end
# Instantiate a new MulAdd passing self and the multiplication and addition arguments
@@ -167,7 +167,7 @@ def params
{}
end
- def instantiate *args
+ def instantiate *args
obj = allocate
obj.__send__ :initialize, *args
obj
View
178 lib/scruby/ugens/ugen_defs.yaml
@@ -184,25 +184,6 @@ BRZ2:
:audio:
- - :input
- 0
-Balance2:
- :control:
- - - :left
- -
- - - :right
- -
- - - :pos
- - 0
- - - :level
- - 1
- :audio:
- - - :left
- -
- - - :right
- -
- - - :pos
- - 0
- - - :level
- - 1
Ball:
:audio:
- - :input
@@ -213,25 +194,6 @@ Ball:
- 0
- - :friction
- 0.01
-BiPanB2:
- :control:
- - - :inA
- -
- - - :inB
- -
- - - :azimuth
- -
- - - :gain
- - 1
- :audio:
- - - :inA
- -
- - - :inB
- -
- - - :azimuth
- -
- - - :gain
- - 1
Blip:
:audio:
- - :freq
@@ -639,25 +601,6 @@ Decay:
- 0
- - :decayTime
- 1
-DecodeB2:
- :control:
- - - :w
- -
- - - :x
- -
- - - :y
- -
- - - :orientation
- - 0.5
- :audio:
- - - :w
- -
- - - :x
- -
- - - :y
- -
- - - :orientation
- - 0.5
DegreeToKey:
:control:
- - :bufnum
@@ -1811,21 +1754,6 @@ LinLin:
- 1
- - :dsthi
- 2
-LinPan2:
- :control:
- - - :input
- -
- - - :pos
- - 0
- - - :level
- - 1
- :audio:
- - - :input
- -
- - - :pos
- - 0
- - - :level
- - 1
LinRand:
:scalar:
- - :lo
@@ -2338,97 +2266,6 @@ PV_RectComb:
- 0
- - :width
- 0.5
-Pan2:
- :control:
- - - :input
- -
- - - :pos
- - 0
- - - :level
- - 1
- :audio:
- - - :input
- -
- - - :pos
- - 0
- - - :level
- - 1
-Pan4:
- :control:
- - - :input
- -
- - - :xpos
- - 0
- - - :ypos
- - 0
- - - :level
- - 1
- :audio:
- - - :input
- -
- - - :xpos
- - 0
- - - :ypos
- - 0
- - - :level
- - 1
-PanAz:
- :control:
- - - :input
- -
- - - :pos
- - 0
- - - :level
- - 1
- - - :width
- - 2
- - - :orientation
- - 0.5
- :audio:
- - - :input
- -
- - - :pos
- - 0
- - - :level
- - 1
- - - :width
- - 2
- - - :orientation
- - 0.5
-PanB2:
- :control:
- - - :input
- -
- - - :azimuth
- - 0
- - - :gain
- - 1
- :audio:
- - - :input
- -
- - - :azimuth
- - 0
- - - :gain
- - 1
-PanB:
- :control:
- - - :input
- -
- - - :azimuth
- - 0
- - - :elevation
- - 0
- - - :gain
- - 1
- :audio:
- - - :input
- -
- - - :azimuth
- - 0
- - - :elevation
- - 0
- - - :gain
- - 1
Pause:
:control:
- - :gate
@@ -2732,21 +2569,6 @@ Ringz:
- 440
- - :decaytime
- 1
-Rotate2:
- :control:
- - - :x
- -
- - - :y
- -
- - - :pos
- - 0
- :audio:
- - - :x
- -
- - - :y
- -
- - - :pos
- - 0
RunningSum:
:control:
- - :input
View
204 spec/pan_spec.rb
@@ -0,0 +1,204 @@
+require File.expand_path(File.dirname(__FILE__)) + "/helper"
+
+require "scruby/control_name"
+require "scruby/env"
+require "scruby/ugens/ugen"
+require "scruby/ugens/ugen_operations"
+require "scruby/ugens/multi_out_ugens"
+require "scruby/ugens/ugens"
+require "scruby/ugens/pan"
+
+include Scruby
+include Ugens
+
+describe 'Panner' do
+ shared_examples_for 'Panner' do
+ before do
+ @pan = @class.new :audio, *@params
+ @inputs ||= @params
+ @instance = @pan.first.source
+ end
+
+ it "should instantiate using control rate" do
+ @class.should_receive(:new).with(:control, *@params)
+ @class.kr *@params
+ end
+
+ it "should instantiate using audio rate" do
+ @class.should_receive(:new).with(:audio, *@params)
+ @class.ar *@params
+ end
+
+ it "should return an array of output proxies" do
+ @pan.should be_a(Array)
+ @pan.should have(@channels).proxies
+ @pan.each_with_index do |proxy, i|
+ proxy.source.should be_a(@class)
+ proxy.should be_a(OutputProxy)
+ proxy.output_index.should == i
+ end
+ end
+
+ it "should set inputs" do
+ @instance.inputs.should == @inputs
+ end
+
+ it "should just accept audio inputs if rate is audio" do
+ lambda { @class.new( :audio, Ugen.new(:control) ) }.should raise_error(ArgumentError)
+ end
+
+ it "should accept control rate inputs unless rate is audio" do
+ @class.new :control, 1, Ugen.new(:control), Ugen.new(:audio)
+ end
+ end
+
+ describe Pan2 do
+ before do
+ @class = Pan2
+ @ugen = Ugen.new :audio, 1, 2
+ @params = @ugen, 0.5, 1.0
+ @channels = 2
+ end
+
+ it_should_behave_like 'Panner'
+
+ it "should have keyword args" do
+ @class.ar( @ugen, :level => 2.0 ).first.source.inputs.should == [@ugen, 0.0, 2.0]
+ end
+ end
+
+ describe LinPan2 do
+ before do
+ @class = LinPan2
+ @ugen = Ugen.new :audio, 1, 2
+ @params = @ugen, 0.5, 1.0
+ @channels = 2
+ end
+
+ it_should_behave_like 'Panner'
+
+ it "should have keyword args" do
+ @class.ar( @ugen, :level => 2.0 ).first.source.inputs.should == [@ugen, 0.0, 2.0]
+ end
+ end
+
+ describe Pan4 do
+ before do
+ @class = Pan4
+ @ugen = Ugen.new :audio, 1, 2
+ @params = @ugen, 0.5, 0.5, 1.0
+ @channels = 4
+ end
+
+ it_should_behave_like 'Panner'
+
+ it "should have keyword args" do
+ @class.ar( @ugen, :level => 2.0 ).first.source.inputs.should == [@ugen, 0.0, 0.0, 2.0]
+ end
+ end
+
+ describe Balance2 do
+ before do
+ @class = Balance2
+ @ugen = Ugen.new :audio, 1, 2
+ @ugen2 = Ugen.new(:audio, 2, 4)
+ @params = @ugen, @ugen2, 0.5, 1.0
+ @channels = 2
+ end
+
+ it_should_behave_like 'Panner'
+
+ it "should have keyword args" do
+ @class.ar( @ugen, @ugen2 , :level => 2.0 ).first.source.inputs.should == [@ugen, @ugen2 , 0.0, 2.0]
+ end
+ end
+
+ describe Rotate2 do
+ before do
+ @class = Rotate2
+ @ugen = Ugen.new :audio, 1, 2
+ @ugen2 = Ugen.new :audio, 2, 4
+ @params = @ugen, @ugen2, 0.5
+ @channels = 2
+ end
+
+ it_should_behave_like 'Panner'
+ # it "should have keyword args" do
+ # @class.ar( @ugen, @ugen2 , :level => 2.0 ).first.source.inputs.should == [@ugen, @ugen2 , 0.0, 2.0]
+ # end
+ end
+
+ describe PanB do
+ before do
+ @class = PanB
+ @ugen = Ugen.new :audio, 1, 2
+ @params = @ugen, 0.5, 0.5, 1.0
+ @channels = 4
+ end
+
+ it_should_behave_like 'Panner'
+ # it "should have keyword args" do
+ # @class.ar( @ugen, @ugen2 , :level => 2.0 ).first.source.inputs.should == [@ugen, @ugen2 , 0.0, 2.0]
+ # end
+ end
+
+ describe PanB2 do
+ before do
+ @class = PanB2
+ @ugen = Ugen.new :audio, 1, 2
+ @params = @ugen, 0.5, 1.0
+ @channels = 3
+ end
+
+ it_should_behave_like 'Panner'
+ # it "should have keyword args" do
+ # @class.ar( @ugen, @ugen2 , :level => 2.0 ).first.source.inputs.should == [@ugen, @ugen2 , 0.0, 2.0]
+ # end
+ end
+
+ describe BiPanB2 do
+ before do
+ @class = BiPanB2
+ @ugen2 = Ugen.new(:audio, 2, 4)
+ @ugen = Ugen.new :audio, 1, 2
+ @params = @ugen, @ugen2, 0.5, 0.5
+ @channels = 3
+ end
+
+ it_should_behave_like 'Panner'
+ # it "should have keyword args" do
+ # @class.ar( @ugen, @ugen2 , :level => 2.0 ).first.source.inputs.should == [@ugen, @ugen2 , 0.0, 2.0]
+ # end
+ end
+
+ describe DecodeB2, 'five channels' do
+ before do
+ @class = DecodeB2
+ @params = 5, 0.5, 0.5, 0.5, 0.5
+ @inputs = 0.5, 0.5, 0.5, 0.5
+ @channels = 5
+ end
+ it_should_behave_like 'Panner'
+ end
+
+ describe DecodeB2, 'seven channels' do
+ before do
+ @class = DecodeB2
+ @params = 7, 0.5, 0.5, 0.5, 0.5
+ @inputs = 0.5, 0.5, 0.5, 0.5
+ @channels = 7
+ end
+ it_should_behave_like 'Panner'
+ end
+
+ describe PanAz, 'five channels' do
+ before do
+ @class = PanAz
+ @ugen = Ugen.new(:audio, 1, 2)
+ @params = 5, @ugen, 0.5, 0.5, 0.5, 0.5
+ @inputs = @ugen, 0.5, 0.5, 0.5, 0.5
+ @channels = 5
+ end
+ it_should_behave_like 'Panner'
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.