Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

moved named arguments into a gem

  • Loading branch information...
commit 2d5071dd9006100ab4a03c1eefd431b3cf838f92 1 parent b775dbf
@maca authored
View
BIN  .DS_Store
Binary file not shown
View
34 lib/scruby/audio/ugens/ugen_defs.yaml
@@ -418,7 +418,7 @@ BufWr:
- - :loop
- 1.0
- - :inputArray
- -
+ - "[]"
:audio:
- - :bufnum
- 0.0
@@ -427,7 +427,7 @@ BufWr:
- - :loop
- 1.0
- - :inputArray
- -
+ - "[]"
COsc:
:control:
- - :bufnum
@@ -1373,31 +1373,31 @@ InRange:
- 1.0
InRect:
:control:
- - - :y
+ - - :x
- 0.0
- - :y
- 0.0
- - :left
- -
+ - :nil
- - :top
- -
+ - :nil
- - :right
- -
+ - :nil
- - :bottom
- -
+ - :nil
:audio:
- - - :y
+ - - :x
- 0.0
- - :y
- 0.0
- - :left
- -
+ - :nil
- - :top
- -
+ - :nil
- - :right
- -
+ - :nil
- - :bottom
- -
+ - :nil
InTrig:
:control:
- - :bus
@@ -2719,7 +2719,7 @@ RecordBuf:
- - :trigger
- 1.0
- - :inputArray
- -
+ - "[]"
ReplaceOut:
:control:
- - :bus
@@ -2831,12 +2831,12 @@ ScopeOut:
- - :bufnum
- 0.0
- - :inputArray
- -
+ - "[]"
:audio:
- - :bufnum
- 0.0
- - :inputArray
- -
+ - "[]"
Select:
:control:
- - :which
@@ -3147,14 +3147,14 @@ TWindex:
- - :normalize
- 0.0
- - :array
- -
+ - "[]"
:audio:
- - :input
-
- - :normalize
- 0.0
- - :array
- -
+ - "[]"
Timer:
:control:
- - :trig
View
17 lib/scruby/audio/ugens/ugens.rb
@@ -7,21 +7,18 @@ 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
- klass = "class #{name} < Ugen\n" +
+ methods = rates.collect{ |r| ":#{rate_name[r.first]}" }.join(', ')
+
+ klass = "class #{name} < Ugen\nclass << self\n" +
rates.collect do |r|
new_args = ( [r.first] + r.last.collect{|a|a.first} ).join(', ')
args = (r.last + [[:mul,1],[:add,0]]).collect{ |a| a.compact.join(' = ')}.join(', ')
- " def self.#{rate_name[r.first]}(#{args})\n" +
+ " def #{rate_name[r.first]}(#{args})\n" +
" new(:#{new_args}).muladd(mul, add)" +
"\n end"
- end.join("\n\n") + "\nend\n\n"
+ end.join("\n") + "\nnamed_args_for #{methods}\nend\nend\n"
- unless %w(InRect TWindex RecordBuf BufWr ScopeOut).include?(name)
- self.class_eval klass
- klass = eval(name)
- methods = rates.collect{ |r| ":#{rate_name[r.first]}" }.join(', ')
- self.class_eval "class #{name}; class << self; named_args_for #{methods}; end; end;"
- end
+ self.class_eval klass
end
ugen_defs.each_pair do |key, value|
@@ -30,4 +27,4 @@ def self.define_ugen(name, rates)
end
end
-end
+end
View
BIN  spec/.DS_Store
Binary file not shown
View
12 spec/audio/ugens_spec.rb
@@ -1,7 +1,7 @@
require File.join( File.expand_path(File.dirname(__FILE__)), '..',"helper")
require 'yaml'
+require 'named_arguments'
-require "#{LIB_DIR}/named_args"
require "#{LIB_DIR}/audio/ugens/ugen_operations"
require "#{LIB_DIR}/audio/ugens/ugen"
require "#{LIB_DIR}/audio/ugens/ugens"
@@ -42,11 +42,19 @@ class Klass
Gendy1.should respond_to(:named_args_for)
end
- it do
+ it "should use default values" do
Gendy1.should_receive(:new).with( :audio, 1.0, 1.0, 1.0, 1.0, 440.0, 660.0, 0.5, 0.5, 12.0, nil ).and_return( mock('ugen', :muladd => nil) )
Gendy1.ar
end
+ it "should accept named args" do
+ ugen = mock('ugen')
+ ugen.should_receive( :muladd ).with(2,3)
+ Gendy1.should_receive(:new).with( :audio, 4, 5, 6, 1.0, 440.0, 660.0, 0.5, 0.5, 12.0, 100 ).and_return( ugen )
+ Gendy1.ar( 4, 5, 6, :knum => 100, :mul => 2, :add => 3 )
+ end
+
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.