Class: CoreMIDI::Destination
- Inherits:
-
Object
- Object
- CoreMIDI::Destination
- Includes:
- Endpoint
- Defined in:
- lib/coremidi/destination.rb
Overview
Type of endpoint used for output
Instance Attribute Summary collapse
-
#entity ⇒ Object
readonly
Returns the value of attribute entity.
Attributes included from Endpoint
#enabled, #id, #resource_id, #type
Class Method Summary collapse
-
.all ⇒ Array<Destination>
All output endpoints.
-
.first ⇒ Destination
Shortcut to the first output endpoint available.
-
.last ⇒ Destination
Shortcut to the last output endpoint available.
Instance Method Summary collapse
-
#close ⇒ Boolean
Close this output.
-
#enable(_options = {}) ⇒ Destination
(also: #open, #start)
Enable this device.
-
#puts(*args) ⇒ Boolean
(also: #write)
Send a MIDI message of indeterminate type.
-
#puts_bytes(*data) ⇒ Boolean
Send a MIDI message comprised of numeric bytes.
-
#puts_s(data) ⇒ Boolean
(also: #puts_bytestr, #puts_hex)
Send a MIDI message comprised of a String of hex digits.
Methods included from Endpoint
all_by_type, destinations, get_class, #initialize, #online?, sources
Instance Attribute Details
#entity ⇒ Object (readonly)
Returns the value of attribute entity.
8 9 10 |
# File 'lib/coremidi/destination.rb', line 8 def entity @entity end |
Class Method Details
.all ⇒ Array<Destination>
All output endpoints
88 89 90 |
# File 'lib/coremidi/destination.rb', line 88 def self.all Endpoint.all_by_type[:destination] end |
.first ⇒ Destination
Shortcut to the first output endpoint available
76 77 78 |
# File 'lib/coremidi/destination.rb', line 76 def self.first Endpoint.first(:destination) end |
.last ⇒ Destination
Shortcut to the last output endpoint available
82 83 84 |
# File 'lib/coremidi/destination.rb', line 82 def self.last Endpoint.last(:destination) end |
Instance Method Details
#close ⇒ Boolean
Close this output
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 = {}) ⇒ Destination Also known as: open, start
Enable this device
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/coremidi/destination.rb', line 60 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
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 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
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}", 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
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 |