Class: MIDICommunicationsMacOS::Destination
- Inherits:
-
Object
- Object
- MIDICommunicationsMacOS::Destination
- Includes:
- Endpoint
- Defined in:
- lib/midi-communications-macos/destination.rb
Overview
MIDI output endpoint for sending MIDI messages.
A Destination represents a MIDI output that can send messages to external MIDI devices or software. Messages can be sent as numeric bytes, hex strings, or arrays.
Instance Attribute Summary collapse
-
#enabled ⇒ Boolean
(also: #enabled?)
included
from Endpoint
readonly
Whether the endpoint has been initialized.
- #entity ⇒ Object readonly
-
#entity ⇒ Entity
included
from Endpoint
readonly
The parent entity.
-
#id ⇒ Integer
included
from Endpoint
Unique local numeric ID of the endpoint.
-
#resource_id ⇒ Integer
included
from Endpoint
readonly
Core MIDI resource identifier.
- #type ⇒ Object included from Endpoint readonly
Class Method Summary collapse
-
.all ⇒ Array<Destination>
Returns all available output endpoints.
-
.first ⇒ Destination
Returns the first available output endpoint.
-
.last ⇒ Destination
Returns the last available output endpoint.
Instance Method Summary collapse
-
#close ⇒ Boolean
Closes this output.
-
#display_name ⇒ String
included
from Endpoint
Formatted display name (delegated to entity).
-
#enable {|destination| ... } ⇒ Destination
(also: #open, #start)
Opens this output for use.
- #initialize(resource_id, entity) ⇒ Object included from Endpoint
-
#manufacturer ⇒ String
included
from Endpoint
Device manufacturer name (delegated to entity).
-
#model ⇒ String
included
from Endpoint
Device model name (delegated to entity).
-
#name ⇒ String
included
from Endpoint
Endpoint name (delegated to entity).
-
#online? ⇒ Boolean
included
from Endpoint
Is this endpoint online?.
-
#puts(*args) ⇒ Boolean
(also: #write)
Sends a MIDI message in any supported format.
-
#puts_bytes(*data) ⇒ Boolean
Sends a MIDI message as numeric bytes.
-
#puts_s(data) ⇒ Boolean
(also: #puts_bytestr, #puts_hex)
Sends a MIDI message as a hex string.
Instance Attribute Details
#enabled ⇒ Boolean (readonly) Also known as: enabled? Originally defined in module Endpoint
Returns whether the endpoint has been initialized.
#entity ⇒ Object (readonly)
26 27 28 |
# File 'lib/midi-communications-macos/destination.rb', line 26 def entity @entity end |
#id ⇒ Integer Originally defined in module Endpoint
Returns unique local numeric ID of the endpoint.
#resource_id ⇒ Integer (readonly) Originally defined in module Endpoint
Returns Core MIDI resource identifier.
#type ⇒ Object (readonly) Originally defined in module Endpoint
Class Method Details
.all ⇒ Array<Destination>
Returns all available output endpoints.
152 153 154 |
# File 'lib/midi-communications-macos/destination.rb', line 152 def self.all Endpoint.all_by_type[:destination] end |
.first ⇒ Destination
Returns the first available output endpoint.
134 135 136 |
# File 'lib/midi-communications-macos/destination.rb', line 134 def self.first Endpoint.first(:destination) end |
.last ⇒ Destination
Returns the last available output endpoint.
141 142 143 |
# File 'lib/midi-communications-macos/destination.rb', line 141 def self.last Endpoint.last(:destination) end |
Instance Method Details
#close ⇒ Boolean
Closes this output.
31 32 33 34 35 36 37 38 |
# File 'lib/midi-communications-macos/destination.rb', line 31 def close if @enabled @enabled = false true else false end end |
#display_name ⇒ String Originally defined in module Endpoint
Returns formatted display name (delegated to entity).
#enable {|destination| ... } ⇒ Destination Also known as: open, start
Opens this output for use.
When a block is given, the output is automatically closed when the block exits.
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/midi-communications-macos/destination.rb', line 114 def enable @enabled ||= true if block_given? begin yield(self) ensure close end end self end |
#initialize(resource_id, entity) ⇒ Object Originally defined in module Endpoint
#manufacturer ⇒ String Originally defined in module Endpoint
Returns device manufacturer name (delegated to entity).
#model ⇒ String Originally defined in module Endpoint
Returns device model name (delegated to entity).
#name ⇒ String Originally defined in module Endpoint
Returns endpoint name (delegated to entity).
#online? ⇒ Boolean Originally defined in module Endpoint
Is this endpoint online?
#puts(*args) ⇒ Boolean Also known as: write
Sends a MIDI message in any supported format.
Accepts multiple formats:
- Numeric bytes:
puts(0x90, 0x40, 0x40) - Array of bytes:
puts([0x90, 0x40, 0x40]) - Hex string:
puts("904040")
92 93 94 95 96 97 98 |
# File 'lib/midi-communications-macos/destination.rb', line 92 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
Sends a MIDI message as numeric bytes.
67 68 69 70 71 72 |
# File 'lib/midi-communications-macos/destination.rb', line 67 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
Sends a MIDI message as a hex string.
48 49 50 51 52 53 54 55 56 |
# File 'lib/midi-communications-macos/destination.rb', line 48 def puts_s(data) data = data.dup bytes = [] until (str = data.slice!(0, 2)).eql?('') bytes << str.hex end puts_bytes(*bytes) true end |