Permalink
Browse files

bring back midi channel filter

  • Loading branch information...
1 parent 5b176b5 commit df7d768e2d48a10a37b04415e86ce2f235e89102 @arirusso committed Aug 14, 2011
Showing with 31 additions and 1 deletion.
  1. +3 −0 lib/diamond.rb
  2. +1 −1 lib/diamond/arpeggiator.rb
  3. +27 −0 lib/diamond/midi_channel_filter.rb
View
@@ -11,6 +11,9 @@
require "topaz"
require "unimidi"
+# modules
+require "diamond/midi_channel_filter"
+
# classes
require "diamond/arpeggiator"
require "diamond/pattern"
@@ -3,7 +3,7 @@ module Diamond
class Arpeggiator
- include MusicGrid::MIDIChannelFilter
+ include MIDIChannelFilter
include MusicGrid::MIDIEmitter
include MusicGrid::MIDIReceiver
include MusicGrid::EventSequencer
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+module Diamond
+
+ module MIDIChannelFilter
+
+ def self.included(base)
+ base.send(:attr_accessor, :input_channel, :output_channel)
+ end
+
+ def input_channel_filter(notes)
+ @input_channel.nil? ? notes : notes.find_all { |note| note.channel == @input_channel }
+ end
+
+ def output_channel_filter(msgs)
+ @output_channel.nil? ? msgs : msgs.map { |msg| msg.channel = @output_channel; msg }
+ end
+
+ private
+
+ def initialize_midi_channel_filter(input_channel, output_channel)
+ @input_channel ||= input_channel
+ @output_channel ||= output_channel
+ end
+
+ end
+
+end

0 comments on commit df7d768

Please sign in to comment.