Class: RubyBuzz::Pad
- Inherits:
-
Object
- Object
- RubyBuzz::Pad
- Defined in:
- lib/ruby_buzz/pad.rb
Overview
Each of these is an individual players controller
Each USB device has four of these.
Each pad has 5 buttons:
-
buzz
-
yellow
-
green
-
orange
-
blue
Accessed by ‘pad.buttons` etc
Each pad has a single LED light under the buzz button.
Accessed by ‘pad.light`
Accessing Pad objects:
-
‘Pad.all`
-
‘Pad` etc.
Defining an event on a button
‘pad.add_event(:buzz, lambda{ puts ’Buzz pushed!‘ })`
Triggering a button event (for debugging)
‘pad.trigger_events(:buzz)`
Constant Summary collapse
- MAPPINGS =
Event code mappings for each button. Split into pads. => button_name
[ { 704 => :buzz, 705 => :yellow, 706 => :green, 707 => :orange, 708 => :blue }, { 709 => :buzz, 710 => :yellow, 711 => :green, 712 => :orange, 713 => :blue }, { 714 => :buzz, 715 => :yellow, 716 => :green, 717 => :orange, 718 => :blue }, { 719 => :buzz, 720 => :yellow, 721 => :green, 722 => :orange, 723 => :blue } ]
Instance Attribute Summary collapse
-
#buttons ⇒ Object
Returns the value of attribute buttons.
-
#light ⇒ Object
Returns the value of attribute light.
Class Method Summary collapse
-
.[](index) ⇒ Object
Call a specific pad by index (0 to 3).
-
.all ⇒ Object
Returns all four pads in index order.
-
.init_mappings ⇒ Object
called by lib/ruby_buzz.rb.
Instance Method Summary collapse
-
#add_event(button_name, proc) ⇒ Object
Add an event mapping, to be triggered on button push.
-
#initialize(mapping, index) ⇒ Pad
constructor
Initialize pad objects, called by init_mappings.
-
#trigger_event(button_name) ⇒ Object
For debugging: Trigger a button event directly.
Constructor Details
#initialize(mapping, index) ⇒ Pad
Initialize pad objects, called by init_mappings
Arguments:
-
mapping - hash of event codes against button name (from MAPPINGS)
-
index - index of this pad, from 0 to 3
103 104 105 106 107 108 109 110 |
# File 'lib/ruby_buzz/pad.rb', line 103 def initialize(mapping, index) @index = index = {} @light = RubyBuzz::Light.new(index) mapping.each do |code, name| [name] = RubyBuzz::Button.new(code, name, self) end end |
Instance Attribute Details
#buttons ⇒ Object
Returns the value of attribute buttons.
68 69 70 |
# File 'lib/ruby_buzz/pad.rb', line 68 def end |
#light ⇒ Object
Returns the value of attribute light.
68 69 70 |
# File 'lib/ruby_buzz/pad.rb', line 68 def light @light end |
Class Method Details
.[](index) ⇒ Object
Call a specific pad by index (0 to 3)
91 92 93 |
# File 'lib/ruby_buzz/pad.rb', line 91 def self.[](index) @@pads[index] end |
.all ⇒ Object
Returns all four pads in index order.
84 85 86 |
# File 'lib/ruby_buzz/pad.rb', line 84 def self.all @@pads end |
.init_mappings ⇒ Object
called by lib/ruby_buzz.rb
Reads the MAPPINGS constant and creates the 4 pad objects.
74 75 76 77 78 79 |
# File 'lib/ruby_buzz/pad.rb', line 74 def self.init_mappings @@pads = [] MAPPINGS.each_with_index do |mapping, index| @@pads << new(mapping, index) end end |
Instance Method Details
#add_event(button_name, proc) ⇒ Object
Add an event mapping, to be triggered on button push.
Arguments:
-
button_name - Symbol, name of the button to be pushed
-
proc - Proc, a ruby method to be called.
As the Proc is run on a separate thread, with the same environment, it is wise to change data in a shared space (for instance, a class variable or a setter method) for the main body of your code to respond to instead of doing the heavy lifting in the button event.
125 126 127 |
# File 'lib/ruby_buzz/pad.rb', line 125 def add_event(, proc) [].add_event proc end |
#trigger_event(button_name) ⇒ Object
For debugging: Trigger a button event directly. Also called by watcher in RubyBuzz::Device.
Arguments:
-
button_name - Symbol name of buzzer (:buzz, :yellow, :green, :orange, :blue)
137 138 139 |
# File 'lib/ruby_buzz/pad.rb', line 137 def trigger_event() [].trigger_events end |