Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically Removed Whitespace #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
== Scruby
== Scruby

Is a bare-bones SuperCollider livecoding library for Ruby, it provides comunication with a remote or local scsynth server and SynthDef creation with a
in a similar way to Sclang.

SynthDef creation and sending is robust but some features are not implemented such as SynthDef variations and others I may not be aware of.

livecode.rb executable is located in the bin directory and a TextMate bundle included in extras permits livecoding from TextMate, comunication is
livecode.rb executable is located in the bin directory and a TextMate bundle included in extras permits livecoding from TextMate, comunication is
thrugh *nix pipes. Similar functionality shouldn't be too dificult to implement from Emacs or Vim.

== Install
Expand All @@ -18,10 +18,10 @@ Scruby is just a SuperCollider client so SC must be installed on the system. The
== Usage

require 'scruby'

s = Server.new
s.boot

SynthDef.new :fm do |freq, amp, dur|
mod_env = EnvGen.kr Env.new( d(600, 200, 100), d(0.7,0.3) ), 1, :timeScale => dur
mod = SinOsc.ar freq * 1.4, :mul => mod_env
Expand All @@ -32,12 +32,12 @@ Scruby is just a SuperCollider client so SC must be installed on the system. The
end.send

Synth.new :fm, :freq => 220, :amp => 0.4, :dur => 1


To start a live coding session:

$ live

See http://github.com/maca/live


Expand Down
2 changes: 1 addition & 1 deletion TODO.markdown
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
**Array workarrounds**

* Buffer as Ugen input
* Buffer as Ugen input
6 changes: 3 additions & 3 deletions examples/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
s.stop


sdef = SynthDef.new :perc, :values => [456, 0.34, 0.45] do |freq, amp, a, b|
sdef = SynthDef.new :perc, :values => [456, 0.34, 0.45] do |freq, amp, a, b|
dur = a
amp = amp * 0.25
freq = freq * 0.05
Expand All @@ -40,7 +40,7 @@
sleep 0.05
test = Synth.new :perc, :freq => 1000, :amp => 0.5, :dur => rand

sdef = SynthDef.new :perc, :values => [456, 0.34, 0.45] do |freq, amp, a, b|
sdef = SynthDef.new :perc, :values => [456, 0.34, 0.45] do |freq, amp, a, b|
dur = a
amp = amp
freq = freq * 0.1
Expand All @@ -53,7 +53,7 @@
sleep 0.05
test = Synth.new :perc, :freq => 1000, :amp => 0.5, :dur => rand

sdef = SynthDef.new :perc, :values => [456, 0.34, 0.45] do |freq, amp, a, b|
sdef = SynthDef.new :perc, :values => [456, 0.34, 0.45] do |freq, amp, a, b|
gate = EnvGen.kr Env.perc(0,0.1)
env = EnvGen.kr Env.asr( 0.1, 4, 1 ), gate, :doneAction => 2
sig = DelayC.ar( SinOsc.ar(freq), 4, SinOsc.ar( SinOsc.ar( SinOsc.ar( 2 ) ) ) )
Expand Down
4 changes: 2 additions & 2 deletions lib/scruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# 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/>.
#++
Expand Down
29 changes: 14 additions & 15 deletions lib/scruby/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def expand_path path
path = "~/Scruby/#{ path }" unless path.match %r{^(?:/|~)}
File.expand_path path
end

class Buffer
# readNoUpdate
# loadCollection
Expand Down Expand Up @@ -32,45 +32,45 @@ class Buffer

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
Expand All @@ -88,7 +88,7 @@ def buffnum
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)
Expand All @@ -102,7 +102,7 @@ def allocate_and_read path, start, frames, &message
@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]
Expand All @@ -114,24 +114,24 @@ 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
Expand All @@ -150,4 +150,3 @@ def alloc_consecutive buffers, server, frames = -1, channels = 1, &message
end
end
end

28 changes: 14 additions & 14 deletions lib/scruby/bus.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
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!
Expand All @@ -33,35 +33,35 @@ def set *args
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."
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."
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
6 changes: 3 additions & 3 deletions lib/scruby/core_ext/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def to_array; self; end
def encode_floats #:nodoc:
[self.size].pack('n') + self.pack('g*') #TODO: Deprecate
end

def peel!
self.replace self.first if self.first.kind_of? Array if self.size == 1
end

def peel
self.dup.peel! || self
end

private
def collect_constants #:nodoc:
self.collect{ |e| e.send( :collect_constants ) }
Expand Down
12 changes: 6 additions & 6 deletions lib/scruby/core_ext/delegator_array.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class DelegatorArray < Array

def method_missing meth, *args, &block
return self.map! { |item| item.send meth, *args, &block }
end

def to_da; self; end
def to_a; Array.new self; end

Expand All @@ -12,18 +12,18 @@ def to_a; Array.new self; end
binary_op meth, args
end
end

private
def binary_op op, inputs
return method_missing(op, inputs) unless inputs.kind_of? Array

results = self.class.new
self.zip(inputs).collect_with_index do |pair, index|
left, right = pair
next results.push(right) if index + 1 > self.size
next results.push(left) if index + 1 > inputs.size
next results.push(left) if index + 1 > inputs.size
results.push left.send(op, right)
end
end
results
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/scruby/core_ext/fixnum.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Musical math
class Fixnum
class Fixnum
def freq
440 * (2 ** ((self - 69) * 0.083333333333) )
end
Expand Down
4 changes: 2 additions & 2 deletions lib/scruby/core_ext/numeric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def min other
#:nodoc:
def collect_constants
self
end
end

#:nodoc:
def input_specs synthdef
[-1, synthdef.constants.index(self)]
Expand Down
2 changes: 1 addition & 1 deletion lib/scruby/core_ext/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Object
def to_array
[*self]
end

def to_proc
Proc.new{ self }
end
Expand Down
Loading