Class: Arcenciel::Surfaces::Knob
- Inherits:
-
Object
- Object
- Arcenciel::Surfaces::Knob
- Includes:
- Logging
- Defined in:
- lib/arcenciel/surfaces.rb,
lib/arcenciel/surfaces/knob.rb
Defined Under Namespace
Constant Summary collapse
- DEFAULT_OPTIONS =
{ min: 0, max: 100, sweep: 360, type: :float }
Constants included from Logging
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#counter ⇒ Object
readonly
Returns the value of attribute counter.
-
#depressed ⇒ Object
readonly
Returns the value of attribute depressed.
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#on_push ⇒ Object
readonly
Returns the value of attribute on_push.
-
#on_release ⇒ Object
readonly
Returns the value of attribute on_release.
-
#on_value ⇒ Object
readonly
Returns the value of attribute on_value.
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
-
#sweep ⇒ Object
readonly
Returns the value of attribute sweep.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #assign!(device, index) ⇒ Object
- #assigned? ⇒ Boolean
- #confirm! ⇒ Object
- #first_update! ⇒ Object
-
#initialize(options) ⇒ Knob
constructor
A new instance of Knob.
- #on_delta(delta) ⇒ Object
- #on_key(state) ⇒ Object
- #typed_value ⇒ Object
- #unassign! ⇒ Object
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() = DEFAULT_OPTIONS.merge() @name = [:name] @min = [:min] @max = [:max] @type = [:type] @sweep = [:sweep] @value = [:initial] @on_value = [:on_value] @on_push = [:on_push] @on_release = [: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
#context ⇒ Object (readonly)
Returns the value of attribute context.
30 31 32 |
# File 'lib/arcenciel/surfaces/knob.rb', line 30 def context @context end |
#counter ⇒ Object (readonly)
Returns the value of attribute counter.
26 27 28 |
# File 'lib/arcenciel/surfaces/knob.rb', line 26 def counter @counter end |
#depressed ⇒ Object (readonly)
Returns the value of attribute depressed.
28 29 30 |
# File 'lib/arcenciel/surfaces/knob.rb', line 28 def depressed @depressed end |
#device ⇒ Object (readonly)
Returns the value of attribute device.
31 32 33 |
# File 'lib/arcenciel/surfaces/knob.rb', line 31 def device @device end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
32 33 34 |
# File 'lib/arcenciel/surfaces/knob.rb', line 32 def index @index end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
17 18 19 |
# File 'lib/arcenciel/surfaces/knob.rb', line 17 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
16 17 18 |
# File 'lib/arcenciel/surfaces/knob.rb', line 16 def min @min end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/arcenciel/surfaces/knob.rb', line 15 def name @name end |
#on_push ⇒ Object (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_release ⇒ Object (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_value ⇒ Object (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 |
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
27 28 29 |
# File 'lib/arcenciel/surfaces/knob.rb', line 27 def precision @precision end |
#sweep ⇒ Object (readonly)
Returns the value of attribute sweep.
19 20 21 |
# File 'lib/arcenciel/surfaces/knob.rb', line 19 def sweep @sweep end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
18 19 20 |
# File 'lib/arcenciel/surfaces/knob.rb', line 18 def type @type end |
#value ⇒ Object (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
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
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_value ⇒ Object
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 |