Class: RubyBuzz::Button
- Inherits:
-
Object
- Object
- RubyBuzz::Button
- Defined in:
- lib/ruby_buzz/button.rb
Overview
Handles a single button on the Buzz controllers.
Identified by event code, all between 704 and 723. Also identifiable by pad and name.
Possible names:
-
buzz
-
yellow
-
green
-
orange
-
blue
Initialized in RubyBuzz::Pad.init_mappings
Each button holds an array of events, each of which is a Proc to be called without arguments. These are called when the button is pushed.
Constant Summary collapse
[]
Instance Attribute Summary collapse
-
#code ⇒ Object
events will be an array of lambdas.
-
#events ⇒ Object
events will be an array of lambdas.
-
#name ⇒ Object
events will be an array of lambdas.
Class Method Summary collapse
-
.find(code) ⇒ Object
Find a button by its event code.
-
.trigger_key(code) ⇒ Object
Find a button and run all it’s events.
Instance Method Summary collapse
-
#add_event(proc) ⇒ Object
Add a process to be triggered when this button is pressed.
-
#initialize(code, name, pad) ⇒ Button
constructor
Initialize a button.
-
#trigger_events ⇒ Object
Trigger every proc in the @events array.
Constructor Details
#initialize(code, name, pad) ⇒ Button
Initialize a button
called in RubyBuzz::Pad.init_mappings
Arguments:
-
code - Integer, the evnt code generated by this button (704-723)
-
name - Symbol, the name of the button, for referncing via the Pad object
-
pad - RubyBuzz::Pad, the object this button belongs to
40 41 42 43 44 45 46 |
# File 'lib/ruby_buzz/button.rb', line 40 def initialize(code, name, pad) @code = code @name = name @pad = pad @events = [] << self end |
Instance Attribute Details
#code ⇒ Object
events will be an array of lambdas
27 28 29 |
# File 'lib/ruby_buzz/button.rb', line 27 def code @code end |
#events ⇒ Object
events will be an array of lambdas
27 28 29 |
# File 'lib/ruby_buzz/button.rb', line 27 def events @events end |
#name ⇒ Object
events will be an array of lambdas
27 28 29 |
# File 'lib/ruby_buzz/button.rb', line 27 def name @name end |
Class Method Details
.find(code) ⇒ Object
Find a button by its event code. Used by trigger_key to find a button when one is pushed.
Arguments:
-
code - Integer, event code to retrieve button by.
56 57 58 |
# File 'lib/ruby_buzz/button.rb', line 56 def self.find(code) .detect { |b| b.code == code } end |
.trigger_key(code) ⇒ Object
Find a button and run all it’s events.
Used by RubyBuzz::Device when button is pushed.
Arguments:
-
code - Integer, event code to retrieve button by.
89 90 91 92 |
# File 'lib/ruby_buzz/button.rb', line 89 def self.trigger_key(code) btn = self.find(code) btn.trigger_events end |
Instance Method Details
#add_event(proc) ⇒ Object
Add a process to be triggered when this button is pressed.
Arguments:
-
proc - Proc, ruby method to be called, without arguments on button press.
67 68 69 |
# File 'lib/ruby_buzz/button.rb', line 67 def add_event(proc) @events << proc end |
#trigger_events ⇒ Object
Trigger every proc in the @events array.
74 75 76 77 78 |
# File 'lib/ruby_buzz/button.rb', line 74 def trigger_events @events.each do |event| event.call end end |