Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MultiOut ugens can accept an array as input, little gem version bump

  • Loading branch information...
commit e4a6c7f54ef4ba102e5b05fc272ce4478ee3641d 1 parent f7781c6
@maca authored
View
2  Manifest.txt
@@ -37,7 +37,7 @@ lib/scruby/ticker.rb
lib/scruby/ugens/buffer_read_write.rb
lib/scruby/ugens/env_gen.rb
lib/scruby/ugens/in_out.rb
-lib/scruby/ugens/multi_out_ugens.rb
+lib/scruby/ugens/multi_out.rb
lib/scruby/ugens/operation_indices.yaml
lib/scruby/ugens/operation_ugens.rb
lib/scruby/ugens/panner.rb
View
4 lib/scruby.rb
@@ -25,7 +25,7 @@
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
module Scruby
- VERSION = '0.2.6'
+ VERSION = '0.2.6.2'
end
require "scruby/core_ext/object"
@@ -42,7 +42,7 @@ module Scruby
require "scruby/ugens/ugen"
require "scruby/ugens/ugen_operations"
-require "scruby/ugens/multi_out_ugens"
+require "scruby/ugens/multi_out"
require "scruby/ugens/panner"
require "scruby/ugens/buffer_read_write"
require "scruby/ugens/in_out"
View
4 lib/scruby/synthdef.rb
@@ -46,9 +46,9 @@ def initialize name, options = {}, &block
# For complex synthdefs the encoded synthdef can vary a little bit from what SClang would generate
# but the results will be interpreted in the same way
def encode
- controls = @control_names.reject { |cn| cn.non_control? }
+ controls = @control_names.reject { |cn| cn.non_control? }
encoded_controls = [controls.size].pack('n') + controls.collect{ |c| c.name.encode + [c.index].pack('n') }.join
-
+
init_stream + name.encode + constants.encode_floats + values.flatten.encode_floats + encoded_controls +
[children.size].pack('n') + children.collect{ |u| u.encode }.join('') +
[@variants.size].pack('n') #stub!!!
View
53 lib/scruby/ugens/multi_out.rb
@@ -0,0 +1,53 @@
+module Scruby
+ module Ugens
+ module MultiOut #:nodoc:
+ def self.included base
+ base.extend ClassMethods
+ end
+
+ def initialize rate, channels, *inputs
+ super rate, *inputs
+ @channels = Array === channels ? channels : (0...channels).map{ |i| OutputProxy.new rate, self, i }
+ @channels = @channels.to_da
+ end
+
+ def output_specs
+ channels.output_specs.flatten
+ end
+
+ module ClassMethods
+ private
+ def new rate, channels, *inputs
+ instantiated = super
+ Array === instantiated ? instantiated : instantiated.channels
+ end
+ end
+ end
+
+ class OutputProxy < Ugen #:nodoc:
+ attr_reader :source, :control_name, :output_index
+ class << self; public :new; end
+
+ def initialize rate, source, output_index, name = nil
+ super rate
+ @source, @control_name, @output_index = source, name, output_index
+ end
+
+ def index; @source.index; end
+
+ def add_to_synthdef; end
+ end
+
+ class Control < Ugen #:nodoc:
+ include MultiOut
+
+ def initialize rate, *names
+ super rate, names.collect_with_index{ |n, i| OutputProxy.new rate, self, i, n }
+ end
+
+ def self.and_proxies_from names
+ new names.first.rate, *names
+ end
+ end
+ end
+end
View
11 lib/scruby/ugens/multi_out_ugens.rb
@@ -8,16 +8,18 @@ def self.included base
def initialize rate, channels, *inputs
super rate, *inputs
@channels = Array === channels ? channels : (0...channels).map{ |i| OutputProxy.new rate, self, i }
+ @channels = @channels.to_da
end
- private
def output_specs
- channels.collect{ |output| output.send :output_specs }.flatten
+ channels.output_specs
end
module ClassMethods
- def new *args
- super.channels #returns the channels but gets instantiated, TODO: Maybe not a good idea
+ private
+ def new rate, channels, *inputs
+ instantiated = super
+ Array === instantiated ? instantiated : instantiated.channels
end
end
end
@@ -34,7 +36,6 @@ def initialize rate, source, output_index, name = nil
def index; @source.index; end
def add_to_synthdef; end
-
end
class Control < Ugen #:nodoc:
View
6 scruby.gemspec
@@ -2,17 +2,17 @@
Gem::Specification.new do |s|
s.name = %q{scruby}
- s.version = "0.2.6"
+ s.version = "0.2.6.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Macario Ortega"]
- s.date = %q{2009-08-18}
+ s.date = %q{2009-08-19}
s.default_executable = %q{livecode.rb}
s.description = %q{}
s.email = ["macarui@gmail.com"]
s.executables = ["livecode.rb"]
s.extra_rdoc_files = ["History.txt", "Manifest.txt"]
- s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "TODO.markdown", "bin/livecode.rb", "examples/example.live.rb", "extras/Ruby Live.tmbundle/Commands/Run selection:line in session.tmCommand", "extras/Ruby Live.tmbundle/Commands/Run selection:scope in session.tmCommand", "extras/Ruby Live.tmbundle/Commands/Run update blocks in session.tmCommand", "extras/Ruby Live.tmbundle/Commands/Start Session.tmCommand", "extras/Ruby Live.tmbundle/Commands/Stop server.tmCommand", "extras/Ruby Live.tmbundle/Support/lib/live_session.rb", "extras/Ruby Live.tmbundle/Syntaxes/Ruby Live.tmLanguage", "extras/Ruby Live.tmbundle/info.plist", "lib/live/session.rb", "lib/scruby.rb", "lib/scruby/buffer.rb", "lib/scruby/bus.rb", "lib/scruby/control_name.rb", "lib/scruby/core_ext/array.rb", "lib/scruby/core_ext/delegator_array.rb", "lib/scruby/core_ext/fixnum.rb", "lib/scruby/core_ext/numeric.rb", "lib/scruby/core_ext/object.rb", "lib/scruby/core_ext/proc.rb", "lib/scruby/core_ext/string.rb", "lib/scruby/core_ext/symbol.rb", "lib/scruby/core_ext/typed_array.rb", "lib/scruby/env.rb", "lib/scruby/group.rb", "lib/scruby/node.rb", "lib/scruby/server.rb", "lib/scruby/synth.rb", "lib/scruby/synthdef.rb", "lib/scruby/ticker.rb", "lib/scruby/ugens/buffer_read_write.rb", "lib/scruby/ugens/env_gen.rb", "lib/scruby/ugens/in_out.rb", "lib/scruby/ugens/multi_out_ugens.rb", "lib/scruby/ugens/operation_indices.yaml", "lib/scruby/ugens/operation_ugens.rb", "lib/scruby/ugens/panner.rb", "lib/scruby/ugens/ugen.rb", "lib/scruby/ugens/ugen_defs.yaml", "lib/scruby/ugens/ugen_operations.rb", "lib/scruby/ugens/ugens.rb", "script/console", "script/destroy", "script/generate", "scruby.gemspec", "spec/buffer_read_write_spec.rb", "spec/buffer_spec.rb", "spec/bus_spec.rb", "spec/core_ext/core_ext_spec.rb", "spec/core_ext/delegator_array_spec.rb", "spec/core_ext/typed_array_spec.rb", "spec/env_gen_spec.rb", "spec/env_spec.rb", "spec/group_spec.rb", "spec/helper.rb", "spec/in_out_spec.rb", "spec/integration_spec.rb", "spec/multiout_ugen_spec.rb", "spec/node_spec.rb", "spec/operation_ugens_spec.rb", "spec/panner_spec.rb", "spec/server.rb", "spec/server_spec.rb", "spec/synth_spec.rb", "spec/synthdef_spec.rb", "spec/ugen_operations_spec.rb", "spec/ugen_spec.rb", "spec/ugens_spec.rb", "test.live.rb"]
+ s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "TODO.markdown", "bin/livecode.rb", "examples/example.live.rb", "extras/Ruby Live.tmbundle/Commands/Run selection:line in session.tmCommand", "extras/Ruby Live.tmbundle/Commands/Run selection:scope in session.tmCommand", "extras/Ruby Live.tmbundle/Commands/Run update blocks in session.tmCommand", "extras/Ruby Live.tmbundle/Commands/Start Session.tmCommand", "extras/Ruby Live.tmbundle/Commands/Stop server.tmCommand", "extras/Ruby Live.tmbundle/Support/lib/live_session.rb", "extras/Ruby Live.tmbundle/Syntaxes/Ruby Live.tmLanguage", "extras/Ruby Live.tmbundle/info.plist", "lib/live/session.rb", "lib/scruby.rb", "lib/scruby/buffer.rb", "lib/scruby/bus.rb", "lib/scruby/control_name.rb", "lib/scruby/core_ext/array.rb", "lib/scruby/core_ext/delegator_array.rb", "lib/scruby/core_ext/fixnum.rb", "lib/scruby/core_ext/numeric.rb", "lib/scruby/core_ext/object.rb", "lib/scruby/core_ext/proc.rb", "lib/scruby/core_ext/string.rb", "lib/scruby/core_ext/symbol.rb", "lib/scruby/core_ext/typed_array.rb", "lib/scruby/env.rb", "lib/scruby/group.rb", "lib/scruby/node.rb", "lib/scruby/server.rb", "lib/scruby/synth.rb", "lib/scruby/synthdef.rb", "lib/scruby/ticker.rb", "lib/scruby/ugens/buffer_read_write.rb", "lib/scruby/ugens/env_gen.rb", "lib/scruby/ugens/in_out.rb", "lib/scruby/ugens/multi_out.rb", "lib/scruby/ugens/operation_indices.yaml", "lib/scruby/ugens/operation_ugens.rb", "lib/scruby/ugens/panner.rb", "lib/scruby/ugens/ugen.rb", "lib/scruby/ugens/ugen_defs.yaml", "lib/scruby/ugens/ugen_operations.rb", "lib/scruby/ugens/ugens.rb", "script/console", "script/destroy", "script/generate", "scruby.gemspec", "spec/buffer_read_write_spec.rb", "spec/buffer_spec.rb", "spec/bus_spec.rb", "spec/core_ext/core_ext_spec.rb", "spec/core_ext/delegator_array_spec.rb", "spec/core_ext/typed_array_spec.rb", "spec/env_gen_spec.rb", "spec/env_spec.rb", "spec/group_spec.rb", "spec/helper.rb", "spec/in_out_spec.rb", "spec/integration_spec.rb", "spec/multiout_ugen_spec.rb", "spec/node_spec.rb", "spec/operation_ugens_spec.rb", "spec/panner_spec.rb", "spec/server.rb", "spec/server_spec.rb", "spec/synth_spec.rb", "spec/synthdef_spec.rb", "spec/ugen_operations_spec.rb", "spec/ugen_spec.rb", "spec/ugens_spec.rb", "test.live.rb"]
s.has_rdoc = true
s.homepage = %q{Is a bare-bones SuperCollider livecoding library for Ruby, it provides comunication with a remote or local scsynth server and SynthDef creation with a}
s.rdoc_options = ["--main", "README.rdoc"]
View
13 spec/buffer_read_write_spec.rb
@@ -1,11 +1,12 @@
require File.expand_path(File.dirname(__FILE__)) + "/helper"
+require "scruby/core_ext/delegator_array"
require "scruby/control_name"
require "scruby/env"
require "scruby/ugens/ugen"
require "scruby/ugens/ugen_operations"
require "scruby/ugens/operation_ugens"
-require "scruby/ugens/multi_out_ugens"
+require "scruby/ugens/multi_out"
require "scruby/ugens/ugens"
require "scruby/ugens/buffer_read_write"
@@ -24,7 +25,11 @@ class << self; public :new; end
@inputs ||= @params
@instance = @proxies.first.source
end
-
+
+ it "should output a DelegatorArray" do
+ @proxies.should be_a(DelegatorArray)
+ end
+
it "should have correct rate" do
@instance.rate.should == @rate
end
@@ -99,7 +104,7 @@ class << self; public :new; end
it_should_behave_like 'Buffer reader Ugen with audio rate'
it "should require at least two channels" do
- lambda { @class.new :audio, 1, *@params[1..-1] }.should raise_error(ArgumentError)
+ lambda { @class.ar 1, *@params[1..-1] }.should raise_error(ArgumentError)
end
end
@@ -114,7 +119,7 @@ class << self; public :new; end
it_should_behave_like 'Buffer reader Ugen with audio rate'
it "should require at least two channels" do
- lambda { @class.new :audio, 1, *@params[1..-1] }.should raise_error(ArgumentError)
+ lambda { @class.ar 1, *@params[1..-1] }.should raise_error(ArgumentError)
end
end
View
9 spec/in_out_spec.rb
@@ -1,10 +1,11 @@
require File.expand_path(File.dirname(__FILE__)) + "/helper"
+require "scruby/core_ext/delegator_array"
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/multi_out"
require "scruby/ugens/in_out"
include Scruby
@@ -40,7 +41,7 @@ class << self; public :new; end
end
it "should spec #ar" do
- @ar.should be_instance_of( Array )
+ @ar.should be_instance_of( DelegatorArray )
@ar.should have(1).proxy
@ar.first.should == @proxy
end
@@ -93,8 +94,8 @@ class << self; public :new; end
it "should accept several inputs" do
@ugen1 = MockUgen.new :audio
- @ugen2 = MockUgenMockUgen.new :audio
- @ugen3 = MockUgenMockUgen.new :audio
+ @ugen2 = MockUgen.new :audio
+ @ugen3 = MockUgen.new :audio
Out.kr 1, @ugen1, @ugen2, @ugen3
@sdef.children.should have(4).ugens
View
39 spec/multiout_ugen_spec.rb
@@ -1,43 +1,20 @@
require File.expand_path(File.dirname(__FILE__)) + "/helper"
+require "scruby/core_ext/delegator_array"
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/multi_out"
include Scruby
include Ugens
-# describe MultiOut do
-# before do
-# sdef = mock( 'sdef', :children => [] )
-# Ugen.should_receive( :synthdef ).and_return( sdef )
-# @proxies = MultiOutUgen.new( :audio, 1, 2, 3 )
-# @multi = sdef.children.first
-# end
-#
-# it "should return an array of channels" do
-# @proxies.should be_instance_of( Array )
-# @proxies.should == [1,2,3]
-# end
-#
-# it "should be instace of Control" do
-# @multi.should be_instance_of( MultiOutUgen )
-# end
-#
-# it do
-# @multi.rate.should == :audio
-# end
-#
-# it do
-# @multi.channels.should == [1,2,3]
-# end
-#
-# it do
-# @multi.inputs.should == []
-# end
-# end
+class Control
+ class << self
+ public :new
+ end
+end
describe Control do
before do
@@ -56,7 +33,7 @@
end
it "should return an array of proxies" do
- @proxies.should be_instance_of( Array )
+ @proxies.should be_a( DelegatorArray )
@proxies.should have( @names.size ).proxies
end
View
6 spec/operation_ugens_spec.rb
@@ -20,9 +20,9 @@ class << self; public :new; end
before do
@scalar = MockUgen.new :scalar
- @demand = MockUgenMockUgen.new :demand
- @control = MockUgenMockUgen.new :control
- @audio = MockUgenMockUgen.new :audio
+ @demand = MockUgen.new :demand
+ @control = MockUgen.new :control
+ @audio = MockUgen.new :audio
end
describe UnaryOpUGen do
View
59 spec/panner_spec.rb
@@ -1,10 +1,11 @@
require File.expand_path(File.dirname(__FILE__)) + "/helper"
+require "scruby/core_ext/delegator_array"
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/multi_out"
require "scruby/ugens/ugens"
require "scruby/ugens/panner"
@@ -15,7 +16,6 @@ class MockUgen < Ugen
class << self; public :new; end
end
-
describe 'Panner' do
shared_examples_for 'Panner' do
before do
@@ -24,6 +24,10 @@ class << self; public :new; end
@instance = @pan.first.source
end
+ it "should output a DelegatorArray" do
+ @pan.should be_a(DelegatorArray)
+ end
+
it "should have correct rate" do
@instance.rate.should == @rate
end
@@ -42,9 +46,7 @@ class << self; public :new; end
@instance.inputs.should == @inputs
end
- it "should accept control rate inputs unless rate is audio" do
- @class.new :control, 1, MockUgen.new(:control), MockUgen.new(:audio)
- end
+ it "should accept control rate inputs unless rate is audio"
end
shared_examples_for 'Panner with control rate' do
@@ -67,6 +69,38 @@ class << self; public :new; end
# end
end
+ shared_examples_for 'Panner with array as input' do
+ it "should have n channels" do
+ @arrayed.should have(@ugens.size).proxies
+ end
+
+ it "should have array as channel" do
+ @arrayed.each { |a| a.should have(@channels).proxies }
+ end
+
+ it "should have the same source class" do
+ @arrayed.flatten.source.uniq.should have(@ugens.size).elements
+ end
+ end
+
+ shared_examples_for 'Multi input panner' do
+ describe "two ugens as input" do
+ before do
+ @params[0] = @ugens = [@ugen] * 2
+ @arrayed = @class.ar *@params
+ end
+ it_should_behave_like 'Panner with array as input'
+ end
+
+ describe "four ugens as input" do
+ before do
+ @params[0] = @ugens = [@ugen] * 4
+ @arrayed = @class.ar *@params
+ # p @arrayed.first.first.source.output_specs
+ end
+ it_should_behave_like 'Panner with array as input'
+ end
+ end
describe Pan2 do
before do
@@ -77,6 +111,8 @@ class << self; public :new; end
end
it_should_behave_like 'Panner with audio rate'
it_should_behave_like 'Panner with control rate'
+ it_should_behave_like 'Multi input panner'
+
it "should have keyword args" do
@class.ar( @ugen, :level => 2.0 ).first.source.inputs.should == [@ugen, 0.0, 2.0]
@@ -92,6 +128,7 @@ class << self; public :new; end
end
it_should_behave_like 'Panner with audio rate'
it_should_behave_like 'Panner with control rate'
+ it_should_behave_like 'Multi input panner'
it "should have keyword args" do
@class.ar( @ugen, :level => 2.0 ).first.source.inputs.should == [@ugen, 0.0, 2.0]
@@ -107,6 +144,7 @@ class << self; public :new; end
end
it_should_behave_like 'Panner with audio rate'
it_should_behave_like 'Panner with control rate'
+ it_should_behave_like 'Multi input panner'
it "should have keyword args" do
@class.ar( @ugen, :level => 2.0 ).first.source.inputs.should == [@ugen, 0.0, 0.0, 2.0]
@@ -117,12 +155,13 @@ class << self; public :new; end
before do
@class = Balance2
@ugen = MockUgen.new :audio, 1, 2
- @ugen2 = MockUgen.new(:audio, 2, 4)
+ @ugen2 = MockUgen.new :audio, 2, 4
@params = @ugen, @ugen2, 0.5, 1.0
@channels = 2
end
it_should_behave_like 'Panner with audio rate'
it_should_behave_like 'Panner with control rate'
+ it_should_behave_like 'Multi input panner'
it "should have keyword args" do
@class.ar( @ugen, @ugen2 , :level => 2.0 ).first.source.inputs.should == [@ugen, @ugen2 , 0.0, 2.0]
@@ -139,6 +178,8 @@ class << self; public :new; end
end
it_should_behave_like 'Panner with audio rate'
it_should_behave_like 'Panner with control rate'
+ it_should_behave_like 'Multi input 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
@@ -153,6 +194,8 @@ class << self; public :new; end
end
it_should_behave_like 'Panner with audio rate'
it_should_behave_like 'Panner with control rate'
+ it_should_behave_like 'Multi input 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
@@ -167,6 +210,7 @@ class << self; public :new; end
end
it_should_behave_like 'Panner with audio rate'
it_should_behave_like 'Panner with control rate'
+ it_should_behave_like 'Multi input panner'
# it "should have keyword args" do
# @class.ar( @ugen, @ugen2 , :level => 2.0 ).first.source.inputs.should == [@ugen, @ugen2 , 0.0, 2.0]
@@ -183,6 +227,8 @@ class << self; public :new; end
end
it_should_behave_like 'Panner with audio rate'
it_should_behave_like 'Panner with control rate'
+ it_should_behave_like 'Multi input 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
@@ -197,6 +243,7 @@ class << self; public :new; end
end
it_should_behave_like 'Panner with audio rate'
it_should_behave_like 'Panner with control rate'
+
end
describe DecodeB2, 'seven channels' do
View
3  spec/synthdef_spec.rb
@@ -1,11 +1,12 @@
require File.expand_path(File.dirname(__FILE__)) + "/helper"
require "scruby/control_name"
+require "scruby/core_ext/delegator_array"
require "scruby/env"
require "scruby/ugens/ugen"
require "scruby/ugens/ugen_operations"
require "scruby/synthdef"
-require "scruby/ugens/multi_out_ugens"
+require "scruby/ugens/multi_out"
require "scruby/core_ext/typed_array"
include Scruby
Please sign in to comment.
Something went wrong with that request. Please try again.