Permalink
Browse files

refactored module structure, removed Audio module

  • Loading branch information...
1 parent d13a17c commit 54ff5c165484a8067a33f376eccf407f13ba810d Macario committed Jul 27, 2009
View
@@ -49,21 +49,21 @@ doc/created.rid
doc/files/README_rdoc.html
doc/files/bin/live_session_rb.html
doc/files/lib/live/session_rb.html
-doc/files/lib/scruby/audio/control_name_rb.html
-doc/files/lib/scruby/audio/env_rb.html
-doc/files/lib/scruby/audio/node_rb.html
-doc/files/lib/scruby/audio/server_rb.html
-doc/files/lib/scruby/audio/synth_rb.html
-doc/files/lib/scruby/audio/synthdef_rb.html
-doc/files/lib/scruby/audio/ugens/env_gen_rb.html
-doc/files/lib/scruby/audio/ugens/in_out_rb.html
-doc/files/lib/scruby/audio/ugens/multi_out_ugens_rb.html
-doc/files/lib/scruby/audio/ugens/operation_indices_yaml.html
-doc/files/lib/scruby/audio/ugens/operation_ugens_rb.html
-doc/files/lib/scruby/audio/ugens/ugen_defs_yaml.html
-doc/files/lib/scruby/audio/ugens/ugen_operations_rb.html
-doc/files/lib/scruby/audio/ugens/ugen_rb.html
-doc/files/lib/scruby/audio/ugens/ugens_rb.html
+doc/files/lib/scruby/control_name_rb.html
+doc/files/lib/scruby/env_rb.html
+doc/files/lib/scruby/node_rb.html
+doc/files/lib/scruby/server_rb.html
+doc/files/lib/scruby/synth_rb.html
+doc/files/lib/scruby/synthdef_rb.html
+doc/files/lib/scruby/ugens/env_gen_rb.html
+doc/files/lib/scruby/ugens/in_out_rb.html
+doc/files/lib/scruby/ugens/multi_out_ugens_rb.html
+doc/files/lib/scruby/ugens/operation_indices_yaml.html
+doc/files/lib/scruby/ugens/operation_ugens_rb.html
+doc/files/lib/scruby/ugens/ugen_defs_yaml.html
+doc/files/lib/scruby/ugens/ugen_operations_rb.html
+doc/files/lib/scruby/ugens/ugen_rb.html
+doc/files/lib/scruby/ugens/ugens_rb.html
doc/files/lib/scruby/control/metro_rb.html
doc/files/lib/scruby/extensions_rb.html
doc/files/lib/scruby/typed_array_rb.html
@@ -84,39 +84,39 @@ extras/Ruby Live.tmbundle/Syntaxes/Ruby Live.tmLanguage
extras/Ruby Live.tmbundle/info.plist
lib/live/session.rb
lib/scruby.rb
-lib/scruby/audio/control_name.rb
-lib/scruby/audio/env.rb
-lib/scruby/audio/node.rb
-lib/scruby/audio/server.rb
-lib/scruby/audio/synth.rb
-lib/scruby/audio/synthdef.rb
-lib/scruby/audio/ugens/env_gen.rb
-lib/scruby/audio/ugens/in_out.rb
-lib/scruby/audio/ugens/multi_out_ugens.rb
-lib/scruby/audio/ugens/operation_indices.yaml
-lib/scruby/audio/ugens/operation_ugens.rb
-lib/scruby/audio/ugens/ugen.rb
-lib/scruby/audio/ugens/ugen_defs.yaml
-lib/scruby/audio/ugens/ugen_operations.rb
-lib/scruby/audio/ugens/ugens.rb
+lib/scruby/control_name.rb
+lib/scruby/env.rb
+lib/scruby/node.rb
+lib/scruby/server.rb
+lib/scruby/synth.rb
+lib/scruby/synthdef.rb
+lib/scruby/ugens/env_gen.rb
+lib/scruby/ugens/in_out.rb
+lib/scruby/ugens/multi_out_ugens.rb
+lib/scruby/ugens/operation_indices.yaml
+lib/scruby/ugens/operation_ugens.rb
+lib/scruby/ugens/ugen.rb
+lib/scruby/ugens/ugen_defs.yaml
+lib/scruby/ugens/ugen_operations.rb
+lib/scruby/ugens/ugens.rb
lib/scruby/extensions.rb
lib/scruby/typed_array.rb
script/console
script/destroy
script/generate
-spec/audio/env_gen_specs.rb
-spec/audio/in_out_spec.rb
-spec/audio/integration_spec.rb
-spec/audio/lib_spec.rb
-spec/audio/multiout_ugen_spec.rb
-spec/audio/node_spec.rb
-spec/audio/operation_ugens_spec.rb
-spec/audio/server_spec.rb
-spec/audio/synth_spec.rb
-spec/audio/synthdef_spec.rb
-spec/audio/ugen_operations_spec.rb
-spec/audio/ugen_spec.rb
-spec/audio/ugens_spec.rb
+spec/env_gen_specs.rb
+spec/in_out_spec.rb
+spec/integration_spec.rb
+spec/lib_spec.rb
+spec/multiout_ugen_spec.rb
+spec/node_spec.rb
+spec/operation_ugens_spec.rb
+spec/server_spec.rb
+spec/synth_spec.rb
+spec/synthdef_spec.rb
+spec/ugen_operations_spec.rb
+spec/ugen_spec.rb
+spec/ugens_spec.rb
spec/control/timer_spec.rb
spec/env_spec.rb
spec/extensions_spec.rb
View
@@ -39,29 +39,28 @@ module Scruby
require "scruby/core_ext/symbol"
require "scruby/core_ext/typed_array"
require "scruby/core_ext/delegator_array"
-require "scruby/audio/env"
-require "scruby/audio/control_name"
+require "scruby/env"
+require "scruby/control_name"
-require "scruby/audio/ugens/ugen"
-require "scruby/audio/ugens/ugen_operations"
-require "scruby/audio/ugens/multi_out_ugens"
-require "scruby/audio/ugens/in_out"
+require "scruby/ugens/ugen"
+require "scruby/ugens/ugen_operations"
+require "scruby/ugens/multi_out_ugens"
+require "scruby/ugens/in_out"
-require "scruby/audio/ugens/operation_ugens"
+require "scruby/ugens/operation_ugens"
-require "scruby/audio/ugens/ugens"
-require "scruby/audio/synthdef"
+require "scruby/ugens/ugens"
+require "scruby/synthdef"
-require "scruby/audio/server"
-require "scruby/audio/ugens/env_gen"
+require "scruby/server"
+require "scruby/ugens/env_gen"
-require "scruby/audio/node"
-require "scruby/audio/synth"
-require "scruby/audio/bus"
-require "scruby/audio/buffer"
+require "scruby/node"
+require "scruby/synth"
+require "scruby/bus"
+require "scruby/buffer"
include Scruby
-include Audio
include Ugens
View
Binary file not shown.
View
@@ -0,0 +1,153 @@
+module Scruby
+ def expand_path path
+ path = "~/Scruby/#{ path }" unless path.match %r{^(?:/|~)}
+ File.expand_path path
+ end
+
+ class Buffer
+ # readNoUpdate
+ # loadCollection
+ # sendCollection
+ # streamCollection
+ # loadToFloatArray
+ # getToFloatArray
+ # set
+ # setn
+ # get
+ # getn
+ # fill
+ # normalize
+ # gen
+ # sine1
+ # ...
+ # copy
+ # copyData
+ # query
+ # updateInfo
+ # queryDone
+ # printOn
+ # play
+ # duration
+ # asBufWithValues
+
+ attr_reader :server
+ attr_accessor :path, :frames, :channels, :rate
+
+ def read path, file_start = 0, frames = -1, buff_start = 0, leave_open = false, &message
+ # @on_info = message
+ message ||= ["/b_query", buffnum]
+ @server.send "/b_read", buffnum, expand_path(path), file_start, frames, buff_start, leave_open, message.value(self)
+ self
+ end
+
+ def read_channel path, file_start = 0, frames = -1, buff_start = 0, leave_open = false, channels = [], &message
+ message ||= 0
+ @server.send *(["/b_ReadChannel", buffnum, expand_path(path), start, frames, buff_start, leave_open] + channels << message.value(self))
+ self
+ end
+
+ def close &message
+ message ||= 0
+ @server.send '/b_close', buffnum, message.value(self)
+ self
+ end
+
+ def zero &message
+ message ||= 0
+ @server.send '/b_zero', buffnum, message.value(self)
+ self
+ end
+
+ def cue_sound_file path, start = 0, &message
+ message ||= 0
+ @server.send "/b_read", buffnum, expand_path(path), start, @frames, 0, 1, message.value(self)
+ self
+ end
+
+ def write path = nil, format = 'aiff', sample_format = 'int24', frames = -1, start = 0, leave_open = false, &message
+ message ||= 0
+ path ||= "#{ DateTime.now }.#{ format }"
+ @server.send "/b_write", buffnum, expand_path(path), format, sample_format, frames, start, leave_open, message.value(self)
+ self
+ end
+
+ def initialize server, frames = -1, channels = 1
+ @server, @frames, @channels = server, frames, channels
+ end
+
+ def allocate &message
+ message ||= 0
+ @server.allocate :buffers, self
+ @server.send '/b_alloc', buffnum, frames, channels, message.value(self)
+ self
+ end
+
+ def buffnum
+ @server.buffers.index self
+ end
+ alias :as_ugen_input :buffnum
+ alias :index :buffnum
+ # alias :as_control_input :buffnum
+
+ def free &message
+ message ||= 0
+ @server.send "/b_free", buffnum, message.value(self)
+ @server.buffers.delete self
+ end
+
+ # :nodoc:
+ def allocate_and_read path, start, frames, &message
+ @server.allocate :buffers, self
+ message ||= ["/b_query", buffnum]
+ @server.send "/b_allocRead", buffnum, @path = expand_path(path), start, frames, message.value(self)
+ self
+ end
+
+ def allocate_read_channel path, start, frames, channels, &message
+ @server.allocate :buffers, self
+ message ||= ["/b_query", buffnum]
+ @server.send *(["/b_allocReadChannel", buffnum, expand_path(path), start, frames] + channels << message.value(self))
+ self
+ end
+
+ class << self
+ def allocate server, frames = -1, channels = 1, &message
+ new(server, frames, channels).allocate &message
+ end
+
+ def cue_sound_file server, path, start, channels = 2, buff_size = 32768, &message
+ allocate server, buff_size, channels do |buffer|
+ message ||= 0
+ ['/b_read', buffer.buffnum, expand_path(path), start, buff_size, 0, true, message.value(buffer)]
+ end
+ end
+
+ # Allocate a buffer and immediately read a soundfile into it.
+ def read server, path, start = 0, frames = -1, &message
+ buffer = new server, &message
+ buffer.allocate_and_read expand_path(path), start, frames
+ end
+
+ def read_channel server, path, start = 0, frames = -1, channels = [], &message
+ new(server, frames, channels).allocate_read_channel expand_path(path), start, frames, channels, &message
+ end
+
+ def alloc_consecutive buffers, server, frames = -1, channels = 1, &message
+ buffers = Array.new(buffers){ new server, frames, channels }
+ server.allocate :buffers, buffers
+ message ||= 0
+ buffers.each do |buff|
+ server.send '/b_alloc', buff.buffnum, frames, channels, message.value(buff)
+ end
+ end
+
+ named_arguments_for :allocate, :read, :cue_sound_file, :alloc_consecutive, :read_channel
+
+ # readNoUpdate
+ # loadCollection
+ # sendCollection
+ # loadDialog
+ end
+ end
+end
+
View
@@ -0,0 +1,67 @@
+module Scruby
+
+ class Bus
+ attr_reader :server, :rate, :channels, :main_bus
+
+ def initialize server, rate, channels = 1, main_bus = self, hardware_out = false
+ @server, @rate, @channels, @main_bus, @hardware_out = server, rate, channels, main_bus, hardware_out
+ end
+
+ def index
+ @index ||= @server.__send__("#{ @rate }_buses").index(self)
+ end
+
+ def free
+ @index = nil
+ @server.__send__("#{ @rate }_buses").delete(self)
+ end
+
+ def to_map
+ raise SCError, 'Audio buses cannot be mapped' if rate == :audio
+ "c#{ index }"
+ end
+
+ def audio_out?
+ index < @server.instance_variable_get(:@opts)[:audio_outputs]
+ end
+
+ # Messaging
+ def set *args
+ args.flatten!
+ message_args = []
+ (index...channels).to_a.zip(args) do |chan, val|
+ message_args.push(chan).push(val) if chan and val
+ end
+ if args.size > channels
+ warn "You tried to set #{ args.size } values for bus #{ index } that only has #{ channels } channels, extra values are ignored."
+ end
+ @server.send '/c_set', *message_args
+ end
+
+ def fill value, channels = @channels
+ if channels > @channels
+ warn "You tried to set #{ channels } values for bus #{ index } that only has #{ @channels } channels, extra values are ignored."
+ end
+ @server.send '/c_fill', index, channels.min(@channels), value
+ end
+
+ class << self
+ private :new
+
+ def control server, channels = 1
+ buses = [new(server, :control, channels)]
+ buses.push new(server, :control, channels, buses.first) while buses.size < channels
+ server.allocate :control_buses, buses
+ buses.first
+ end
+
+ def audio server, channels = 1
+ buses = [new(server, :audio, channels)]
+ buses.push new(server, :audio, channels, buses.first) while buses.size < channels
+ server.allocate :audio_buses, buses
+ buses.first
+ end
+ end
+
+ end
+end
Oops, something went wrong.

0 comments on commit 54ff5c1

Please sign in to comment.