Class: Webmidi::Middleware::Panic
- Defined in:
- lib/webmidi/middleware/panic.rb
Constant Summary collapse
- DEFAULT_CONTROLS =
[:all_sound_off, :all_notes_off].freeze
- DEFAULT_TRIGGER =
Message::System::SystemReset
Class Method Summary collapse
- .all_notes_off(channels: 0..15, timestamp: nil) ⇒ Object
- .messages(channels: 0..15, controls: DEFAULT_CONTROLS, timestamp: nil) ⇒ Object
Instance Method Summary collapse
- #call(message) ⇒ Object
-
#initialize(app, channels: 0..15, controls: DEFAULT_CONTROLS, trigger: DEFAULT_TRIGGER, pass_trigger: false, **options) ⇒ Panic
constructor
A new instance of Panic.
Constructor Details
#initialize(app, channels: 0..15, controls: DEFAULT_CONTROLS, trigger: DEFAULT_TRIGGER, pass_trigger: false, **options) ⇒ Panic
Returns a new instance of Panic.
9 10 11 12 13 14 15 16 |
# File 'lib/webmidi/middleware/panic.rb', line 9 def initialize(app, channels: 0..15, controls: DEFAULT_CONTROLS, trigger: DEFAULT_TRIGGER, pass_trigger: false, **) super(app, **) @channels = self.class.send(:normalize_channels, channels) @controls = self.class.send(:normalize_controls, controls) @trigger = trigger @pass_trigger = pass_trigger end |
Class Method Details
.all_notes_off(channels: 0..15, timestamp: nil) ⇒ Object
27 28 29 |
# File 'lib/webmidi/middleware/panic.rb', line 27 def self.all_notes_off(channels: 0..15, timestamp: nil) (channels: channels, controls: [:all_notes_off], timestamp: ) end |
.messages(channels: 0..15, controls: DEFAULT_CONTROLS, timestamp: nil) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/webmidi/middleware/panic.rb', line 31 def self.(channels: 0..15, controls: DEFAULT_CONTROLS, timestamp: nil) normalize_channels(channels).flat_map do |channel| normalize_controls(controls).map do |control| Message.control_change(control, 0, channel: channel, timestamp: ) end end end |
Instance Method Details
#call(message) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/webmidi/middleware/panic.rb', line 18 def call() return @app.call() unless trigger?() results = self.class.(channels: @channels, controls: @controls, timestamp: .) .filter_map { || @app.call() } results << @app.call() if @pass_trigger results.compact end |