Class: Pachelbel::OscillatorNode

Inherits:
AudioNode show all
Defined in:
lib/project/Pachelbel.rb

Constant Summary collapse

TYPES =
[:sine, :square, :sawtooth, :triangle]

Instance Attribute Summary

Attributes inherited from AudioNode

#audio_context

Instance Method Summary collapse

Methods inherited from AudioNode

#_audio_context=, #_index=, #_js_snippet, #connect, #disconnect, #run_js

Instance Method Details

#frequencyObject

API Attributes



140
141
142
# File 'lib/project/Pachelbel.rb', line 140

def frequency
  run_js("#{_js_snippet}.frequency.value;").to_f
end

#frequency=(value) ⇒ Object



144
145
146
# File 'lib/project/Pachelbel.rb', line 144

def frequency=(value)
  run_js("#{_js_snippet}.frequency.value = #{value.to_f};").to_f
end

#start(time) ⇒ Object

API Methods



161
162
163
164
# File 'lib/project/Pachelbel.rb', line 161

def start(time)
  js_method = UIDevice.currentDevice.systemVersion[0] == '6' ? 'noteOn' : 'start'
  run_js("#{_js_snippet}.#{js_method}(#{time});")
end

#stop(time) ⇒ Object



166
167
168
169
# File 'lib/project/Pachelbel.rb', line 166

def stop(time)
  js_method = UIDevice.currentDevice.systemVersion[0] == '6' ? 'noteOff' : 'stop'
  run_js("#{_js_snippet}.#{js_method}(#{time});")
end

#typeObject



148
149
150
# File 'lib/project/Pachelbel.rb', line 148

def type
  run_js("#{_js_snippet}.type;").to_sym
end

#type=(value) ⇒ Object

Raises:

  • (ArgumentError)


154
155
156
157
# File 'lib/project/Pachelbel.rb', line 154

def type=(value)
  raise ArgumentError unless TYPES.include? value
  run_js("#{_js_snippet}.type = #{TYPES.index(value)};").to_sym
end