Class: Shmidi::Knob

Inherits:
Control show all
Defined in:
lib/shmidi/controls/knob.rb

Direct Known Subclasses

Encoder, Fader

Constant Summary collapse

CTYPE =
:KNO

Instance Attribute Summary collapse

Attributes inherited from Control

#channel, #note

Attributes included from Base

#_attachments, #_deleted, #_id, #_rev, #version

Instance Method Summary collapse

Methods inherited from Control

#id, #socket

Methods included from Base

#[], #[]=, #clone, #dump, #etag, included, #inspect, #to_hash, #to_s

Constructor Details

#initialize(socket, channel, note, value = 0) ⇒ Knob

Returns a new instance of Knob.



7
8
9
10
# File 'lib/shmidi/controls/knob.rb', line 7

def initialize(socket, channel, note, value = 0)
  super(socket, channel, note)
  init(value)
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/shmidi/controls/knob.rb', line 5

def value
  @value
end

Instance Method Details

#init(value = 0) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/shmidi/controls/knob.rb', line 12

def init(value = 0)
  @prev_value = value
  @value = value
  @__on_value = []
  socket.on_event(channel, :cc, note) do |event|
    reset(event.value)
    Shmidi.TRACE("#{CTYPE}\t#{id}\t#{@value}")
    @__on_value.each { |b| b.call(self) }
  end
end

#on_value(&block) ⇒ Object



28
29
30
# File 'lib/shmidi/controls/knob.rb', line 28

def on_value(&block)
  @__on_value << block
end

#reset(new_value = 0) ⇒ Object



23
24
25
26
# File 'lib/shmidi/controls/knob.rb', line 23

def reset(new_value=0)
  @prev_value = @value
  @value = 0
end