-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtranspose.rb
More file actions
executable file
·51 lines (40 loc) · 1.52 KB
/
Copy pathtranspose.rb
File metadata and controls
executable file
·51 lines (40 loc) · 1.52 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
#!/usr/bin/env ruby
# frozen_string_literal: true
$LOAD_PATH.unshift(File.join('..', 'lib'))
require 'midi-eye'
# This example takes any note messages received from a UniMIDI input,
# transposes them up one octave and sends them to an output
# First, initialize the MIDI io ports
@input = UniMIDI::Input.gets
@output = UniMIDI::Output.gets
# Create a listener for the input port
transpose = MIDIEye::Listener.new(@input)
# Bind an event to the listener using Listener#listen_for
#
# The listener will try to positively match the parameters you pass in to the properties of
# the messages it receives
#
# This example looks for note on/off messages
#
# You also have the option of leaving out the parameters altogether and including a conditional
# in your callback (eg if event[:message].class.eql?(NoteOn) do... etc)
#
# There's no limit to how many events can be binded to a listener
#
transpose.listen_for(class: [MIDIMessage::NoteOn, MIDIMessage::NoteOff]) do |event|
# Raise the note value by an octave
new_note = event[:message].note + 12
puts "Transposing from note #{event[:message].note} to note #{new_note}"
event[:message].note = new_note
# Send the altered note message to the output
@output.puts(event[:message])
end
# Start the listener
p 'Control-C to quit...'
transpose.run
# You can also have the listener run only in a background thread by using
#
# Transpose.run(:background => true)
#
# This will allow you to run multiple listeners at the same time for example, if you
# want to listen on multiple input ports