Permalink
Browse files

not 1.9.1

  • Loading branch information...
1 parent 25bcea6 commit 26b0dee2721386450cbeba91a1f1b0824bcdbb5b Macario committed Jul 7, 2009
View
@@ -1,6 +1,6 @@
require 'rubygems' unless ENV['NO_RUBYGEMS']
%w[rake rake/clean fileutils newgem rubigen].each { |f| require f }
-require File.dirname(__FILE__) + '/lib/Scruby'
+require File.dirname(__FILE__) + '/lib/scruby'
# Generate all the Rake tasks
# Run 'rake -T' to see list of generated tasks (from gem root directory)
@@ -24,5 +24,5 @@ end
require 'newgem/tasks' # load /tasks/*.rake
Dir['tasks/**/*.rake'].each { |t| load t }
-# TODO - want other tests/tasks run by default? Add them to the list
+# # TODO - want other tests/tasks run by default? Add them to the list
task :default => :spec
View
@@ -20,6 +20,8 @@
require 'rosc'
require 'yaml'
+require 'methopara' if RUBY_VERSION.to_f >= 1.9
+
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
@@ -30,6 +32,7 @@ module Scruby
SCRUBY_DIR = File.join( File.expand_path(File.dirname(__FILE__) ), 'scruby' )
require "scruby/typed_array"
+require "scruby/extensions"
require "scruby/audio/ugens/ugen_operations"
require "scruby/audio/ugens/ugen"
@@ -42,10 +45,8 @@ module Scruby
require "scruby/audio/ugens/ugens"
require "scruby/audio/control_name"
require "scruby/audio/synthdef"
-require "scruby/extensions"
require "scruby/audio/server"
-
require "scruby/audio/env"
require "scruby/audio/ugens/env_gen"
View
@@ -4,9 +4,10 @@ class Node
attr_reader :name, :servers
def initialize name, *servers
- @name = name.to_s
- servers = *servers
- @servers = servers ? TypedArray.new( Server, [*servers] ) : Server.all
+ servers.peel!
+ servers.compact!
+ @name = name.to_s
+ @servers = servers.empty? ? Server.all : TypedArray.new( Server, servers )
end
def id
@@ -37,12 +37,12 @@ def initialize name, options = {}, &block
@control_names = collect_control_names block, values, rates
build_ugen_graph block, @control_names
@constants = collect_constants @children
-
- @variants = [] #stub!!!
-
+
+ @variants = [] #stub!!!
+
warn( 'A SynthDef without a block is useless' ) unless block_given?
end
-
+
# Returns a string representing the encoded SynthDef in a way scsynth can interpret and generate.
# This method is called by a server instance when sending the synthdef via OSC.
#
@@ -51,20 +51,20 @@ def initialize name, options = {}, &block
def encode
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!!!
+ [children.size].pack('n') + children.collect{ |u| u.encode }.join('') +
+ [@variants.size].pack('n') #stub!!!
end
-
+
def init_stream file_version = 1, number_of_synths = 1 #:nodoc:
'SCgf' + [file_version].pack('N') + [number_of_synths].pack('n')
end
-
+
def values #:nodoc:
@control_names.collect{ |control| control.value }
end
-
+
alias :send_msg :send
# Sends itself to the given servers. One or more servers or an array of servers can be passed.
# If no arguments are given the synthdef gets sent to all instantiated servers
@@ -80,35 +80,36 @@ def values #:nodoc:
# # this synthdef is sent to both s and r
#
def send *servers
- servers = servers.first if servers.first.kind_of? Array if servers.size == 1
- (servers.empty? ? Server.all : servers.to_array ).each{ |s| s.send_synth_def( self ) }
+ servers.peel!
+ (servers.empty? ? Server.all : servers).each{ |s| s.send_synth_def( self ) }
self
end
-
+
private
- def collect_control_names function, values, rates #:nodoc:
- return [] if (names = function.argument_names).empty?
+ #:nodoc:
+ def collect_control_names function, values, rates
+ names = function.arguments
names.zip( values, rates ).collect_with_index{ |array, index| ControlName.new *(array << index) }
end
-
- def build_controls control_names #:nodoc:
+ #:nodoc:
+ def build_controls control_names
# control_names.select{ |c| c.rate == :noncontrol }.sort_by{ |c| c.control_name.index } +
[:scalar, :trigger, :control].collect do |rate|
same_rate_array = control_names.select{ |control| control.rate == rate }
Control.and_proxies_from( same_rate_array ) unless same_rate_array.empty?
end.flatten.compact.sort_by{ |proxy| proxy.control_name.index }
end
-
- def build_ugen_graph function, control_names #:nodoc:
+ #:nodoc:
+ def build_ugen_graph function, control_names
Ugen.synthdef = self
function.call *build_controls(control_names)
Ugen.synthdef = nil
end
-
- def collect_constants children #:nodoc:
+ #:nodoc:
+ def collect_constants children
children.send( :collect_constants ).flatten.compact.uniq
end
-
+
end
end
end
@@ -3,7 +3,8 @@ module Audio
module Ugens
class In < MultiOutUgen
- def initialize rate, channels, bus #:nodoc:
+ #:nodoc:
+ def initialize rate, channels, bus
super rate, *(0...channels).map{ |i| OutputProxy.new rate, self, i }
@inputs = [bus]
end
@@ -30,19 +31,19 @@ def initialize *args
@channels = []
end
- def output_specs #:nodoc:
- []
- end
+ #:nodoc:
+ def output_specs; []; end
+
class << self
# New Out with :audio rate, inputs should be valid Ugen inputs or Ugens, arguments can be passed as an options hash or in the given order
def ar bus, *inputs
- inputs = *inputs
+ inputs.peel!
new :audio, bus, *inputs; 0.0 #Out has no output
end
# New Out with :control rate, inputs should be valid Ugen inputs or Ugens, arguments can be passed as an options hash or in the given order
def kr bus, *inputs
- inputs = *inputs
+ inputs.peel!
new :control, bus, *inputs; 0.0 #Out has no output
end
@@ -15,10 +15,11 @@ def new operator, *inputs #:nodoc:
private
#:nodoc:
def set_operator_for input, operator
- input.instance_of? Array ? input.map{ |element| set_operator_for element, operator } : input.operator = operator
+ input.kind_of?(Array) ? input.map{ |element| set_operator_for element, operator } : input.operator = operator
end
- def get_rate( *inputs ) #:nodoc:
+ #:nodoc:
+ def get_rate *inputs
max_index = inputs.flatten.collect{ |ugen| Ugen::RATES.index ugen.rate }.max
Ugen::RATES[max_index]
end
@@ -117,26 +117,30 @@ def output_specs #:nodoc:
end
class << self
- def new rate, *inputs #:nodoc:
+ #:nodoc:
+ def new rate, *inputs
raise ArgumentError.new( "#{rate} not a defined rate") unless RATES.include?( rate.to_sym )
+
inputs.each{ |i| raise ArgumentError.new( "#{i} is not a valid ugen input") unless i.valid_ugen_input? }
+ inputs.peel!
- inputs = inputs.first if inputs.first.kind_of? Array if inputs.size == 1
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
inputs = inputs.map{ |input| input.instance_of?( Array ) ? input.wrap_to( size ) : Array.new( size, input ) }.transpose
inputs.map{ |new_inputs| new rate, *new_inputs }
end
-
- def instantiate *args #:nodoc:
+
+ #:nodoc:
+ def instantiate *args
obj = allocate
obj.__send__ :initialize, *args
obj
end
- def synthdef #:nodoc:
+ #:nodoc:
+ def synthdef
@@synthdef
end
@@ -51,4 +51,16 @@ module UnaryOperators
end
end
end
-end
+end
+
+class Fixnum
+ include Scruby::Audio::Ugens::UgenOperations
+end
+
+class Float
+ include Scruby::Audio::Ugens::UgenOperations
+end
+
+class Array
+ include Scruby::Audio::Ugens::UgenOperations
+end
View
@@ -40,16 +40,7 @@ def input_specs( synthdef )
end
end
-class Fixnum
- include Scruby::Audio::Ugens::UgenOperations
-end
-
-class Float
- include Scruby::Audio::Ugens::UgenOperations
-end
-
class Array
- include Scruby::Audio::Ugens::UgenOperations
#collect with index
def collect_with_index
@@ -85,7 +76,15 @@ def encode_floats #:nodoc:
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
+ end
+
+ def peel
+ self.dup.peel! || self
+ end
+
private
def collect_constants #:nodoc:
self.collect{ |e| e.send( :collect_constants ) }
@@ -94,7 +93,7 @@ def collect_constants #:nodoc:
class Proc
# Returns an array of symbols corresponding to the argument names
- def argument_names
+ def arguments
case self.arity
when -1..0 then []
when 1 then self.to_sexp.assoc( :dasgn_curr )[1].to_array
View
@@ -12,16 +12,16 @@
class SinOsc < Ugen
#not interested in muladd
- def self.ar freq=440.0, phase=0.0
+ def self.ar freq = 440.0, phase = 0.0
new :audio, freq, phase
end
end
describe In, Out, 'instantiation' do
it "should not instantiate with #new" do
- lambda { In.new(:audio, 1, 2) }.should raise_error
- lambda { Out.new(:audio, 1, 2) }.should raise_error
+ lambda { In.new :audio, 1, 2 }.should raise_error
+ lambda { Out.new :audio, 1, 2 }.should raise_error
end
end
@@ -35,7 +35,7 @@ def self.ar freq=440.0, phase=0.0
@proxies = (1..10).map{ @proxy }
OutputProxy.stub!(:new).and_return( @proxy )
- @ar = In.ar( 3 )
+ @ar = In.ar 3
end
it "respond to #kr and #ar "do
@@ -65,47 +65,49 @@ def self.ar freq=440.0, phase=0.0
describe Out do
before do
- @sdef = mock( 'sdef', :children => [], :constants => [400, 0] )
- Ugen.should_receive( :synthdef ).at_least( :once ).and_return( @sdef )
+ @sdef = mock 'sdef', :children => [], :constants => [400, 0]
+ Ugen.should_receive( :synthdef ).at_least( :once ).and_return @sdef
end
it "should accept one ugen" do
- @ugen1 = Ugen.new( :audio )
+ @ugen1 = Ugen.new :audio
Out.kr( 1, @ugen1 ).should == 0.0
@sdef.children.should have(2).ugens
out = @sdef.children.last
- out.rate.should == :control
- out.inputs.should == [1, @ugen1]
+ out.rate.should == :control
+ out.inputs.should == [1, @ugen1]
out.channels.should == []
- end
+ end
- it "should accept several inputs" do
- @ugen1 = Ugen.new( :audio )
- @ugen2 = Ugen.new( :audio )
- @ugen3 = Ugen.new( :audio )
+ it "should accept several inputs from array" do
+ @ugen1 = Ugen.new :audio
+ @ugen2 = Ugen.new :audio
+ @ugen3 = Ugen.new :audio
- Out.kr( 1, @ugen1, @ugen2, @ugen3 )
+ Out.kr 1, [@ugen1, @ugen2, @ugen3]
@sdef.children.should have(4).ugens
out = @sdef.children.last
out.inputs.should == [1, @ugen1, @ugen2, @ugen3]
- end
+ end
- it "should accept several inputs from array" do
- @ugen1 = Ugen.new( :audio )
- @ugen2 = Ugen.new( :audio )
- @ugen3 = Ugen.new( :audio )
+ it "should accept several inputs" do
+ @ugen1 = Ugen.new :audio
+ @ugen2 = Ugen.new :audio
+ @ugen3 = Ugen.new :audio
- Out.kr( 1, [@ugen1, @ugen2, @ugen3] )
+ Out.kr 1, @ugen1, @ugen2, @ugen3
@sdef.children.should have(4).ugens
out = @sdef.children.last
out.inputs.should == [1, @ugen1, @ugen2, @ugen3]
- end
+ end
+
+
it "should validate rate"
it "should substitute zero with silence"
Oops, something went wrong.

0 comments on commit 26b0dee

Please sign in to comment.