Permalink
Browse files

fixed a problem where an Ugen could not sum an integer or array

  • Loading branch information...
1 parent 80f6b4a commit fea3df3c909e2d794c9717354a668b6863b7bb82 Macario committed Feb 28, 2009
View
26 README
@@ -1,26 +0,0 @@
-
-
-
-== LICENSE:
-
-Copyright (c) 2008 Macario Ortega
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) 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 <http://www.gnu.org/licenses/>.
-
-== NOTES
-
-Ruby has operation precendence
-
-
-
View
@@ -0,0 +1,2 @@
+
+
View
@@ -0,0 +1,37 @@
+scruby = "#{File.expand_path( File.join( File.dirname( __FILE__), '..', 'scruby' ) )}"
+require scruby
+s = Server.new('localhost', 57140)
+s.boot
+
+require File.expand_path( File.join( File.dirname(__FILE__),'..','..', '..', 'Sequentiable', 'lib', 'metro' ) )
+require File.expand_path( File.join( File.dirname(__FILE__),'..','..', '..', 'HumanGenome', 'lib', 'human_genome' ) )
+
+
+
+sdef = SynthDef.new :test, :values => [456, 0.34, 0.45] do |freq, ancho, amp|
+ gate = EnvGen.kr( Env.perc(0, 0.2) )
+ sig = SinOsc.ar( [freq, freq * 1.01], :mul => SinOsc.kr(40) * amp * 0.7 ) * EnvGen.kr( Env.asr(2, 1, 3), gate, :doneAction => 2 )
+ sig = SinOsc.ar( [freq, freq * 1.01], :mul => SinOsc.kr(8) * amp * 0.3 ) * EnvGen.kr( Env.asr(2, 1, 2), gate ) + sig
+ sig = SinOsc.ar( [freq * 0.25, freq * 0.251], :mul => SinOsc.kr(30) * amp * 0.3 ) * EnvGen.kr( Env.asr(2, 1, 2.5), gate ) + sig
+ sig = SinOsc.ar( freq * 2, :mul => SinOsc.kr(500, :mul => 0.1) * amp * 0.2 ) * EnvGen.kr( Env.asr(0, 1, 2), gate ) + sig
+ sig = SinOsc.ar( freq * 0.25, :mul => amp * 0.2 ) * EnvGen.kr( Env.asr(0, 1, 0.4), gate ) + sig
+ Out.ar( 0, sig)
+end
+sdef.send
+sleep 0.05
+test = Synth.new :test, :freq => 2000, :amp => 1
+sleep 0.2
+
+
+
+
+bass.set( :gate => 0)
+
+
+s.stop
+
+test.free
+bass.free
+
+
+
View
@@ -0,0 +1,8 @@
+
+
+[69,70,71].map( &:freq )
+
+
+
+
+
View
@@ -69,7 +69,8 @@ class Session
# Starts a live session using a named pipe to receive code from a remote source and evaluates it within a context, a bit like an IRB session but evaluates code sent from a text editor
def initialize
- return p( Exception.new("Another session sems to be running") ) if File.exist?( "#{Dir.tmpdir}/ruby_live.pipe" )
+ return p( Exception.new("Another session sems to be running: #{Dir.tmpdir}/ruby_live.pipe") ) if File.exist?( "#{Dir.tmpdir}/ruby_live.pipe" )
+
p( Notice.new("Live Session") )
get_binding
init_pipe
View
@@ -7,6 +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 }
udp_send( OSC::Message.new( command, type_tag(args), *args ), 0, host, port )
end
@@ -36,20 +37,29 @@ def initialize( host = 'localhost', port = 57111)
end
# Boots the local binary of the scsynth forking a process, it will rise a SCError if the scsynth
- # binary is not found in /Applications/SuperCollider/scsynt (default Mac OS path) or given path.
+ # binary is not found in /Applications/SuperCollider/scsynth (default Mac OS path) or given 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?( @@sc_path )
Thread.new do
path = @@sc_path.scan(/[^\/]+/)
@server_pipe = IO.popen( "cd /#{ path[0..-2].join('/') }; ./#{ path.last } -u #{ @port }" )
loop { p Special.new(@server_pipe.gets.chomp) }
- end unless @server_pipe
+ end unless @server_pipe
+ sleep 2 # TODO: There should be a better way to wait for the server to start
+ send "/g_new", 1
+ self
+ end
+
+ def stop
+ send "/g_freeAll", 0
+ send "/clearSched"
+ send "/g_new", 1
end
# Sends the /quit OSC signal to the scsynth server and kills the forked process if the scsynth
# server is running locally
- def stop
+ def quit
send '/quit'
Process.kill 'KILL', @server_pipe.pid if @server_pipe
@server_pipe = nil
@@ -58,7 +68,8 @@ def stop
# Sends an OSC command to the scsyth server.
# E.g. <tt>server.send('/dumpOSC', 1)</tt>
def send( command, *args )
- return $UDP_Sender.send( command, @host, @port, *args )
+ $UDP_Sender.send( command, @host, @port, *args )
+ self
end
# Encodes and sends a SynthDef to the scsynth server
@@ -90,6 +101,11 @@ def sc_path
def all
@@servers
end
+
+ # Clear the servers array
+ def clear_servers
+ @@servers.clear
+ end
# Return a server corresponding to the specified index of the registered servers array
def [](index)
@@ -3,11 +3,16 @@ class Synth < Node
def initialize( name, opts = {} )
super( name, opts.delete(:servers) )
- @servers.each{ |s| s.send '/s_new', *([@name, self.id, 0, 1] + opts.to_a.flatten) }
+ @servers.each{ |s| s.send 9, @name, self.id, 0, 1, *opts.to_a.flatten } #Node?
end
def set( args = {} )
- @servers.each{ |s| s.send '/n_set', *([self.id] + args.to_a.flatten) }
+ @servers.each{ |s| s.send 15, self.id, *args.to_a.flatten }
+ self
+ end
+
+ def free
+ @servers.each{ |s| s.send 9, self.id }
self
end
@@ -1,49 +0,0 @@
-require 'rexml/document'
-require 'yaml'
-include REXML
-
-
-dir = File.expand_path(File.dirname(__FILE__))
-file = File.new File.join( dir, 'ugendefs.xml')
-# p file.read
-doc = Document.new( file )
-
-
-ugens = {}
-
-doc.root.each_element('ugen') do |e|
- klass = e.attribute(:class).value
-
- rates = {}
-
- e.attribute(:rates).value.scan(/\w+/).each do |r|
- args = []
-
- e.each_element('arg') do |a|
- name = a.attribute( :name ).value.to_sym
- begin
- value = a.attribute( :def ).value.to_f
- rescue
- value = nil
- end
- args << [name, value].dup
- end
-
-
-
- rates[r.to_sym] = Array.new(args)
- end
-
- ugens[klass] = rates
-end
-
-puts u = ugens.to_yaml
-
-
-file = File.new("#{dir}/ugen_defs.yaml", "w")
-file.write( u )
-file.close
-
-
-
-
@@ -3330,9 +3330,7 @@ Vibrato:
- 0
WhiteNoise:
:control: []
-
:audio: []
-
Wrap:
:control:
- - :input
@@ -26,7 +26,7 @@ module BinaryOperations
BINARY.each_key do |op|
method_name = OP_SYMBOLS[op] || op #get a 'safe' method name for the method to add
eval "def ugen_#{method_name}( input )
- return BinaryOpUGen.new(:#{op}, self, input) if input.ugen?
+ return BinaryOpUGen.new(:#{op}, self, input) if input.ugen? or (self.kind_of?( Ugen ) and (input.kind_of?( Numeric ) or input.kind_of?( Array )))
return self.original_#{method_name}( input ) if self.respond_to?( :original_#{method_name} )
raise ArgumentError.new( %(Expected \#\{input\} to be an Ugen) )
end"
@@ -9,7 +9,7 @@ def self.define_ugen(name, rates)
rates.delete_if{ |key, value| key == :demand } #I don't know what to do with these
methods = rates.collect{ |r| ":#{rate_name[r.first]}" }.join(', ')
-
+ # TODO: Get rid of meta-metaprogramming (named args)
klass = "class #{name} < Ugen\nclass << self\n" +
rates.collect do |r|
new_args = ( [r.first] + r.last.collect{|a|a.first} ).join(', ')
@@ -1,6 +0,0 @@
-module Scruby
- module Control
- class Metro
- end
- end
-end
View
@@ -107,3 +107,21 @@ def encode
end
end
+
+class Symbol
+ def to_proc
+ proc { |obj, *args| obj.send(self, *args) }
+ end
+end
+
+# Musical math
+class Fixnum
+ def freq
+ 440 * (2 ** ((self - 69) * 0.083333333333) )
+ end
+end
+
+
+
+
+
View
@@ -1 +0,0 @@
-date
@@ -138,6 +138,11 @@
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
@@ -180,9 +185,7 @@
@audio.stub!( :* ).and_return( bin_op_ugen )
MulAdd.new( @audio, @audio, 0 ).should == bin_op_ugen
end
-
- it "should accept array"
-
+
end
end
View
@@ -34,13 +34,17 @@
end
it "should send /s_new message" do
- @servers.each{ |s| s.should_receive(:send).with( '/s_new', ['synth', 2002, 0, 1, :attack, 10] ) }
- s = Synth.new( :synth, :attack => 10, :servers => @servers )
+ servers = (0..3).map{ s = mock( 'server') }
+ servers.each{ |s| s.should_receive(:send).with( 9, 'synth', 2002, 0, 1, :attack, 10 ) }
+ s = Synth.new( :synth, :attack => 10, :servers => servers )
end
it "should send set message and return self" do
- @servers.each{ |s| s.should_receive(:send).with( '/n_set', [2001, :attack, 20] ) }
- @synth.set( :attack => 20 ).should == @synth
+ s = mock('server')
+ s.should_receive(:send).with( 15, 2002, :attack, 20 )
+ s.should_receive(:send).with( 9, "synth", 2002, 0, 1 )
+ synth = Synth.new( :synth, :servers => s)
+ synth.set( :attack => 20 ).should == synth
end
-
+
end
No changes.
@@ -2,6 +2,7 @@
require 'yaml'
require "#{SCRUBY_DIR}/audio/ugens/ugen_operations"
+require "#{SCRUBY_DIR}/audio/ugens/ugen"
require "#{SCRUBY_DIR}/extensions"
include Scruby
@@ -99,6 +100,20 @@ class Klass; def +( input ); end; end
(1.0 + @ugen).inputs.should == [1.0, @ugen]
(1 + @ugen).operator.should == :+
end
+
+ it "ugen should sum numeric" do
+ ugen = Ugen.new( :audio )
+ sum = (ugen + 1)
+ sum.should be_kind_of(BinaryOpUGen)
+ sum.inputs.should == [ugen, 1]
+ end
+
+ it 'ugen should sum array' do
+ ugen = Ugen.new( :audio )
+ sum = (ugen + [1,2])
+ sum.should be_kind_of(BinaryOpUGen)
+ sum.inputs.should == [ugen, [1,2]]
+ end
end
describe Array do
View
@@ -310,7 +310,6 @@ def kr( freq=440.0, phase=0.0 )
@sin.send(:collect_input_specs).flatten.collect { |e| e.encode }
end
-
it "should encode class name" do
@sin.encode[0..6].should == @encoded[0..6]
end
@@ -1,3 +0,0 @@
-def hola
-
-end

0 comments on commit fea3df3

Please sign in to comment.