Class: Charosc::Oscillator

Inherits:
Object
  • Object
show all
Defined in:
lib/charosc/oscillator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, options = {}) ⇒ Oscillator

Returns a new instance of Oscillator.



5
6
7
8
9
# File 'lib/charosc/oscillator.rb', line 5

def initialize(value, options = {})
  @value     = value
  @options   = default_options.merge(options)
  @direction = :up
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/charosc/oscillator.rb', line 3

def options
  @options
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/charosc/oscillator.rb', line 3

def value
  @value
end

Instance Method Details

#nextObject

Public: Get the next value

Returns Integer



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/charosc/oscillator.rb', line 14

def next
  if at_top?
    @direction = :down
  elsif at_bottom?
    @direction = :up
  end

  go_up if going_up?
  go_down if going_down?

  value.round
end