-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmidi_visualizer_framework.pde
31 lines (25 loc) · 1.08 KB
/
midi_visualizer_framework.pde
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
import themidibus.*; // import the midibus library
import java.util.*; // import java util to use ArrayLists
MidiBus bus; // interface with the MidiBus library
NoteManager nm; // note manager to handle tracking of MIDI notes
void setup() {
size(700, 700); // set the size of the window
background(0); // set the background color of window
MidiBus.list(); // list all available Midi devices
bus = new MidiBus(this, 0, 1); // tell MidiBus to listen to connected MIDI instrument
nm = new NoteManager(); // create a note manager
}
void draw() {
background(0); // reset the background color
nm.track(); // track notes being played, updating and displaying them
}
// when a new key is pressed on the MIDI instrument
void noteOn(int channel, int pitch, int velocity) {
// add this note
nm.addNote(new Note(channel, pitch, velocity));
}
// when a key is released on the MIDI instrument
void noteOff(int channel, int pitch, int velocity) {
// release this note
nm.releaseNote(new Note(channel, pitch, velocity));
}