Skip to content

Commit

Permalink
MultiOut ugens can accept an array as input, little gem version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Macario committed Aug 19, 2009
1 parent f7781c6 commit e4a6c7f
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Manifest.txt
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/scruby.rb
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions lib/scruby/synthdef.rb
Expand Up @@ -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!!!
Expand Down
53 changes: 53 additions & 0 deletions 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
11 changes: 6 additions & 5 deletions lib/scruby/ugens/multi_out_ugens.rb
Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions scruby.gemspec
Expand Up @@ -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"]
Expand Down
13 changes: 9 additions & 4 deletions 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"

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
9 changes: 5 additions & 4 deletions 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
39 changes: 8 additions & 31 deletions 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
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions spec/operation_ugens_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit e4a6c7f

Please sign in to comment.