Class: MIDIJRuby::Input

Inherits:
Object
  • Object
show all
Includes:
Device
Defined in:
lib/midi-jruby/input.rb

Overview

Input device class

Instance Attribute Summary collapse

Attributes included from Device

#description, #enabled, #id, #name, #type, #vendor

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Device

all_by_type, #initialize

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



8
9
10
# File 'lib/midi-jruby/input.rb', line 8

def buffer
  @buffer
end

Class Method Details

.allArray<Input>

All inputs

Returns:



90
91
92
# File 'lib/midi-jruby/input.rb', line 90

def self.all
  Device.all_by_type[:input]
end

.clearObject



111
112
113
114
# File 'lib/midi-jruby/input.rb', line 111

def @buffer.clear
  @pointer = 0
  super
end

.firstInput

Select the first input

Returns:



78
79
80
# File 'lib/midi-jruby/input.rb', line 78

def self.first
  Device.first(:input)
end

.lastInput

Select the last input

Returns:



84
85
86
# File 'lib/midi-jruby/input.rb', line 84

def self.last
  Device.last(:input)
end

Instance Method Details

#closeBoolean

Close this input

Returns:

  • (Boolean)


70
71
72
73
74
# File 'lib/midi-jruby/input.rb', line 70

def close
  @listener.kill
  API.close_input(@device)
  @enabled = false
end

#enable(_options = {}) ⇒ Input Also known as: open, start

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

Parameters:

  • options (Hash)
  • block (Proc)

Returns:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/midi-jruby/input.rb', line 50

def enable(_options = {})
  unless @enabled
    initialize_input
    @enabled = true
  end
  if block_given?
    begin
      yield(self)
    ensure
      close
    end
  else
    self
  end
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
# File 'lib/midi-jruby/input.rb', line 22

def gets
  loop until queued_messages?
  messages = queued_messages
  @pointer = @buffer.length
  messages
end

#gets_sArray<Hash> Also known as: gets_bytestr, gets_hex

Same as Input#gets but returns message data as string of hex digits: [

{ :data => "904060", :timestamp => 904 },
{ :data => "804060", :timestamp => 1150 },
{ :data => "90447F", :timestamp => 1300 }

]

Returns:

  • (Array<Hash>)


38
39
40
41
42
# File 'lib/midi-jruby/input.rb', line 38

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