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.



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

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



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

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



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

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

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



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

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)


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

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