Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

all tests are on green againg, DelegatorArray is prefered to Array in…

…side an ugen graph some refactoring
  • Loading branch information...
commit d13a17ca424ffe0f937d1d6da3803665ef1c7d1b 1 parent 48242a9
@maca maca authored
View
4 lib/scruby.rb
@@ -39,6 +39,8 @@ module Scruby
require "scruby/core_ext/symbol"
require "scruby/core_ext/typed_array"
require "scruby/core_ext/delegator_array"
+require "scruby/audio/env"
+require "scruby/audio/control_name"
require "scruby/audio/ugens/ugen"
require "scruby/audio/ugens/ugen_operations"
@@ -48,11 +50,9 @@ module Scruby
require "scruby/audio/ugens/operation_ugens"
require "scruby/audio/ugens/ugens"
-require "scruby/audio/control_name"
require "scruby/audio/synthdef"
require "scruby/audio/server"
-require "scruby/audio/env"
require "scruby/audio/ugens/env_gen"
require "scruby/audio/node"
View
7 lib/scruby/audio/control_name.rb
@@ -19,6 +19,13 @@ def rate_from_name name
def non_control?
@rate == :noncontrol
end
+
+ def == other
+ @name == other.name and
+ @value == other.value and
+ @rate == other.rate and
+ @index == other.index
+ end
end
end
end
View
4 lib/scruby/audio/ugens/operation_ugens.rb
@@ -7,7 +7,7 @@ class BasicOpUgen < Ugen #:nodoc:
class << self
def new operator, *inputs
- obj = super get_rate(inputs), *inputs
+ obj = super get_rate(inputs), inputs
set_operator_for obj, operator
obj
end
@@ -15,7 +15,7 @@ def new operator, *inputs
private
#:nodoc:
def set_operator_for input, operator
- input.kind_of?(Array) ? input.map{ |element| set_operator_for element, operator } : input.operator = operator
+ input.kind_of?(Array) ? input.each{ |element| set_operator_for element, operator } : input.operator = operator
end
#:nodoc:
View
59 lib/scruby/audio/ugens/ugen.rb
@@ -53,12 +53,15 @@ module Ugens
# Otherwise usage is pretty the same as in SuperCollider
#
# TODO: Provide a way of getting the argument names and default values
+
class Ugen
attr_reader :inputs, :rate, :index, :special_index, :output_index, :channels
- RATES = [ :scalar, :trigger, :demand, :control, :audio ]
- E_RATES = [ :scalar, :control, :audio, :demand ]
- @@synthdef = nil
+ RATES = :scalar, :trigger, :demand, :control, :audio
+ E_RATES = :scalar, :control, :audio, :demand
+ VALID_INPUTS = Numeric, Array, Ugen, Env, ControlName
+ @@synthdef = nil
+
def initialize rate, *inputs
@rate, @inputs = rate, inputs.compact
@@ -103,24 +106,47 @@ def collect_input_specs #:nodoc:
def output_specs #:nodoc:
[E_RATES.index(rate)]
end
+
+ public
+ def == other
+ self.class == other.class and
+ self.rate == other.rate and
+ self.inputs == other.inputs and
+ self.channels == other.channels
+ end
class << self
#:nodoc:
- def new rate, *inputs
- raise ArgumentError.new( "#{rate} not a defined rate") unless RATES.include?( rate.to_sym )
+ def new rate, *inputs
- inputs.peel!
- inputs.each_with_index do |input, index|
- inputs[index] = input = input.as_ugen_input if input.respond_to?(:as_ugen_input)
+ if rate.kind_of? Array
+ rate = RATES.slice rate.collect { |rate| # get the highest rate, raise error if rate is not defined
+ rate = rate.to_sym
+ raise ArgumentError.new( "#{rate} not a defined rate") unless RATES.include? rate
+ RATES.index rate
+ }.max
+ else
+ raise ArgumentError.new( "#{rate} not a defined rate") unless RATES.include? rate.to_sym
+ end
+
+ size = 1 # Size of the largest multichannel input (Array)
+ inputs.peel! # First input if input is Array and size is 1
+ inputs.map! do |input|
+ input = input.as_ugen_input if input.respond_to?(:as_ugen_input) # Convert input to prefered form
raise ArgumentError.new( "#{ input.inspect } is not a valid ugen input") unless valid_input? input
+ size = input.size if input.size > size if input.kind_of? Array
+ input
end
- size = inputs.select{ |a| a.kind_of? Array }.map{ |a| a.size }.max || 1 #get the size of the largest array element if present
- inputs.flatten! if size == 1 #if there is one or more arrays with just one element flatten the input array
- return instantiate( rate, *inputs ) unless size > 1 #return an Ugen if no array was passed as an input
+ return instantiate( rate, *inputs.flatten ) unless size > 1 #return an Ugen if no array was passed as an input
- inputs = inputs.map{ |input| input.instance_of?( Array ) ? input.wrap_to( size ) : Array.new( size, input ) }.transpose
- DelegatorArray.new inputs.map{ |new_inputs| new rate, *new_inputs }
+ inputs.map! do |input|
+ Array === input ? input.wrap_to!(size) : input = Array.new(size, input)
+ input
+ end
+ output = inputs.transpose
+ output.map! do |new_inputs| new rate, *new_inputs end
+ output.to_da
end
@@ -133,9 +159,10 @@ def synthdef= synthdef #:nodoc:
end
def valid_input? obj
- not [Ugen, ControlName, Env, UgenOperations].collect do |m|
- true if obj.kind_of? m
- end.compact.empty?
+ case obj
+ when *VALID_INPUTS then true
+ else false
+ end
end
def params
View
62 lib/scruby/audio/ugens/ugen_operations.rb
@@ -14,46 +14,44 @@ module Ugens
module UgenOperations
operation_indices = YAML::load File.open( File.dirname(__FILE__) + "/operation_indices.yaml" )
UNARY = operation_indices['unary']
- BINARY = operation_indices['binary']
+ BINARY = operation_indices['binary']
SAFE_NAMES = { :+ => :plus, :- => :minus, :* => :mult, :/ => :div2, :<= => :less_than_or_eql, :>= => :more_than_or_eql }
-
+
def self.included klass
- klass.send :include, BinaryOperations
- klass.send :include, UnaryOperators if klass.ancestors.include? Ugen
- end
-
- module BinaryOperations
- BINARY.each_key do |op|
- method_name = SAFE_NAMES[op] || op
- define_method "__ugen_#{ method_name }" do |input|
- case input
- when Ugen
- BinaryOpUGen.new op, self, input
- when UgenOperations
- kind_of?( Ugen ) ? BinaryOpUGen.new( op, self, input ) : __send__( "__original_#{ method_name }", input )
- else
- raise ArgumentError.new( "Expected `#{ input.inspect }` to be a valid Ugen input" )
- end
- end
+ # Define unary operations
+ UNARY.each_key do |op|
+ define_method(op){ UnaryOpUGen.new op, self } unless klass.instance_methods.include? op
end
-
- def self.included klass
- BINARY.each_key do |operator|
- safe_name = SAFE_NAMES[operator] || operator
- klass.send( :alias_method, "__original_#{ safe_name }", operator ) rescue nil
- klass.send( :alias_method, operator, "__ugen_#{ safe_name }" )
+
+ # Define binary operations
+ ugen_subclass = klass.ancestors.include? Ugen
+ meth_def =
+ if ugen_subclass
+ proc do |safe, op|
+ proc{ |input| BinaryOpUGen.new op, self, input }
+ end
+ else
+ proc do |safe, op|
+ proc do |input|
+ if input.kind_of? Ugen
+ BinaryOpUGen.new op, self, input
+ else
+ __send__ "__original_#{ safe }", input
+ end
+ end
end
end
- end
-
- module UnaryOperators
- UNARY.each_key do |op|
- define_method(op){ UnaryOpUGen.new op, self }
+
+ BINARY.each_key do |op|
+ safe = SAFE_NAMES[op]
+ define_method "__ugenop_#{ safe || op }", &meth_def.call(safe || op, op)
+ klass.send :alias_method, "__original_#{ safe || op }", op if safe unless ugen_subclass
+ klass.send :alias_method, op, "__ugenop_#{ safe || op }"
end
end
end
-
- [Ugen, ::Fixnum, ::Float, ::Array].each{ |k| k.send :include, UgenOperations }
+
+ [Ugen, Fixnum, Float].each{ |k| k.send :include, UgenOperations }
end
end
end
View
4 lib/scruby/core_ext/array.rb
@@ -28,10 +28,6 @@ def to_array; self; end
def encode_floats #:nodoc:
[self.size].pack('n') + self.pack('g*') #TODO: Deprecate
end
-
- def muladd mul, add #:nodoc:
- self.collect{ |u| MulAdd.new( u, mul, add ) }
- end
def peel!
self.replace self.first if self.first.kind_of? Array if self.size == 1
View
44 lib/scruby/core_ext/delegator_array.rb
@@ -1,34 +1,44 @@
class DelegatorArray < Array
- def method_undefined meth, args
- return self.class.new( self.map { |item| item.send meth, args } ) unless args.kind_of? Array
+ def method_missing meth, *args, &block
+ return self.map! { |item| item.send meth, *args, &block }
+ end
+
+ def to_da; self; end
+ def to_a; Array.new self; end
+ [:*, :+, :-, :/].each do |meth|
+ define_method meth do |args|
+ binary_op meth, args
+ end
+ end
+
+ private
+ def binary_op op, inputs
+ return method_missing(op, inputs) unless inputs.kind_of? Array
+
results = self.class.new
- self.zip(args).collect_with_index do |pair, index|
+ self.zip(inputs).collect_with_index do |pair, index|
left, right = pair
-
next results.push(right) if index + 1 > self.size
- next results.push(left) if index + 1 > args.size
-
- results.push left.send(meth, right)
+ next results.push(left) if index + 1 > inputs.size
+ results.push left.send(op, right)
end
-
results
-
end
-
- [:*, :+, :-, :/].each do |meth|
- define_method meth do |*args|
- method_undefined meth, *args
- end
+end
+
+class Array
+ def to_da
+ DelegatorArray.new self
end
end
module Kernel
def d *args
args.peel!
- carray = DelegatorArray.new
- carray.push *args
- carray
+ darray = DelegatorArray.new
+ darray.push *args
+ darray
end
end
View
2  spec/audio/env_gen_spec.rb
@@ -1,9 +1,9 @@
require File.join( File.expand_path(File.dirname(__FILE__)), '..', "helper")
require "scruby/audio/control_name"
+require "scruby/audio/env"
require "scruby/audio/ugens/ugen"
require "scruby/audio/ugens/ugen_operations"
-require "scruby/audio/env"
require "scruby/audio/ugens/env_gen"
include Scruby
View
10 spec/audio/operation_ugens_spec.rb
@@ -1,10 +1,12 @@
require File.join( File.expand_path(File.dirname(__FILE__)), '..',"helper")
+
require "scruby/audio/control_name"
require "scruby/audio/env"
require "scruby/audio/ugens/ugen"
require "scruby/audio/ugens/ugen_operations"
require "scruby/audio/ugens/operation_ugens"
+require "scruby/core_ext/delegator_array"
include Scruby
include Audio
@@ -82,13 +84,13 @@
it "should have correct inputs and operator when two inputs" do
arr = BinaryOpUGen.new( :+, @audio, @demand )
- arr.inputs.should == [@audio, @demand]
+ arr.inputs.should == [@audio, @demand]
arr.operator.should == :+
- arr.rate.should == :audio
+ arr.rate.should == :audio
end
it "should accept array as input" do
- BinaryOpUGen.new(:+, @audio, [@audio, @scalar] ).should be_instance_of(Array)
+ BinaryOpUGen.new(:+, @audio, [@audio, @scalar] ).should be_instance_of(DelegatorArray)
end
it "should return an array of UnaryOpUGens" do
@@ -156,7 +158,7 @@
it do
MulAdd.new( @audio, 0.5, 0.5 ).inputs.should == [@audio, 0.5, 0.5]
end
-
+
it "should not be instance of MulAdd" do
unary_op = mock 'neg'
mult = mock 'mult'
View
1  spec/audio/synth_spec.rb
@@ -3,6 +3,7 @@
require 'osc'
require "scruby/core_ext/typed_array"
require "scruby/audio/node"
+require "scruby/audio/bus"
require "scruby/audio/group"
require "scruby/audio/synth"
require "scruby/audio/server"
View
21 spec/audio/synthdef_spec.rb
@@ -1,5 +1,6 @@
require File.join( File.expand_path(File.dirname(__FILE__)), '..',"helper")
+require "scruby/audio/control_name"
require "scruby/audio/env"
require "scruby/audio/ugens/ugen"
require "scruby/audio/ugens/ugen_operations"
@@ -11,11 +12,6 @@
include Audio
include Ugens
-class ControlName
- def self.new *args
- args.flatten
- end
-end
describe SynthDef, 'instantiation' do
@@ -101,23 +97,20 @@ def self.new *args
end
it "should pass the argument value, the argument index and the rate(if provided) to the ControlName at instantiation" do
- @sdef.send_msg( :collect_control_names, @function, [:a,:b,:c], [] ).should == [[:arg1, :a, nil, 0], [:arg2, :b, nil, 1], [:arg3, :c, nil, 2]]
- @sdef.send_msg( :collect_control_names, @function, [:a,:b,:c], [:ir, :tr, :ir] ).should == [[:arg1, :a, :ir, 0], [:arg2, :b, :tr, 1], [:arg3, :c, :ir, 2]]
+ cns = @sdef.send_msg :collect_control_names, @function, [1, 2, 3], []
+ cns.should == [1.0, 2.0, 3.0].map{ |val| ControlName.new("arg#{ val.to_i }", val, :control, val.to_i - 1 )}
+ cns = @sdef.send_msg :collect_control_names, @function, [1, 2, 3], [:ir, :tr, :ir]
+ cns.should == [[1.0, :ir], [2.0, :tr], [3.0, :ir]].map{ |val, rate| ControlName.new("arg#{ val.to_i }", val, rate, val.to_i - 1 )}
end
it "should not return more elements than the function argument number" do
- c_name = mock :control_name
- ControlName.should_receive( :new ).at_most(3).times.and_return c_name
- @sdef.send_msg( :collect_control_names, @function, [:a, :b, :c, :d, :e], [] ).should have( 3 ).elements
+ @sdef.send_msg( :collect_control_names, @function, [1, 2, 3, 4, 5], [] ).should have( 3 ).elements
end
end
describe '#build_controls' do
-
before :all do
- Object.send :remove_const, 'ControlName'
- ::RATES = [:scalar, :trigger, :control]
- require "scruby/audio/control_name"
+ RATES = [:scalar, :trigger, :control]
end
before do
View
63 spec/audio/ugen_operations_spec.rb
@@ -1,11 +1,13 @@
require File.join( File.expand_path(File.dirname(__FILE__)), '..',"helper")
require 'yaml'
+require "scruby/core_ext/delegator_array"
require "scruby/audio/control_name"
require "scruby/audio/env"
require "scruby/audio/ugens/ugen"
require "scruby/audio/ugens/operation_ugens"
-require "scruby/audio/ugens/ugen_operations"
+require "scruby/audio/ugens/ugen_operations"
+
include Scruby
include Audio
@@ -14,7 +16,7 @@
describe UgenOperations do
before do
- @ugen = Ugen.new :audio
+ @ugen = Ugen.new :audio
@ugen2 = Ugen.new :audio
end
@@ -29,32 +31,22 @@
sum.should be_instance_of(BinaryOpUGen)
end
- it "respond to #ugen_sum (it will override #+ but can't name a method old_+)" do
- @ugen.should respond_to( :__ugen_plus )
- end
-
it "should raise argument error" do
- lambda { @ugen + :hola }.should raise_error( ArgumentError )
+ lambda { @ugen + :hola }.should raise_error(NoMethodError)
end
end
describe 'unary operations' do
it "should do unary op" do
op = @ugen.distort
-
op.should be_instance_of(UnaryOpUGen)
op.inputs.should == [@ugen]
end
end
describe Numeric do
- it do
- 1.should respond_to( :ring4 )
- 1.should respond_to( :__ugen_plus )
- end
-
- it do
- 1.2.should respond_to( :ring4 )
+ it "do unary operation" do
+ 1.distort.should == UnaryOpUGen.new(:distort, 1)
end
it "should use original +" do
@@ -62,49 +54,35 @@
sum.should == 2
end
- it "should return a BinarayOpUgen when adding an Ugen" do
- sum = 1 + @ugen
- sum.should be_instance_of(BinaryOpUGen)
- end
-
it "should set the correct inputs and operator for the binopugen" do
sum = 1.0 + @ugen
- sum.inputs.should == [1.0, @ugen]
- sum.operator.should == :+
+ sum.should == BinaryOpUGen.new(:+, 1.0, @ugen)
end
it "ugen should sum numeric" do
sum = @ugen + 1
- sum.should be_kind_of(BinaryOpUGen)
- sum.inputs.should == [@ugen, 1]
+ sum.should == BinaryOpUGen.new(:+, @ugen, 1)
end
it 'ugen should sum array' do
- sum = @ugen + [1,2]
- sum.should have(2).ugens
- sum.first.inputs.should == [@ugen, 1]
- sum.last.inputs.should == [@ugen, 2]
+ sum = @ugen * d(1,2)
+ sum.should == d(BinaryOpUGen.new(:*, @ugen, 1), BinaryOpUGen.new(:*, @ugen, 2))
end
end
- describe Array do
- it do
- [].should respond_to( :ring4 )
- [].should respond_to( :__ugen_plus )
- end
-
- it "should sum an ugen" do
- [] + @ugen
+ describe DelegatorArray do
+ before do
+ @ugen = Ugen.new :audio
end
- it "should sum arrays as expected" do
- sum = [1,2] + [3]
- sum.should == [1,2,3]
+ it "do binary operation" do
+ d(@ugen).distort.should == d(@ugen.distort)
end
- it "should return" do
- BinaryOpUGen.should_receive( :new ).with( :*, [1,2], @ugen )
- ([1, 2] * @ugen)
+ it "should do binary operation" do
+ op = d(1, 2) * @ugen
+ op.should be_a(DelegatorArray)
+ op.should == d(BinaryOpUGen.new(:*, 1, @ugen), BinaryOpUGen.new(:*, 2, @ugen))
end
end
@@ -114,7 +92,6 @@
# methods overriden by UgenOperations inclusion:
# Fixnum#+ Fixnum#gcd Fixnum#/ Fixnum#round Fixnum#lcm Fixnum#div Fixnum#- Fixnum#>= Fixnum#* Fixnum#<=
# Float#+ Float#/ Float#round Float#div Float#- Float#>= Float#* Float#<=
-# Array#+ Array#- Array#*
# changed max and min to maximum and minimum because the override Array#max and Array#min wich take no args
View
61 spec/audio/ugen_spec.rb
@@ -5,6 +5,7 @@
require "scruby/audio/env"
require "scruby/audio/ugens/ugen"
require "scruby/audio/ugens/ugen_operations"
+require "scruby/audio/ugens/operation_ugens"
require "scruby/core_ext/object"
require "scruby/core_ext/numeric"
require "scruby/core_ext/string"
@@ -47,9 +48,15 @@ def as_ugen_input; 0; end
end
it "should tell if valid input" do
- Ugen.send( :valid_input?, SinOsc.ar ).should be_true
- Ugen.send( :valid_input?, Env.asr ).should be_true
- Ugen.send( :valid_input?, 'string' ).should be_false
+ cn = ControlName.new 'cn', 1, :audio, 0
+ Ugen.valid_input?( 440 ).should be_true
+ Ugen.valid_input?( 440.0 ).should be_true
+ Ugen.valid_input?( [4,4] ).should be_true
+ Ugen.valid_input?( SinOsc.ar ).should be_true
+ Ugen.valid_input?( SinOsc.ar ).should be_true
+ Ugen.valid_input?( Env.asr ).should be_true
+ Ugen.valid_input?( cn ).should be_true
+ Ugen.valid_input?( 'string' ).should be_false
end
it "should use buffnum as input when a buffer is passed" do
@@ -72,9 +79,8 @@ def as_ugen_input; 0; end
describe 'operations' do
before :all do
- @op_ugen = mock( 'op_ugen' )
- ::BinaryOpUGen = mock 'bynary_op_ugen', :new => @op_ugen
- UnaryOpUGen = mock 'unary_op_ugen', :new => @op_ugen
+ @op_ugen = mock( 'op_ugen' )
+ UnaryOpUGen = mock 'unary_op_ugen', :new => @op_ugen
end
before do
@@ -87,8 +93,7 @@ def as_ugen_input; 0; end
end
it "should sum" do
- ::BinaryOpUGen.should_receive( :new ).with( :+, @ugen, @ugen2)
- @ugen + @ugen2
+ (@ugen + @ugen2).should be_a(BinaryOpUGen)
end
end
@@ -164,6 +169,14 @@ def as_ugen_input; 0; end
lambda { Ugen.new( :not_a_rate, 1 ) }.should raise_error( ArgumentError )
end
+ it "should use the highest rate when passing an array" do
+ Ugen.new([:audio, :control], 1).rate.should == :audio
+ end
+
+ it "should be a defined rate as array" do
+ lambda { Ugen.new( [:not_a_rate, :audio], 1 ) }.should raise_error( ArgumentError )
+ end
+
it "should accept an empty array for inputs and inputs should be an empty array" do
Ugen.new( :audio, [] ).inputs.should eql([])
end
@@ -240,9 +253,16 @@ def as_ugen_input; 0; end
ugen.inputs.should == [1, 2]
end
- it "should instantiate when passing array" do
- Ugen.should_receive(:instantiate).twice
- ugen = Ugen.new( :audio, 100, [210, 220] )
+ it "should make multichannel array (DelegatorArray)" do
+ multichannel = Ugen.new( :audio, 100, [210, 220] )
+ multichannel.should be_a(DelegatorArray)
+ multichannel.should == d(Ugen.new(:audio, 100, 210), Ugen.new(:audio, 100, 220))
+ end
+
+ it "should accept DelegatorArray as inputs" do
+ multichannel = Ugen.new( :audio, 100, d(210, 220) )
+ multichannel.should be_a(DelegatorArray)
+ multichannel.should == d(Ugen.new(:audio, 100, 210), Ugen.new(:audio, 100, 220))
end
it "should instantiate with correct arguments" do
@@ -276,10 +296,13 @@ def as_ugen_input; 0; end
end
it "should return muladd" do
- ::MulAdd = mock( 'MulAdd', :new => nil )
@ugen = Ugen.new(:audio, 100, 100)
- ::MulAdd.should_receive( :new ).with( @ugen, 1, 1)
- @ugen.muladd(1, 1).should be_nil
+ @ugen.muladd(0.5, 0.5).should be_a(MulAdd)
+ end
+
+ it "should return an arrayed muladd" do
+ @ugen = Ugen.new(:audio, [100,100], 100)
+ @ugen.muladd(0.5, 0.5).should be_a(DelegatorArray)
end
end
@@ -318,10 +341,6 @@ def as_ugen_input; 0; end
@sin.send(:collect_input_specs).should == [[-1, 0], [-1, 1]]
end
- # it "should collect input_specs" do
- # @sin.send(:collect_input_specs).flatten.collect { |e| e.encode }
- # end
-
it "should encode class name" do
@sin.encode[0..6].should == @encoded[0..6]
end
@@ -337,9 +356,11 @@ def as_ugen_input; 0; end
it "should encode cn, rt, in, out, si, collect_input_specs" do
@sin.encode.should == @encoded
end
+
+ it "should equal to a similar" do
+ Ugen.new(:audio, 1, 2).should == Ugen.new(:audio, 1, 2)
+ end
end
-
-
end
View
21 spec/audio/ugens_spec.rb
@@ -1,5 +1,7 @@
require File.join( File.expand_path(File.dirname(__FILE__)), '..',"helper")
+require "scruby/audio/control_name"
+require "scruby/audio/env"
require "scruby/audio/ugens/ugen"
require "scruby/audio/ugens/ugen_operations"
require "scruby/audio/ugens/ugens"
@@ -46,8 +48,23 @@ class Klass
end
it "should print description" do
- p PanAz.params
- PanAz.params.should be_a(Hash)
+ PanAz.params.should == {
+ :audio => [
+ [:input, nil],
+ [:pos, 0],
+ [:level, 1],
+ [:width, 2],
+ [:orientation, 0.5],
+ [:mul, 1],
+ [:add, 0] ],
+ :control => [
+ [:input, nil],
+ [:pos, 0],
+ [:level, 1],
+ [:width, 2],
+ [:orientation, 0.5],
+ [:mul, 1],
+ [:add, 0] ]}
end
# it "should work with arrays"
View
66 spec/channel_array_spec.rb → spec/delegator_array_spec.rb
@@ -1,8 +1,37 @@
require File.join( File.expand_path(File.dirname(__FILE__)), "helper")
+
require "scruby/core_ext/array"
require "scruby/core_ext/delegator_array"
+require "scruby/audio/env"
+require "scruby/audio/control_name"
+require "scruby/audio/ugens/ugen"
+require "scruby/audio/ugens/ugens"
+require "scruby/audio/ugens/ugen_operations"
+require "scruby/audio/ugens/operation_ugens"
+
+
+include Scruby
+include Audio
+include Ugens
+#
+class SinOsc < Ugen
+ class << self
+ def ar freq = 440.0, phase = 0.0 #not interested in muladd by now
+ new :audio, freq, phase
+ end
+
+ def kr freq = 440.0, phase = 0.0
+ new :control, freq, phase
+ end
+ end
+end
+
+# Mocks
+class ControlName; end
+class Env; end
+
describe DelegatorArray do
it "should have 'literal' notation" do
@@ -15,6 +44,30 @@
d(nil)
end
+ it "should return DelegatorArray" do
+ sig = SinOsc.ar([100, [100, 100]])
+ sig.should be_a(DelegatorArray)
+ end
+
+ it "should convet to_da" do
+ [].to_da.should be_a(DelegatorArray)
+ end
+
+ it "should pass missing method" do
+ d(1,2).to_f.should == d(1.0,2.0)
+ end
+
+ it "should return a DelegatorArray for muladd" do
+ SinOsc.ar(100).muladd(1, 0.5).should be_a(BinaryOpUGen)
+ SinOsc.ar([100, [100, 100]]).muladd(0.5, 0.5).should be_a(DelegatorArray)
+ # SinOsc.ar([100, [100, 100]]).muladd(1, 0.5).should be_a(DelegatorArray)
+ end
+
+
+ it "should pass method missing" do
+ d(1,2,3).to_i.should == [1.0, 2.0, 3.0]
+ end
+
shared_examples_for 'aritmetic operand' do
before do
@numeric_op = eval %{ d(1,2) #{ @op } 3.0 }
@@ -37,8 +90,18 @@
@asim_array_op1.should be_a(DelegatorArray)
end
+ it "should blow passing nil" do
+ lambda { d(1,2,3,nil) + 1 }.should raise_error(NoMethodError)
+ end
+
it "should blow pass nil" do
- lambda { d(nil,2,3) + 1 }.should raise_error(NoMethodError)
+ actual = eval %{ d(1,2,3) #{ @op } Ugen.new(:audio, 2)}
+ expected = BinaryOpUGen.new(@op.to_sym, [1,2,3], Ugen.new(:audio, 2) )
+ actual.should == expected
+ end
+
+ it "should allow passing an Ugen Array" do
+ eval %{ SinOsc.ar([100, [100, 100]]) #{@op} SinOsc.ar }
end
end
@@ -76,4 +139,5 @@
end
it_should_behave_like 'aritmetic operand'
end
+
end
View
4 spec/env_spec.rb
@@ -1,9 +1,9 @@
require File.join( File.expand_path(File.dirname(__FILE__)),"helper")
-
+require "scruby/audio/env"
+require "scruby/audio/control_name"
require "scruby/audio/ugens/ugen"
require "scruby/audio/ugens/ugen_operations"
-require "scruby/audio/env"
class ControlName; end
View
3  test.live.rb
@@ -202,6 +202,9 @@
+require 'yaml'
+
+puts SinOsc.ar(100, [200,[100, 100]]).to_yaml
Please sign in to comment.
Something went wrong with that request. Please try again.