Class: MIDICommunicationsMacOS::Destination

Inherits:
Object
  • Object
show all
Includes:
Endpoint
Defined in:
lib/midi-communications-macos/destination.rb

Overview

Type of endpoint used for output

Instance Attribute Summary collapse

Attributes included from Endpoint

#enabled, #id, #resource_id, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Endpoint

all_by_type, destinations, get_class, #initialize, #online?, sources

Instance Attribute Details

#entityObject (readonly)

Returns the value of attribute entity.



6
7
8
# File 'lib/midi-communications-macos/destination.rb', line 6

def entity
  @entity
end

Class Method Details

.allArray<Destination>

All output endpoints

Returns:



86
87
88
# File 'lib/midi-communications-macos/destination.rb', line 86

def self.all
  Endpoint.all_by_type[:destination]
end

.firstDestination

Shortcut to the first output endpoint available

Returns:



74
75
76
# File 'lib/midi-communications-macos/destination.rb', line 74

def self.first
  Endpoint.first(:destination)
end

.lastDestination

Shortcut to the last output endpoint available

Returns:



80
81
82
# File 'lib/midi-communications-macos/destination.rb', line 80

def self.last
  Endpoint.last(:destination)
end

Instance Method Details

#closeBoolean

Close this output

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
# File 'lib/midi-communications-macos/destination.rb', line 10

def close
  if @enabled
    @enabled = false
    true
  else
    false
  end
end

#enableDestination Also known as: open, start

Enable this device

Returns:



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/midi-communications-macos/destination.rb', line 58

def enable
  @enabled ||= true
  if block_given?
    begin
      yield(self)
    ensure
      close
    end
  end
  self
end

#puts(*args) ⇒ Boolean Also known as: write

Send a MIDI message of indeterminate type

Parameters:

  • args (*Array<Integer>, *Array<String>, *Integer, *String)

Returns:

  • (Boolean)


47
48
49
50
51
52
53
# File 'lib/midi-communications-macos/destination.rb', line 47

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

#puts_bytes(*data) ⇒ Boolean

Send a MIDI message comprised of numeric bytes

Parameters:

  • data (*Integer)

    Numeric bytes eg 0x90, 0x40, 0x40

Returns:

  • (Boolean)


37
38
39
40
41
42
# File 'lib/midi-communications-macos/destination.rb', line 37

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_s(data) ⇒ Boolean Also known as: puts_bytestr, puts_hex

Send a MIDI message comprised of a String of hex digits

Parameters:

  • data (String)

    A string of hex digits eg “904040”

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
# File 'lib/midi-communications-macos/destination.rb', line 22

def puts_s(data)
  data = data.dup
  bytes = []
  until (str = data.slice!(0, 2)).eql?('')
    bytes << str.hex
  end
  puts_bytes(*bytes)
  true
end