Class: MIDICommunicationsMacOS::Source
- Inherits:
- 
      Object
      
        - Object
- MIDICommunicationsMacOS::Source
 
- Includes:
- Endpoint
- Defined in:
- lib/midi-communications-macos/source.rb
Overview
Type of endpoint used for input
Instance Attribute Summary
Attributes included from Endpoint
#enabled, #entity, #id, #resource_id, #type
Class Method Summary collapse
- 
  
    
      .all  ⇒ Array<Source> 
    
    
  
  
  
  
  
  
  
  
  
    All input endpoints. 
- 
  
    
      .first  ⇒ Source 
    
    
  
  
  
  
  
  
  
  
  
    Shortcut to the first available input endpoint. 
- 
  
    
      .last  ⇒ Source 
    
    
  
  
  
  
  
  
  
  
  
    Shortcut to the last available input endpoint. 
Instance Method Summary collapse
- 
  
    
      #close  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Close this input. 
- 
  
    
      #enable  ⇒ Source 
    
    
      (also: #open, #start)
    
  
  
  
  
  
  
  
  
  
    Enable this the input for use; can be passed a block. 
- 
  
    
      #gets  ⇒ Array<Hash> 
    
    
      (also: #read)
    
  
  
  
  
  
  
  
  
  
    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 } ]. 
- 
  
    
      #gets_s  ⇒ Array<Hash> 
    
    
      (also: #gets_bytestr)
    
  
  
  
  
  
  
  
  
  
    Same as Source#gets except that it returns message data as string of hex digits as such: [ { data: “904060”, timestamp: 904 }, { data: “804060”, timestamp: 1150 }, { data: “90447F”, timestamp: 1300 } ]. 
Methods included from Endpoint
all_by_type, destinations, get_class, #initialize, #online?, sources
Class Method Details
.all ⇒ Array<Source>
All input endpoints
| 90 91 92 | # File 'lib/midi-communications-macos/source.rb', line 90 def self.all Endpoint.all_by_type[:source] end | 
Instance Method Details
#close ⇒ Boolean
Close this input
| 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | # File 'lib/midi-communications-macos/source.rb', line 59 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 | 
#enable ⇒ Source Also known as: open, start
Enable this the input for use; can be passed a block
| 43 44 45 46 47 48 49 50 51 52 53 | # File 'lib/midi-communications-macos/source.rb', line 43 def enable @enabled ||= true if block_given? begin yield(self) ensure close end end self end | 
#gets ⇒ Array<Hash> Also known as: read
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
| 18 19 20 | # File 'lib/midi-communications-macos/source.rb', line 18 def gets end | 
#gets_s ⇒ Array<Hash> Also known as: gets_bytestr
Same as Source#gets except that it returns message data as string of hex digits as such:
[
  { data: "904060", timestamp: 904 },
  { data: "804060", timestamp: 1150 },
  { data: "90447F", timestamp: 1300 }
]
| 32 33 34 35 36 37 38 | # File 'lib/midi-communications-macos/source.rb', line 32 def gets_s = gets .each do || [:data] = TypeConversion.numeric_bytes_to_hex_string([:data]) end end |