Class: MIDICommunicationsMacOS::Source
- Inherits:
-
Object
- Object
- MIDICommunicationsMacOS::Source
- Includes:
- Endpoint
- Defined in:
- lib/midi-communications-macos/source.rb
Overview
Instance Attribute Summary collapse
-
#enabled ⇒ Boolean
(also: #enabled?)
included
from Endpoint
readonly
Whether the endpoint has been initialized.
-
#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<Source>
Returns all available input endpoints.
-
.first ⇒ Source
Returns the first available input endpoint.
-
.last ⇒ Source
Returns the last available input endpoint.
Instance Method Summary collapse
-
#close ⇒ Boolean
Closes this input.
-
#display_name ⇒ String
included
from Endpoint
Formatted display name (delegated to entity).
-
#enable {|source| ... } ⇒ Source
(also: #open, #start)
Opens this input for use.
-
#gets ⇒ Array<Hash>
(also: #read)
Reads MIDI messages from the input buffer.
-
#gets_s ⇒ Array<Hash>
(also: #gets_bytestr)
Reads MIDI messages as hex strings.
- #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?.
Instance Attribute Details
#enabled ⇒ Boolean (readonly) Also known as: enabled? Originally defined in module Endpoint
Returns whether the endpoint has been initialized.
#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<Source>
Returns all available input endpoints.
150 151 152 |
# File 'lib/midi-communications-macos/source.rb', line 150 def self.all Endpoint.all_by_type[:source] end |
.first ⇒ Source
Returns the first available input endpoint.
132 133 134 |
# File 'lib/midi-communications-macos/source.rb', line 132 def self.first Endpoint.first(:source) end |
.last ⇒ Source
Returns the last available input endpoint.
139 140 141 |
# File 'lib/midi-communications-macos/source.rb', line 139 def self.last Endpoint.last(:source) end |
Instance Method Details
#close ⇒ Boolean
Closes this input.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/midi-communications-macos/source.rb', line 109 def close #error = API.MIDIPortDisconnectSource( @handle, @resource ) #raise "MIDIPortDisconnectSource returned error code #{error}" unless error.zero? #error = API.MIDIClientDispose(@handle) #raise "MIDIClientDispose returned error code #{error}" unless error.zero? #error = API.MIDIPortDispose(@handle) #raise "MIDIPortDispose returned error code #{error}" unless error.zero? #error = API.MIDIEndpointDispose(@resource) #raise "MIDIEndpointDispose returned error code #{error}" unless error.zero? 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 {|source| ... } ⇒ Source Also known as: open, start
Opens this input for use.
When a block is given, the input is automatically closed when the block exits.
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/midi-communications-macos/source.rb', line 92 def enable @enabled ||= true if block_given? begin yield(self) ensure close end end self end |
#gets ⇒ Array<Hash> Also known as: read
Reads MIDI messages from the input buffer.
Returns an array of MIDI event hashes. Each hash contains:
:data- Array of numeric bytes (e.g., [144, 60, 100]):timestamp- Float timestamp when the message was received
This method blocks until at least one message is available.
An array of MIDI event hashes as such: [ { data: [144, 60, 100], timestamp: 1024 }, { data: [128, 60, 100], timestamp: 1100 }, { data: [144, 40, 120], timestamp: 1200 } ]
The data is an array of Numeric bytes The timestamp is the number of millis since this input was enabled
50 51 52 |
# File 'lib/midi-communications-macos/source.rb', line 50 def gets end |
#gets_s ⇒ Array<Hash> Also known as: gets_bytestr
Reads MIDI messages as hex strings.
Same as #gets but returns message data as hex strings instead of byte arrays.
66 67 68 69 70 71 72 |
# File 'lib/midi-communications-macos/source.rb', line 66 def gets_s = gets .each do || [:data] = TypeConversion.numeric_bytes_to_hex_string([:data]) end 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?