Class: Scruby::Ugens::Ugen
Overview
All ugens inherit from this “abstract” class
Creation
Ugens are usually instantiated inside an “ugen graph” or the block passed when creating a SynthDef using either the ar, kr, ir or new methods wich will determine the rate.
* ar: audio rate
* kr: control rate
* ir: scalar rate
* new: demand rate
Not all the ugens provide all the rates
Two ugens inside an ugen graph:
SynthDef.new('simple'){ Out.ar(0, SinOsc.ar) }
# Out and SinOsc are both ugens
Passing arguments when creating
Usually when instantiating an ugen the arguments can be passed in order:
Pitch.kr(0, 220, 80, ...)
Or using a hash where the keys are symbols corresponding to the argument name.
Pitch.kr( :initFreq => 220, :execFreq => 300 )
Or a combination of both ways:
Pitch.kr(0, 220, :execFreq => 300)
Arguments not passed in either way will resort to default
Defining ugens
This named arguments functionality is provided for all the default Ugens but can be provided when defining a new Ugen by calling #named_arguments_for
passing a symbol with the name of a defined method:
class Umaguma < Ugen
class << self
def ar(karma = 200, pitch = 20, rate = 200)
...
end
named_arguments_for :ar
end
end
For more info and limitations on named arguments check the gem: github.com/maca/arguments
Otherwise usage is pretty the same as in SuperCollider
TODO: Provide a way of getting the argument names and default values
Direct Known Subclasses
Balance2, BasicOpUgen, BiPanB2, BufRd, BufWr, Control, DecodeB2, Demand, DiskIn, DiskOut, EnvGen, In, MulAdd, Out, OutputProxy, Pan2, Pan4, PanAz, PanB, PanB2, PlayBuf, RecordBuf, Rotate2, ScopeOut, TGrains, Tap, VDiskIn
Constant Summary collapse
- RATES =
:scalar, :trigger, :demand, :control, :audio
- E_RATES =
:scalar, :control, :audio, :demand
- VALID_INPUTS =
Numeric, Array, Ugen, Env, ControlName
- @@synthdef =
nil
Instance Attribute Summary collapse
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#output_index ⇒ Object
readonly
Returns the value of attribute output_index.
-
#rate ⇒ Object
readonly
Returns the value of attribute rate.
-
#special_index ⇒ Object
readonly
Returns the value of attribute special_index.
Class Method Summary collapse
- .params ⇒ Object
-
.synthdef ⇒ Object
:nodoc:.
-
.synthdef=(synthdef) ⇒ Object
:nodoc:.
- .valid_input?(obj) ⇒ Boolean
Instance Method Summary collapse
- #==(other) ⇒ Object
- #encode ⇒ Object
-
#initialize(rate, *inputs) ⇒ Ugen
constructor
A new instance of Ugen.
-
#muladd(mul, add) ⇒ Object
Instantiate a new MulAdd passing self and the multiplication and addition arguments.
Constructor Details
#initialize(rate, *inputs) ⇒ Ugen
Returns a new instance of Ugen.
64 65 66 67 68 69 70 |
# File 'lib/scruby/ugens/ugen.rb', line 64 def initialize rate, *inputs @rate, @inputs = rate, inputs.compact @special_index ||= 0 @output_index ||= 0 @channels ||= [1] @index = add_to_synthdef || 0 end |
Instance Attribute Details
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
56 57 58 |
# File 'lib/scruby/ugens/ugen.rb', line 56 def channels @channels end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
56 57 58 |
# File 'lib/scruby/ugens/ugen.rb', line 56 def index @index end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
56 57 58 |
# File 'lib/scruby/ugens/ugen.rb', line 56 def inputs @inputs end |
#output_index ⇒ Object (readonly)
Returns the value of attribute output_index.
56 57 58 |
# File 'lib/scruby/ugens/ugen.rb', line 56 def output_index @output_index end |
#rate ⇒ Object (readonly)
Returns the value of attribute rate.
56 57 58 |
# File 'lib/scruby/ugens/ugen.rb', line 56 def rate @rate end |
#special_index ⇒ Object (readonly)
Returns the value of attribute special_index.
56 57 58 |
# File 'lib/scruby/ugens/ugen.rb', line 56 def special_index @special_index end |
Class Method Details
.params ⇒ Object
166 167 168 |
# File 'lib/scruby/ugens/ugen.rb', line 166 def params {} end |
.synthdef ⇒ Object
:nodoc:
158 159 160 |
# File 'lib/scruby/ugens/ugen.rb', line 158 def synthdef #:nodoc: @@synthdef end |
.synthdef=(synthdef) ⇒ Object
:nodoc:
162 163 164 |
# File 'lib/scruby/ugens/ugen.rb', line 162 def synthdef= synthdef #:nodoc: @@synthdef = synthdef end |
.valid_input?(obj) ⇒ Boolean
151 152 153 154 155 156 |
# File 'lib/scruby/ugens/ugen.rb', line 151 def valid_input? obj case obj when *VALID_INPUTS then true else false end end |
Instance Method Details
#==(other) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/scruby/ugens/ugen.rb', line 109 def == other self.class == other.class and self.rate == other.rate and self.inputs == other.inputs and self.channels == other.channels end |