Media Lab/Media Art

Processing에서 MIDI 연주 예제

바나나인간 2019. 2. 26. 14:56

Processing에서 MIDI 소리를 출력하기 위해 먼저 midibus 라이브러리를 설치한다.


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
import themidibus.*;
 
MidiBus bus;
int velocity;
int note;
 
void setup(){
  size(256256);
  background(0);
  MidiBus.list(); 
  bus= new MidiBus(this02);
}
 
void draw(){
 
}
 
void mousePressed(){
  note= mouseX;
  velocity= mouseY;
  bus.sendNoteOn(0, note, velocity);
}
 
void mouseReleased(){
  bus.sendNoteOff(0, note, velocity);
}
cs


이렇게 되면 마우스의 위치에 따라 음의 높낮이와 강세가 다른 음이 클릭할 때 출력된다.