class CoreMIDI::Destination
Type of endpoint used for output
Constants
- SysexCompletionCallback
Attributes
Public Class Methods
All output endpoints @return [Array<Destination>]
# File lib/coremidi/destination.rb, line 88 def self.all Endpoint.all_by_type[:destination] end
Shortcut to the first output endpoint available @return [Destination]
# File lib/coremidi/destination.rb, line 76 def self.first Endpoint.first(:destination) end
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 this output @return [Boolean]
# File lib/coremidi/destination.rb, line 12 def close if @enabled @enabled = false true else false end end
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
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
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
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
Protected Instance Methods
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
Private Instance Methods
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
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
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
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