From 0211ee00cc60310380ffb1e558e073cd2ceafc27 Mon Sep 17 00:00:00 2001 From: "Gun.io Whitespace Robot" Date: Mon, 30 Jan 2012 19:10:36 -0500 Subject: [PATCH] Remove whitespace [WhitespaceBot] --- README.rdoc | 12 +-- TODO.markdown | 2 +- examples/example.rb | 6 +- lib/scruby.rb | 4 +- lib/scruby/buffer.rb | 29 +++---- lib/scruby/bus.rb | 28 +++--- lib/scruby/core_ext/array.rb | 6 +- lib/scruby/core_ext/delegator_array.rb | 12 +-- lib/scruby/core_ext/fixnum.rb | 2 +- lib/scruby/core_ext/numeric.rb | 4 +- lib/scruby/core_ext/object.rb | 2 +- lib/scruby/core_ext/typed_array.rb | 22 ++--- lib/scruby/group.rb | 4 +- lib/scruby/node.rb | 22 ++--- lib/scruby/server.rb | 36 ++++---- lib/scruby/synth.rb | 8 +- lib/scruby/synthdef.rb | 12 +-- lib/scruby/ticker.rb | 10 +-- lib/scruby/ugens/buffer_read_write.rb | 4 +- lib/scruby/ugens/demand.rb | 4 +- lib/scruby/ugens/in_out.rb | 2 +- lib/scruby/ugens/multi_out.rb | 14 +-- lib/scruby/ugens/operation_ugens.rb | 8 +- lib/scruby/ugens/panner.rb | 30 +++---- lib/scruby/ugens/ugen.rb | 34 ++++---- lib/scruby/ugens/ugen_operations.rb | 14 +-- lib/scruby/ugens/ugens.rb | 24 ++--- spec/buffer_read_write_spec.rb | 22 ++--- spec/buffer_spec.rb | 62 ++++++------- spec/bus_spec.rb | 54 ++++++------ spec/core_ext/core_ext_spec.rb | 44 +++++----- spec/core_ext/delegator_array_spec.rb | 36 ++++---- spec/core_ext/typed_array_spec.rb | 34 ++++---- spec/demand_spec.rb | 28 +++--- spec/disk_in_out_spec.rb | 10 +-- spec/env_gen_spec.rb | 6 +- spec/env_spec.rb | 14 +-- spec/group_spec.rb | 24 ++--- spec/helper.rb | 6 +- spec/in_out_spec.rb | 6 +- spec/integration_spec.rb | 16 ++-- spec/multiout_ugen_spec.rb | 20 ++--- spec/node_spec.rb | 38 ++++---- spec/operation_ugens_spec.rb | 80 ++++++++--------- spec/panner_spec.rb | 44 +++++----- spec/server.rb | 2 +- spec/server_spec.rb | 40 ++++----- spec/synth_spec.rb | 4 +- spec/synthdef_spec.rb | 90 +++++++++---------- spec/ugen_operations_spec.rb | 30 +++---- spec/ugen_spec.rb | 116 ++++++++++++------------- spec/ugens_spec.rb | 16 ++-- 52 files changed, 598 insertions(+), 599 deletions(-) diff --git a/README.rdoc b/README.rdoc index 6f99edd..e966674 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,11 +1,11 @@ -== Scruby +== Scruby Is a bare-bones SuperCollider livecoding library for Ruby, it provides comunication with a remote or local scsynth server and SynthDef creation with a in a similar way to Sclang. SynthDef creation and sending is robust but some features are not implemented such as SynthDef variations and others I may not be aware of. -livecode.rb executable is located in the bin directory and a TextMate bundle included in extras permits livecoding from TextMate, comunication is +livecode.rb executable is located in the bin directory and a TextMate bundle included in extras permits livecoding from TextMate, comunication is thrugh *nix pipes. Similar functionality shouldn't be too dificult to implement from Emacs or Vim. == Install @@ -18,10 +18,10 @@ Scruby is just a SuperCollider client so SC must be installed on the system. The == Usage require 'scruby' - + s = Server.new s.boot - + SynthDef.new :fm do |freq, amp, dur| mod_env = EnvGen.kr Env.new( d(600, 200, 100), d(0.7,0.3) ), 1, :timeScale => dur mod = SinOsc.ar freq * 1.4, :mul => mod_env @@ -32,12 +32,12 @@ Scruby is just a SuperCollider client so SC must be installed on the system. The end.send Synth.new :fm, :freq => 220, :amp => 0.4, :dur => 1 - + To start a live coding session: $ live - + See http://github.com/maca/live diff --git a/TODO.markdown b/TODO.markdown index beaf935..f9a1ed3 100644 --- a/TODO.markdown +++ b/TODO.markdown @@ -1,3 +1,3 @@ **Array workarrounds** -* Buffer as Ugen input +* Buffer as Ugen input diff --git a/examples/example.rb b/examples/example.rb index 0c01fc4..3edd75b 100644 --- a/examples/example.rb +++ b/examples/example.rb @@ -24,7 +24,7 @@ s.stop -sdef = SynthDef.new :perc, :values => [456, 0.34, 0.45] do |freq, amp, a, b| +sdef = SynthDef.new :perc, :values => [456, 0.34, 0.45] do |freq, amp, a, b| dur = a amp = amp * 0.25 freq = freq * 0.05 @@ -40,7 +40,7 @@ sleep 0.05 test = Synth.new :perc, :freq => 1000, :amp => 0.5, :dur => rand -sdef = SynthDef.new :perc, :values => [456, 0.34, 0.45] do |freq, amp, a, b| +sdef = SynthDef.new :perc, :values => [456, 0.34, 0.45] do |freq, amp, a, b| dur = a amp = amp freq = freq * 0.1 @@ -53,7 +53,7 @@ sleep 0.05 test = Synth.new :perc, :freq => 1000, :amp => 0.5, :dur => rand -sdef = SynthDef.new :perc, :values => [456, 0.34, 0.45] do |freq, amp, a, b| +sdef = SynthDef.new :perc, :values => [456, 0.34, 0.45] do |freq, amp, a, b| gate = EnvGen.kr Env.perc(0,0.1) env = EnvGen.kr Env.asr( 0.1, 4, 1 ), gate, :doneAction => 2 sig = DelayC.ar( SinOsc.ar(freq), 4, SinOsc.ar( SinOsc.ar( SinOsc.ar( 2 ) ) ) ) diff --git a/lib/scruby.rb b/lib/scruby.rb index 0890b9c..eb97525 100644 --- a/lib/scruby.rb +++ b/lib/scruby.rb @@ -5,12 +5,12 @@ # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program. If not, see . #++ diff --git a/lib/scruby/buffer.rb b/lib/scruby/buffer.rb index b0eff0a..c9ec12c 100644 --- a/lib/scruby/buffer.rb +++ b/lib/scruby/buffer.rb @@ -3,7 +3,7 @@ def expand_path path path = "~/Scruby/#{ path }" unless path.match %r{^(?:/|~)} File.expand_path path end - + class Buffer # readNoUpdate # loadCollection @@ -32,45 +32,45 @@ class Buffer attr_reader :server attr_accessor :path, :frames, :channels, :rate - + def read path, file_start = 0, frames = -1, buff_start = 0, leave_open = false, &message # @on_info = message message ||= ["/b_query", buffnum] @server.send "/b_read", buffnum, expand_path(path), file_start, frames, buff_start, leave_open, message.value(self) self end - + def read_channel path, file_start = 0, frames = -1, buff_start = 0, leave_open = false, channels = [], &message message ||= 0 @server.send *(["/b_ReadChannel", buffnum, expand_path(path), start, frames, buff_start, leave_open] + channels << message.value(self)) self end - + def close &message message ||= 0 @server.send '/b_close', buffnum, message.value(self) self end - + def zero &message message ||= 0 @server.send '/b_zero', buffnum, message.value(self) self end - + def cue_sound_file path, start = 0, &message message ||= 0 @server.send "/b_read", buffnum, expand_path(path), start, @frames, 0, 1, message.value(self) self end - + def write path = nil, format = 'aiff', sample_format = 'int24', frames = -1, start = 0, leave_open = false, &message message ||= 0 path ||= "#{ DateTime.now }.#{ format }" @server.send "/b_write", buffnum, expand_path(path), format, sample_format, frames, start, leave_open, message.value(self) self end - + def initialize server, frames = -1, channels = 1 @server, @frames, @channels = server, frames, channels end @@ -88,7 +88,7 @@ def buffnum alias :as_ugen_input :buffnum alias :index :buffnum # alias :as_control_input :buffnum - + def free &message message ||= 0 @server.send "/b_free", buffnum, message.value(self) @@ -102,7 +102,7 @@ def allocate_and_read path, start, frames, &message @server.send "/b_allocRead", buffnum, @path = expand_path(path), start, frames, message.value(self) self end - + def allocate_read_channel path, start, frames, channels, &message @server.allocate :buffers, self message ||= ["/b_query", buffnum] @@ -114,24 +114,24 @@ class << self def allocate server, frames = -1, channels = 1, &message new(server, frames, channels).allocate &message end - + def cue_sound_file server, path, start, channels = 2, buff_size = 32768, &message allocate server, buff_size, channels do |buffer| message ||= 0 ['/b_read', buffer.buffnum, expand_path(path), start, buff_size, 0, true, message.value(buffer)] end end - + # Allocate a buffer and immediately read a soundfile into it. def read server, path, start = 0, frames = -1, &message buffer = new server, &message buffer.allocate_and_read expand_path(path), start, frames end - + def read_channel server, path, start = 0, frames = -1, channels = [], &message new(server, frames, channels).allocate_read_channel expand_path(path), start, frames, channels, &message end - + def alloc_consecutive buffers, server, frames = -1, channels = 1, &message buffers = Array.new(buffers){ new server, frames, channels } server.allocate :buffers, buffers @@ -150,4 +150,3 @@ def alloc_consecutive buffers, server, frames = -1, channels = 1, &message end end end - \ No newline at end of file diff --git a/lib/scruby/bus.rb b/lib/scruby/bus.rb index 9db39b9..09b4e5b 100644 --- a/lib/scruby/bus.rb +++ b/lib/scruby/bus.rb @@ -1,30 +1,30 @@ module Scruby - + class Bus attr_reader :server, :rate, :channels, :main_bus - + def initialize server, rate, channels = 1, main_bus = self, hardware_out = false @server, @rate, @channels, @main_bus, @hardware_out = server, rate, channels, main_bus, hardware_out end - + def index @index ||= @server.__send__("#{ @rate }_buses").index(self) end - + def free @index = nil @server.__send__("#{ @rate }_buses").delete(self) end - + def to_map raise SCError, 'Audio buses cannot be mapped' if rate == :audio "c#{ index }" end - + def audio_out? index < @server.instance_variable_get(:@opts)[:audio_outputs] end - + # Messaging def set *args args.flatten! @@ -33,28 +33,28 @@ def set *args message_args.push(chan).push(val) if chan and val end if args.size > channels - warn "You tried to set #{ args.size } values for bus #{ index } that only has #{ channels } channels, extra values are ignored." + warn "You tried to set #{ args.size } values for bus #{ index } that only has #{ channels } channels, extra values are ignored." end @server.send '/c_set', *message_args end - + def fill value, channels = @channels if channels > @channels - warn "You tried to set #{ channels } values for bus #{ index } that only has #{ @channels } channels, extra values are ignored." + warn "You tried to set #{ channels } values for bus #{ index } that only has #{ @channels } channels, extra values are ignored." end @server.send '/c_fill', index, channels.min(@channels), value end - + class << self private :new - + def control server, channels = 1 buses = [new(server, :control, channels)] buses.push new(server, :control, channels, buses.first) while buses.size < channels server.allocate :control_buses, buses buses.first end - + def audio server, channels = 1 buses = [new(server, :audio, channels)] buses.push new(server, :audio, channels, buses.first) while buses.size < channels @@ -62,6 +62,6 @@ def audio server, channels = 1 buses.first end end - + end end \ No newline at end of file diff --git a/lib/scruby/core_ext/array.rb b/lib/scruby/core_ext/array.rb index 1f1cbf4..9dbdc6e 100644 --- a/lib/scruby/core_ext/array.rb +++ b/lib/scruby/core_ext/array.rb @@ -28,15 +28,15 @@ def to_array; self; end def encode_floats #:nodoc: [self.size].pack('n') + self.pack('g*') #TODO: Deprecate 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 ) } diff --git a/lib/scruby/core_ext/delegator_array.rb b/lib/scruby/core_ext/delegator_array.rb index 964bc4f..d14aba2 100644 --- a/lib/scruby/core_ext/delegator_array.rb +++ b/lib/scruby/core_ext/delegator_array.rb @@ -1,9 +1,9 @@ class DelegatorArray < 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 @@ -12,18 +12,18 @@ def to_a; Array.new self; end 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(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 > inputs.size + next results.push(left) if index + 1 > inputs.size results.push left.send(op, right) - end + end results end end diff --git a/lib/scruby/core_ext/fixnum.rb b/lib/scruby/core_ext/fixnum.rb index 1d8c3be..1153f8b 100644 --- a/lib/scruby/core_ext/fixnum.rb +++ b/lib/scruby/core_ext/fixnum.rb @@ -1,5 +1,5 @@ # Musical math -class Fixnum +class Fixnum def freq 440 * (2 ** ((self - 69) * 0.083333333333) ) end diff --git a/lib/scruby/core_ext/numeric.rb b/lib/scruby/core_ext/numeric.rb index fe5c5d1..dadd510 100644 --- a/lib/scruby/core_ext/numeric.rb +++ b/lib/scruby/core_ext/numeric.rb @@ -16,8 +16,8 @@ def min other #:nodoc: def collect_constants self - end - + end + #:nodoc: def input_specs synthdef [-1, synthdef.constants.index(self)] diff --git a/lib/scruby/core_ext/object.rb b/lib/scruby/core_ext/object.rb index 5f8864e..734af83 100644 --- a/lib/scruby/core_ext/object.rb +++ b/lib/scruby/core_ext/object.rb @@ -3,7 +3,7 @@ class Object def to_array [*self] end - + def to_proc Proc.new{ self } end diff --git a/lib/scruby/core_ext/typed_array.rb b/lib/scruby/core_ext/typed_array.rb index 8f7db1c..69d9a28 100644 --- a/lib/scruby/core_ext/typed_array.rb +++ b/lib/scruby/core_ext/typed_array.rb @@ -1,9 +1,9 @@ -# Typed array is a kind of Array that only accepts elements of a given Class, it will raise a TypeError if an element of +# Typed array is a kind of Array that only accepts elements of a given Class, it will raise a TypeError if an element of # diferent Class is passed to the operation methods or if an Array containing objects of a diferent class is concatenated. class TypedArray < Array attr_reader :type - + # +Type+ a Class or an instance, on the operation methods it will match the argument against the Class or instance's Class def initialize type, elements = [] @type = type.instance_of?(Class) ? type : type.class @@ -11,43 +11,43 @@ def initialize type, elements = [] check_types_for_array elements super elements end - + # alias :old_plus :+ #:nodoc: - # + # # def + array # self.class.new @type, self.old_plus( array ) # end - + def concat array check_array_passed array check_types_for_array array super end - + def << e check_type_for_obj e super end - + def []= index, e check_type_for_obj e super end - + def push e check_type_for_obj e super end - + private def check_array_passed obj raise TypeError.new( "#{obj} is not Array" ) unless obj.instance_of? Array end - + def check_types_for_array array raise TypeError.new("All elements of #{array} should be instance of #{@type}") unless array.reject{ |e| e.instance_of? @type }.empty? end - + def check_type_for_obj obj raise TypeError.new("#{obj} is not instance of #{@type}") unless obj.instance_of? @type end diff --git a/lib/scruby/group.rb b/lib/scruby/group.rb index 7c0eda9..d4f4193 100644 --- a/lib/scruby/group.rb +++ b/lib/scruby/group.rb @@ -4,12 +4,12 @@ def free_all send '/g_freeAll', self.id self end - + def deep_free send '/g_deepFree', self.id self end - + def dump_tree post = false send '/g_dumpTree', self.id, post self diff --git a/lib/scruby/node.rb b/lib/scruby/node.rb index fab36c1..589ceee 100644 --- a/lib/scruby/node.rb +++ b/lib/scruby/node.rb @@ -2,7 +2,7 @@ module Scruby class Node @@base_id = 999 attr_reader :servers, :group, :id - + ACTIONS = [:head, :tail, :before, :after, :replace] def initialize *args @@ -13,7 +13,7 @@ def initialize *args @servers = args.empty? ? Server.all : args @id ||= @@base_id += 1 end - + def set args = {} send '/n_set', self.id, *args.to_a.flatten self @@ -24,12 +24,12 @@ def free @group, @playing, @running = nil, false, false self end - + def run run = true send '/n_run', self.id, run self end - + # Map controls in this Node to read from control or audio rate Buses. Controls are defined in a SynthDef as args or instances of # Control or its subclasses. They are specified here using symbols, strings, or indices, and are listed in pairs with Bus objects. # The number of sequential controls mapped corresponds to the Bus' number of channels. If this Node is a Group this will map all @@ -49,30 +49,30 @@ def map args send_bundle nil, *content self end - + # mapn def trace send '/n_trace', self.id self end - + def move_before node @group = node.group send '/n_before', self.id, node.id self end - + def move_after node @group = node.group send '/n_after', self.id, node.id self end - + # def move_to_head group # @group = node.group # @server.each{ |s| s.send '/n_after', self.id, node.id } # end - # + # # def move_to_tail group # @group = node.group # @server.each{ |s| s.send '/n_after', self.id, node.id } @@ -85,13 +85,13 @@ def playing?; @playing || false; end def self.reset! @@base_id = 2000 end - + # Sends a bundle to all registered +servers+ for this node def send_bundle timestamp, *messages bundle = Bundle.new( timestamp, *messages.map{ |message| Message.new *message } ) @servers.each{ |s| s.send bundle } end - + # Sends a message to all registered +servers+ for this node def send command, *args message = Message.new command, *args diff --git a/lib/scruby/server.rb b/lib/scruby/server.rb index 69c105f..099a9e6 100644 --- a/lib/scruby/server.rb +++ b/lib/scruby/server.rb @@ -1,16 +1,16 @@ require 'singleton' -module Scruby +module Scruby include OSC - + TrueClass.send :include, OSC::OSCArgument TrueClass.send(:define_method, :to_osc_type){ 1 } - + FalseClass.send :include, OSC::OSCArgument FalseClass.send(:define_method, :to_osc_type){ 0 } - + Hash.send :include, OSC::OSCArgument - Hash.send :define_method, :to_osc_type do + Hash.send :define_method, :to_osc_type do self.to_a.collect{ |pair| pair.collect{ |a| OSC.coerce_argument a } } end @@ -21,18 +21,18 @@ module Scruby class Server attr_reader :host, :port, :path, :buffers, :control_buses, :audio_buses - DEFAULTS = { :buffers => 1024, :control_buses => 4096, :audio_buses => 128, :audio_outputs => 8, :audio_inputs => 8, + DEFAULTS = { :buffers => 1024, :control_buses => 4096, :audio_buses => 128, :audio_outputs => 8, :audio_inputs => 8, :host => 'localhost', :port => 57111, :path => '/Applications/SuperCollider/scsynth' } # Initializes and registers a new Server instance and sets the host and port for it. - # The server is a Ruby representation of scsynth which can be a local binary or a remote + # The server is a Ruby representation of scsynth which can be a local binary or a remote # server already running. # Server class keeps an array with all the instantiated servers - # - # For more info + # + # For more info # $ man scsynth - # + # # @param [Hash] opts the options to create a message with. # @option opts [String] :path ('scsynt' on Linux, '/Applications/SuperCollider/scsynth' on Mac) scsynth binary path # @option opts [String] :host ('localhost') SuperCollider Server address @@ -42,7 +42,7 @@ class Server # @option opts [Fixnum] :audio_outputs (8) Reserved buses for hardware output, indices start at 0 # @option opts [Fixnum] :audio_inputs (8) Reserved buses for hardware input, indices starting from the number of audio outputs # @option opts [Fixnum] :buffers (1024) Number of available sample buffers - # + # def initialize opts = {} @opts = DEFAULTS.dup.merge opts @buffers = [] @@ -53,26 +53,26 @@ def initialize opts = {} Bus.audio self, @opts[:audio_inputs] self.class.all << self end - + def host; @opts[:host]; end def port; @opts[:port]; end def path; @opts[:path]; end - # Boots the local binary of the scsynth forking a process, it will rise a SCError if the scsynth - # binary is not found in path. + # Boots the local binary of the scsynth forking a process, it will rise a SCError if the scsynth + # binary is not found in path. # The default path can be overriden using Server.scsynt_path=('path') def boot raise SCError.new('Scsynth not found in the given path') unless File.exists? path if running? warn "Server on port #{ port } allready running" - return self + return self end ready = false timeout = Time.now + 2 @thread = Thread.new do IO.popen "cd #{ File.dirname path }; ./#{ File.basename path } -u #{ port }" do |pipe| - loop do + loop do if response = pipe.gets puts response ready = true if response.match /ready/ @@ -83,7 +83,7 @@ def boot sleep 0.01 until ready or !@thread.alive? or Time.now > timeout sleep 0.01 # just to be shure send "/g_new", 1 # default group - self + self end def running? @@ -141,7 +141,7 @@ def allocate kind, *elements end end - case + case when indices.size >= elements.size collection[indices.first, elements.size] = elements when collection.size + elements.size <= max_size diff --git a/lib/scruby/synth.rb b/lib/scruby/synth.rb index 5bad9ab..3157b91 100644 --- a/lib/scruby/synth.rb +++ b/lib/scruby/synth.rb @@ -28,19 +28,19 @@ def new name, args = {}, target = nil, action = :head def after target, name, args = {} new name, args, target, :after end - + def before target, name, args = {} new name, args, target, :before end - + def head target, name, args = {} new name, args, target, :head end - + def tail target, name, args = {} new name, args, target, :tail end - + def replace target, name, args = {} new name, args, target, :replace end diff --git a/lib/scruby/synthdef.rb b/lib/scruby/synthdef.rb index f231923..94ba7a6 100644 --- a/lib/scruby/synthdef.rb +++ b/lib/scruby/synthdef.rb @@ -1,7 +1,7 @@ module Scruby class SynthDef attr_reader :name, :children, :constants, :control_names - # Creates a new SynthDef instance + # Creates a new SynthDef instance # An "ugen graph" block should be passed: # # SynthDef.new('simple') do |rate| @@ -48,9 +48,9 @@ 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 + + [children.size].pack('n') + children.collect{ |u| u.encode }.join + [@variants.size].pack('n') #stub!!! end @@ -78,7 +78,7 @@ def values #:nodoc: # def send *servers servers.peel! - (servers.empty? ? Server.all : servers).each{ |s| s.send_synth_def( self ) } + (servers.empty? ? Server.all : servers).each{ |s| s.send_synth_def( self ) } self end @@ -89,8 +89,8 @@ def collect_control_names function, values, rates end 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| + # 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 } diff --git a/lib/scruby/ticker.rb b/lib/scruby/ticker.rb index 8546ee4..41a6d7c 100644 --- a/lib/scruby/ticker.rb +++ b/lib/scruby/ticker.rb @@ -7,21 +7,21 @@ module Scruby # end # end # end - + # A timer will call a given block periodically. The period is specified in beats per minute. class Ticker attr_reader :start, :tick, :interval attr_accessor :tempo, :resolution, :size, :loop - + def initialize tempo = 120, size = 16, resolution = 1, loop = true, &block @tempo , @resolution, @size, @loop = tempo , resolution, size, loop @interval = 60.0 / @tempo @tick = 0 @block = block end - + named_args_for :initialize - + def block &block @block = block end @@ -88,5 +88,5 @@ def at tick, &proc @queue[tick].push proc end end - + end \ No newline at end of file diff --git a/lib/scruby/ugens/buffer_read_write.rb b/lib/scruby/ugens/buffer_read_write.rb index 28d800c..7ef9245 100644 --- a/lib/scruby/ugens/buffer_read_write.rb +++ b/lib/scruby/ugens/buffer_read_write.rb @@ -19,7 +19,7 @@ class TGrains < Ugen include MultiOut def initialize rate, channels, *inputs - raise ArgumentError.new("#{ self.class } instance needs at least two channels.") unless channels > 1 + raise ArgumentError.new("#{ self.class } instance needs at least two channels.") unless channels > 1 super end @@ -84,7 +84,7 @@ def ar input, bufnum = 0 named_args_for :kr, :ar end end - + class Tap < Ugen class << self def ar bufnum = 0, num_channels = 1, delay_time = 0.2 diff --git a/lib/scruby/ugens/demand.rb b/lib/scruby/ugens/demand.rb index e5c65dc..04ae4da 100644 --- a/lib/scruby/ugens/demand.rb +++ b/lib/scruby/ugens/demand.rb @@ -2,8 +2,8 @@ module Scruby module Ugens class Demand < Ugen include MultiOut - - + + end end end \ No newline at end of file diff --git a/lib/scruby/ugens/in_out.rb b/lib/scruby/ugens/in_out.rb index 3f07f87..d1f7608 100644 --- a/lib/scruby/ugens/in_out.rb +++ b/lib/scruby/ugens/in_out.rb @@ -39,7 +39,7 @@ def kr bus, *inputs end end end - + class ReplaceOut < Out end end diff --git a/lib/scruby/ugens/multi_out.rb b/lib/scruby/ugens/multi_out.rb index cc59b23..c26e3e0 100644 --- a/lib/scruby/ugens/multi_out.rb +++ b/lib/scruby/ugens/multi_out.rb @@ -1,20 +1,20 @@ module Scruby - module Ugens + 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 @@ -23,7 +23,7 @@ def new rate, channels, *inputs end end end - + class OutputProxy < Ugen #:nodoc: attr_reader :source, :control_name, :output_index class << self; public :new; end @@ -40,11 +40,11 @@ def add_to_synthdef; 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 diff --git a/lib/scruby/ugens/operation_ugens.rb b/lib/scruby/ugens/operation_ugens.rb index 9bfdfe9..edd9f2c 100644 --- a/lib/scruby/ugens/operation_ugens.rb +++ b/lib/scruby/ugens/operation_ugens.rb @@ -5,7 +5,7 @@ class BasicOpUgen < Ugen #:nodoc: attr_accessor :operator class << self - def new operator, *inputs + def new operator, *inputs obj = super get_rate(inputs), inputs set_operator_for obj, operator obj @@ -13,7 +13,7 @@ def new operator, *inputs private #:nodoc: - def set_operator_for input, operator + def set_operator_for input, operator input.kind_of?(Array) ? input.each{ |element| set_operator_for element, operator } : input.operator = operator end @@ -25,7 +25,7 @@ def get_rate *inputs end end - class UnaryOpUGen < BasicOpUgen + class UnaryOpUGen < BasicOpUgen def self.new operator, input super end @@ -59,5 +59,5 @@ def self.new input, mul, add end end end - + end \ No newline at end of file diff --git a/lib/scruby/ugens/panner.rb b/lib/scruby/ugens/panner.rb index 3ba6873..fc16aab 100644 --- a/lib/scruby/ugens/panner.rb +++ b/lib/scruby/ugens/panner.rb @@ -2,21 +2,21 @@ module Scruby module Ugens class Pan2 < Ugen include MultiOut - + class << self def ar input, pos = 0.0, level = 1.0 new :audio, 2, input, pos, level end - + def kr input, pos = 0.0, level = 1.0 new :control, 2, input, pos, level end named_args_for :ar, :kr end end - + class LinPan2 < Pan2; end - + class Pan4 < Ugen include MultiOut @@ -24,14 +24,14 @@ class << self def ar input, xpos = 0.0, ypos = 0.0, level = 1.0 new :audio, 4, input, xpos, ypos, level end - + def kr input, xpos = 0.0, ypos = 0.0, level = 1.0 new :control, 4, input, xpos, ypos, level end named_args_for :ar, :kr end end - + class Balance2 < Ugen include MultiOut @@ -39,28 +39,28 @@ class << self def ar left, right, pos = 0.0, level = 1.0 new :audio, 2, left, right, pos, level end - + def kr left, right, pos = 0.0, level = 1.0 new :control, 2, left, right, pos, level end named_args_for :ar, :kr end end - + class Rotate2 < Ugen include MultiOut - + class << self def ar x, y, pos = 0.0 new :audio, 2, x, y, pos end - + def kr x, y, pos = 0.0 new :control, 2, x, y, pos end end end - + class PanB < Ugen include MultiOut @@ -75,7 +75,7 @@ def kr input, azimuth = 0, elevation = 0, gain = 1 named_args_for :ar, :kr end end - + class PanB2 < Ugen include MultiOut @@ -90,7 +90,7 @@ def kr input, azimuth = 0, gain = 1 named_args_for :ar, :kr end end - + class BiPanB2 < Ugen include MultiOut @@ -104,7 +104,7 @@ def kr a, b, azimuth, gain = 1 end end end - + class DecodeB2 < Ugen include MultiOut @@ -118,7 +118,7 @@ def kr num_channels, w, x, y, orientation = 0.5 end end end - + class PanAz < Ugen include MultiOut diff --git a/lib/scruby/ugens/ugen.rb b/lib/scruby/ugens/ugen.rb index 380a233..87aedd5 100644 --- a/lib/scruby/ugens/ugen.rb +++ b/lib/scruby/ugens/ugen.rb @@ -4,7 +4,7 @@ module Ugens # # == Creation # - # Ugens are usually instantiated inside an "ugen graph" or the block passed when creating a SynthDef + # Ugens are usually instantiated inside an "ugen graph" or the block passed when creating a SynthDef # using either the ar, kr, ir or new methods wich will determine the rate. # * ar: audio rate # * kr: control rate @@ -13,7 +13,7 @@ module Ugens # # Not all the ugens provide all the rates # - # Two ugens inside an ugen graph: + # Two ugens inside an ugen graph: # SynthDef.new('simple'){ Out.ar(0, SinOsc.ar) } # # Out and SinOsc are both ugens # @@ -23,7 +23,7 @@ module Ugens # Usually when instantiating an ugen the arguments can be passed in order: # Pitch.kr(0, 220, 80, ...) # - # Or using a hash where the keys are symbols corresponding to the argument name. + # Or using a hash where the keys are symbols corresponding to the argument name. # Pitch.kr( :initFreq => 220, :execFreq => 300 ) # # Or a combination of both ways: @@ -44,7 +44,7 @@ module Ugens # end # named_arguments_for :ar # end - # + # # end # # For more info and limitations on named arguments check the gem: http://github.com/maca/arguments @@ -54,7 +54,7 @@ module Ugens # 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 VALID_INPUTS = Numeric, Array, Ugen, Env, ControlName @@ -68,18 +68,18 @@ def initialize rate, *inputs @channels ||= [1] @index = add_to_synthdef || 0 end - + # Instantiate a new MulAdd passing self and the multiplication and addition arguments def muladd mul, add MulAdd.new self, mul, add end def encode - self.class.to_s.split('::').last.encode + [ E_RATES.index(rate) ].pack('w') + - [ inputs.size, channels.size, special_index, collect_input_specs ].flatten.pack('n*') + + self.class.to_s.split('::').last.encode + [ E_RATES.index(rate) ].pack('w') + + [ inputs.size, channels.size, special_index, collect_input_specs ].flatten.pack('n*') + output_specs.pack('w*') end - + private def synthdef #:nodoc: @synthdef ||= Ugen.synthdef @@ -88,29 +88,29 @@ def synthdef #:nodoc: def add_to_synthdef #:nodoc: (synthdef.children << self).size - 1 if synthdef end - + def collect_constants #:nodoc: @inputs.send( :collect_constants ) end - + def input_specs synthdef #:nodoc: [index, output_index] end - + def collect_input_specs #:nodoc: @inputs.collect{ |i| i.send :input_specs, synthdef } end - + 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 + self.channels == other.channels end class << self @@ -126,7 +126,7 @@ def new rate, *inputs 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| @@ -154,7 +154,7 @@ def valid_input? obj else false end end - + def synthdef #:nodoc: @@synthdef end diff --git a/lib/scruby/ugens/ugen_operations.rb b/lib/scruby/ugens/ugen_operations.rb index 0c3f947..d5b5605 100644 --- a/lib/scruby/ugens/ugen_operations.rb +++ b/lib/scruby/ugens/ugen_operations.rb @@ -1,15 +1,15 @@ module Scruby module Ugens - # This module enables Ugen operations for Ugens, Numeric and Arrays, when any instance of this classes executes an operation with an Ugen a BinaryUgenOp + # This module enables Ugen operations for Ugens, Numeric and Arrays, when any instance of this classes executes an operation with an Ugen a BinaryUgenOp # is instantiated where both objects are the inputs of the operation, an UnaryUgenOp is instantiated for unary operations # This are the permited operations: # - # Binary: - # +, -, *, div, /, mod, <=, >=, minimum, maximum, lcm, gcd, round, roundUp, trunc, atan2, hypot, hypotApx, pow, leftShift, rightShift, unsignedRightShift, ring1, ring2, ring3, ring4, difsqr, sumsqr, sqrsum, sqrdif, absdif, thresh, amclip, scaleneg, clip2, excess, fold2, wrap2, rrand and exprand - # + # Binary: + # +, -, *, div, /, mod, <=, >=, minimum, maximum, lcm, gcd, round, roundUp, trunc, atan2, hypot, hypotApx, pow, leftShift, rightShift, unsignedRightShift, ring1, ring2, ring3, ring4, difsqr, sumsqr, sqrsum, sqrdif, absdif, thresh, amclip, scaleneg, clip2, excess, fold2, wrap2, rrand and exprand + # # Unary: - # neg, bitNot, abs, asFloat, ceil, floor, frac, sign, squared, cubed, sqrt, exp, reciprocal, midicps, cpsmidi, midiratio, ratiomidi, dbamp, ampdb, octcps, cpsoct, log, log2, log10, sin, cos, tam, asin, acos, atan, sinh, cosh, tanh, rand, rand2, linrand, bilinrand, sum3rand, distort, softclip, coin, rectWindow, hanWindow, welWindow, triWindow, ramp and scurve - # + # neg, bitNot, abs, asFloat, ceil, floor, frac, sign, squared, cubed, sqrt, exp, reciprocal, midicps, cpsmidi, midiratio, ratiomidi, dbamp, ampdb, octcps, cpsoct, log, log2, log10, sin, cos, tam, asin, acos, atan, sinh, cosh, tanh, rand, rand2, linrand, bilinrand, sum3rand, distort, softclip, coin, rectWindow, hanWindow, welWindow, triWindow, ramp and scurve + # module UgenOperations operation_indices = YAML::load File.open( File.dirname(__FILE__) + "/operation_indices.yaml" ) UNARY = operation_indices['unary'] @@ -18,7 +18,7 @@ module UgenOperations def self.included klass # Define unary operations - UNARY.each_key do |op| + UNARY.each_key do |op| define_method(op){ UnaryOpUGen.new op, self } unless klass.instance_methods.include? op end diff --git a/lib/scruby/ugens/ugens.rb b/lib/scruby/ugens/ugens.rb index b0a8214..9609bda 100644 --- a/lib/scruby/ugens/ugens.rb +++ b/lib/scruby/ugens/ugens.rb @@ -3,31 +3,31 @@ module Ugens # # Default SuperCollider Ugens definitions are stored in the ugen_defs.yml file and are defined as Ruby classes on the fly, the yml format is: - # - # NewUgen: - # :control: + # + # NewUgen: + # :control: # - - :input - # - + # - # - - :freq # - 440 - # :audio: + # :audio: # - - :input - # - + # - # - - :freq # - 440 # # To define a Ruby class corresponding to an Ugen +name+ should be passed and a hash of +rates+, inputs and default values, default values can be nil - # + # # Ugens.define_ugen( 'NewUgen', {:control => [[:input, nil], [:freq, 440]], :audio => [[:input, nil], [:freq, 440]]} ) # # The previous is equivalent as the following ruby code: - # + # # class NewUgen < Ugen # class << self # def kr( input, freq = 440 ) # new :control, input, freq # end - # + # # def ar( input, freq = 440) # new :audio, input, freq # end @@ -35,7 +35,7 @@ module Ugens # named_arguments_for :ar, :kr # end # end - # + # # In future versions Ugen definitions will be loaded from ~/Ugens or ~/.Ugens directories either as yml files or rb files # def self.define_ugen name, rates @@ -55,7 +55,7 @@ def new #{ args.collect{ |a, v| "#{ a } = #{ v.inspect }" }.join(', ') } assigns = [] args.each_with_index do |arg, index| key, val = arg - assigns << %{ + assigns << %{ #{ key } = opts[:#{ key }] || args[#{ index }] || #{ val } raise( ArgumentError.new("`#{ key }` value must be provided") ) unless #{ key } } @@ -88,7 +88,7 @@ class << self # # TODO: Load from ~/Ugens directory end - YAML::load( File.open( File.dirname(__FILE__) + "/ugen_defs.yaml" ) ).each_pair do |key, value| + YAML::load( File.open( File.dirname(__FILE__) + "/ugen_defs.yaml" ) ).each_pair do |key, value| self.define_ugen key, value end end diff --git a/spec/buffer_read_write_spec.rb b/spec/buffer_read_write_spec.rb index a285e32..974bcee 100644 --- a/spec/buffer_read_write_spec.rb +++ b/spec/buffer_read_write_spec.rb @@ -3,11 +3,11 @@ require "scruby/core_ext/delegator_array" require "scruby/control_name" require "scruby/env" -require "scruby/ugens/ugen" +require "scruby/ugens/ugen" require "scruby/ugens/ugen_operations" -require "scruby/ugens/operation_ugens" +require "scruby/ugens/operation_ugens" require "scruby/ugens/multi_out" -require "scruby/ugens/ugens" +require "scruby/ugens/ugens" require "scruby/ugens/buffer_read_write" include Scruby @@ -25,11 +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 @@ -259,7 +259,7 @@ class << self; public :new; end it "should require phase to be audio rate" end - + describe Tap, 'single input' do before do @inputs = 5, 1, 0, SampleRate.ir.neg * 3, 1, 0 @@ -278,14 +278,14 @@ class << self; public :new; end @buff_ugen.inputs.should == @inputs end end - + describe Tap, 'single input' do before do @inputs = 5, 1, 0, SampleRate.ir.neg * 3, 1, 0 @channels = 1 @proxies = Tap.ar( 5, @channels, 3 ) end - + it "should have one proxy" do @proxies.should have(@channels).proxy end @@ -302,14 +302,14 @@ class << self; public :new; end @proxies.each{ |p| p.source.inputs == @inputs } end end - + describe Tap, 'multi input' do before do @inputs = 5, 1, 0, SampleRate.ir.neg * 3, 1, 0 @channels = 4 @proxies = Tap.ar( 5, @channels, 3 ) end - + it "should have one proxy" do @proxies.should have(@channels).proxy end @@ -326,7 +326,7 @@ class << self; public :new; end @proxies.each{ |p| p.source.inputs == @inputs } end end - + #LocalBuf #MaxLocalBufs #ClearBuf diff --git a/spec/buffer_spec.rb b/spec/buffer_spec.rb index dbd1771..e3c1f8b 100644 --- a/spec/buffer_spec.rb +++ b/spec/buffer_spec.rb @@ -22,22 +22,22 @@ @server.send "/dumpOSC", 3 sleep 0.05 end - + after :all do @server.quit end - + describe 'Buffer.read' do before do @buffer = Buffer.read @server, "sounds/a11wlk01-44_1.aiff" sleep 0.005 end - + it "should instantiate and send /b_allocRead message" do @buffer.should be_a(Buffer) @server.output.should =~ %r{\[ "/b_allocRead", #{ @buffer.buffnum }, "/.+/Scruby/sounds/a11wlk01-44_1.aiff", 0, -1, DATA\[20\] \]} end - + it "should allow passing a completion message" end @@ -46,31 +46,31 @@ @buffer = Buffer.allocate @server, 44100 * 8.0, 2 sleep 0.005 end - + it "should call allocate and send /b_alloc message" do @buffer.should be_a(Buffer) @server.output.should =~ %r{\[ "/b_alloc", #{ @buffer.buffnum }, 352800, 2, 0 \]} @server.output.should =~ /69 00 00 00 00 00 00 00 00 44 ac 48 00 00 00 02/ end - + it "should allow passing a completion message" end - + describe 'Buffer.cueSoundFile' do before do @buffer = Buffer.cue_sound_file @server, "/sounds/a11wlk01-44_1.aiff", 0, 1 sleep 0.005 end - + it "should send /b_alloc message and instantiate" do @buffer.should be_a(Buffer) @server.output.should =~ %r{\[ "/b_alloc", #{ @buffer.buffnum }, 32768, 1, DATA\[72\] \]} @server.output.should =~ /6e 64 73 2f 61 31 31 77 6c 6b 30 31 2d 34 34 5f/ end - + it "should allow passing a completion message" end - + describe '#free' do before do @buffer = Buffer.allocate @server, 44100 * 10.0, 2 @@ -79,72 +79,72 @@ @buffer2.free sleep 0.005 end - + it "should remove itself from the server @buffers array and send free message" do @buffer2.buffnum.should be_nil @server.output.should =~ %r{\[ "/b_free", #{ @bnum }, 0 \]} end - + it "should allow passing a completion message" - + end - + describe 'Buffer.alloc_consecutive' do before do @buffers = Buffer.alloc_consecutive 8, @server, 4096, 2 sleep 0.005 end - + it "should send alloc message for each Buffer and instantiate" do @buffers.should have(8).buffers @buffers.each do |buff| @server.output.should =~ %r{\[ "/b_alloc", #{ buff.buffnum }, 4096, 2, 0 \]} end end - + it "should allow passing a message" end - + describe 'Buffer.read_channel' do before do @buffer = Buffer.read_channel @server, "sounds/SinedPink.aiff", :channels => [0] sleep 0.005 end - + it "should allocate and send /b_allocReadChannel message" do @buffer.should be_a(Buffer) @server.output.should =~ %r{\[ "/b_allocReadChannel", #{ @buffer.buffnum }, "/.+/Scruby/sounds/SinedPink.aiff", 0, -1, 0, DATA\[20\] \]} end end - + describe '#read' do before do @buffer = Buffer.allocate( @server, 44100 * 10.0, 2 ).read( "sounds/robot.aiff" ) sleep 0.005 end - + it "should send message" do @buffer.should be_a(Buffer) @server.output.should =~ %r{\[ "/b_read", #{ @buffer.buffnum }, "/.+/Scruby/sounds/robot.aiff", 0, -1, 0, 0, DATA\[20\] \]} end - + it "should allow passing a completion message" end - + describe '#close' do before do @buffer = Buffer.read( @server, "sounds/a11wlk01-44_1.aiff" ).close sleep 0.005 end - + it "should send message" do @buffer.should be_a(Buffer) @server.output.should =~ %r{\[ "/b_close", #{ @buffer.buffnum }, 0 \]} end - + it "should allow passing a completion message" end - + describe '#zero' do before do @buffer = Buffer.read( @server, "sounds/a11wlk01-44_1.aiff" ).zero @@ -164,15 +164,15 @@ @buffer = Buffer.allocate( @server, 44100, 2 ).cue_sound_file( "sounds/robot.aiff" ) sleep 0.005 end - + it "should send message" do @buffer.should be_a(Buffer) @server.output.should =~ %r{\[ "/b_read", #{ @buffer.buffnum }, "/.+/Scruby/sounds/robot.aiff", 0, 44100, 0, 1, 0 \]} end - + it "should allow passing a completion message" end - + describe '#write' do before do @buffer = Buffer.allocate( @server, 44100 * 10.0, 2 ).write( @@ -180,19 +180,19 @@ ); sleep 0.005 end - + it "should send message" do @buffer.should be_a(Buffer) @server.output.should =~ %r{\[ "/b_write", #{ @buffer.buffnum }, "/.+/Scruby/sounds/test.aiff", "aiff", "int16", 0, 0, 1, 0 \]} end - + it "should have a default path" do @server.flush buffer = Buffer.allocate( @server, 44100 * 10.0, 2 ).write( nil, "aiff", "int16", 0, 0, true ); sleep 0.005 @server.output.should =~ %r{\[ "/b_write", #{ buffer.buffnum }, "/.+/Scruby/\d\d\d\d.+\.aiff", "aiff", "int16", 0, 0, 1, 0 \]} end - + it "should allow passing a completion message" end end diff --git a/spec/bus_spec.rb b/spec/bus_spec.rb index 49e64a3..bef235e 100644 --- a/spec/bus_spec.rb +++ b/spec/bus_spec.rb @@ -17,33 +17,33 @@ @audio = Bus.audio @server @control = Bus.control @server end - + it "should be a bus" do @audio.should be_a(Bus) @control.should be_a(Bus) end - + it "should not instantiate with new" do lambda { Bus.new @server, :control, 1 }.should raise_error(NoMethodError) end - + it "should set server" do @audio.server.should == @server end - + it "should set audio rate" do @audio.rate.should == :audio end - + it "should set control rate" do Bus.control(@server).rate.should == :control end - + it "should allocate in server on instantiation and have index" do @server.audio_buses.should include(@audio) @server.control_buses.should include(@control) end - + it "should have index" do @audio.index.should == 16 @control.index.should == 0 @@ -57,47 +57,47 @@ @server.audio_buses.should_not include(@control) @control.index.should == nil end - + it "should return as map if control" do @control.to_map.should == "c0" end - + it "should raise error if calling to_map on an audio bus" do lambda { @audio.to_map }.should raise_error(SCError) end - + it "should print usefull information with to_s" - + it "should be hardware out" do @server.audio_buses[0].should be_audio_out @audio.should_not be_audio_out end - + describe 'multichannel' do before do @server = Server.new @audio = Bus.audio @server, 4 @control = Bus.control @server, 4 end - + it "should allocate consecutive when passing more than one channel for audio" do @audio.index.should == 16 buses = @server.audio_buses buses[16..-1].should have(4).elements Bus.audio(@server).index.should == 20 end - + it "should allocate consecutive when passing more than one channel for control" do @control.index.should == 0 @server.control_buses.should have(4).elements Bus.control(@server).index.should == 4 end - + it "should set the number of channels" do @audio.channels.should == 4 @control.channels.should == 4 end - + it "should depend on a main bus" do @server.audio_buses[16].main_bus.should == @audio #main bus @server.audio_buses[17].main_bus.should == @audio #main bus @@ -106,7 +106,7 @@ end end end - + describe "messaging" do before :all do @server = Server.new @@ -114,35 +114,35 @@ @server.send "/dumpOSC", 3 @bus = Bus.control @server, 4 sleep 0.05 - end + end after :all do @server.quit end - + before do @server.flush end - + describe 'set' do it "should send set message with one value" do @bus.set 101 sleep 0.01 @server.output.should =~ %r{\[ "/c_set", #{ @bus.index }, 101 \]} end - + it "should accept value list and send set with them" do @bus.set 101, 202 sleep 0.01 @server.output.should =~ %r{\[ "/c_set", #{ @bus.index }, 101, #{ @bus.index + 1}, 202 \]} end - + it "should accept an array and send set with them" do @bus.set [101, 202] sleep 0.01 @server.output.should =~ %r{\[ "/c_set", #{ @bus.index }, 101, #{ @bus.index + 1}, 202 \]} end - + it "should warn but not set if trying to set more values than channels" do @bus.should_receive(:warn).with("You tried to set 5 values for bus #{ @bus.index } that only has 4 channels, extra values are ignored.") @bus.set 101, 202, 303, 404, 505 @@ -150,20 +150,20 @@ @server.output.should =~ %r{\[ "/c_set", #{ @bus.index }, 101, #{ @bus.index + 1}, 202, #{ @bus.index + 2}, 303, #{ @bus.index + 3}, 404 \]} end end - + describe 'set' do it "should send fill just one channel" do @bus.fill 101, 1 sleep 0.01 @server.output.should =~ %r{\[ "/c_fill", #{ @bus.index }, 1, 101 \]} end - + it "should fill all channels" do @bus.fill 101 sleep 0.01 @server.output.should =~ %r{\[ "/c_fill", #{ @bus.index }, 4, 101 \]} end - + it "should raise error if trying to fill more than assigned channels" do @bus.should_receive(:warn).with("You tried to set 5 values for bus #{ @bus.index } that only has 4 channels, extra values are ignored.") @bus.fill 101, 5 @@ -171,7 +171,7 @@ @server.output.should =~ %r{\[ "/c_fill", #{ @bus.index }, 4, 101 \]} end end - + describe 'get' do it "should send get message with one value" it "should send get message for various channels" diff --git a/spec/core_ext/core_ext_spec.rb b/spec/core_ext/core_ext_spec.rb index 9a03006..1a751ad 100644 --- a/spec/core_ext/core_ext_spec.rb +++ b/spec/core_ext/core_ext_spec.rb @@ -9,50 +9,50 @@ @ugen = mock 'ugen' ::Ugen = mock 'Ugen', :new => @ugen end - + it "shoud have an scalar rate" do 1.rate.should == :scalar end - + it "should have an scalar rate" do 100.0.rate.should == :scalar end - + it "sum as usual" do - (100 + 100).should == 200 + (100 + 100).should == 200 end - + it "should #collect_constants" do 1.send( :collect_constants ).should == 1 1.5.send( :collect_constants ).should == 1.5 end - + it "should spec #input_specs" do synthdef = mock('synthdef', :constants => [200.0,1,3, 400.0] ) 200.0.send( :input_specs, synthdef ).should == [-1,0] 3.send( :input_specs, synthdef ).should == [-1,2] 400.0.send( :input_specs, synthdef ).should == [-1,3] end - - it "should spec encode" + + it "should spec encode" end describe Proc do describe "#arguments" do - + it do Proc.new{}.should respond_to( :arguments ) end - + it "should get empty array if proc has no args" do Proc.new{}.arguments.should eql( [] ) end - + it "should get one argument name" do Proc.new{ |arg| }.arguments.should eql( [ :arg ] ) end - + it "should get arg names with several args" do Proc.new{ |arg, arg2, arg3| }.arguments.should eql( [ :arg, :arg2, :arg3 ] ) end @@ -64,42 +64,42 @@ it do [].should respond_to( :collect_with_index ) end - + it "should return an array the same size as the original" do [1,2,3,4].collect_with_index{ nil }.should have( 4 ).items end - + it "should collect_with_index" do array = %w(a, b, c, d) array.collect_with_index{ |element, index| [index, element] }.should eql( [0,1,2,3].zip( array ) ) end - + it "should wrap and zip" do [:a,:b,:c].wrap_and_zip([1]).flatten.should == [:a,1,:b,1,:c,1] [0.5, 0.5].wrap_and_zip([3],[5]).flatten.should == [0.5,3,5,0.5,3,5] [0.01, 1.0].wrap_and_zip([-4.0],[5]).flatten.should == [0.01, -4.0, 5, 1.0, -4.0, 5] end end - + describe "#wrap_to" do it do Array.new.should respond_to( :wrap_to ) end - + it "should wrap_to!" do [1,2].wrap_to!(4).should == [1,2,1,2] end - + it do Array.new.should respond_to( :wrap_to ) end - + it "should return self if the passed size is the same as self.size" do a = [1,2,3,4] a.wrap_to( 4 ).should == a end end - + it "should sum with Ugen" it "should collect constants" end @@ -108,12 +108,12 @@ it "should encode" do "SinOsc".encode.should == [6, 83, 105, 110, 79, 115, 99].pack('C*') end - + it "should encode large strings" do 'set arguments cn.argNum << this is the size of controlNames when controlName was added'.encode.should == [86, 115, 101, 116, 32, 97, 114, 103, 117, 109, 101, 110, 116, 115, 32, 99, 110, 46, 97, 114, 103, 78, 117, 109, 32, 60, 60, 32, 116, 104, 105, 115, 32, 105, 115, 32, 116, 104, 101, 32, 115, 105, 122, 101, 32, 111, 102, 32, 99, 111, 110, 116, 114, 111, 108, 78, 97, 109, 101, 115, 32, 119, 104, 101, 110, 32, 99, 111, 110, 116, 114, 111, 108, 78, 97, 109, 101, 32, 119, 97, 115, 32, 97, 100, 100, 101, 100].pack('C*') end - + end diff --git a/spec/core_ext/delegator_array_spec.rb b/spec/core_ext/delegator_array_spec.rb index ce85b38..db0f63e 100644 --- a/spec/core_ext/delegator_array_spec.rb +++ b/spec/core_ext/delegator_array_spec.rb @@ -22,7 +22,7 @@ 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 @@ -34,67 +34,67 @@ class ControlName; end class Env; end describe DelegatorArray do - + it "should have 'literal' notation" do d(1,2).should == [1,2] d(1,2).should be_instance_of(DelegatorArray) d([1,2]).should == d(1,2) end - + it "should allow nil" do 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 } @array_op = eval %{ d(1,2) #{ @op } d(1.0, 2.0) } @asim_array_op1 = eval %{ d(1,2,3) #{ @op } d(1.0, 2.0) } end - + it "should do operation" do @numeric_op.should == @numeric_op @numeric_op.should be_a(DelegatorArray) end - + it "should do operation with array of the same size" do @array_op.should == @array_result @array_op.should be_a(DelegatorArray) end - + it "should do operation with array of diferent size (left bigger)" do @asim_array_op1.should == @asim_result1 @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 actual = eval %{ d(1,2,3) #{ @op } MockUgen.new(:audio, 2)} expected = BinaryOpUGen.new(@op.to_sym, [1,2,3], MockUgen.new(:audio, 2) ) @@ -105,7 +105,7 @@ class Env; end eval %{ SinOsc.ar([100, [100, 100]]) #{@op} SinOsc.ar } end end - + describe "should override sum" do before do @op = '+' @@ -114,7 +114,7 @@ class Env; end end it_should_behave_like 'aritmetic operand' end - + describe "should override subs" do before do @op = '-' @@ -122,7 +122,7 @@ class Env; end @asim_result1 = d(1-1.0, 2-2.0, 3) end end - + describe "should override mult" do before do @op = '*' @@ -131,7 +131,7 @@ class Env; end end it_should_behave_like 'aritmetic operand' end - + describe "should override div" do before do @op = '/' diff --git a/spec/core_ext/typed_array_spec.rb b/spec/core_ext/typed_array_spec.rb index 431ee92..6659fa8 100644 --- a/spec/core_ext/typed_array_spec.rb +++ b/spec/core_ext/typed_array_spec.rb @@ -1,38 +1,38 @@ require File.expand_path(File.dirname(__FILE__)) + "/../helper" -require "scruby/core_ext/typed_array" +require "scruby/core_ext/typed_array" class Type end describe TypedArray do - + before do @t1 = Type.new @t2 = Type.new end - + it "should initialize with attributes" do objs = (0..3).map{ Type.new } ta = TypedArray.new( Type, objs ) ta.type.should == Type ta.should == objs end - + it "should instantiate with an array" do objs = (0..3).map{ Type.new } ta = TypedArray.new( Type, objs ) ta.should == objs end - + it "set type by instance" do ta = TypedArray.new( Type.new ) ta.type.should == Type end - + it "should raise error if wrong type" do lambda{ TypedArray.new(Type, 1) }.should raise_error(TypeError) end - + it "+ success" do ta = TypedArray.new( Type ) o = Type.new @@ -40,51 +40,51 @@ class Type # sum.should be_instance_of(TypedArray) sum.should == [o] end - + it "+ failure" do lambda{ TypedArray.new(Type, Type.new) + [1] }.should raise_error(TypeError) end - + it "concat success" do ta = TypedArray.new( Type, [@t1] ) ta.concat( [@t2] ).should == ta ta.should == [@t1,@t2] end - + it "concat failure" do lambda{ TypedArray.new(Type, Type.new).concat( 1 ) }.should raise_error(TypeError) lambda{ TypedArray.new(Type, Type.new).concat( [1] ) }.should raise_error(TypeError) end - + it "<< success" do ta = TypedArray.new(Type) << @t1 ta.should == [@t1] end - + it "<< failure" do lambda{ TypedArray.new(Type, Type.new) << [1] }.should raise_error(TypeError) end - + it "[]= success" do ta = TypedArray.new(Type) ta[0]= @t1 ta[0].should == @t1 end - + it "[]= failure" do lambda{ TypedArray.new(Type, Type.new)[0]= 1 }.should raise_error(TypeError) end - + it "push success" do ta = TypedArray.new(Type) ta.push( @t1 ) ta.should == [@t1] end - + it "push failure" do lambda{ TypedArray.new(Type, Type.new).push(1) }.should raise_error(TypeError) end - + it "should convert to array" do ta = TypedArray.new(Type) ta.to_a.should be_instance_of(Array) diff --git a/spec/demand_spec.rb b/spec/demand_spec.rb index e35a3e3..da8106d 100644 --- a/spec/demand_spec.rb +++ b/spec/demand_spec.rb @@ -3,10 +3,10 @@ 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/ugen" +require "scruby/ugens/ugen_operations" require "scruby/ugens/multi_out" -require "scruby/ugens/ugens" +require "scruby/ugens/ugens" require "scruby/ugens/demand" include Scruby @@ -22,44 +22,44 @@ class << self; public :new; end @prox = @splatted ? Demand.send( @method, *@ugens) : Demand.send( @method, @ugens) @instance = @splatted ? @prox.source : @prox.first.source end - + it "should output proxies or single proxie" do @splatted ? @prox.each{ |prox| prox.should be_a(OutputProxy) } : @prox.should( be_a(OutputProxy) ) end end - + shared_examples_for 'Demand with ar' do before do @method = :ar end it_should_behave_like 'Demand Ugen' end - + shared_examples_for 'Demand with kr' do before do @method = :ar end it_should_behave_like 'Demand Ugen' end - - + + describe 'Single channel splatted input' do before do @channels = 1 @ugens = [MockUgen.new(:audio, 1, 2)] * 4 @splatted = true end - + end - + describe "Single channel array input" do before do @channels = 1 @ugens = [MockUgen.new(:audio, 1, 2)] * 4 @splatted = false end - + end # describe "Two channel splatted input" do @@ -67,15 +67,15 @@ class << self; public :new; end # @channels = 2 # @splatted = false # end - # + # # end - # + # # describe "Two channel array input" do # before do # @channels = 2 # @splatted = false # end - # + # # end end diff --git a/spec/disk_in_out_spec.rb b/spec/disk_in_out_spec.rb index d98139d..ca3650d 100644 --- a/spec/disk_in_out_spec.rb +++ b/spec/disk_in_out_spec.rb @@ -5,11 +5,11 @@ require "scruby/control_name" require "scruby/env" require "scruby/synthdef" -require "scruby/ugens/ugen" +require "scruby/ugens/ugen" require "scruby/ugens/ugen_operations" -require "scruby/ugens/operation_ugens" +require "scruby/ugens/operation_ugens" require "scruby/ugens/multi_out" -require "scruby/ugens/ugens" +require "scruby/ugens/ugens" require "scruby/ugens/disk_in_out" include Scruby @@ -89,7 +89,7 @@ class << self; public :new; end it "should set inputs" do @instance.inputs.should == @inputs end - + it "should encode" do @sdef.encode.should == @expected.pack('C*') end @@ -114,7 +114,7 @@ class << self; public :new; end end it_should_behave_like 'DiskIn' end - + describe VDiskIn, 'single channel' do before do @channels = 1 diff --git a/spec/env_gen_spec.rb b/spec/env_gen_spec.rb index 55e08a1..b1fa522 100644 --- a/spec/env_gen_spec.rb +++ b/spec/env_gen_spec.rb @@ -7,14 +7,14 @@ require "scruby/ugens/env_gen" include Scruby -include Ugens +include Ugens describe EnvGen do - + it "should not instantiate with #new" do lambda { EnvGen.new :audio, 1, 2 }.should raise_error end - + it "should have correct inputs" do envgen = EnvGen.kr Env.adsr envgen.rate.should == :control diff --git a/spec/env_spec.rb b/spec/env_spec.rb index e3a529b..017acb1 100644 --- a/spec/env_spec.rb +++ b/spec/env_spec.rb @@ -9,7 +9,7 @@ class ControlName; end include Scruby -describe Env do +describe Env do it "Env.new [0,1,0], [0.5, 1]" do env = Env.new [0,1,0], [0.5, 1] env.times.should == [0.5, 1] @@ -17,7 +17,7 @@ class ControlName; end env.shape_numbers.should == [1] env.curve_values.should == [0] end - + it do env = Env.new [0,1,0], [0.5, 1] env.to_array.collect{ |i| i.to_f }.should == [ 0, 2, -99, -99, 1, 0.5, 1, 0, 0, 1, 1, 0 ].collect{ |i| i.to_f } @@ -56,18 +56,18 @@ class ControlName; end env = Env.dadsr env.to_array.collect{ |i| i.to_f }.should == [ 0, 4, 3, -99, 0, 0.1, 5, -4, 1, 0.01, 5, -4, 0.5, 0.3, 5, -4, 0, 1, 5, -4 ].collect{ |i| i.to_f } end - + it "#dadsr" do env = Env.adsr env.to_array.collect{ |i| i.to_f }.should == [ 0, 3, 2, -99, 1, 0.01, 5, -4, 0.5, 0.3, 5, -4, 0, 1, 5, -4 ].collect{ |i| i.to_f } end - + describe 'Overriding defaults' do - + it "#asr" do Env.asr(2, 1, 2).to_array.should == [ 0, 2, 1, -99, 1, 2, 5, -4, 0, 2, 5, -4 ] end - + end - + end \ No newline at end of file diff --git a/spec/group_spec.rb b/spec/group_spec.rb index 58a1c84..2f9c842 100644 --- a/spec/group_spec.rb +++ b/spec/group_spec.rb @@ -1,7 +1,7 @@ require File.expand_path(File.dirname(__FILE__)) + "/helper" -require "scruby/core_ext/typed_array" +require "scruby/core_ext/typed_array" require "scruby/node" require "scruby/group" require 'scruby/bus' @@ -13,15 +13,15 @@ include Scruby class Bus; end # mock -describe Group do +describe Group do before :all do end - + before do Node.reset! Server.stub!(:all).and_return([@server]) end - + describe 'Server interaction' do before :all do @server = Server.new @@ -29,32 +29,32 @@ class Bus; end # mock @server.send "/dumpOSC", 3 sleep 0.05 end - + after :all do @server.quit end - + before do @server.flush @group = Group.new @server @node = Node.new @server end - + describe 'position' do end - + it "should send free all message" do @group.free_all.should be_a(Group) sleep 0.05 @server.output.should =~ %r{\[ "/g_freeAll", #{ @group.id } \]} end - + it "should send deepFree message" do @group.deep_free.should be_a(Group) sleep 0.05 @server.output.should =~ %r{\[ "/g_deepFree", #{ @group.id } \]} end - + it "should send dump tree message" do @group.dump_tree.should be_a(Group) sleep 0.05 @@ -63,9 +63,9 @@ class Bus; end # mock sleep 0.05 @server.output.should =~ %r{\[ "/g_dumpTree", #{ @group.id }, 1 \]} end - + it "should send dump tree message with arg" it "should query_tree" end - + end \ No newline at end of file diff --git a/spec/helper.rb b/spec/helper.rb index 5abefe3..cd4ad2f 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -1,10 +1,10 @@ -require "rubygems" -require "rspec" +require "rubygems" +require "rspec" require 'arguments' require 'yaml' require 'ruby-osc' -$:.unshift( File.dirname(__FILE__) + '/../lib' ) +$:.unshift( File.dirname(__FILE__) + '/../lib' ) require "scruby/core_ext/object" require "scruby/core_ext/array" diff --git a/spec/in_out_spec.rb b/spec/in_out_spec.rb index f0f3b43..67b65ca 100644 --- a/spec/in_out_spec.rb +++ b/spec/in_out_spec.rb @@ -39,7 +39,7 @@ class << self; public :new; end In.should respond_to(:ar) end - it "should spec #ar" do + it "should spec #ar" do @ar.should be_instance_of( DelegatorArray ) @ar.should have(1).proxy @ar.first.should == @proxy @@ -63,7 +63,7 @@ class << self; public :new; end before do @sdef = mock 'sdef', :children => [], :constants => [400, 0] Ugen.should_receive( :synthdef ).at_least( :once ).and_return @sdef - end + end it "should accept one ugen" do @ugen1 = MockUgen.new :audio @@ -98,7 +98,7 @@ class << self; public :new; end out = @sdef.children.last out.inputs.should == [1, @ugen1, @ugen2, @ugen3] - end + end it "should validate rate" it "should substitute zero with silence" diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 371bc05..a029200 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -31,13 +31,13 @@ it "should encode with out" do sdef = SynthDef.new(:out){ Out.ar(0, SinOsc.ar) } sdef.children.should have(2).children - + sdef.children[0].should be_instance_of( SinOsc ) - sdef.children[1].should be_instance_of( Out ) - + sdef.children[1].should be_instance_of( Out ) + sdef.constants.should == [ 440, 0 ] sdef.children[1].channels.should == [] - + expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 3, 111, 117, 116, 0, 2, 67, -36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 3, 79, 117, 116, 2, 0, 2, 0, 0, 0, 0, -1, -1, 0, 1, 0, 0, 0, 0, 0, 0 ].pack('C*') sdef.encode.should == expected end @@ -46,18 +46,18 @@ sdef = SynthDef.new(:out){ sig = SinOsc.ar(100, 200) * SinOsc.ar(200); Out.ar(0, sig) } sdef.encode.should == [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 3, 111, 117, 116, 0, 3, 66, -56, 0, 0, 67, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 1, -1, -1, 0, 2, 2, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 2, 3, 79, 117, 116, 2, 0, 2, 0, 0, 0, 0, -1, -1, 0, 2, 0, 2, 0, 0, 0, 0 ].pack('C*') end - + it "should encode out with two channels" do sdef = SynthDef.new( :out ){ sig = SinOsc.ar(100, [200, 200]) * SinOsc.ar(200); Out.ar(0, sig) } expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 3, 111, 117, 116, 0, 3, 66, -56, 0, 0, 67, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 1, -1, -1, 0, 2, 2, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 2, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 1, 0, 0, 0, 2, 0, 0, 2, 3, 79, 117, 116, 2, 0, 3, 0, 0, 0, 0, -1, -1, 0, 2, 0, 3, 0, 0, 0, 4, 0, 0, 0, 0 ].pack('C*') sdef.encode.should == expected end - + it "should instantiate and encode" do expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 4, 104, 101, 108, 112, 0, 2, 67, -36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 2, 0, 0, 0, 3, 0, 0, 2, 0, 0 ].pack('C*') SynthDef.new( :help ){ (SinOsc.ar() + SinOsc.ar()) * SinOsc.ar() }.encode.should == expected end - + it "should encode out with multidimensional array" do sdef = SynthDef.new( :out ){ sig = SinOsc.ar(100, [200,[100, 100]]) * SinOsc.ar(200); Out.ar(0, sig) } children = sdef.children @@ -70,7 +70,7 @@ #the order of the elements is different than in supercollider, but at least has the encoded string is the same size so i guess its fine sdef.encode.should have(261).chars end - + it "should encode 'complex' sdef" do sdef = SynthDef.new :am do |gate, portadora, moduladora, amp| mod = SinOsc.kr moduladora, 0, 0.5, 0.5 diff --git a/spec/multiout_ugen_spec.rb b/spec/multiout_ugen_spec.rb index e2d3116..cea39a1 100644 --- a/spec/multiout_ugen_spec.rb +++ b/spec/multiout_ugen_spec.rb @@ -3,8 +3,8 @@ 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/ugen" +require "scruby/ugens/ugen_operations" require "scruby/ugens/multi_out" include Scruby @@ -27,7 +27,7 @@ class << self @names = Array.new( rand(7) + 3 ) do |i| ControlName.new "control_#{i}", 1, :control, i end - + @proxies = Control.new( :audio, *@names ) @control = sdef.children.first end @@ -46,20 +46,20 @@ class << self Ugen.should_receive( :synthdef ) Control.new( :audio, []) end - + it "should instantiate with #and_proxies_from" do Control.should_receive(:new).with( :control, *@names ) Control.and_proxies_from( @names ) end - + it "should have index" do @control.index.should == 0 end - + end describe OutputProxy do - + before do @sdef = mock( 'sdef', :children => [] ) Ugen.stub!( :synthdef ).and_return( @sdef ) @@ -67,16 +67,16 @@ class << self @names = [@name] @output_index = 1 end - + it "should receive index from control" do Control.and_proxies_from( @names ).first.index.should == 0 @sdef.children.first.index.should == 0 end - + it "should have empty inputs" do OutputProxy.new( :audio, @name, @output_index, @name ).inputs.should == [] end - + it "should not be added to synthdef" do Ugen.should_not_receive( :synthdef ) OutputProxy.new( :audio, @name, @output_index, @name ) diff --git a/spec/node_spec.rb b/spec/node_spec.rb index 30e74e5..454459e 100644 --- a/spec/node_spec.rb +++ b/spec/node_spec.rb @@ -1,6 +1,6 @@ require File.expand_path(File.dirname(__FILE__)) + "/helper" -require "scruby/core_ext/typed_array" +require "scruby/core_ext/typed_array" require "scruby/node" require "scruby/bus" @@ -9,43 +9,43 @@ include Scruby -describe Node do +describe Node do before :all do @server = Server.new end - + before do Node.reset! Server.stub!(:all).and_return([@server]) end - + it "should have incremental uniq id" do 10.times do |i| Node.new.id.should == 2001 + i - end + end end - + it "should reset" do Node.new.id.should == 2001 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 n = Node.new @server n.servers.should == [@server] end - + it "should have default servers if no server is passed" do n = Node.new n.servers.should == [@server] end end - + describe 'Server interaction' do before :all do @server = Server.new @@ -53,15 +53,15 @@ @server.send "/dumpOSC", 3 sleep 0.05 end - + after :all do @server.quit end - + before do @node = Node.new @server end - + it "should send free" do @node.free @node.should_not be_running @@ -70,7 +70,7 @@ sleep 0.05 @server.output.should =~ %r{\[ "/n_free", #{ @node.id } \]} end - + it "should send run" do @node.run sleep 0.05 @@ -79,7 +79,7 @@ sleep 0.05 @server.output.should =~ %r{\[ "/n_run", #{ @node.id }, 0 \]} end - + it "should send run" do @node.run sleep 0.05 @@ -88,14 +88,14 @@ 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 b1.should_receive(:kind_of?).and_return(false) lambda { @node.map :freq1 => b1 }.should raise_error(ArgumentError) end - + it "should send map" do b1 = mock 'Bus', :index => 1, :channels => 1, :rate => :control b1.should_receive(:kind_of?).and_return(true) @@ -106,7 +106,7 @@ @server.output.should =~ %r{\[ \"#bundle\", 1, \n \[ \"/n_mapn\", #{ @node.id }, \"freq1\", #{ b1.index }, 1 \],\n \[ \"/n_mapan\", #{ @node.id }, \"freq2\", #{ b2.index }, 2 \]\n\]} end end - + end - + end \ No newline at end of file diff --git a/spec/operation_ugens_spec.rb b/spec/operation_ugens_spec.rb index f7bacec..c137936 100644 --- a/spec/operation_ugens_spec.rb +++ b/spec/operation_ugens_spec.rb @@ -4,7 +4,7 @@ require "scruby/control_name" require "scruby/env" require "scruby/ugens/ugen" -require "scruby/ugens/ugen_operations" +require "scruby/ugens/ugen_operations" require "scruby/ugens/operation_ugens" require "scruby/core_ext/delegator_array" @@ -17,69 +17,69 @@ class << self; public :new; end describe UnaryOpUGen do ::RATES = :scalar, :demand, :control, :audio - + before do @scalar = MockUgen.new :scalar @demand = MockUgen.new :demand @control = MockUgen.new :control @audio = MockUgen.new :audio end - + describe UnaryOpUGen do - + before do @op = UnaryOpUGen.new( :neg, @audio ) end - + it "should return special index" do UnaryOpUGen.new( :neg, @audio ).special_index.should == 0 UnaryOpUGen.new( :bitNot, @audio ).special_index.should == 4 UnaryOpUGen.new( :abs, @audio ).special_index.should == 5 UnaryOpUGen.new( :asFloat, @audio ).special_index.should == 6 end - + it "should accept just one input" do lambda{ UnaryOpUGen.new(:neg, @audio, @demand) }.should raise_error( ArgumentError ) end - + it "should just accept defined operators" # do # lambda{ UnaryOpUGen.new(:not_operator, @audio) }.should raise_error( ArgumentError ) # end - + it "should get max rate" do UnaryOpUGen.send(:get_rate, @scalar, @demand ).should == :demand UnaryOpUGen.send(:get_rate, @scalar, @demand, @audio ).should == :audio UnaryOpUGen.send(:get_rate, @scalar, [@demand, [@control, @audio]] ).should == :audio end - + it do UnaryOpUGen.new(:neg, @audio).should be_instance_of(UnaryOpUGen) end - + it "should set rate" do UnaryOpUGen.new(:neg, @audio).rate.should == :audio UnaryOpUGen.new(:neg, @scalar).rate.should == :scalar end - + it "should set operator" do UnaryOpUGen.new(:neg, @audio).operator.should == :neg - end + end end - + describe BinaryOpUGen do - + before do @arg_array = [@audio, [@scalar, @audio, [@demand, [@control, @demand]]] ] @op_arr = BinaryOpUGen.new(:+, @audio, @arg_array ) end - + it "should return special index" do BinaryOpUGen.new( :+, @audio, @audio ).special_index.should == 0 BinaryOpUGen.new( :-, @audio, @audio ).special_index.should == 1 BinaryOpUGen.new( :*, @audio, @audio ).special_index.should == 2 BinaryOpUGen.new( :/, @audio, @audio ).special_index.should == 4 end - + it "should accept exactly two inputs" do lambda{ BinaryOpUGen.new(:+, @audio) }.should raise_error( ArgumentError ) lambda{ BinaryOpUGen.new(:+, @audio, @demand, @demand) }.should raise_error( ArgumentError ) @@ -91,64 +91,64 @@ class << self; public :new; end arr.operator.should == :+ arr.rate.should == :audio end - + it "should accept array as input" do BinaryOpUGen.new(:+, @audio, [@audio, @scalar] ).should be_instance_of(DelegatorArray) end - + it "should return an array of UnaryOpUGens" do @op_arr.flatten.map { |op| op.should be_instance_of(BinaryOpUGen) } end - + it "should set rate for all operations" do @op_arr.flatten.map { |op| op.rate.should eql(:audio) } end - + it "should set operator for all operations" do @op_arr.flatten.map { |op| op.operator.should eql(:+) } end - + it "should set correct inputs when provided an array" do arr = BinaryOpUGen.new(:+, @control, [@audio, @scalar] ) arr.first.inputs.should == [@control, @audio] arr.last.inputs.should == [@control, @scalar] end - + it "should create the correct number of operations" do @op_arr.flatten.size.should eql( @arg_array.flatten.size ) end - + it "should replicate the array passed" do - last = lambda do |i| - if i.instance_of?( BinaryOpUGen) + last = lambda do |i| + if i.instance_of?( BinaryOpUGen) i.inputs.first.should == @audio - i.inputs.last - else - i.map{ |e| last.call(e) } + i.inputs.last + else + i.map{ |e| last.call(e) } end end last.call(@op_arr).should == @arg_array end - + it "should accept numbers as inputs" do arr = BinaryOpUGen.new(:+, @control, [100, 200.0] ) arr.first.inputs.should == [@control, 100] arr.last.inputs.should == [@control, 200.0] BinaryOpUGen.new(:+, 100, @control ).inputs.should == [100, @control] end - + it "should accept array as input" do arr = BinaryOpUGen.new(:+, [@audio, @scalar], @control ) arr.first.inputs.should == [@audio, @control] arr.last.inputs.should == [@scalar, @control] end - + it "should accept numeric arg as first arg" do arr = BinaryOpUGen.new(:+, 1, @control ) arr.inputs.should == [1, @control] end end - + describe MulAdd do it do MulAdd.new( @audio, 0.5, 0.5 ).should be_instance_of(MulAdd) @@ -157,22 +157,22 @@ class << self; public :new; end it do MulAdd.new( @audio, 0.5, 0.5 ).rate.should == :audio end - + 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' minus = mock 'minus' plus = mock 'plus' - + @audio.should_receive( :neg ).and_return( unary_op ) @audio.should_receive( :* ).and_return( mult ) add = mock( '0.5', :- => minus, :zero? => false ) @audio.should_receive( :+ ).and_return( plus ) - + MulAdd.new( @audio, 0, 0.5 ).should be_instance_of( Float ) MulAdd.new( @audio, 1, 0 ).should == @audio MulAdd.new( @audio, -1, 0 ).should == unary_op @@ -180,17 +180,17 @@ class << self; public :new; end MulAdd.new( @audio, -1, add ).should == minus MulAdd.new( @audio, 1, 0.5 ).should == plus end - + it "should accept ugens" do MulAdd.new( @audio, @audio, 1 ).should be_instance_of(MulAdd) MulAdd.new( @audio, @audio, @scalar ).should be_instance_of(MulAdd) - + bin_op_ugen = mock 'binary op ugen' @audio.stub!( :* ).and_return bin_op_ugen MulAdd.new( @audio, @audio, 0 ).should == bin_op_ugen end - + end - + end diff --git a/spec/panner_spec.rb b/spec/panner_spec.rb index 26d030e..81505ab 100644 --- a/spec/panner_spec.rb +++ b/spec/panner_spec.rb @@ -3,10 +3,10 @@ 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/ugen" +require "scruby/ugens/ugen_operations" require "scruby/ugens/multi_out" -require "scruby/ugens/ugens" +require "scruby/ugens/ugens" require "scruby/ugens/panner" include Scruby @@ -23,11 +23,11 @@ class << self; public :new; end @inputs ||= @params @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 @@ -48,7 +48,7 @@ class << self; public :new; end it "should accept control rate inputs unless rate is audio" end - + shared_examples_for 'Panner with control rate' do before do @method = :kr @@ -56,33 +56,33 @@ class << self; public :new; end end it_should_behave_like 'Panner' end - + shared_examples_for 'Panner with audio rate' do before do @method = :ar @rate = :audio end it_should_behave_like 'Panner' - + it "should just accept audio inputs if rate is audio" # do # lambda { @class.new( :audio, MockUgen.new(:control) ) }.should raise_error(ArgumentError) # 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 @@ -91,7 +91,7 @@ class << self; public :new; end end it_should_behave_like 'Panner with array as input' end - + describe "four ugens as input" do before do @params[0] = @ugens = [@ugen] * 4 @@ -101,7 +101,7 @@ class << self; public :new; end it_should_behave_like 'Panner with array as input' end end - + describe Pan2 do before do @class = Pan2 @@ -112,7 +112,7 @@ class << self; public :new; 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] @@ -144,7 +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_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] @@ -179,7 +179,7 @@ class << self; public :new; 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 @@ -195,7 +195,7 @@ class << self; public :new; 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 @@ -228,12 +228,12 @@ class << self; public :new; 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 end - + describe DecodeB2, 'five channels' do before do @class = DecodeB2 @@ -243,9 +243,9 @@ 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 before do @class = DecodeB2 diff --git a/spec/server.rb b/spec/server.rb index 4d8259f..aa59b1d 100644 --- a/spec/server.rb +++ b/spec/server.rb @@ -5,7 +5,7 @@ def puts string @output << string string end - + def flush @output = '' end diff --git a/spec/server_spec.rb b/spec/server_spec.rb index 6e5ae0e..6f260ec 100644 --- a/spec/server_spec.rb +++ b/spec/server_spec.rb @@ -19,13 +19,13 @@ class Buffer; end class Scruby::Server attr_reader :output - + def puts string @output ||= "" @output << string string end - + def flush @output = '' end @@ -45,7 +45,7 @@ def == other end describe Server do - + describe "booting" do before do @server = Server.new @@ -64,7 +64,7 @@ def == other Thread.should_not_receive(:new) @server.boot end - + it "should remove server from server list" do @server.boot @server.quit @@ -88,28 +88,28 @@ def == other @server.send "/dumpOSC", 3 sleep 0.05 end - + after :all do @server.quit end - + before do @server.flush end - + it "should send dump" do @server.send "/dumpOSC", 1 sleep 0.1 @server.output.should =~ %r{/dumpOSC} end - + it "should send synthdef" do sdef = mock 'sdef', :encode => [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 4, 104, 111, 108, 97, 0, 2, 67, -36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 0, 0 ].pack('C*') @server.send_synth_def sdef sleep 0.1 @server.output.should =~ %r{\[ "#bundle", 1, \n\s*\[ "/d_recv", DATA\[56\], 0 \]\n\]} end - + it "should send synthdef2" do sdef = mock 'sdef', :encode => [83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 3, 114, 101, 99, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 6, 98, 117, 102, 110, 117, 109, 0, 0, 0, 3, 7, 67, 111, 110, 116, 114, 111, 108, 1, 0, 0, 0, 1, 0, 0, 1, 2, 73, 110, 2, 0, 1, 0, 2, 0, 0, 255, 255, 0, 0, 2, 2, 7, 68, 105, 115, 107, 79, 117, 116, 2, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0].pack('C*') @server.send_synth_def sdef @@ -117,7 +117,7 @@ def == other @server.output.should =~ %r{\[ "#bundle", 1, \n\s*\[ "/d_recv", DATA\[100\], 0 \]\n\]} end end - + shared_examples_for 'allocator' do it "should allow less than @max_size elements" do @server.__send__( :allocate, @kind, (1..@allowed_elements).map{ @class.new } ) @@ -127,39 +127,39 @@ def == other it "should not allow more than @max_size elements" do lambda { @server.__send__( :allocate, @kind, (1..@max_size+1).map{ @class.new } ) }.should raise_error(SCError) end - + it "should try to allocate lowest nil slot" do @server.__send__(@kind).concat([nil, nil, @class.new, nil, nil, nil, @class.new]) @server.__send__ :allocate, @kind, buffer = @class.new @server.__send__(@kind).index(buffer).should == @index_start end - + it "should allocate various elements in available contiguous indices" do @server.__send__(@kind).concat([nil, nil, @class.new, nil, nil, nil, @class.new]) @server.__send__ :allocate, @kind, @class.new, @class.new, @class.new elements = @server.__send__(@kind)[@max_size-@allowed_elements..-1].compact elements.should have(5).elements end - + it "should allocate by appending various elements" do @server.__send__(@kind).concat([nil, nil, @class.new, nil, nil, nil, @class.new]) @server.__send__ :allocate, @kind, @class.new, @class.new, @class.new, @class.new elements = @server.__send__(@kind)[@max_size-@allowed_elements..-1].compact elements.should have(6).elements end - + it "should not surpass the max buffer limit" do @server.__send__( :allocate, @kind, (1..@allowed_elements-2).map{ |i| @class.new if i % 2 == 0 } ) lambda { @server.__send__ :allocate, @kind, @class.new, @class.new, @class.new }.should raise_error end - + it "should allocate by appending" do @server.__send__( :allocate, @kind, (1..@allowed_elements-3).map{ |i| @class.new if i % 2 == 0 } ) @server.__send__ :allocate, @kind, @class.new, @class.new, @class.new @server.__send__(@kind).size.should == @max_size end end - + describe 'buffers allocation' do before do @server = Server.new @@ -170,7 +170,7 @@ def == other end it_should_behave_like 'allocator' end - + describe 'control_buses allocation' do before do @server = Server.new @@ -181,7 +181,7 @@ def == other end it_should_behave_like 'allocator' end - + describe 'audio_buses allocation' do before do @server = Server.new @@ -193,6 +193,6 @@ def == other end it_should_behave_like 'allocator' end - -end + +end diff --git a/spec/synth_spec.rb b/spec/synth_spec.rb index 7a7c37c..ff175a1 100644 --- a/spec/synth_spec.rb +++ b/spec/synth_spec.rb @@ -1,7 +1,7 @@ require File.expand_path(File.dirname(__FILE__)) + "/helper" -require "scruby/core_ext/typed_array" +require "scruby/core_ext/typed_array" require "scruby/node" require "scruby/bus" require "scruby/group" @@ -29,7 +29,7 @@ before do @server.flush end - + describe 'instantiation with node target' do before do Node.reset! diff --git a/spec/synthdef_spec.rb b/spec/synthdef_spec.rb index d900686..d067e8f 100644 --- a/spec/synthdef_spec.rb +++ b/spec/synthdef_spec.rb @@ -5,7 +5,7 @@ require "scruby/env" require "scruby/ugens/ugen" require "scruby/ugens/ugen_operations" -require "scruby/synthdef" +require "scruby/synthdef" require "scruby/ugens/multi_out" require "scruby/core_ext/typed_array" @@ -18,7 +18,7 @@ class << self; public :new; end describe SynthDef, 'instantiation' do - + describe 'initialize' do before do @sdef = SynthDef.new( :name ){} @@ -29,7 +29,7 @@ class << self; public :new; end @sdef.should_not be_nil @sdef.should be_instance_of( SynthDef ) end - + it "should protect attributes" do @sdef.should_not respond_to( :name= ) @sdef.should_not respond_to( :children= ) @@ -41,7 +41,7 @@ class << self; public :new; end @sdef.should respond_to( :constants ) @sdef.should respond_to( :control_names ) end - + it "should accept name and set it as an attribute as string" do @sdef.name.should == 'name' end @@ -50,48 +50,48 @@ class << self; public :new; end @sdef.children.should == [] end end - + describe "options" do before do @options = mock Hash end - + it "should accept options" do sdef = SynthDef.new( :hola, :values => [] ){} end - + it "should use options" do @options.should_receive(:delete).with :values @options.should_receive(:delete).with :rates - + sdef = SynthDef.new( :hola, @options ){} end - - it "should set default values if not provided" + + it "should set default values if not provided" it "should accept a graph function" - + end - + describe '#collect_control_names' do before do @sdef = SynthDef.new( :name ){} @function = mock "grap_function", :arguments => [:arg1, :arg2, :arg3] end - + it "should get the argument names for the provided function" do @function.should_receive( :arguments ).and_return [] @sdef.send_msg :collect_control_names, @function, [], [] end - + it "should return empty array if the names are empty" do @function.should_receive( :arguments ).and_return [] @sdef.send_msg( :collect_control_names, @function, [], [] ).should == [] end - + it "should not return empty array if the names are not empty" do @sdef.send_msg( :collect_control_names, @function, [], [] ).should_not == [] end - + it "should instantiate and return a ControlName for each function name" do c_name = mock :control_name ControlName.should_receive( :new ).at_most(3).times.and_return c_name @@ -99,14 +99,14 @@ class << self; public :new; end control_names.size.should == 3 control_names.collect { |e| e.should == c_name } end - + it "should pass the argument value, the argument index and the rate(if provided) to the ControlName at instantiation" do 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 @sdef.send_msg( :collect_control_names, @function, [1, 2, 3, 4, 5], [] ).should have( 3 ).elements end @@ -116,7 +116,7 @@ class << self; public :new; end before :all do RATES = [:scalar, :trigger, :control] end - + before do @sdef = SynthDef.new( :name ){} @function = mock "grap_function", :arguments => [:arg1, :arg2, :arg3, :arg4] @@ -128,14 +128,14 @@ class << self; public :new; end Control.should_receive(:and_proxies_from).exactly( rates.size ).times @sdef.send_msg :build_controls, @control_names end - + it "should call Control#and_proxies.. with args" do Control.should_receive(:and_proxies_from).with( @control_names.select{ |c| c.rate == :scalar } ) unless @control_names.select{ |c| c.rate == :scalar }.empty? Control.should_receive(:and_proxies_from).with( @control_names.select{ |c| c.rate == :trigger } ) unless @control_names.select{ |c| c.rate == :trigger }.empty? Control.should_receive(:and_proxies_from).with( @control_names.select{ |c| c.rate == :control } ) unless @control_names.select{ |c| c.rate == :control }.empty? @sdef.send_msg( :build_controls, @control_names ) end - + it do @sdef.send_msg( :build_controls, @control_names ).should be_instance_of(Array) end @@ -143,11 +143,11 @@ class << self; public :new; end it "should return an array of OutputProxies" do @sdef.send_msg( :build_controls, @control_names ).each { |e| e.should be_instance_of(OutputProxy) } end - + it "should return an array of OutputProxies sorted by ControlNameIndex" do @sdef.send_msg( :build_controls, @control_names ).collect{ |p| p.control_name.index }.should == (0...@control_names.size).to_a end - + it "should call graph function with correct args" do function = mock("function", :call => [] ) proxies = @sdef.send_msg( :build_controls, @control_names ) @@ -155,28 +155,28 @@ class << self; public :new; end function.should_receive( :call ).with( *proxies ) @sdef.send_msg( :build_ugen_graph, function, @control_names) end - + it "should set @sdef" do function = lambda{} Ugen.should_receive( :synthdef= ).with( @sdef ) - Ugen.should_receive( :synthdef= ).with( nil ) + Ugen.should_receive( :synthdef= ).with( nil ) @sdef.send_msg( :build_ugen_graph, function, [] ) end - + it "should collect constants for simple children array" do children = [MockUgen.new(:audio, 100), MockUgen.new(:audio, 200), MockUgen.new(:audio, 100, 300)] @sdef.send_msg( :collect_constants, children).should == [100.0, 200.0, 300.0] end - + it "should collect constants for children arrays" do children = [ MockUgen.new(:audio, 100), [ MockUgen.new(:audio, 400), [ MockUgen.new(:audio, 200), MockUgen.new(:audio, 100, 300) ] ] ] @sdef.send_msg( :collect_constants, children).should == [100.0, 400.0, 200.0, 300.0] end - + it "should remove nil from constants array" - + end - + end @@ -189,28 +189,28 @@ def self.ar freq = 440.0, phase = 0.0 #not interested in muladd end end end - + before do @sdef = SynthDef.new(:hola) { Spec::SinOsc.ar } @encoded = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 4, 104, 111, 108, 97, 0, 2, 67, -36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 0, 0 ].pack('C*') end - + it "should get values" do @sdef.values end - + it "should encode init stream" do @sdef.encode[0..9].should == @encoded[0..9] end - + it "should encode is, name" do @sdef.encode[0..14].should == @encoded[0..14] end - + it "should encode is, name, constants" do @sdef.encode[0..24].should == @encoded[0..24] end - + it "should encode is, name, consts, values" do @sdef.encode[0..26].should == @encoded[0..26] end @@ -218,48 +218,48 @@ def self.ar freq = 440.0, phase = 0.0 #not interested in muladd it "should encode is, name, consts, values, controls" do @sdef.encode[0..28].should == @encoded[0..28] end - + it "should encode is, name, consts, values, controls, children" do @sdef.encode[0..53].should == @encoded[0..53] end - + it "should encode is, name, consts, values, controls, children, variants stub" do @sdef.encode.should == @encoded end - + describe "sending" do before :all do @server = mock('server', :instance_of? => true, :send_synth_def => nil) ::Server = mock('Server', :all => [@server]) end - + before do @servers = (0..3).map{ mock('server', :instance_of? => true, :send_synth_def => nil) } @sdef = SynthDef.new(:hola) { Spec::SinOsc.ar } end - + it "should accept an array or several Servers" do @sdef.send @servers @sdef.send *@servers end - + it "should not accept non servers" do lambda{ @sdef.send [1, 2] }.should raise_error(NoMethodError) lambda{ @sdef.send 1, 2 }.should raise_error(NoMethodError) end - + it "should send self to each of the servers" do @servers.each{ |s| s.should_receive(:send_synth_def).with(@sdef) } @sdef.send( @servers ) end - + it "should send to Server.all if not provided with a list of servers" do @server.should_receive(:send_synth_def).with(@sdef) Server.should_receive(:all).and_return([@server]) @sdef.send end - end + end end diff --git a/spec/ugen_operations_spec.rb b/spec/ugen_operations_spec.rb index 9541a88..e62cf54 100644 --- a/spec/ugen_operations_spec.rb +++ b/spec/ugen_operations_spec.rb @@ -17,7 +17,7 @@ class << self; public :new; end end describe UgenOperations do - + before do @ugen = MockUgen.new :audio @ugen2 = MockUgen.new :audio @@ -28,17 +28,17 @@ class << self; public :new; end sum = @ugen + @ugen2 sum.should be_instance_of(BinaryOpUGen) end - + it 'should sum integer' do sum = @ugen + 1.0 sum.should be_instance_of(BinaryOpUGen) end - + it "should raise argument error" do lambda { @ugen + :hola }.should raise_error(NoMethodError) end end - + describe 'unary operations' do it "should do unary op" do op = @ugen.distort @@ -46,7 +46,7 @@ class << self; public :new; end op.inputs.should == [@ugen] end end - + describe Numeric do it "do unary operation" do 1.distort.should == UnaryOpUGen.new(:distort, 1) @@ -56,28 +56,28 @@ class << self; public :new; end sum = 1 + 1 sum.should == 2 end - + it "should set the correct inputs and operator for the binopugen" do sum = 1.0 + @ugen sum.should == BinaryOpUGen.new(:+, 1.0, @ugen) end - + it "ugen should sum numeric" do sum = @ugen + 1 sum.should == BinaryOpUGen.new(:+, @ugen, 1) end - + it 'ugen should sum array' do sum = @ugen * d(1,2) sum.should == d(BinaryOpUGen.new(:*, @ugen, 1), BinaryOpUGen.new(:*, @ugen, 2)) end end - + describe DelegatorArray do before do @ugen = MockUgen.new :audio end - + it "do binary operation" do d(@ugen).distort.should == d(@ugen.distort) end @@ -86,15 +86,15 @@ class << self; public :new; end op = d(1, 2) * @ugen op.should be_a(DelegatorArray) op.should == d(BinaryOpUGen.new(:*, 1, @ugen), BinaryOpUGen.new(:*, 2, @ugen)) - end + end end - + end -# 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#<= +# 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#<= # changed max and min to maximum and minimum because the override Array#max and Array#min wich take no args diff --git a/spec/ugen_spec.rb b/spec/ugen_spec.rb index 696492e..950b2ac 100644 --- a/spec/ugen_spec.rb +++ b/spec/ugen_spec.rb @@ -26,7 +26,7 @@ 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 @@ -36,10 +36,10 @@ def kr freq = 440.0, phase = 0.0 class Scruby::Buffer def as_ugen_input; 0; end end - + describe Ugen do - + before do @sdef = mock 'sdef', :children => [] end @@ -49,7 +49,7 @@ def as_ugen_input; 0; end UgenOperations::BINARY.should_not be_nil Ugen::RATES.should_not be_nil end - + it "should tell if valid input" do cn = ControlName.new 'cn', 1, :audio, 0 Ugen.valid_input?( 440 ).should be_true @@ -61,7 +61,7 @@ def as_ugen_input; 0; end 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 MockUgen.new( :audio, Buffer.new ).inputs.should == [0] end @@ -70,11 +70,11 @@ def as_ugen_input; 0; end before do @ugen = SinOsc.ar end - + it do @ugen.should respond_to( :inputs ) end - + it do @ugen.should respond_to( :rate ) end @@ -85,52 +85,52 @@ def as_ugen_input; 0; end @op_ugen = mock( 'op_ugen' ) UnaryOpUGen = mock 'unary_op_ugen', :new => @op_ugen end - + before do @ugen = SinOsc.ar @ugen2 = SinOsc.ar end - + it do #this specs all binary operations @ugen.should respond_to( :+ ) end - + it "should sum" do (@ugen + @ugen2).should be_a(BinaryOpUGen) end end - + describe 'ugen graph in synth def' do before do Ugen.synthdef = nil @ugen = MockUgen.new( :audio, 1, 2 ) @ugen2 = MockUgen.new( :audio, 1, 2 ) end - + it "should not have synthdef" do MockUgen.new( :audio, 1, 2 ).send( :synthdef ).should be_nil end - + it "should have 0 as index if not belonging to ugen" do MockUgen.new( :audio, 1, 2 ).index.should be_zero end - + it "should have synthdef" do Ugen.synthdef = @sdef @ugen.send( :synthdef ).should == @sdef end - + it do @ugen.should_not respond_to(:add_to_synthdef) #private method end - + it "should add to synth def on instantiation" do Ugen.synthdef = @sdef ugen = MockUgen.new( :audio, 1, 2) ugen.send( :synthdef ).should == @sdef @sdef.children.should == [ugen] end - + it "should add to synthdef and return synthdef.children size" do Ugen.synthdef = @sdef ugen, ugen2 = MockUgen.new(:audio, 1, 2), MockUgen.new(:audio, 1, 2) @@ -138,163 +138,163 @@ def as_ugen_input; 0; end ugen.index.should == 0 ugen2.index.should == 1 end - + it "should not add to synthdef" do Ugen.synthdef = nil @sdef.children.should_not_receive( :<< ) MockUgen.new( :audio, 1, 2 ).send( :add_to_synthdef ).should eql( nil ) end - + it "should collect constants" do MockUgen.new( :audio, 100, @ugen, 200 ).send( :collect_constants ).flatten.sort.should == [1, 2, 100, 200] end - + it "should collect constants on arrayed inputs" do MockUgen.new( :audio, 100, [@ugen, [200, @ugen2, 100] ] ).send( :collect_constants ).flatten.uniq.sort.should == [1, 2, 100, 200] end - + end - + describe 'initialization and inputs' do before do @ugen = MockUgen.new(:audio, 1, 2, 3) end - + it "should not accept non valid inputs" do lambda{ @ugen = MockUgen.new(:audio, "hola") }.should raise_error( ArgumentError ) end - + it "should require at least one argument" do lambda { MockUgen.new }.should raise_error( ArgumentError ) end - + it "should be a defined rate as the first argument" do lambda { MockUgen.new( :not_a_rate, 1 ) }.should raise_error( ArgumentError ) end - + it "should use the highest rate when passing an array" do MockUgen.new([:audio, :control], 1).rate.should == :audio end - + it "should be a defined rate as array" do lambda { MockUgen.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 MockUgen.new( :audio, [] ).inputs.should eql([]) end - + it "should instantiate" do MockUgen.new( :audio, 1, 2 ).should be_instance_of( MockUgen ) end - + it "should accept any number of args" do MockUgen.new( :audio, 1, 2 ) MockUgen.new( :audio, 1, 2, 3, 4 ) end - + it "should set inputs" do @ugen.inputs.should == [1, 2, 3] end - + it "should set rate" do @ugen.rate.should == :audio end - + it "should have empty inputs" do MockUgen.new( :audio ).inputs.should == [] MockUgen.new( :audio, [] ).inputs.should == [] end end - + describe 'initialization with array as argument' do - + before :all do - @i_1 = 100, 210 - @i_2 = 100, 220 - @i_3 = 100, 230 + @i_1 = 100, 210 + @i_2 = 100, 220 + @i_3 = 100, 230 @i_4 = 100, 240 end - + it "should not care if an array was passed" do MockUgen.new( :audio, [1, 2, 3] ).should be_instance_of(MockUgen) end - + it "should return an array of Ugens if an array as one arg is passed on instantiation" do MockUgen.new( :audio, 1, [2, 3] ).should be_instance_of(DelegatorArray) end - + it do MockUgen.new( :audio, 1, [2,3], [4,5] ).should have( 2 ).items end - + it do MockUgen.new( :audio, 1, [2,3, 3], [4,5] ).should have( 3 ).items end - + it "should return an array of ugens" do ugens = MockUgen.new( :audio, 100, [210, 220, 230, 240] ) ugens.each do |u| u.should be_instance_of(MockUgen) end end - + it "should return ugen" do ugen = MockUgen.new( :audio, [1], [2] ) ugen.should be_instance_of( MockUgen ) ugen.inputs.should == [1, 2] end - + it "should return ugen" do ugen = MockUgen.new( :audio, [1, 2] ) ugen.should be_instance_of( MockUgen ) ugen.inputs.should == [1, 2] end - + it "should make multichannel array (DelegatorArray)" do multichannel = MockUgen.new( :audio, 100, [210, 220] ) multichannel.should be_a(DelegatorArray) multichannel.should == d(MockUgen.new(:audio, 100, 210), MockUgen.new(:audio, 100, 220)) end - + it "should accept DelegatorArray as inputs" do multichannel = MockUgen.new( :audio, 100, d(210, 220) ) multichannel.should be_a(DelegatorArray) multichannel.should == d(MockUgen.new(:audio, 100, 210), MockUgen.new(:audio, 100, 220)) 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| e.first.inputs.should eql( e.last ) end end - + it "should match the structure of the inputs array(s)" do array = [ 200, [210, [220, 230] ] ] ugens = MockUgen.new( :audio, 100, array ) - last = lambda do |i| - if i.instance_of?(MockUgen) + last = lambda do |i| + if i.instance_of?(MockUgen) i.inputs.first.should == 100 - i.inputs.last - else - i.map{ |e| last.call(e) } + i.inputs.last + else + i.map{ |e| last.call(e) } end end last.call(ugens).should == array end - + it "should return muladd" do @ugen = MockUgen.new(:audio, 100, 100) @ugen.muladd(0.5, 0.5).should be_a(MulAdd) end - + it "should return an arrayed muladd" do @ugen = MockUgen.new(:audio, [100,100], 100) @ugen.muladd(0.5, 0.5).should be_a(DelegatorArray) end end - + describe Ugen, 'encoding' do before do args = [400.0, 0.0] @@ -345,7 +345,7 @@ 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 MockUgen.new(:audio, 1, 2).should == MockUgen.new(:audio, 1, 2) end diff --git a/spec/ugens_spec.rb b/spec/ugens_spec.rb index 3243ab0..bc317a3 100644 --- a/spec/ugens_spec.rb +++ b/spec/ugens_spec.rb @@ -3,8 +3,8 @@ require "scruby/control_name" require "scruby/env" require "scruby/ugens/ugen" -require "scruby/ugens/ugen_operations" -require "scruby/ugens/operation_ugens" +require "scruby/ugens/ugen_operations" +require "scruby/ugens/operation_ugens" require "scruby/ugens/ugens" @@ -19,7 +19,7 @@ class Klass describe Ugens do - + before do @udefs = YAML::load( File.open( "#{ File.dirname __FILE__ }/../lib/scruby/ugens/ugen_defs.yaml" ) ) end @@ -41,24 +41,24 @@ class Klass Gendy1.should_receive(:new).with( :audio, 10, 20, 1, 1, 550, 660, 0.5, 0.5, 12, 1 ).and_return( mock('ugen', :muladd => nil) ) Gendy1.ar 10, 20, :knum => 1, :minfreq => 550 end - + it "should raise argumen error if not passed required" do Gendy1.stub!(:new) lambda { Gendy1.ar }.should raise_error(ArgumentError) end - + it "should not accept more than the required arguments" do lambda { SinOsc.ar(1,2,3,4,5,6) }.should raise_error(ArgumentError) end - + it "should initialize using demand" do Dbrown.new(1,2,3,4).inputs.should == [1,2,3,4] end - + it "should have public new method for scalar" do ExpRand.new(1,2) end - + it "should output params" end