Skip to content
Browse files

Implemented Synth order of execution eg: tail, head... Group function…

…ality is still mainly missing
  • Loading branch information...
1 parent eb4ac23 commit b438a7467a05a4294b4c3b61e9db6ff4c71dbeab @maca maca committed Aug 23, 2009
Showing with 116 additions and 103 deletions.
  1. +4 −0 lib/scruby/group.rb
  2. +9 −13 lib/scruby/node.rb
  3. +25 −32 lib/scruby/synth.rb
  4. +1 −7 lib/scruby/ugens/ugen.rb
  5. +13 −9 spec/node_spec.rb
  6. +64 −28 spec/synth_spec.rb
  7. +0 −14 spec/ugen_spec.rb
View
4 lib/scruby/group.rb
@@ -16,5 +16,9 @@ def dump_tree post = false
self
end
+ class << self
+
+ end
+
end
end
View
22 lib/scruby/node.rb
@@ -1,17 +1,17 @@
module Scruby
class Node
- @@base_id = 2000
+ @@base_id = 999
attr_reader :servers, :group, :id
- alias :node_id :id
ACTIONS = [:head, :tail, :before, :after, :replace]
def initialize *args
args.flatten!
args.compact!
- @id = args.pop if args.last.is_a? Integer
- @servers = args.empty? ? Server.all : TypedArray.new( Server, args )
- @id ||= @@base_id += 1
+ args.each{ |s| raise TypeError.new("#{s} should be instance of Server") unless Server === s }
+ @id = args.pop if args.last.is_a? Integer
+ @servers = args.empty? ? Server.all : args
+ @id ||= @@base_id += 1
end
def set args = {}
@@ -78,14 +78,9 @@ def move_after node
# @server.each{ |s| s.send '/n_after', self.id, node.id }
# end
- # def playing?
- # @playing || false
- # end
- #
- # def running?
- # @running || false
- # end
-
+ def playing?; @playing || false; end
+ alias :running? :playing?
+
# Reset the node count
def self.reset!
@@base_id = 2000
@@ -101,6 +96,7 @@ def send_bundle timestamp, *messages
def send command, *args
message = Message.new command, *args
@servers.each{ |s| s.send message }
+ self
end
end
end
View
57 lib/scruby/synth.rb
@@ -1,55 +1,48 @@
module Scruby
class Synth < Node
attr_reader :name
-
+
def initialize name, servers
super servers
@name = name.to_s
end
-
- protected
-
class << self
def new name, args = {}, target = nil, action = :head
- servers, target_id = params_from_target target
- synth = instantiate name, servers
+ case target
+ when nil
+ target_id, servers = 1, nil
+ when Group
+ target_id, servers = group.id, target.servers
+ when Node
+ target_id, servers = 1, target.servers
+ else
+ raise TypeError.new("expected #{ target } to kind of Node or nil")
+ end
+
+ synth = super name, servers
synth.send '/s_new', synth.name, synth.id, Node::ACTIONS.index(action), target_id, *args.to_a.flatten
synth
end
-
- def paused
+
+ def after target, name, args = {}
+ new name, args, target, :after
end
- def after
+ def before target, name, args = {}
+ new name, args, target, :before
end
- # before
- # head
- # tail
- # replace
-
- # def as_target obj
- # case obj
- # when Server then Group.new obj, 1
- # when Node then obj
- # when nil then Group.new
- # end
- # end
-
+ def head target, name, args = {}
+ new name, args, target, :head
+ end
- private
- def params_from_target target
- servers = target.servers if target.respond_to? :servers
- target_id = target if target.is_a? Integer
- target_id ||= target.respond_to?(:node_id) ? target.node_id : 1
- [servers, target_id]
+ def tail target, name, args = {}
+ new name, args, target, :tail
end
- def instantiate *args
- obj = allocate
- obj.__send__ :initialize, *args
- obj
+ def replace target, name, args = {}
+ new name, args, target, :replace
end
end
View
8 lib/scruby/ugens/ugen.rb
@@ -136,7 +136,7 @@ def new rate, *inputs
input
end
- return instantiate( rate, *inputs.flatten ) unless size > 1 #return an Ugen if no array was passed as an input
+ return super( rate, *inputs.flatten ) unless size > 1 #return an Ugen if no array was passed as an input
inputs.map! do |input|
Array === input ? input.wrap_to!(size) : input = Array.new(size, input)
@@ -146,12 +146,6 @@ def new rate, *inputs
output.map! do |new_inputs| new rate, *new_inputs end
output.to_da
end
-
- def instantiate *args
- obj = allocate
- obj.__send__ :initialize, *args
- obj
- end
public
def valid_input? obj
View
22 spec/node_spec.rb
@@ -1,6 +1,5 @@
require File.expand_path(File.dirname(__FILE__)) + "/helper"
-
require "scruby/core_ext/typed_array"
require "scruby/node"
require "scruby/bus"
@@ -10,10 +9,9 @@
include Scruby
-
describe Node do
before :all do
- @server = mock('server')
+ @server = Server.new
end
before do
@@ -32,14 +30,12 @@
end
describe 'instantiation' do
-
it "should not accept non servers" do
lambda{ Node.new(1,2) }.should raise_error(TypeError)
lambda{ Node.new([1,2]) }.should raise_error(TypeError)
end
it "should accept a server and have a TypedArray of Servers" do
- @server.should_receive(:instance_of?).exactly(:once).and_return(true)
n = Node.new @server
n.servers.should == [@server]
end
@@ -48,7 +44,6 @@
n = Node.new
n.servers.should == [@server]
end
-
end
describe 'Server interaction' do
@@ -69,9 +64,9 @@
it "should send free" do
@node.free
- @node.should_not be_running
- @node.group.should be_nil
- @node.should_not be_playing
+ @node.should_not be_running
+ @node.group.should be_nil
+ @node.should_not be_playing
sleep 0.05
@server.output.should =~ %r{\[ "/n_free", #{ @node.id } \]}
end
@@ -85,6 +80,15 @@
@server.output.should =~ %r{\[ "/n_run", #{ @node.id }, 0 \]}
end
+ it "should send run" do
+ @node.run
+ sleep 0.05
+ @server.output.should =~ %r{\[ "/n_run", #{ @node.id }, 1 \]}
+ @node.run false
+ sleep 0.05
+ @server.output.should =~ %r{\[ "/n_run", #{ @node.id }, 0 \]}
+ end
+
describe 'map' do
it "should just accept instances of Bus" do
b1 = mock 'Bus', :index => 1, :channels => 1, :rate => :audio
View
92 spec/synth_spec.rb
@@ -9,30 +9,28 @@
require "scruby/server"
require File.join( File.expand_path(File.dirname(__FILE__)), "server")
-
include Scruby
describe Synth do
-
- before :all do
- end
-
- before do
- Node.reset!
- @target = Node.new( (0..3).map{ Server.new } )
- @synth = Synth.new :synth, {:attack => 10}, @target
- end
- it "should initialize" do
- @synth.name.should == 'synth'
- @synth.servers.should == @target.servers
- end
-
- it "should initialize not passing servers and have default servers" do
- s = Synth.new( 'synth' )
- s.servers.should == Server.all
+ describe 'instantiation with node target' do
+ before do
+ Node.reset!
+ @target = Node.new( (0..3).map{ Server.new } )
+ @synth = Synth.new :synth, {:attack => 10}, @target
+ end
+
+ it "should initialize" do
+ @synth.name.should == 'synth'
+ @synth.servers.should == @target.servers
+ end
+
+ it "should initialize not passing servers and have default servers" do
+ s = Synth.new( 'synth' )
+ s.servers.should == Server.all
+ end
end
-
+
describe 'Server interaction' do
before :all do
Server.clear
@@ -41,26 +39,64 @@
@server.send "/dumpOSC", 3
sleep 0.05
end
-
+
after :all do
@server.quit
end
-
+
before do
@server.flush
- @synth = Synth.new :synth, :attack => 10
end
-
+
it "should send /s_new message" do
+ synth = Synth.new :synth, :attack => 10
sleep 0.05
- @server.output.should =~ %r{\[ "/s_new", "#{ @synth.name }", #{ @synth.id }, 0, 1, "attack", 10 \]}
+ @server.output.should =~ %r{\[ "/s_new", "#{ synth.name }", #{ synth.id }, 0, 1, "attack", 10 \]}
end
-
+
it "should send set message and return self" do
- @synth.set( :attack => 20 ).should == @synth
+ synth = Synth.new :synth, :attack => 10
+ synth.set( :attack => 20 ).should be_a(Synth)
sleep 0.05
- @server.output.should =~ %r{\[ "/n_set", #{ @synth.id }, "attack", 20 \]}
+ @server.output.should =~ %r{\[ "/n_set", #{ synth.id }, "attack", 20 \]}
+ end
+
+ describe 'Default Group' do
+ it "should send after message" do
+ synth = Synth.after nil, :synth, :attack => 10
+ synth.should be_a(Synth)
+ sleep 0.05
+ @server.output.should =~ %r{\[ "/s_new", "#{ synth.name }", #{ synth.id }, 3, 1, "attack", 10 \]}
+ end
+
+ it "should send before message" do
+ synth = Synth.before nil, :synth, :attack => 10
+ synth.should be_a(Synth)
+ sleep 0.05
+ @server.output.should =~ %r{\[ "/s_new", "#{ synth.name }", #{ synth.id }, 2, 1, "attack", 10 \]}
+ end
+
+ it "should send head message" do
+ synth = Synth.head nil, :synth, :attack => 10
+ synth.should be_a(Synth)
+ sleep 0.05
+ @server.output.should =~ %r{\[ "/s_new", "#{ synth.name }", #{ synth.id }, 0, 1, "attack", 10 \]}
+ end
+
+ it "should send tail message" do
+ synth = Synth.tail nil, :synth, :attack => 10
+ synth.should be_a(Synth)
+ sleep 0.05
+ @server.output.should =~ %r{\[ "/s_new", "#{ synth.name }", #{ synth.id }, 1, 1, "attack", 10 \]}
+ end
+
+ it "should send replace message" do
+ synth = Synth.replace nil, :synth, :attack => 10
+ synth.should be_a(Synth)
+ sleep 0.05
+ @server.output.should =~ %r{\[ "/s_new", "#{ synth.name }", #{ synth.id }, 4, 1, "attack", 10 \]}
+ end
end
end
-
+
end
View
14 spec/ugen_spec.rb
@@ -193,11 +193,6 @@ def as_ugen_input; 0; end
MockUgen.new( :audio, 1, 2, 3, 4 )
end
- it "should description" do
- MockUgen.should_receive( :instantiate ).with( :audio, 1, 2 )
- MockUgen.new( :audio, 1, 2 )
- end
-
it "should set inputs" do
@ugen.inputs.should == [1, 2, 3]
end
@@ -268,15 +263,6 @@ def as_ugen_input; 0; end
multichannel.should == d(MockUgen.new(:audio, 100, 210), MockUgen.new(:audio, 100, 220))
end
- it "should instantiate with correct arguments" do
- MockUgen.should_receive(:instantiate).with( :audio, *@i_1 )
- MockUgen.should_receive(:instantiate).with( :audio, *@i_2 )
- MockUgen.should_receive(:instantiate).with( :audio, *@i_3 )
- MockUgen.should_receive(:instantiate).with( :audio, *@i_4 )
- ugens = MockUgen.new( :audio, 100, [210, 220, 230, 240] )
- ugens.should have(4).ugens
- end
-
it "should return an delegator array of ugens with correct inputs" do
ugens = MockUgen.new( :audio, 100, [210, 220, 230, 240] )
ugens.zip( [@i_1, @i_2, @i_3, @i_4] ).each do |e|

0 comments on commit b438a74

Please sign in to comment.
Something went wrong with that request. Please try again.