-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmidi.rb
More file actions
52 lines (44 loc) · 1.04 KB
/
midi.rb
File metadata and controls
52 lines (44 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'unimidi'
def list_midi_devices
puts "Available MIDI Input Devices:"
UniMIDI::Input.list.each_with_index do |input, index|
puts "#{index}) #{input.inspect}"
end
end
def select_midi_device
list_midi_devices
print "Select a MIDI device by number: "
$stdout.flush
device_index = gets.chomp.to_i
begin
input = UniMIDI::Input.use(device_index)
puts "Selected MIDI device: #{input.inspect}"
input
rescue
puts "Invalid selection. Exiting."
exit
end
end
def monitor_midi_signals(input)
puts "Listening for MIDI signals from #{input.inspect}..."
puts "Press Ctrl+C to exit."
loop do
messages = input.gets
messages.each do |message|
timestamp = message[:timestamp]
data = message[:data]
# Active Sensing (254) を無視
next if data[0] == 254
puts "[#{timestamp}] #{data.inspect}"
end
rescue Interrupt
puts "\nExiting MIDI monitor."
exit
end
end
begin
input = select_midi_device
monitor_midi_signals(input)
rescue Interrupt
puts "\nExiting program."
end