Class: MusaLCEServer::Control
- Inherits:
-
Object
- Object
- MusaLCEServer::Control
- Defined in:
- lib/surface.rb
Overview
Abstract base for all controls on a Surface.
Subclasses declare a Control.type_name matching the inventory string received from the surface, expose typed state accessors, and implement #emit_all_state to push their current state outbound.
Setting a property emits exactly one OSC
+/musalce/surface/state/
Instance Attribute Summary collapse
-
#event ⇒ Symbol
readonly
The event name this control is bound to.
-
#message ⇒ String?
The displayable message, +nil+ if unset.
Class Method Summary collapse
-
.create(type, **kwargs) ⇒ Control
private
Instantiates the right subclass for the given type.
-
.type_name ⇒ Symbol
The inventory type identifier.
Instance Method Summary collapse
-
#emit_all_state ⇒ void
private
Re-emits every state property of this control.
-
#initialize(event:, surface:) ⇒ Control
constructor
A new instance of Control.
-
#set(**attrs) ⇒ self
Sets multiple attributes in a single call.
Constructor Details
#initialize(event:, surface:) ⇒ Control
Returns a new instance of Control.
173 174 175 176 177 |
# File 'lib/surface.rb', line 173 def initialize(event:, surface:) @event = event @surface = surface @message = nil end |
Instance Attribute Details
#event ⇒ Symbol (readonly)
Returns the event name this control is bound to.
168 169 170 |
# File 'lib/surface.rb', line 168 def event @event end |
#message ⇒ String?
Returns the displayable message, +nil+ if unset.
171 172 173 |
# File 'lib/surface.rb', line 171 def @message end |
Class Method Details
.create(type, **kwargs) ⇒ Control
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instantiates the right subclass for the given type.
239 240 241 242 243 244 245 246 |
# File 'lib/surface.rb', line 239 def self.create(type, **kwargs) case type.to_sym when :toggle then Toggle.new(**kwargs) when :trigger then Trigger.new(**kwargs) when :encoder then Encoder.new(**kwargs) else raise ArgumentError, "Unknown control type: #{type.inspect}" end end |
.type_name ⇒ Symbol
Returns the inventory type identifier.
230 231 232 |
# File 'lib/surface.rb', line 230 def self.type_name raise NotImplementedError, "#{self} must implement .type_name" end |
Instance Method Details
#emit_all_state ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Re-emits every state property of this control. Called by the surface during +state_request+ or after inventory dumps.
225 226 227 |
# File 'lib/surface.rb', line 225 def emit_all_state emit(:message, @message.to_s) unless @message.nil? end |
#set(**attrs) ⇒ self
Sets multiple attributes in a single call. Each key must name a writable attribute of the receiver's type; unknown keys raise +ArgumentError+ so a typo can't silently no-op.
Order of assignment follows the kwargs hash insertion order
(Ruby >= 1.9 guarantees insertion-ordered iteration). Each
assignment goes through the regular setter, so each property
emits its own +/musalce/surface/state/
209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/surface.rb', line 209 def set(**attrs) attrs.each do |key, value| writer = :"#{key}=" unless respond_to?(writer) raise ArgumentError, "#{self.class.type_name} control has no '#{key}' attribute" end public_send(writer, value) end self end |