class CoreMIDI::Destination

Type of endpoint used for output

Constants

SysexCompletionCallback

Attributes

entity[R]

Public Class Methods

all() click to toggle source

All output endpoints @return [Array<Destination>]

# File lib/coremidi/destination.rb, line 88
def self.all
  Endpoint.all_by_type[:destination]
end
first() click to toggle source

Shortcut to the first output endpoint available @return [Destination]

# File lib/coremidi/destination.rb, line 76
def self.first
  Endpoint.first(:destination)
end
last() click to toggle source

Shortcut to the last output endpoint available @return [Destination]

# File lib/coremidi/destination.rb, line 82
def self.last
  Endpoint.last(:destination)
end

Public Instance Methods

close() click to toggle source

Close this output @return [Boolean]

# File lib/coremidi/destination.rb, line 12
def close
  if @enabled
    @enabled = false
    true
  else
    false
  end
end
enable(options = {}) { |self| ... } click to toggle source

Enable this device @return [Destination]

# File lib/coremidi/destination.rb, line 60
def enable(options = {}, &block)
  @enabled = true unless @enabled
  if block_given?
    begin
      yield(self)
    ensure
      close
    end
  end
  self
end
Also aliased as: open, start
open(options = {}, &block)
Alias for: enable
puts(*args) click to toggle source

Send a MIDI message of indeterminate type @param [*Array<Integer>, *Array<String>, *Integer, *String] args @return [Boolean]

# File lib/coremidi/destination.rb, line 49
def puts(*args)
  case args.first
  when Array then args.each { |arg| puts(*arg) }
  when Integer then puts_bytes(*args)
  when String then puts_bytestr(*args)
  end
end
Also aliased as: write
puts_bytes(*data) click to toggle source

Send a MIDI message comprised of numeric bytes @param [*Integer] data Numeric bytes eg 0x90, 0x40, 0x40 @return [Boolean]

# File lib/coremidi/destination.rb, line 39
def puts_bytes(*data)
  type = sysex?(data) ? :sysex : :small
  bytes = API.get_midi_packet(data)
  send("puts_#{type.to_s}", bytes, data.size)
  true
end
puts_bytestr(data)
Alias for: puts_s
puts_hex(data)
Alias for: puts_s
puts_s(data) click to toggle source

Send a MIDI message comprised of a String of hex digits @param [String] data A string of hex digits eg “904040” @return [Boolean]

# File lib/coremidi/destination.rb, line 24
def puts_s(data)
  data = data.dup
  bytes = []
  until (str = data.slice!(0,2)).eql?("")
    bytes << str.hex
  end
  puts_bytes(*bytes)
  true
end
Also aliased as: puts_bytestr, puts_hex
start(options = {}, &block)
Alias for: enable
write(*args)
Alias for: puts

Protected Instance Methods

connect() click to toggle source

Base initialization for this endpoint – done whether or not the endpoint is enabled to check whether it is truly available for use @return [Boolean]

# File lib/coremidi/destination.rb, line 97
def connect
  client_error = enable_client
  port_error = initialize_port
  @resource = API.MIDIEntityGetDestination( @entity.resource, @resource_id )
  !@resource.address.zero? && client_error.zero? && port_error.zero?
end
Also aliased as: connect?
connect?()
Alias for: connect

Private Instance Methods

initialize_port() click to toggle source

Initialize a coremidi port for this endpoint

# File lib/coremidi/destination.rb, line 133
def initialize_port
  port = API.create_midi_output_port(@client, @resource_id, @name)
  @handle = port[:handle]
  port[:error]
end
puts_small(bytes, size) click to toggle source

Output a short MIDI message

# File lib/coremidi/destination.rb, line 108
def puts_small(bytes, size)
  packet_list = API.get_midi_packet_list(bytes, size)
  API.MIDISend(@handle, @resource, packet_list)
  true
end
puts_sysex(bytes, size) click to toggle source

Output a System Exclusive MIDI message

# File lib/coremidi/destination.rb, line 115
def puts_sysex(bytes, size)
  request = API::MIDISysexSendRequest.new
  request[:destination] = @resource
  request[:data] = bytes
  request[:bytes_to_send] = size
  request[:complete] = 0
  request[:completion_proc] = SysexCompletionCallback
  request[:completion_ref_con] = request
  API.MIDISendSysex(request)
  true
end
sysex?(data) click to toggle source

Is the given data a MIDI sysex message?

# File lib/coremidi/destination.rb, line 140
def sysex?(data)
  data.first.eql?(0xF0) && data.last.eql?(0xF7)
end