Class: Webmidi::Middleware::ChannelMap

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

Instance Method Summary collapse

Constructor Details

#initialize(app, map: nil, from: nil, to: nil, **options) ⇒ ChannelMap

Returns a new instance of ChannelMap.



6
7
8
9
# File 'lib/webmidi/middleware/channel_map.rb', line 6

def initialize(app, map: nil, from: nil, to: nil, **options)
  super(app, **options)
  @map = normalize_map(map, from, to)
end

Instance Method Details

#call(message) ⇒ Object



11
12
13
14
15
16
# File 'lib/webmidi/middleware/channel_map.rb', line 11

def call(message)
  return @app.call(message) unless message.channel

  target = @map.fetch(message.channel, message.channel)
  @app.call(message.with(channel: target))
end