Class: CoreMIDI::Input
- Inherits:
-
Object
- Object
- CoreMIDI::Input
- Includes:
- Endpoint
- Defined in:
- lib/coremidi/input.rb
Overview
Input endpoint class
Instance Attribute Summary (collapse)
-
- (Object) buffer
readonly
Returns the value of attribute buffer.
Attributes included from Endpoint
#enabled, #entity, #id, #resource_id, #type
Class Method Summary (collapse)
-
+ (Object) all
all input endpoints.
- + (Object) clear
-
+ (Object) first
shortcut to the first available input endpoint.
-
+ (Object) last
shortcut to the last available input endpoint.
Instance Method Summary (collapse)
-
- (Object) close
close this input.
-
- (Object) enable(options = {}, &block)
(also: #open, #start)
enable this the input for use; can be passed a block.
-
- (Object) gets
(also: #read)
returns an array of MIDI event hashes as such:.
-
- (Object) gets_s
(also: #gets_bytestr)
same as gets but returns message data as string of hex digits as such:.
Methods included from Endpoint
all_by_type, #initialize, #online?
Instance Attribute Details
- (Object) buffer (readonly)
Returns the value of attribute buffer
12 13 14 |
# File 'lib/coremidi/input.rb', line 12 def buffer @buffer end |
Class Method Details
+ (Object) all
all input endpoints
90 91 92 |
# File 'lib/coremidi/input.rb', line 90 def self.all Endpoint.all_by_type[:input] end |
+ (Object) clear
168 169 170 171 |
# File 'lib/coremidi/input.rb', line 168 def @buffer.clear super @pointer = 0 end |
+ (Object) first
shortcut to the first available input endpoint
80 81 82 |
# File 'lib/coremidi/input.rb', line 80 def self.first Endpoint.first(:input) end |
+ (Object) last
shortcut to the last available input endpoint
85 86 87 |
# File 'lib/coremidi/input.rb', line 85 def self.last Endpoint.last(:input) end |
Instance Method Details
- (Object) close
close this input
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/coremidi/input.rb', line 67 def close error = Map.MIDIPortDisconnectSource( @handle, @resource ) raise "MIDIPortDisconnectSource returned error code #{error}" unless error.zero? error = Map.MIDIClientDispose(@handle) raise "MIDIClientDispose returned error code #{error}" unless error.zero? error = Map.MIDIPortDispose(@handle) raise "MIDIPortDisposePort returned error code #{error}" unless error.zero? error = Map.MIDIEndpointDispose(@resource) raise "MIDIEndpointDispose returned error code #{error}" unless error.zero? @enabled = false end |
- (Object) enable(options = {}, &block) Also known as: open, start
enable this the input for use; can be passed a block
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/coremidi/input.rb', line 50 def enable( = {}, &block) @enabled = true unless block.nil? begin yield(self) ensure close end else self end end |
- (Object) gets Also known as: read
returns 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
25 26 27 28 29 30 31 |
# File 'lib/coremidi/input.rb', line 25 def gets until end msgs = @pointer = @buffer.length msgs end |
- (Object) gets_s Also known as: gets_bytestr
same as gets but returns message data as string of hex digits as such:
[
{ :data => "904060", :timestamp => 904 },
{ :data => "804060", :timestamp => 1150 },
{ :data => "90447F", :timestamp => 1300 }
]
42 43 44 45 46 |
# File 'lib/coremidi/input.rb', line 42 def gets_s msgs = gets msgs.each { |msg| msg[:data] = numeric_bytes_to_hex_string(msg[:data]) } msgs end |