Class: CoreMIDI::Destination

Inherits:
Object
  • Object
show all
Includes:
Endpoint
Defined in:
lib/coremidi/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



8
9
10
# File 'lib/coremidi/destination.rb', line 8

def entity
  @entity
end

Class Method Details

.allArray<Destination>

All output endpoints

Returns:



88
89
90
# File 'lib/coremidi/destination.rb', line 88

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

.firstDestination

Shortcut to the first output endpoint available

Returns:



76
77
78
# File 'lib/coremidi/destination.rb', line 76

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

.lastDestination

Shortcut to the last output endpoint available

Returns:



82
83
84
# File 'lib/coremidi/destination.rb', line 82

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

Instance Method Details

#closeBoolean

Close this output

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
# File 'lib/coremidi/destination.rb', line 12

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

#enable(options = {}, &block) ⇒ Destination Also known as: open, start

Enable this device

Returns:



60
61
62
63
64
65
66
67
68
69
70
# 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

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

Send a MIDI message of indeterminate type

Parameters:

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

Returns:

  • (Boolean)


49
50
51
52
53
54
55
# File 'lib/coremidi/destination.rb', line 49

def puts(*args)
  case args.first
  when Array then args.each { |arg| puts(*arg) }
  when Fixnum 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 (*Fixnum)

    Numeric bytes eg 0x90, 0x40, 0x40

Returns:

  • (Boolean)


39
40
41
42
43
44
# 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_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)


24
25
26
27
28
29
30
31
32
# 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