module Diamond::MIDI::Output

Methods dealing with MIDI output

Public Class Methods

included(base) click to toggle source
# File lib/diamond/midi.rb, line 94
def self.included(base)
  base.send(:extend, Forwardable)
  base.send(:def_delegators, :@midi,
            :mute,
            :mute=,
            :output,
            :outputs,
            :toggle_mute,
            :tx_channel, 
            :transmit_channel,
            :tx_channel=,
            :transmit_channel=)
end

Public Instance Methods

enable_output(arpeggiator) click to toggle source

Initialize MIDI output, enabling the sequencer to emit notes @param [Arpeggiator] arpeggiator @return [Boolean]

# File lib/diamond/midi.rb, line 111
def enable_output(arpeggiator)
  arpeggiator.sequencer.event.perform << proc do |bucket|
    unless bucket.empty?
      if @debug
        bucket.each do |message|
          puts "[DEBUG] MIDI: output #{message.name} channel: #{message.channel}"
        end
      end
      @midi.output.puts(bucket)
    end
  end
  arpeggiator.sequencer.event.stop << proc { emit_pending_note_offs(arpeggiator) }
  true
end

Private Instance Methods

emit_pending_note_offs(arpeggiator) click to toggle source

Emit any note off messages that are currently pending in the queue. The clock triggers this when stopping or pausing @param [Arpeggiator] arpeggiator @return [Array<MIDIMessage::NoteOff>]

# File lib/diamond/midi.rb, line 132
def emit_pending_note_offs(arpeggiator)
  messages = arpeggiator.sequence.pending_note_offs
  @midi.output.puts(*messages)
  messages
end
initialize_output(outputs, options = {}) click to toggle source

Initialize MIDI output @param [Array<UniMIDI::Output>] outputs @param [Hash] options @option options [Fixnum] :tx_channel The transmit channel

# File lib/diamond/midi.rb, line 142
def initialize_output(outputs, options = {})
  @midi.output.devices.concat(outputs)
  @midi.output.channel = options[:transmit_channel]
end