Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

all specs on green, switched to yet cleaner maca-ruby-osc gem

  • Loading branch information...
commit 7f8079b50edffe24de1ef4d4a694d7f54b99a98e 1 parent be73c99
@maca maca authored
View
2  Rakefile
@@ -16,7 +16,7 @@ $hoe = Hoe.spec 'scruby' do
self.rubyforge_name = self.name
self.extra_deps = [
['maca-arguments', '>= 0.6'],
- ['aberant-osc-ruby','>= 0.1.5']
+ ['maca-ruby-osc', '>= 0.3.1']
]
end
View
4 lib/scruby.rb
@@ -18,14 +18,14 @@
require 'date'
require 'rubygems'
require 'arguments'
-require 'osc-ruby'
+require 'ruby-osc'
require 'eventmachine'
require 'yaml'
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
module Scruby
- VERSION = '0.2.6.5'
+ VERSION = '0.2.6.7'
end
require "scruby/core_ext/object"
View
38 lib/scruby/server.rb
@@ -2,25 +2,21 @@
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
+ self.to_a.collect{ |pair| pair.collect{ |a| OSC.coerce_argument a } }
+ end
- class ::OSC::Message
- def initialize address, *args
- args.peel!
- @address = address
- @args = args.collect do |arg|
- case arg
- when Integer then OSCInt32.new arg
- when Float then OSCFloat32.new arg
- when String, Symbol then OSCString.new arg.to_s
- when true then OSCInt32.new 1
- when false then OSCInt32.new 0
- when Array then OSCBlob.new self.class.new(*arg).encode
- when OSCArgument then arg
- else
- raise TypeError.new("#{ arg } is not a valid Message argument.")
- end
- end
- end
+ Array.send(:include, OSC::OSCArgument)
+ Array.send( :define_method, :to_osc_type) do
+ Blob.new Message.new(*self).encode
end
class Server
@@ -53,7 +49,7 @@ def initialize opts = {}
@buffers = []
@control_buses = []
@audio_buses = []
- @client = SimpleClient.new host, port
+ @client = Client.new port, host
Bus.audio self, @opts[:audio_outputs] # register hardware buses
Bus.audio self, @opts[:audio_inputs]
self.class.all << self
@@ -111,7 +107,7 @@ def quit
# Sends an OSC command or +Message+ to the scsyth server.
# E.g. +server.send('/dumpOSC', 1)+
def send message, *args
- message = Message.new message, *args unless Packet === message
+ message = Message.new message, *args unless Message === message or Bundle === message
@client.send message
end
@@ -121,7 +117,7 @@ def send_bundle timestamp = nil, *messages
# Encodes and sends a SynthDef to the scsynth server
def send_synth_def synth_def
- send Bundle.new( nil, Message.new( '/d_recv', OSCBlob.new(synth_def.encode), 0 ) )
+ send Bundle.new( nil, Message.new('/d_recv', Blob.new(synth_def.encode), 0) )
end
# Allocates either buffer or bus indices, should be consecutive
View
17 lib/scruby/ticker.rb
@@ -1,13 +1,12 @@
module Scruby
- Thread.new do
- EventMachine.run do
- EM.set_quantum 5
-
- EM.error_handler do |e|
- puts e
- end
- end
- end
+ # Thread.new do
+ # EventMachine.run do
+ # EM.set_quantum 5
+ # EM.error_handler do |e|
+ # puts e
+ # end
+ # end
+ # end
# A timer will call a given block periodically. The period is specified in beats per minute.
class Ticker
View
2  spec/buffer_spec.rb
@@ -3,7 +3,7 @@
require 'date'
require 'arguments'
require 'tempfile'
-require 'osc-ruby'
+
require "scruby/buffer"
require "scruby/bus"
require "scruby/server"
View
2  spec/bus_spec.rb
@@ -1,7 +1,7 @@
require File.expand_path(File.dirname(__FILE__)) + "/helper"
require 'tempfile'
-require 'osc-ruby'
+
require "scruby/core_ext/numeric"
require "scruby/bus"
require "scruby/server"
View
4 spec/demand_spec.rb
@@ -24,10 +24,8 @@ class << self; public :new; end
end
it "should output proxies or single proxie" do
- @splatted ? @prox.each{ |prox| prox.should be_a(OutputProxy) } : @prox.should be_a(OutputProxy)
+ @splatted ? @prox.each{ |prox| prox.should be_a(OutputProxy) } : @prox.should( be_a(OutputProxy) )
end
-
-
end
shared_examples_for 'Demand with ar' do
View
2  spec/group_spec.rb
@@ -5,7 +5,7 @@
require "scruby/node"
require "scruby/group"
require 'scruby/bus'
-require 'osc-ruby'
+
require 'scruby/server'
require File.join( File.expand_path(File.dirname(__FILE__)), "server")
View
4 spec/helper.rb
@@ -2,6 +2,10 @@
require "spec"
require 'arguments'
require 'yaml'
+# require 'ruby-osc'
+# require 'osc-ruby'
+require "#{ File.dirname __FILE__ }/../../ruby-osc/lib/ruby-osc"
+
$:.unshift( File.dirname(__FILE__) + '/../lib' )
View
2  spec/node_spec.rb
@@ -3,7 +3,7 @@
require "scruby/core_ext/typed_array"
require "scruby/node"
require "scruby/bus"
-require 'osc-ruby'
+
require 'scruby/server'
require File.join( File.expand_path(File.dirname(__FILE__)), "server")
View
17 spec/server_spec.rb
@@ -2,7 +2,6 @@
require 'arguments'
require 'tempfile'
-require 'osc-ruby'
require 'scruby/node'
require 'scruby/core_ext/array'
require 'scruby/core_ext/typed_array'
@@ -26,7 +25,10 @@ def puts string
@output << string
string
end
-
+
+ def flush
+ @output = ''
+ end
end
class Scruby::Buffer
@@ -91,6 +93,10 @@ def == other
@server.quit
end
+ before do
+ @server.flush
+ end
+
it "should send dump" do
@server.send "/dumpOSC", 1
sleep 0.1
@@ -103,6 +109,13 @@ def == other
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
+ sleep 0.1
+ @server.output.should =~ %r{\[ "#bundle", 1, \n\s*\[ "/d_recv", DATA\[100\], 0 \]\n\]}
+ end
end
shared_examples_for 'allocator' do
View
2  spec/synth_spec.rb
@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__)) + "/helper"
-require 'osc-ruby'
+
require "scruby/core_ext/typed_array"
require "scruby/node"
require "scruby/bus"
View
62 test.live.rb
@@ -115,7 +115,7 @@
SynthDef.new :ring do |mod_freq, amp, buffnum|
gate = EnvGen.kr Env.perc(0, 0.2)
- sig = PlayBuf.ar buffnum, :rate => 1, :mul => SinOsc.ar(mod_freq, :mul => amp), :loop => 1.0
+ sig = PlayBuf.ar(buffnum, :rate => 1, :loop => 1.0) * SinOsc.ar(mod_freq, :mul => amp)
Out.ar 0, [sig, sig]
end.send
@@ -140,33 +140,47 @@
# Síntesis por FM
SynthDef.new :campana do |freq, amp, dur|
- gate = EnvGen.kr Env.perc(0, 0.2)
- mod_env = EnvGen.kr Env.new([600, 200, 100], [0.7,0.3].map{|v|v*dur}), gate
+ gate = EnvGen.kr Env.perc(0, 0.1)
+ mod_env = EnvGen.kr Env.new( d(600, 200, 100), d(0.7,0.3)*dur ), gate
mod = SinOsc.ar freq * 1.4, :mul => mod_env
sig = SinOsc.ar freq + mod
- env = EnvGen.kr Env.new( [0, 1, 0.6, 0.2, 0.1, 0 ], [0.001, 0.005, 0.3, 0.5, 0.7].map{|v|v*dur} ), gate, :doneAction => 2
+ # sig += SinOsc.ar(freq*0.5) + SinOsc.ar(freq)
+ env = EnvGen.kr Env.new( d(0, 1, 0.6, 0.2, 0.1, 0), d(0.001, 0.005, 0.3, 0.5, 0.7)*dur ), gate, :doneAction => 2
sig = sig * amp * env
- Out.ar [sig, sig]
+ Out.ar 0, [sig, sig]
end.send
-camp = Synth.new :campana, :freq => 200, :amp => 0.8, :dur => 5
+camp = Synth.new :campana, :freq => 220, :amp => 0.4, :dur => 5
+ticker = Ticker.new :tempo => 120*2
+ar = [200,400,600,1200,1100]
+ar = [2400,2600]
-# Chido
-SynthDef.new :wood_drum do |freq, amp, dur|
+ticker.block do |i|
+ Synth.new :campana, :freq => ar[rand(ar.size)], :amp => rand*0.1, :dur => 1
+end
+
+ticker.run
+
+ticker.stop
+
+s.stop
+
+
+SynthDef.new :scifi do |freq, amp, dur|
gate = EnvGen.kr Env.perc(0, 0.2)
mod_env = EnvGen.kr Env.new([1600, 200, 50, 90, 10], d(0.7,0.3,0.4,0.4)*dur ), gate
mod = SinOsc.ar freq * 0.6875, :mul => mod_env
sig = SinOsc.ar freq + mod
- env = EnvGen.kr Env.new( [0, 1, 0.6, 0.2, 0.1, 0 ], [0.1, 0.5, 0.5, 0.7, 0.9].map{|v|v*dur} ), gate, :doneAction => 2
+ env = EnvGen.kr Env.new( [0, 1, 0.6, 0.2, 0.1, 0 ], d(0.1, 0.5, 0.5, 0.7, 0.9)*dur ), gate, :doneAction => 2
sig = sig * amp * env
- Out.ar [sig, sig]
+ Out.ar 0, [sig, sig]
end.send
-camp = Synth.new :wood_drum, :freq => 184, :amp => 0.8, :dur => 10
-camp = Synth.new :wood_drum, :freq => 180, :amp => 0.8, :dur => 10
+camp = Synth.new :scifi, :freq => 1000, :amp => 0.1, :dur => 10
+camp = Synth.new :scifi, :freq => 200, :amp => 0.1, :dur => 10
s.stop
@@ -180,12 +194,12 @@
sig = SinOsc.ar freq + mod
env = EnvGen.kr Env.new( [0, 1, 0.6, 0.2, 0.1, 0 ], [0.1, 0.5, 0.5, 0.7, 0.9].map{|v|v*dur} ), gate, :doneAction => 2
sig = sig * amp * env
- Out.ar [sig, sig]
+ Out.ar 0, [sig, sig]
end.send
-camp = Synth.new :wood_drum, :freq => 184, :amp => 0.8, :dur => 100
-camp = Synth.new :wood_drum, :freq => 180, :amp => 0.8, :dur => 10
-camp = Synth.new :wood_drum, :freq => 180, :amp => 0.8, :dur => 1
+camp = Synth.new :wood_drum, :freq => 184, :amp => 0.2, :dur => 15
+camp = Synth.new :wood_drum, :freq => 180, :amp => 0.2, :dur => 9
+camp = Synth.new :wood_drum, :freq => 180, :amp => 0.2, :dur => 8
s.stop
@@ -218,6 +232,22 @@
+buffer = Buffer.read_channel s, "azteca/Olla percutiva, sampleos.wav", :channels => [0]
+
+SynthDef.new :granular do |bufnum|
+ trate = MouseY.kr 8, 1200, 1
+ clk = Impulse.ar trate
+ dur = 12 / trate
+ pos = MouseX.kr(0, BufDur.kr(bufnum)) + TRand.kr(0, 0.1, clk)
+ pan = WhiteNoise.kr 2, -1.0
+ sig = TGrains.ar 2, clk, bufnum, 1, pos, dur, pan, 0.1, 4
+ sig *= 15
+ Out.ar 0, sig
+end.send s
+
+g = Synth.new :granular, :bufnum => buffer.buffnum
+
+g.free
Please sign in to comment.
Something went wrong with that request. Please try again.