-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathoutput.rb
More file actions
31 lines (24 loc) · 739 Bytes
/
Copy pathoutput.rb
File metadata and controls
31 lines (24 loc) · 739 Bytes
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
#!/usr/bin/env ruby
# frozen_string_literal: true
dir = File.dirname(File.expand_path(__FILE__))
$LOAD_PATH.unshift "#{dir}/../lib"
require 'alsa-rawmidi'
# Selects the first MIDI output and sends some arpeggiated chords to it
notes = [36, 40, 43] # C E G
octaves = 5
duration = 0.1
# AlsaRawMIDI::Device.all.to_s will list your midi devices
# or amidi -l from the command line
puts 'Press Control-C to exit...'
AlsaRawMIDI::Output.first.open do |output|
loop do
(0..((octaves - 1) * 12)).step(12) do |oct|
notes.each do |note|
output.puts(0x90, note + oct, 100) # NOTE: on
sleep(duration) # wait
output.puts(0x80, note + oct, 100) # NOTE: off
sleep(duration)
end
end
end
end