Permalink
Browse files

Heavy refactoring, load time is miliseconds

  • Loading branch information...
1 parent 72b30a5 commit 47fcf7ec6e9041271d749d7de2fb6dcdb0ced88e Macario committed Jul 8, 2009
View
@@ -1,7 +0,0 @@
-
-For more information on Scruby, see http://Scruby.rubyforge.org
-
-NOTE: Change this information in PostInstall.txt
-You can also delete it if you don't want it.
-
-
View
@@ -7,11 +7,11 @@ require File.dirname(__FILE__) + '/lib/scruby'
$hoe = Hoe.new('Scruby', Scruby::VERSION) do |p|
p.developer('FIXME full name', 'FIXME email')
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
- p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
p.rubyforge_name = p.name # TODO this is default value
- # p.extra_deps = [
- # ['activesupport','>= 2.0.2'],
- # ]
+ p.extra_deps = [
+ ['maca-arguments','>= 0.4.2'],
+ ['maca-rosc','>= 0.4.2']
+ ]
p.extra_dev_deps = [
['newgem', ">= #{::Newgem::VERSION}"]
]
View
@@ -20,7 +20,7 @@
require 'rosc'
require 'yaml'
-require 'methopara' if RUBY_VERSION.to_f >= 1.9
+# require 'methopara' if RUBY_VERSION.to_f >= 1.9
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
@@ -29,8 +29,6 @@ module Scruby
VERSION = '0.1'
end
-SCRUBY_DIR = File.join( File.expand_path(File.dirname(__FILE__) ), 'scruby' )
-
require "scruby/typed_array"
require "scruby/extensions"
@@ -23,37 +23,37 @@ def initialize levels, times, curves = :lin, release_node = nil, loop_node = nil
end
class << self
- def triangle dur = 1.0, level = 1.0
+ def triangle dur = 1, level = 1
dur = dur * 0.5
new [0, level, 0], [dur, dur]
end
- def sine dur = 1.0, level = 1.0
+ def sine dur = 1, level = 1
dur = dur * 0.5
new [0, level, 0], [dur, dur], :sine
end
- def perc attackTime = 0.01, releaseTime = 1.0, level = 1.0, curve = -4.0
+ def perc attackTime = 0.01, releaseTime = 1, level = 1, curve = -4
new [0, level, 0], [attackTime, releaseTime], curve
end
- def linen attackTime = 0.01, sustainTime = 1.0, releaseTime = 1.0, level = 1.0, curve = :lin
+ def linen attackTime = 0.01, sustainTime = 1, releaseTime = 1, level = 1, curve = :lin
new [0, level, level, 0], [attackTime, sustainTime, releaseTime], curve
end
- def cutoff releaseTime = 0.1, level = 1.0, curve = :lin
+ def cutoff releaseTime = 0.1, level = 1, curve = :lin
new [level, 0], [releaseTime], curve, 0
end
- def dadsr delayTime = 0.1, attackTime = 0.01, decayTime = 0.3, sustainLevel = 0.5, releaseTime = 1.0, peakLevel = 1.0, curve = -4.0, bias = 0.0
+ def dadsr delayTime = 0.1, attackTime = 0.01, decayTime = 0.3, sustainLevel = 0.5, releaseTime = 1, peakLevel = 1, curve = -4, bias = 0
new [0, 0, peakLevel, peakLevel * sustainLevel, 0].collect{ |e| e + bias }, [delayTime, attackTime, decayTime, releaseTime], curve, 3
end
- def adsr attackTime = 0.01, decayTime = 0.3, sustainLevel = 0.5, releaseTime = 1.0, peakLevel = 1.0, curve = -4.0, bias = 0.0
+ def adsr attackTime = 0.01, decayTime = 0.3, sustainLevel = 0.5, releaseTime = 1, peakLevel = 1, curve = -4, bias = 0
new [0, peakLevel, peakLevel * sustainLevel, 0].collect{ |e| e + bias }, [attackTime, decayTime, releaseTime], curve, 2
end
- def asr attackTime = 0.01, sustainLevel = 1.0, releaseTime = 1.0, curve = -4.0
+ def asr attackTime = 0.01, sustainLevel = 1, releaseTime = 1, curve = -4
new [0, sustainLevel, 0], [attackTime, releaseTime], curve, 1
end
@@ -62,7 +62,7 @@ def asr attackTime = 0.01, sustainLevel = 1.0, releaseTime = 1.0, curve = -4.0
def to_array
contents = levels[0], times.size, release_node, loop_node
- contents + levels[1..-1].wrap_and_zip( times, shape_numbers, curve_values ).flatten
+ contents + levels[1..-1].wrap_and_zip( times, shape_numbers, curve_values ).flatten
end
def shape_numbers
@@ -7,7 +7,7 @@ class UDPSender < OSC::UDPServer #:nodoc:
alias :udp_send :send
def send command, host, port, *args
- args = args.collect{ |arg| arg.kind_of? Symbol ? arg.to_s : arg }
+ args = args.collect{ |arg| arg.kind_of?( Symbol ) ? arg.to_s : arg }
udp_send OSC::Message.new( command, type_tag(args), *args ), 0, host, port
end
@@ -86,7 +86,6 @@ def send_message message #:nodoc:
public
class << self
-
# Specify the scsynth binary path
def sc_path= path
@@sc_path = path
@@ -123,6 +122,5 @@ def []= index
class SCError < StandardError
end
-
end
end
@@ -29,18 +29,16 @@ class SynthDef
#
def initialize name, options = {}, &block
@name, @children = name.to_s, []
-
+ raise( ArgumentError.new('An UGen graph (block) must be passed') ) unless block_given?
+
values = options.delete( :values ) || []
rates = options.delete( :rates ) || []
- block = block || Proc.new{}
@control_names = collect_control_names block, values, rates
build_ugen_graph block, @control_names
@constants = collect_constants @children
@variants = [] #stub!!!
-
- warn( 'A SynthDef without a block is useless' ) unless block_given?
end
# Returns a string representing the encoded SynthDef in a way scsynth can interpret and generate.
@@ -1253,7 +1253,6 @@ Gendy3:
- :nil
GrayNoise:
:control: []
-
:audio: []
HPF:
@@ -12,7 +12,7 @@ module Ugens
# 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("#{SCRUBY_DIR}/audio/ugens/operation_indices.yaml")
+ operation_indices = YAML::load File.open( File.dirname(__FILE__) + "/operation_indices.yaml" )
UNARY = operation_indices['unary']
BINARY = operation_indices['binary']
SAFE_NAMES = { :+ => :plus, :- => :minus, :* => :mult, :/ => :div2, :<= => :less_than_or_eql, :>= => :more_than_or_eql }
@@ -75,7 +75,7 @@ class << self
# # TODO: Load from ~/Ugens directory
end
- YAML::load( File.open( "#{SCRUBY_DIR}/audio/ugens/ugen_defs.yaml" ) ).each_pair{ |key, value| self.define_ugen key, value }
+ YAML::load( File.open( File.dirname(__FILE__) + "/ugen_defs.yaml" ) ).each_pair{ |key, value| self.define_ugen key, value }
end
end
end
@@ -1,27 +1,25 @@
class Object
-
# Wraps self int an array, #to_a seems to be deprecated
def to_array
[*self]
end
- def valid_ugen_input? #:nodoc:
- false
- end
+ # Returns false
+ def valid_ugen_input?; false; end
end
class Numeric
# Rate is :scalar
def rate; :scalar; end
# Compares itself with +other+ and returns biggest
- def max( other )
+ def max other
self > other ? self : other
end
# Compares itself with +other+ and returns smallest
- def min( other )
+ def min other
self < other ? self : other
end
end
@@ -32,7 +30,7 @@ def collect_constants #:nodoc:
self
end
- def input_specs( synthdef )
+ def input_specs synthdef
[-1, synthdef.constants.index(self)]
end
end
@@ -41,23 +39,22 @@ class Array
#collect with index
def collect_with_index
- indices = (0...self.size).map
- self.zip( indices ).collect{ |element_with_index| yield( element_with_index.first, element_with_index.last ) }
+ self.zip( (0...self.size).map ).collect{ |element, index| yield element, index }
end
- def wrap_to( size )
+ def wrap_to size
return self if size == self.size
- self.dup.wrap_to!( size )
+ self.dup.wrap_to! size
end
- def wrap_to!( size )
+ def wrap_to! size
return nil if size == self.size
original_size = self.size
size.times { |i| self[ i ] = self[ i % original_size ] }
self
end
- def wrap_and_zip( *args )
+ def wrap_and_zip *args
max = args.map{ |a| instance_of?(Array) ? a.size : 0 }.max.max( self.size )
args = args.collect{ |a| a.to_array.wrap_to( max ) }
self.wrap_to( max ).zip( *args )
@@ -67,10 +64,10 @@ def wrap_and_zip( *args )
def to_array; self; end
def encode_floats #:nodoc:
- [self.size].pack('n') + self.pack('g*')
+ [self.size].pack('n') + self.pack('g*') #TODO: Deprecate
end
- def muladd( mul, add ) #:nodoc:
+ def muladd mul, add #:nodoc:
self.collect{ |u| MulAdd.new( u, mul, add ) }
end
@@ -1,18 +1,15 @@
require File.join( File.expand_path(File.dirname(__FILE__)), '..', "helper")
-require "#{SCRUBY_DIR}/audio/ugens/ugen_operations"
-require "#{SCRUBY_DIR}/audio/ugens/ugen"
-require "#{SCRUBY_DIR}/extensions"
-require "#{SCRUBY_DIR}/audio/env"
-require "#{SCRUBY_DIR}/audio/ugens/env_gen"
+require "scruby/audio/ugens/ugen"
+require "scruby/audio/ugens/ugen_operations"
+require "scruby/extensions"
+require "scruby/audio/env"
+require "scruby/audio/ugens/env_gen"
include Scruby
include Audio
include Ugens
-
-
-
describe EnvGen do
it "should not instantiate with #new" do
@@ -1,10 +1,10 @@
require File.join( File.expand_path(File.dirname(__FILE__)),"../helper")
-require "#{SCRUBY_DIR}/audio/ugens/ugen_operations"
-require "#{SCRUBY_DIR}/extensions"
-require "#{SCRUBY_DIR}/audio/ugens/ugen"
-require "#{SCRUBY_DIR}/audio/ugens/multi_out_ugens"
-require "#{SCRUBY_DIR}/audio/ugens/in_out"
+require "scruby/audio/ugens/ugen"
+require "scruby/audio/ugens/ugen_operations"
+require "scruby/extensions"
+require "scruby/audio/ugens/multi_out_ugens"
+require "scruby/audio/ugens/in_out"
include Scruby
include Audio
@@ -1,6 +1,6 @@
require File.join( File.expand_path(File.dirname(__FILE__)), '..',"helper")
-require "#{SCRUBY_DIR}/../scruby"
+require "scruby"
include Scruby
include Audio
@@ -54,16 +54,20 @@
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) }
-
- child = sdef.children
- child[0..3].map { |u| u.should be_instance_of(SinOsc) }
- child[4].should be_instance_of(BinaryOpUGen)
- child[5].should be_instance_of(BinaryOpUGen)
- child[6].should be_instance_of(BinaryOpUGen)
- child[7].should be_instance_of(Out)
- child[8].should be_instance_of(Out)
+ sdef = SynthDef.new( :out ){ sig = SinOsc.ar(100, [200,[100, 100]]) * SinOsc.ar(200); Out.ar(0, sig) }
+ children = sdef.children
+ children[0..3].map { |u| u.should be_instance_of(SinOsc) }
+ children[4].should be_instance_of(BinaryOpUGen)
+ children[5].should be_instance_of(BinaryOpUGen)
+ children[6].should be_instance_of(BinaryOpUGen)
+ children[7].should be_instance_of(Out)
+ children[8].should be_instance_of(Out)
#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
@@ -75,13 +79,11 @@
env = EnvGen.kr Env.asr(2, 1, 2), gate, :doneAction => 2
Out.ar 0, sig*env
end
-
+
sdef.children.should have(8).children
sdef.constants.should == [0, 0.5, 1, 2, -99, 5, -4]
expected = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 2, 97, 109, 0, 7, 0, 0, 0, 0, 63, 0, 0, 0, 63, -128, 0, 0, 64, 0, 0, 0, -62, -58, 0, 0, 64, -96, 0, 0, -64, -128, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 103, 97, 116, 101, 0, 0, 9, 112, 111, 114, 116, 97, 100, 111, 114, 97, 0, 1, 10, 109, 111, 100, 117, 108, 97, 100, 111, 114, 97, 0, 2, 3, 97, 109, 112, 0, 3, 0, 8, 7, 67, 111, 110, 116, 114, 111, 108, 1, 0, 0, 0, 4, 0, 0, 1, 1, 1, 1, 6, 83, 105, 110, 79, 115, 99, 1, 0, 2, 0, 1, 0, 0, 0, 0, 0, 2, -1, -1, 0, 0, 1, 6, 77, 117, 108, 65, 100, 100, 1, 0, 3, 0, 1, 0, 0, 0, 1, 0, 0, -1, -1, 0, 1, -1, -1, 0, 1, 1, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, 0, 0, 0, 1, -1, -1, 0, 0, 2, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 3, 0, 0, 0, 2, 0, 0, 2, 6, 69, 110, 118, 71, 101, 110, 1, 0, 17, 0, 1, 0, 0, 0, 0, 0, 0, -1, -1, 0, 2, -1, -1, 0, 0, -1, -1, 0, 2, -1, -1, 0, 3, -1, -1, 0, 0, -1, -1, 0, 3, -1, -1, 0, 2, -1, -1, 0, 4, -1, -1, 0, 2, -1, -1, 0, 3, -1, -1, 0, 5, -1, -1, 0, 6, -1, -1, 0, 0, -1, -1, 0, 3, -1, -1, 0, 5, -1, -1, 0, 6, 1, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 4, 0, 0, 0, 5, 0, 0, 2, 3, 79, 117, 116, 2, 0, 2, 0, 0, 0, 0, -1, -1, 0, 0, 0, 6, 0, 0, 0, 0 ].pack('c*')
sdef.encode.should == expected
end
-
-
end
@@ -1,13 +0,0 @@
-require File.join( File.expand_path(File.dirname(__FILE__)), '..',"helper")
-
-
-require "#{SCRUBY_DIR}/../scruby"
-
-describe 'Lib' do
-
- 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
-
-end
@@ -1,9 +1,9 @@
require File.join( File.expand_path(File.dirname(__FILE__)), '..',"helper")
-require "#{SCRUBY_DIR}/audio/ugens/ugen_operations"
-require "#{SCRUBY_DIR}/audio/ugens/ugen"
-require "#{SCRUBY_DIR}/extensions"
-require "#{SCRUBY_DIR}/audio/ugens/multi_out_ugens"
+require "scruby/audio/ugens/ugen"
+require "scruby/audio/ugens/ugen_operations"
+require "scruby/extensions"
+require "scruby/audio/ugens/multi_out_ugens"
include Scruby
include Audio
@@ -1,16 +1,15 @@
require File.join( File.expand_path(File.dirname(__FILE__)), '..',"helper")
-require "#{SCRUBY_DIR}/extensions"
-require "#{SCRUBY_DIR}/typed_array"
-require "#{SCRUBY_DIR}/audio/node"
+require "scruby/extensions"
+require "scruby/typed_array"
+require "scruby/audio/node"
class Server; end
include Scruby
describe Node do
before :all do
@server = mock('server')
- Server = mock('Server' )
end
before do
Oops, something went wrong. Retry.

0 comments on commit 47fcf7e

Please sign in to comment.