Class: CoreMIDI::Source

Inherits:
Object
  • Object
show all
Includes:
Endpoint
Defined in:
lib/shmidi/ffi-coremidi-patch.rb

Overview

Type of endpoint used for input

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



8
9
10
# File 'lib/shmidi/ffi-coremidi-patch.rb', line 8

def buffer
  @buffer
end

Class Method Details

.allArray<Source>

All input endpoints

Returns:



103
104
105
# File 'lib/shmidi/ffi-coremidi-patch.rb', line 103

def self.all
  Endpoint.all_by_type[:source]
end

.clearObject



250
251
252
253
# File 'lib/shmidi/ffi-coremidi-patch.rb', line 250

def @buffer.clear
  super
  @pointer = 0
end

.firstSource

Shortcut to the first available input endpoint

Returns:



91
92
93
# File 'lib/shmidi/ffi-coremidi-patch.rb', line 91

def self.first
  Endpoint.first(:source)
end

.lastSource

Shortcut to the last available input endpoint

Returns:



97
98
99
# File 'lib/shmidi/ffi-coremidi-patch.rb', line 97

def self.last
  Endpoint.last(:source)
end

Instance Method Details

#closeBoolean

Close this input

Returns:

  • (Boolean)


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/shmidi/ffi-coremidi-patch.rb', line 72

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(options = {}, &block) ⇒ Source Also known as: open, start

Enable this the input for use; can be passed a block

Returns:



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/shmidi/ffi-coremidi-patch.rb', line 56

def enable(options = {}, &block)
  @enabled = true unless @enabled
  if block_given?
    begin
      yield(self)
    ensure
      close
    end
  end
  self
end

#getsArray<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

Returns:

  • (Array<Hash>)


22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/shmidi/ffi-coremidi-patch.rb', line 22

def gets
  # SINM ADDED
  @queue.pop
  # SINM COMMENTED OUT
  # until queued_messages?
  #   # per https://github.com/arirusso/unimidi/issues/20#issuecomment-44761318
  #   sleep(0.0001) # patch to prevent 100% CPU issue with some midi controllers
  # end
  # messages = queued_messages
  # @pointer = @buffer.length
  # messages
end

#gets_sArray<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 }
]

Returns:

  • (Array<Hash>)


45
46
47
48
49
50
51
# File 'lib/shmidi/ffi-coremidi-patch.rb', line 45

def gets_s
  messages = gets
  messages.each do |message|
    message[:data] = TypeConversion.numeric_bytes_to_hex_string(message[:data])
  end
  messages
end