Permalink
Browse files

refactored Server class, better spec coverage

  • Loading branch information...
1 parent 47fcf7e commit cccff37be969ef43adb56e1456ed6e33aa4931f3 Macario committed Jul 15, 2009
View
@@ -1,12 +1,8 @@
#!/usr/bin/env ruby
-live_session_dir = File.join( File.expand_path(File.dirname(__FILE__) ), '..', 'lib', 'live' )
+live_session_dir = File.dirname(__FILE__) + '/../lib/live'
+require 'rubygems'
require 'tempfile'
-require "#{live_session_dir}/session"
-
+require "#{ live_session_dir }/session"
Live::Session.new
-
-
-
-
View
@@ -1,17 +1,14 @@
require 'tempfile'
-require 'rubygems'
require 'highline'
-require 'parse_tree'
-require 'ruby2ruby'
module Kernel
alias :l :lambda
# Calls Kernel#eval with the given args but catches posible errors
- def resilient_eval( *args )
+ def resilient_eval *args
begin
begin
- eval( *args )
+ eval *args
rescue SyntaxError => e
e
end
@@ -20,7 +17,7 @@ def resilient_eval( *args )
end
end
- def p( obj ) #:nodoc:
+ def p obj #:nodoc:
puts obj.to_live_output
end
@@ -35,11 +32,11 @@ def to_live_output
"\e[41m\e[33m#{self.inspect}\e[0m"
when Numeric, Symbol, TrueClass, FalseClass, NilClass
"\e[35m#{self.inspect}\e[0m"
- when Notice
+ when Live::Notice
"\e[42m\e[30m#{self}\e[0m"
- when Warning
+ when Live::Warning
"\e[43m\e[30m#{self}\e[0m"
- when Special
+ when Live::Special
"\e[44m\e[37m#{self}\e[0m"
when String
"\e[32m#{self.inspect}\e[0m"
@@ -53,11 +50,12 @@ def to_live_output
end
end
-class Notice < String; end
-class Warning < String; end
-class Special < String; end
module Live
+ class Notice < String; end
+ class Warning < String; end
+ class Special < String; end
+
class Pipe < Tempfile
def make_tmpname( *args )
"ruby_live.pipe"
@@ -70,8 +68,7 @@ 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: #{Dir.tmpdir}/ruby_live.pipe") ) if File.exist?( "#{Dir.tmpdir}/ruby_live.pipe" )
-
- p( Notice.new("Live Session") )
+ p Notice.new("Live Session")
get_binding
init_pipe
expect_input
@@ -103,15 +100,15 @@ def expect_input
end
# Expects a one char Symbol or String which will bind to a passed block so it can be called later with a keystroke
- def bind( key, &block )
+ def bind key, &block
@bindings = [] unless @bindings.instance_of?(Array)
block ||= Proc.new{}
@bindings[ key.to_s[0] ] = Ruby2Ruby.new.process( [:block, block.to_sexp.last] )
Notice.new( "Key '#{key}' is bound to an action")
end
# Evaluates a ruby expression within the @context Binding
- def evaluate( string = nil )
+ def evaluate string = nil
return resilient_eval( string, @context ) if string
end
@@ -123,20 +120,18 @@ def get_binding #:nodoc:
@context = binding
end
- def run_updates( code )
+ def run_updates code
source = ParseTree.new.parse_tree_for_string( code ).first
- final = []
+ final = []
while iter = source.assoc(:iter)
- source -= [iter]
+ source -= [iter]
final << [:block, iter.last] if iter[1].include?(:update)
end
evaluate( final.collect{ |exp| Ruby2Ruby.new.process(exp) }.join("\n") )
Notice.new('Update blocks evaluated')
end
- def update # Allmost a stub
- yield
- end
+ def update; yield end
alias :reaload! :get_binding
end
View
@@ -29,8 +29,14 @@ module Scruby
VERSION = '0.1'
end
-require "scruby/typed_array"
-require "scruby/extensions"
+require "scruby/core_ext/object"
+require "scruby/core_ext/array"
+require "scruby/core_ext/fixnum"
+require "scruby/core_ext/numeric"
+require "scruby/core_ext/proc"
+require "scruby/core_ext/string"
+require "scruby/core_ext/symbol"
+require "scruby/core_ext/typed_array"
require "scruby/audio/ugens/ugen"
require "scruby/audio/ugens/ugen_operations"
@@ -50,13 +56,13 @@ module Scruby
require "scruby/audio/node"
require "scruby/audio/synth"
+require "scruby/audio/buffer"
+
+
include Scruby
include Audio
include Ugens
-class Notice < String; end
-class Warning < String; end
-class Special < String; end
View
@@ -0,0 +1,124 @@
+module Scruby
+ class Buffer
+
+
+ # allocReadChannel
+
+ # allocReadMsg
+ # alloc ReadCannelMsg
+ # read
+ # readChannel
+ # readNoUpdate
+ # readMsg
+ # readChannelMsg
+ # cueSoundFile
+ # cueSoundFilMsg
+ # loadCollection
+ # sendCollection
+ # streamCollection
+ # loadToFloatArray
+ # getToFloatArray
+ # write
+ # writeMsg
+ # free
+ # zero
+ # zeroMsg
+ # set
+ # setMsg
+ # setn
+ # setnMsgArgs
+ # setnMsg
+ # get
+ # getMsg
+ # getn
+ # getnMsg
+ # fill
+ # fillMsg
+ # normalize
+ # gen
+ # genMsg
+ # sine1
+ # ...
+ # copy
+ # copyData
+ # copyMsg
+ # close
+ # closeMsg
+ # query
+ # updateInfo
+ # cache
+ # uncache
+ # queryDone
+ # printOn
+ # play
+ # duration
+ # asUgenInput
+ # asControlInput
+ # asBufWithValues
+ # readMsg { arg argpath, fileStartFrame = 0, numFrames,
+ # bufStartFrame = 0, leaveOpen = false, completionMessage;
+ # path = argpath;
+ # ^["/b_read", bufnum, path, fileStartFrame, numFrames ? -1,
+ # bufStartFrame, leaveOpen.binaryValue, completionMessage.value(this)]
+ # // doesn't set my numChannels etc.
+ # }
+
+ attr_reader :server
+ attr_accessor :path, :frames, :channels, :rate
+
+ def initialize server, frames = -1, channels = 1
+ @server, @frames, @channels = server, frames, channels
+ @server.allocate_buffers self
+ end
+
+ def read path, file_start = 0, frames = -1, buf_start = 0, leave_open = false
+ message = Message.new "/b_read", bufnum, path, file_start, frames, buf_start, leave_open.to_i# , *Blob.new('/b_query', buf.bufnum)
+ self
+ end
+
+ def allocate &message
+ @server.send_message Message.new( '/b_alloc', bufnum, frames, channels, *Blob.new( message.call(self) ) )
+ end
+
+ def bufnum
+ @bufnum ||= @server.buffers.index self
+ end
+
+ # :nodoc:
+ def allocate_and_read path, start, frames, &completion
+ @path = path
+ @server.send "/b_allocRead", bufnum# , path, start, frames, yield(self)
+ self
+ end
+
+ class << self
+ def read server, path, start = 0, frames = -1, &action
+ buffer = new server, &action
+ buffer.allocate_and_read( path, start, frames ){ |buf| ["/b_query", buf.bufnum] }
+ end
+
+ def allocate server, frames = -1, channels = 1
+ buffer = new server, frames, channels
+ # buffer.rate = server.rate
+ buffer.alloc
+ end
+
+ named_arguments_for :read
+
+ # alloc
+ # allocConsecutive
+ # readChannel
+ # readNoUpdate
+ # cueSoundFile
+ # loadCollection
+ # sendCollection
+ # freeAllinitServerCache
+ # initServerCache
+ # clearServerCaches
+ # cachedBuffersDo
+ # cachedBufferAt
+ # loadDialog
+ end
+ end
+end
+
@@ -19,10 +19,6 @@ def rate_from_name name
def non_control?
@rate == :noncontrol
end
-
- def valid_ugen_input?
- true
- end
end
end
end
View
@@ -66,14 +66,14 @@ def to_array
end
def shape_numbers
- curves.collect do |curve|
- curve.valid_ugen_input? ? 5 : SHAPE_NAMES[curve]
+ curves.collect do |curve|
+ Ugen.valid_input?( curve ) ? 5 : SHAPE_NAMES[curve]
end
end
def curve_values
- curves.collect do |curve|
- curve.valid_ugen_input? ? curve : 0
+ curves.collect do |curve|
+ Ugen.valid_input?( curve ) ? curve : 0
end
end
@@ -85,10 +85,6 @@ def loop_node
@loop_node ||= -99
end
- def valid_ugen_input? #returns true
- true
- end
-
def collect_constants #:nodoc:
end
end
Oops, something went wrong.

0 comments on commit cccff37

Please sign in to comment.