Skip to content

Commit

Permalink
Encoding seems to be working, have to try with sdef default values
Browse files Browse the repository at this point in the history
  • Loading branch information
Macario committed Nov 13, 2008
1 parent bda79b0 commit 7b71da4
Show file tree
Hide file tree
Showing 25 changed files with 275 additions and 1,940 deletions.
33 changes: 32 additions & 1 deletion README
@@ -1,3 +1,34 @@


Ruby has operation precendence

== LICENSE:

(The MIT License)

Copyright (c) 2008 Macario Ortega

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

== NOTES

Ruby has operation precendence



Binary file removed lib/.DS_Store
Binary file not shown.
28 changes: 21 additions & 7 deletions lib/scruby.rb
Expand Up @@ -14,21 +14,35 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++

require 'rubygems'
require 'ruby2ruby'
require "named_arguments"
require 'osc'
require 'yaml'

LIB_DIR = File.join( File.expand_path(File.dirname(__FILE__) ), 'scruby' )

$:.unshift( File.dirname(__FILE__) ) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))

require 'scruby/audio/ugens/ugen_operations'
require 'scruby/audio/ugens/ugen'
require 'scruby/audio/ugens/operation_ugens'
require 'scruby/audio/control_name'
require 'scruby/audio/synthdef'
require 'scruby/extensions'

require "scruby/audio/ugens/ugen_operations"
require "scruby/audio/ugens/ugen"
require "scruby/audio/ugens/multi_out_ugens"
require "scruby/audio/ugens/in_out"

require "scruby/audio/ugens/operation_ugens"
require "scruby/audio/ugens/ugen"

require "scruby/audio/ugens/ugens"
require "scruby/audio/control_name"
require "scruby/audio/synthdef"
require "scruby/extensions"

require "scruby/audio/server"

include Scruby
include Audio
include Ugens
include OperationUgens

19 changes: 16 additions & 3 deletions lib/scruby/audio/env.rb
@@ -1,5 +1,4 @@
class Env

