Class: Musicality::SuperCollider::SynthDef

Inherits:
Object
  • Object
show all
Includes:
Packable
Defined in:
lib/musicality/performance/supercollider/synthdef.rb

Defined Under Namespace

Classes: Settings

Constant Summary

Constants included from Packable

Packable::PACKED_CLASS_KEY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Packable

#class_str, included, #init_params, #pack, pack_val, recover_class, unpack_val

Constructor Details

#initialize(name: "", params: {}, body: "", credit: "", source: "") ⇒ SynthDef

Returns a new instance of SynthDef.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
# File 'lib/musicality/performance/supercollider/synthdef.rb', line 8

def initialize name: "", params: {}, body: "", credit: "", source: ""
  raise ArgumentError if name.empty?
  raise ArgumentError if body.empty?

  @name, @params, @body = name, params, body
  @credit, @source = credit, source
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/musicality/performance/supercollider/synthdef.rb', line 7

def body
  @body
end

#creditObject (readonly)

Returns the value of attribute credit.



7
8
9
# File 'lib/musicality/performance/supercollider/synthdef.rb', line 7

def credit
  @credit
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/musicality/performance/supercollider/synthdef.rb', line 7

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'lib/musicality/performance/supercollider/synthdef.rb', line 7

def params
  @params
end

#sourceObject (readonly)

Returns the value of attribute source.



7
8
9
# File 'lib/musicality/performance/supercollider/synthdef.rb', line 7

def source
  @source
end

Instance Method Details

#settings(args = {}) ⇒ Object



44
45
46
# File 'lib/musicality/performance/supercollider/synthdef.rb', line 44

def settings args = {}
  Settings.new(self, args)
end

#to_sclangObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/musicality/performance/supercollider/synthdef.rb', line 16

def to_sclang
  params_str = "|" + @params.map {|k,v| v.nil? ? k.to_s : "#{k} = #{v}" }.join(", ") + "|"
  output = "SynthDef(\"#{@name}\", {" + params_str + "\n" + @body + "#{"\n" unless @body[-1] == "\n"}\}"
  
  unless (@credit.empty? && @source.empty?)
     = ", metadata: (\n"
    unless @credit.empty?
       += "  credit: \"#{@credit}\",\n"
    end
    unless @source.empty?
       += "  source: \"#{@source}\"\n"
    end
     += ")\n"
    output += 
  end

  output += ").writeDefFile;"
end