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:

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

code[RW]

events will be an array of lambdas

events[RW]

events will be an array of lambdas

name[RW]

events will be an array of lambdas

Public Class Methods

find(code) click to toggle source

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
new(code, name, pad) click to toggle source

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
trigger_key(code) click to toggle source

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_event(proc) click to toggle source

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_events() click to toggle source

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