Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

implemented Disk IO Ugens: DiskOut, DiskIn, VDiskIn

  • Loading branch information...
commit b5c6ac8ce6f1c3dd8e424fcdc6e8428435465b3b 1 parent 47fb03f
@maca maca authored
View
1  lib/scruby/synth.rb
@@ -1,5 +1,4 @@
module Scruby
-
class Synth < Node
attr_reader :name
View
2  lib/scruby/synthdef.rb
@@ -50,7 +50,7 @@ def encode
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
View
9 lib/scruby/ugens/demand.rb
@@ -0,0 +1,9 @@
+module Scruby
+ module Ugens
+ class Demand < Ugen
+ include MultiOut
+
+
+ end
+ end
+end
View
31 lib/scruby/ugens/disk_io.rb
@@ -0,0 +1,31 @@
+module Scruby
+ module Ugens
+ class DiskOut < Ugen
+ def output_specs; []; end
+ def channels; []; end
+
+ class << self
+ def ar bufnum, *inputs
+ inputs.peel!
+ new :audio, bufnum, *inputs
+ 0.0
+ end
+ end
+ end
+
+ class DiskIn < Ugen
+ include MultiOut
+ def self.ar channels, bufnum, loop = 0
+ new :audio, channels, bufnum, loop
+ end
+ end
+
+ class VDiskIn < Ugen
+ include MultiOut
+ def self.ar channels, bufnum, rate = 1, loop = 0, send_id = 0
+ new :audio, channels, bufnum, rate, loop, send_id
+ end
+ named_args_for 'self.ar'
+ end
+ end
+end
View
10 lib/scruby/ugens/ugen_defs.yaml
@@ -732,16 +732,6 @@ Dibrown:
-
- - :length
- 0
-DiskIn:
- :audio:
- - - :bufnum
- -
-DiskOut:
- :audio:
- - - :bufnum
- -
- - - :channelsArray
- -
Diwhite:
:demand:
- - :lo
View
52 lib/scruby/ugens/ugens.rb
@@ -40,33 +40,41 @@ module Ugens
#
def self.define_ugen name, rates
rate_name = {:audio => :ar, :control => :kr, :scalar => :ir, :demand => :new}
- rates.delete_if{ |key, value| key == :demand } #I don't know what to do with these
methods = rates.collect do |rate, args|
- args ||= []
- args.push [:mul, 1], [:add, 0]
- args.uniq!
- assigns = []
- args.each_with_index do |arg, index|
- key, val = arg
- assigns << %{
- #{ key } = opts[:#{ key }] || args[#{ index }] || #{ val }
- raise( ArgumentError.new("`#{ key }` value must be provided") ) unless #{ key }
- }
- end
+ if rate == :demand
+ <<-RUBY_EVAL
+ def new #{ args.collect{ |a, v| "#{ a } = #{ v.inspect }" }.join(', ') }
+ super :demand, #{ args.collect{ |a| a.first }.join(', ') }
+ end
+ RUBY_EVAL
+ else
+ args ||= []
+ args.push [:mul, 1], [:add, 0]
+ args.uniq!
+ assigns = []
+ args.each_with_index do |arg, index|
+ key, val = arg
+ assigns << %{
+ #{ key } = opts[:#{ key }] || args[#{ index }] || #{ val }
+ raise( ArgumentError.new("`#{ key }` value must be provided") ) unless #{ key }
+ }
+ end
- args = [":#{ rate }"] + args[0...-2].collect{ |a| a.first }
- <<-RUBY_EVAL
- def #{ rate_name[rate] } *args
- opts = args.last.kind_of?( Hash ) ? args.pop : {}
- #{ assigns.join("\n") }
- new( #{ args.join(', ') } ).muladd( mul, add )
- end
+ new_args = [":#{ rate }"] + args[0...-2].collect{ |a| a.first }
+ <<-RUBY_EVAL
+ def #{ rate_name[rate] } *args
+ raise ArgumentError.new("wrong number of arguments (\#{ args } for #{ args.size })") if args.size > #{args.size}
+ opts = args.last.kind_of?( Hash ) ? args.pop : {}
+ #{ assigns.join("\n") }
+ new( #{ new_args.join(', ') } ).muladd( mul, add )
+ end
- def params
- @params
+ def params
+ @params
+ end
+ RUBY_EVAL
end
- RUBY_EVAL
end.join("\n")
self.class_eval <<-RUBY_EVAL
View
83 spec/demand_spec.rb
@@ -0,0 +1,83 @@
+require File.expand_path(File.dirname(__FILE__)) + "/helper"
+
+require "scruby/core_ext/delegator_array"
+require "scruby/control_name"
+require "scruby/env"
+require "scruby/ugens/ugen"
+require "scruby/ugens/ugen_operations"
+require "scruby/ugens/multi_out"
+require "scruby/ugens/ugens"
+require "scruby/ugens/demand"
+
+include Scruby
+include Ugens
+
+class MockUgen < Ugen
+ class << self; public :new; end
+end
+
+describe Demand do
+ shared_examples_for 'Demand Ugen' do
+ before do
+ @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
+ # before do
+ # @channels = 2
+ # @splatted = false
+ # end
+ #
+ # end
+ #
+ # describe "Two channel array input" do
+ # before do
+ # @channels = 2
+ # @splatted = false
+ # end
+ #
+ # end
+
+end
View
138 spec/disk_io_spec.rb
@@ -0,0 +1,138 @@
+require File.expand_path(File.dirname(__FILE__)) + "/helper"
+
+require "scruby/core_ext/delegator_array"
+require "scruby/core_ext/array"
+require "scruby/control_name"
+require "scruby/env"
+require "scruby/synthdef"
+require "scruby/ugens/ugen"
+require "scruby/ugens/ugen_operations"
+require "scruby/ugens/operation_ugens"
+require "scruby/ugens/multi_out"
+require "scruby/ugens/ugens"
+require "scruby/ugens/disk_io"
+
+include Scruby
+include Ugens
+
+class MockUgen < Ugen
+ class << self; public :new; end
+end
+
+describe 'IO ugens' do
+ describe DiskOut, 'one channel' do
+ before do
+ @sdef = SynthDef.new :out do |bufnum|
+ @out = DiskOut.ar bufnum, WhiteNoise.ar
+ end
+ end
+
+ it "should output zero" do
+ @out.should == 0.0
+ end
+
+ it "should encode correctly" do
+ expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 3, 111, 117, 116, 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, 10, 87, 104, 105, 116, 101, 78, 111, 105, 115, 101, 2, 0, 0, 0, 1, 0, 0, 2, 7, 68, 105, 115, 107, 79, 117, 116, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
+ @sdef.encode.should == expected.pack('C*')
+ end
+ end
+
+ describe DiskOut, 'two channel' do
+ before do
+ @sdef = SynthDef.new :out do |bufnum|
+ @out = DiskOut.ar bufnum, [WhiteNoise.ar, WhiteNoise.ar]
+ end
+ @sdef2 = SynthDef.new :out do |bufnum|
+ @out2 = DiskOut.ar bufnum, WhiteNoise.ar, WhiteNoise.ar
+ end
+ end
+
+ it "should output zero" do
+ @out.should == 0.0
+ end
+
+ it "should encode the same" do
+ @sdef.encode.should == @sdef2.encode
+ end
+
+ it "should encode correctly" do
+ expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 3, 111, 117, 116, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 6, 98, 117, 102, 110, 117, 109, 0, 0, 0, 4, 7, 67, 111, 110, 116, 114, 111, 108, 1, 0, 0, 0, 1, 0, 0, 1, 10, 87, 104, 105, 116, 101, 78, 111, 105, 115, 101, 2, 0, 0, 0, 1, 0, 0, 2, 10, 87, 104, 105, 116, 101, 78, 111, 105, 115, 101, 2, 0, 0, 0, 1, 0, 0, 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, 2, 0, 0, 0, 0 ]
+ @sdef.encode.should == expected.pack('C*')
+ end
+ end
+
+ shared_examples_for 'DiskIn' do
+ before do
+ @sdef = SynthDef.new :in do
+ @proxies = @class.send :ar, @channels, *@inputs
+ end
+ @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 == :audio
+ end
+
+ it "should return an array of output proxies" do
+ @proxies.should have(@channels).proxies
+ @proxies.each_with_index do |proxy, i|
+ proxy.source.should be_a(@class)
+ proxy.should be_a(OutputProxy)
+ proxy.output_index.should == i
+ end
+ end
+
+ it "should set inputs" do
+ @instance.inputs.should == @inputs
+ end
+
+ it "should encode" do
+ @sdef.encode.should == @expected.pack('C*')
+ end
+ end
+
+ describe DiskIn, 'single channel' do
+ before do
+ @channels = 1
+ @inputs = 1, 0
+ @class = DiskIn
+ @expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 2, 105, 110, 0, 2, 63, -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 68, 105, 115, 107, 73, 110, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 0, 0 ]
+ end
+ it_should_behave_like 'DiskIn'
+ end
+
+ describe DiskIn, 'two channels' do
+ before do
+ @channels = 2
+ @inputs = 1, 0
+ @class = DiskIn
+ @expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 2, 105, 110, 0, 2, 63, -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 68, 105, 115, 107, 73, 110, 2, 0, 2, 0, 2, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 2, 0, 0 ]
+ end
+ it_should_behave_like 'DiskIn'
+ end
+
+ describe VDiskIn, 'single channel' do
+ before do
+ @channels = 1
+ @inputs = 1, 2, 3, 4
+ @class = VDiskIn
+ @expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 2, 105, 110, 0, 4, 63, -128, 0, 0, 64, 0, 0, 0, 64, 64, 0, 0, 64, -128, 0, 0, 0, 0, 0, 0, 0, 1, 7, 86, 68, 105, 115, 107, 73, 110, 2, 0, 4, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, -1, -1, 0, 2, -1, -1, 0, 3, 2, 0, 0 ]
+ end
+ it_should_behave_like 'DiskIn'
+ end
+
+ describe VDiskIn, 'two channels' do
+ before do
+ @channels = 2
+ @inputs = 1, 2, 3, 4
+ @class = VDiskIn
+ @expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 2, 105, 110, 0, 4, 63, -128, 0, 0, 64, 0, 0, 0, 64, 64, 0, 0, 64, -128, 0, 0, 0, 0, 0, 0, 0, 1, 7, 86, 68, 105, 115, 107, 73, 110, 2, 0, 4, 0, 2, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, -1, -1, 0, 2, -1, -1, 0, 3, 2, 2, 0, 0 ]
+ end
+ it_should_behave_like 'DiskIn'
+ end
+
+end
View
29 spec/ugens_spec.rb
@@ -4,6 +4,7 @@
require "scruby/env"
require "scruby/ugens/ugen"
require "scruby/ugens/ugen_operations"
+require "scruby/ugens/operation_ugens"
require "scruby/ugens/ugens"
@@ -46,27 +47,15 @@ class Klass
lambda { Gendy1.ar }.should raise_error(ArgumentError)
end
- # it "should print params" do
- # PanAz.params.should == {
- # :audio => [
- # [:input, nil],
- # [:pos, 0],
- # [:level, 1],
- # [:width, 2],
- # [:orientation, 0.5],
- # [:mul, 1],
- # [:add, 0] ],
- # :control => [
- # [:input, nil],
- # [:pos, 0],
- # [:level, 1],
- # [:width, 2],
- # [:orientation, 0.5],
- # [:mul, 1],
- # [:add, 0] ]}
- # 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 work with arrays"
+ it "should output params"
end
Please sign in to comment.
Something went wrong with that request. Please try again.