class RubyBuzz::Button
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.
Attributes
events will be an array of lambdas
events will be an array of lambdas
events will be an array of lambdas
Public Class Methods
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.
# File lib/ruby_buzz/button.rb, line 56 def self.find(code) @@buttons.detect { |b| b.code == code } end
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
# File lib/ruby_buzz/button.rb, line 40 def initialize(code, name, pad) @code = code @name = name @pad = pad @events = [] @@buttons << self end
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.
# File lib/ruby_buzz/button.rb, line 89 def self.trigger_key(code) btn = self.find(code) btn.trigger_events end
Public Instance Methods
Add a process to be triggered when this button is pressed.
Arguments:
-
proc - Proc, ruby method to be called, without arguments on button press.
# File lib/ruby_buzz/button.rb, line 67 def add_event(proc) @events << proc end
Trigger every proc in the @events array.
# File lib/ruby_buzz/button.rb, line 74 def trigger_events @events.each do |event| event.call end end