Class: Arcenciel::Surfaces::Knob

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/arcenciel/surfaces.rb,
lib/arcenciel/surfaces/knob.rb

Defined Under Namespace

Classes: Context, DSL

Constant Summary collapse

DEFAULT_OPTIONS =
{
  min:      0,
  max:      100,
  sweep:    360,
  type:     :float
}

Constants included from Logging

Logging::DEFAULT_LOGGER

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#log_error, #log_info, #log_warn, #logger

Constructor Details

#initialize(options) ⇒ Knob

Returns a new instance of Knob.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/arcenciel/surfaces/knob.rb', line 38

def initialize(options)
  options = DEFAULT_OPTIONS.merge(options)

  @name       = options[:name]
  @min        = options[:min]
  @max        = options[:max]
  @type       = options[:type]
  @sweep      = options[:sweep]
  @value      = options[:initial]

  @on_value   = options[:on_value]
  @on_push    = options[:on_push]
  @on_release = options[:on_release]

  @name       ||= default_name
  @value      ||= @min

  @precision  = precision_for_sweep(sweep)
  @counter    = counter_for_value(@value)
  @depressed  = false

  @context = Context.new(self)
  @device = nil
  @index = nil

  clamp_counter
  update_value
  trigger_value
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



30
31
32
# File 'lib/arcenciel/surfaces/knob.rb', line 30

def context
  @context
end

#counterObject (readonly)

Returns the value of attribute counter.



26
27
28
# File 'lib/arcenciel/surfaces/knob.rb', line 26

def counter
  @counter
end

#depressedObject (readonly)

Returns the value of attribute depressed.



28
29
30
# File 'lib/arcenciel/surfaces/knob.rb', line 28

def depressed
  @depressed
end

#deviceObject (readonly)

Returns the value of attribute device.



31
32
33
# File 'lib/arcenciel/surfaces/knob.rb', line 31

def device
  @device
end

#indexObject (readonly)

Returns the value of attribute index.



32
33
34
# File 'lib/arcenciel/surfaces/knob.rb', line 32

def index
  @index
end

#maxObject (readonly)

Returns the value of attribute max.



17
18
19
# File 'lib/arcenciel/surfaces/knob.rb', line 17

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



16
17
18
# File 'lib/arcenciel/surfaces/knob.rb', line 16

def min
  @min
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/arcenciel/surfaces/knob.rb', line 15

def name
  @name
end

#on_pushObject (readonly)

Returns the value of attribute on_push.



22
23
24
# File 'lib/arcenciel/surfaces/knob.rb', line 22

def on_push
  @on_push
end

#on_releaseObject (readonly)

Returns the value of attribute on_release.



23
24
25
# File 'lib/arcenciel/surfaces/knob.rb', line 23

def on_release
  @on_release
end

#on_valueObject (readonly)

Returns the value of attribute on_value.



21
22
23
# File 'lib/arcenciel/surfaces/knob.rb', line 21

def on_value
  @on_value
end

#precisionObject (readonly)

Returns the value of attribute precision.



27
28
29
# File 'lib/arcenciel/surfaces/knob.rb', line 27

def precision
  @precision
end

#sweepObject (readonly)

Returns the value of attribute sweep.



19
20
21
# File 'lib/arcenciel/surfaces/knob.rb', line 19

def sweep
  @sweep
end

#typeObject (readonly)

Returns the value of attribute type.



18
19
20
# File 'lib/arcenciel/surfaces/knob.rb', line 18

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



25
26
27
# File 'lib/arcenciel/surfaces/knob.rb', line 25

def value
  @value
end

Class Method Details

.from_dsl(&blk) ⇒ Object



34
35
36
# File 'lib/arcenciel/surfaces/knob.rb', line 34

def self.from_dsl(&blk)
  new(DSL.eval(&blk))
end

Instance Method Details

#assign!(device, index) ⇒ Object



78
79
80
81
# File 'lib/arcenciel/surfaces/knob.rb', line 78

def assign!(device, index)
  @device = device
  @index = index
end

#assigned?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/arcenciel/surfaces/knob.rb', line 74

def assigned?
  !!@device
end

#confirm!Object



88
89
90
91
92
93
94
95
96
# File 'lib/arcenciel/surfaces/knob.rb', line 88

def confirm!
  start_chaser

  log_info "Illuminated knob '#{name}' (#{index}). Press any key."
  wait_for_key

  stop_chaser
  ring_clear
end

#first_update!Object



98
99
100
# File 'lib/arcenciel/surfaces/knob.rb', line 98

def first_update!
  update_ring
end

#on_delta(delta) ⇒ Object



102
103
104
105
106
107
108
109
# File 'lib/arcenciel/surfaces/knob.rb', line 102

def on_delta(delta)
  @counter += delta
  clamp_counter

  update_value
  update_ring
  trigger_value
end

#on_key(state) ⇒ Object



111
112
113
114
115
116
117
118
119
120
# File 'lib/arcenciel/surfaces/knob.rb', line 111

def on_key(state)
  case state
  when 0
    @depressed = false
    trigger_release
  when 1
    @depressed = true
    trigger_push
  end
end

#typed_valueObject



68
69
70
71
72
# File 'lib/arcenciel/surfaces/knob.rb', line 68

def typed_value
  integer_type? ?
    value.to_i :
    value.to_f
end

#unassign!Object



83
84
85
86
# File 'lib/arcenciel/surfaces/knob.rb', line 83

def unassign!
  @device = nil
  @index = nil
end