Class: Arcenciel::Surfaces::Controller
- Inherits:
-
Object
- Object
- Arcenciel::Surfaces::Controller
- Includes:
- Logging
- Defined in:
- lib/arcenciel/surfaces.rb,
lib/arcenciel/surfaces/controller.rb
Defined Under Namespace
Classes: DSL
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#knobs ⇒ Object
readonly
Returns the value of attribute knobs.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #assign!(device) ⇒ Object
- #assigned? ⇒ Boolean
-
#initialize(options) ⇒ Controller
constructor
A new instance of Controller.
- #on_delta(index, delta) ⇒ Object
- #on_key(index, state) ⇒ Object
- #unassign! ⇒ Object
Methods included from Logging
#log_error, #log_info, #log_warn, #logger
Constructor Details
#initialize(options) ⇒ Controller
Returns a new instance of Controller.
15 16 17 18 19 20 |
# File 'lib/arcenciel/surfaces/controller.rb', line 15 def initialize() @name = [:name] || default_name @knobs = [:knobs] || [] @device = nil end |
Instance Attribute Details
#device ⇒ Object (readonly)
Returns the value of attribute device.
9 10 11 |
# File 'lib/arcenciel/surfaces/controller.rb', line 9 def device @device end |
#knobs ⇒ Object (readonly)
Returns the value of attribute knobs.
7 8 9 |
# File 'lib/arcenciel/surfaces/controller.rb', line 7 def knobs @knobs end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/arcenciel/surfaces/controller.rb', line 6 def name @name end |
Class Method Details
.from_dsl(&blk) ⇒ Object
11 12 13 |
# File 'lib/arcenciel/surfaces/controller.rb', line 11 def self.from_dsl(&blk) new(DSL.eval(&blk)) end |
Instance Method Details
#assign!(device) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/arcenciel/surfaces/controller.rb', line 26 def assign!(device) log_info "Assigning controller '#{name}' to device..." @device = device knobs.each_with_index do |k, i| k.assign!(device, i) k.confirm! end device.attach!(self) device.validate! knobs.each do |k| k.first_update! end log_info "Assigned controller '#{name}'." end |
#assigned? ⇒ Boolean
22 23 24 |
# File 'lib/arcenciel/surfaces/controller.rb', line 22 def assigned? !!@device end |
#on_delta(index, delta) ⇒ Object
51 52 53 54 |
# File 'lib/arcenciel/surfaces/controller.rb', line 51 def on_delta(index, delta) return unless index < knobs.size knobs[index].on_delta(delta) end |
#on_key(index, state) ⇒ Object
56 57 58 59 |
# File 'lib/arcenciel/surfaces/controller.rb', line 56 def on_key(index, state) return unless index < knobs.size knobs[index].on_key(state) end |
#unassign! ⇒ Object
45 46 47 48 49 |
# File 'lib/arcenciel/surfaces/controller.rb', line 45 def unassign! @device = nil knobs.each(&:unassign!) log_warn "Controller '#{name}' is unassigned." end |