Processing.org with Midi Interface
- ซาลาเปา หมั่นโถว
- 10 มิ.ย. 2561
- ยาว 1 นาที
วัตถุประสงค์
เพื่อศึกษาวิธีใช้ซอฟต์แวร์ Processing.org
เพื่อสร้างโปรแกรมเชื่อมต่อระหว่าง Processing.org และ Midi interface
วัสดุอุปกรณ์
- Processing

- Novation Launchkey Mini

Code
Code: Import Function
import javax.sound.midi.*;
import themidibus.*;
Code: กำหนดตัวแปร
int channel = 0;
int pitch = 64;
int velocity = 127;
Synthesizer synth;
Receiver receiver;
MidiBus myBus;
Code: ตั้งค่าหน้าจอ Input Output และเสียงดนตรี
void setup() {
size(400, 400);
background(0);
MidiBus.list();
myBus = new MidiBus(this, "Launchkey Mini", "Real Time Sequencer");
try {
// Get Java Synthesizer
synth = javax.sound.midi.MidiSystem.getSynthesizer();
synth.open();
receiver = synth.getReceiver();
}
catch (MidiUnavailableException e) {
println(e); }
}
Code: ใช้คำสั่ง NoteOn NoteOff เพื่อรับค่าจาก Midi Interface แล้วส่งไปที่ฟังก์ชัน Real Time Sequencer ในคอมพิวเตอร์
void draw()
{
myBus.sendNoteOn(channel, pitch, velocity); // Send a Midi noteOn
//delay(200);
myBus.sendNoteOff(channel, pitch, velocity); // Send a Midi nodeOff
//delay(100);
}
Code: Control
void noteOn(int channel, int pitch, int velocity)
{
try {
receiver.send( new ShortMessage(ShortMessage.NOTE_ON, channel, pitch, velocity), millis() );
} catch (Exception e) { println(e); }
}
void noteOff(int channel, int pitch, int velocity)
{
try {
receiver.send( new ShortMessage(ShortMessage.NOTE_OFF, channel, pitch, velocity), millis() );
} catch (Exception e) { println(e); }
}
Comentários