Class: RtMidi::In

Inherits:
Object
  • Object
show all
Defined in:
lib/rtmidi/in.rb

Overview

Ruby representation of a RtMidiIn C++ object

See Also:

Instance Method Summary collapse

Constructor Details

#initializeIn

Create a new RtMidiIn wrapper object.



8
9
10
11
# File 'lib/rtmidi/in.rb', line 8

def initialize
  @midiin = Interface::midiin_new()
  at_exit{ Interface::midiin_delete @midiin }
end

Instance Method Details

#cancel_callbackObject

Cancel previously registered callbacks.

See Also:



70
71
72
# File 'lib/rtmidi/in.rb', line 70

def cancel_callback
  Interface::midiin_cancel_callback(@midiin)
end

#close_portsObject

Close all opened ports.



45
46
47
# File 'lib/rtmidi/in.rb', line 45

def close_ports()
  Interface::midiin_close_port(@midiin)
end

#open_port(index) ⇒ Object

Open the MIDI input port at the given index.

See Also:



40
41
42
# File 'lib/rtmidi/in.rb', line 40

def open_port(index)
  Interface::midiin_open_port(@midiin, index)
end

#port_countObject

The number of MIDI input ports available.



14
15
16
# File 'lib/rtmidi/in.rb', line 14

def port_count      
  @port_count ||= Interface::midiin_port_count(@midiin)
end

#port_name(index) ⇒ Object

The name of the MIDI input port at the given index.

See Also:



20
21
22
# File 'lib/rtmidi/in.rb', line 20

def port_name(index)
  port_names[index]
end

#port_namesObject

The list of all MIDI input port names.

The index of a port in this list is the index to be passed to #port_name and #open_port.



30
31
32
33
34
35
36
# File 'lib/rtmidi/in.rb', line 30

def port_names
  @port_names ||= (
    names = []
    port_count.times{|i| names << Interface::midiin_port_name(@midiin, i) }
    names
  )       
end

#set_callback(&callback) ⇒ Object

Setup a callback block to handle incoming MIDI channel messages from opened ports.

The block should receive 3 bytes (Ruby integers)

All messages are assumed to have 3 bytes. Some channel messages only have 2 bytes in which case the 3rd byte is 0.

Examples:

midiin.set_callback do |byte1, byte2, byte3|
  puts "#{byte1} #{byte2} #{byte3}"
end

See Also:



64
65
66
# File 'lib/rtmidi/in.rb', line 64

def set_callback &callback      
  Interface::midiin_set_callback(@midiin, callback)
end