attr_accessor :levels, :times, :curves, :release_node, :array
SHAPE_NAMES = {
:step => 0,
Expand Down Expand Up @@ -63,7 +62,7 @@ def asr( attackTime=0.01, sustainLevel=1.0, releaseTime=1.0, curve = -4.0 )


def to_array
*contents = levels[0], times.size, @release_node || -99, @loop_node || -99
*contents = levels[0], times.size, release_node, loop_node
contents + levels[1..-1].wrap_and_zip( times, shape_numbers, curve_values ).flatten
end

Expand All @@ -78,6 +77,20 @@ def curve_values
curve.valid_ugen_input? ? curve : 0
end
end

def release_node
@release_node ||= -99
end

def loop_node
@loop_node ||= -99
end

def valid_ugen_input? #returns true
true
end

def collect_constants #:nodoc:
end


end
53 changes: 53 additions & 0 deletions lib/scruby/audio/server.rb
@@ -0,0 +1,53 @@
module Scruby
module Audio
class Server < OSC::UDPServer
attr_reader :host, :port
@@sc_path = '/Applications/SuperCollider/scsynth'

def initialize( host = 'localhost', port = 57110)
@host, @port = host, port
end

alias :udp_send :send
def send( command, *args )
udp_send( OSC::Message.new( command, type_tag(args), *args ), 0, @host, @port )
end

def send_message( message )
udp_send( message, 0, @host, @port )
end

def type_tag(*args)
args = *args
args.collect{ |msg| OSC::Packet.tag( msg ) }.to_s
end

def send_synth_def( synth_def )
*blob = OSC::Blob.new( synth_def.encode ), 0
def_message = OSC::Message.new( '/d_recv', type_tag( blob ), *blob )
self.send_message( OSC::Bundle.new( nil, def_message ) )
end

def stop
end

def boot
raise SCError.new('Scsynth not found in the given path') unless File.exists?( @@sc_path )
end

class << self
def sc_path=( path )
@@sc_path = path
end

def sc_path
@@sc_path
end
end

class SCError < StandardError
end
end

end
end
2 changes: 1 addition & 1 deletion lib/scruby/audio/synthdef.rb
Expand Up @@ -58,7 +58,7 @@ def build_ugen_graph( function, control_names ) #:nodoc:
end

def collect_constants( children ) #:nodoc:
children.send( :collect_constants ).flatten.uniq
children.send( :collect_constants ).flatten.compact.uniq
end

end
Expand Down
62 changes: 5 additions & 57 deletions lib/scruby/audio/ugens/env_gen.rb
@@ -1,72 +1,20 @@
module Scruby
module Audio
module Ugens

class EnvGen < Ugen

class << self
def ar( envelope, gate = 1.0, levelScale = 1.0, levelBias = 0.0, timeScale = 1.0, doneAction = 0 )
def ar( envelope, gate = 1, levelScale = 1, levelBias = 0, timeScale = 1, doneAction = 0 )
new(:audio, gate, levelScale, levelBias, timeScale, doneAction, *envelope.to_array)
end

def kr( envelope, gate = 1.0, levelScale = 1.0, levelBias = 0.0, timeScale = 1.0, doneAction = 0 )
def kr( envelope, gate = 1, levelScale = 1, levelBias = 0, timeScale = 1, doneAction = 0 )
new(:control, gate, levelScale, levelBias, timeScale, doneAction, *envelope.to_array)
end
named_args_for :ar, :kr
end

end

class Done < Ugen
def self.kr( src )
self.init( :control, src )
end
end

class FreeSelf < Ugen
def self.kr( input )
self.init(:control, input)
input
end
end

class PauseSelf < Ugen
def self.kr(input)
self.init(:control, input)
input
end
end

class FreeSelfWhenDone < Ugen
def self.kr(src)
self.init(:control, src)
end
end

class PauseSelfWhenDone < Ugen
def self.kr(src)
self.init(:control, src)
end
end

class Pause < Ugen
def self.kr(gate, id)
self.init(:control, gate, id)
end
end

class Free < Ugen
def self.kr(trig, id)
self.init(:control, trig, id)
end
end

class Linen < Ugen
class << self
def kr( gate = 1.0, attackTime = 0.01, susLevel = 1.0, releaseTime = 1.0, doneAction = 0 )
new( :control, gate, attackTime, susLevel, releaseTime, doneAction )
end
named_args_for :kr
end
end

end
end
end
2 changes: 1 addition & 1 deletion lib/scruby/audio/ugens/multi_out_ugens.rb
Expand Up @@ -24,7 +24,7 @@ def initialize( rate, *channels )
end

def self.new( rate, *args )
super( rate, *args ).channels.compact #returns the channels but gets instantiated
super( rate, *args ).channels #returns the channels but gets instantiated
end

private
Expand Down
2 changes: 0 additions & 2 deletions lib/scruby/audio/ugens/operation_ugens.rb
Expand Up @@ -46,8 +46,6 @@ def special_index

class MulAdd < Ugen
def self.new( input, mul, add )


no_mul = ( mul == 1.0 )
minus = ( mul == -1.0 )
return add if mul == 0
Expand Down
2 changes: 1 addition & 1 deletion lib/scruby/audio/ugens/ugen.rb
Expand Up @@ -25,7 +25,7 @@ def muladd( mul, add )
end

def to_s
"#{self.class.to_s.split('::').last} inputs:[#{self.inputs.join(',')}]"
"#{self.class.to_s.split('::').last}"
end

def ugen?
Expand Down
54 changes: 27 additions & 27 deletions lib/scruby/audio/ugens/ugen_defs.yaml
Expand Up @@ -927,33 +927,33 @@ Dxrand:
- 1
- - :list
-
EnvGen:
:control:
- - :envelope
-
- - :gate
- 1
- - :levelScale
- 1
- - :levelBias
- 0
- - :timeScale
- 1
- - :doneAction
- 0
:audio:
- - :envelope
-
- - :gate
- 1
- - :levelScale
- 1
- - :levelBias
- 0
- - :timeScale
- 1
- - :doneAction
- 0
# EnvGen:
# :control:
# - - :envelope
# -
# - - :gate
# - 1
# - - :levelScale
# - 1
# - - :levelBias
# - 0
# - - :timeScale
# - 1
# - - :doneAction
# - 0
# :audio:
# - - :envelope
# -
# - - :gate
# - 1
# - - :levelScale
# - 1
# - - :levelBias
# - 0
# - - :timeScale
# - 1
# - - :doneAction
# - 0
ExpRand:
:scalar:
- - :lo
Expand Down
3 changes: 3 additions & 0 deletions lib/scruby/audio/ugens/ugen_operations.rb
Expand Up @@ -34,6 +34,9 @@ module BinaryOperations
end

module UnaryOperators



UNARY.each_key do |op|
eval "def #{op}; UnaryOpUgen.new(:#{op}, self); end"
end
Expand Down

0 comments on commit 7b71da4

Please sign in to comment.