Class: Webmidi::Middleware::SplitByChannel

Inherits:
Base
  • Object
show all
Defined in:
lib/webmidi/middleware/split_by_channel.rb

Constant Summary collapse

SYSTEM_ROUTE =
:system

Instance Method Summary collapse

Constructor Details

#initialize(app, routes:, passthrough: false, **options) ⇒ SplitByChannel

Returns a new instance of SplitByChannel.



8
9
10
11
12
# File 'lib/webmidi/middleware/split_by_channel.rb', line 8

def initialize(app, routes:, passthrough: false, **options)
  super(app, **options)
  @routes = normalize_routes(routes)
  @passthrough = passthrough
end

Instance Method Details

#call(message) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/webmidi/middleware/split_by_channel.rb', line 14

def call(message)
  targets = @routes[route_key(message)]
  return @app.call(message) unless targets

  targets.each { |target| deliver(target, message) }
  return @app.call(message) if @passthrough

  nil
end