Class: MTK::IO::MIDIInput
- Inherits:
-
Object
- Object
- MTK::IO::MIDIInput
show all
- Defined in:
- lib/mtk/io/midi_input.rb
Overview
Common behavior for realtime MIDI input.
Instance Attribute Summary collapse
-
#device ⇒ Object
readonly
The underlying output device implementation wrapped by this class.
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(input_device, options = {}) ⇒ MIDIInput
Returns a new instance of MIDIInput.
57
58
59
60
61
|
# File 'lib/mtk/io/midi_input.rb', line 57
def initialize(input_device, options={})
@device = input_device
@device.open
@options = options
end
|
Instance Attribute Details
#device ⇒ Object
The underlying output device implementation wrapped by this class. The device type depends on the platform.
70
71
72
|
# File 'lib/mtk/io/midi_input.rb', line 70
def device
@device
end
|
Class Method Details
14
15
16
|
# File 'lib/mtk/io/midi_input.rb', line 14
def available_input_types
@available_input_types ||= []
end
|
.devices ⇒ Object
All available input devices.
27
28
29
|
# File 'lib/mtk/io/midi_input.rb', line 27
def devices
@devices ||= available_input_types.map{|input_type| input_type.devices }.flatten
end
|
.devices_by_name ⇒ Object
Maps input device names to the input device.
32
33
34
35
36
37
38
|
# File 'lib/mtk/io/midi_input.rb', line 32
def devices_by_name
@devices_by_name ||= (
available_input_types.each_with_object( Hash.new ) do |input_type,hash|
hash.merge!( input_type.devices_by_name )
end
)
end
|
.find_by_name(name) ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/mtk/io/midi_input.rb', line 40
def find_by_name(name)
if name.is_a? Regexp
matching_name = devices_by_name.keys.find{|device_name| device_name =~ name }
device = devices_by_name[matching_name]
else
device = devices_by_name[name.to_s]
end
open(device) if device
end
|
18
19
20
21
22
23
24
|
# File 'lib/mtk/io/midi_input.rb', line 18
def input_types_by_device
@input_types_by_device ||= (
available_input_types.each_with_object( Hash.new ) do |input_type,hash|
input_type.devices.each{|device| hash[device] = input_type }
end
)
end
|
.open(device) ⇒ Object
50
51
52
53
|
# File 'lib/mtk/io/midi_input.rb', line 50
def open(device)
input_type = input_types_by_device[device]
input_type.new(device) if input_type
end
|
Instance Method Details
#name ⇒ Object
72
73
74
|
# File 'lib/mtk/io/midi_input.rb', line 72
def name
@device.name
end
|
#record ⇒ Object
76
77
|
# File 'lib/mtk/io/midi_input.rb', line 76
def record
end
|
#stop ⇒ Object
79
80
|
# File 'lib/mtk/io/midi_input.rb', line 79
def stop
end
|