Class: Browser::Audio::Node::Base

Inherits:
Object
  • Object
show all
Includes:
Native::Wrapper
Defined in:
opal/browser/audio/node.rb

Instance Method Summary collapse

Constructor Details

#initialize(native) ⇒ Base

Returns a new instance of Base.


6
7
8
# File 'opal/browser/audio/node.rb', line 6

def initialize(native)
  @native = native
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, value = nil) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
# File 'opal/browser/audio/node.rb', line 10

def method_missing(name, value = nil)
  if name.end_with? '='
    `#@native[#{name.delete '='}].value = value`
  elsif value.nil? || value == true
    `#@native[#{name}].value`
  elsif value == false
    `#@native[#{name}]`
  else
    super
  end
end

Instance Method Details

#connect(destination) ⇒ Object


26
27
28
# File 'opal/browser/audio/node.rb', line 26

def connect(destination)
  `#@native.connect(#{Native.convert(destination)})`
end

#disconnect(destination = nil, options = {}) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'opal/browser/audio/node.rb', line 30

def disconnect(destination = nil, options = {})
  destination = Native.try_convert(destination)
  output      = options[:output] || 0
  input       = options[:input]  || 0

  if options.any?
    `#@native.disconnect(#{destination}, #{output}, #{input}) || nil`
  elsif destination
    `#@native.disconnect(#{destination})`
  else
    `#@native.disconnect()`
  end
end

#respond_to_missing?(method, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)

22
23
24
# File 'opal/browser/audio/node.rb', line 22

def respond_to_missing?(method, include_all = false)
  `#@native[#{method.delete('=')}] != null`
end