⊥Źródło: https://github.com/sparks/themidibus
Pierwszy program wysyła nuty przez interfejs MIDI do dowolnego instrumentu. Po pierwszym uruchomieniu w konsoli interfejsu programu sprawdzamy numer portu MIDI instrumentu, który ma odegrać nuty. Osobno dla wejścia i wyjścia. W moim przypadku wygląda to tak:
Available MIDI Devices:
———-Input———-
[0] “Magistrala 1”
[1] “Saffire 6USB”
[2] “LPD8”
[3] “Maschine Mikro MK2 Input”
[4] “Real Time Sequencer”
———-Output———-
[0] “Gervill”
[1] “Magistrala 1”
[2] “Saffire 6USB”
[3] “LPD8”
[4] “Maschine Mikro MK2 Output”
[5] “Real Time Sequencer”
Wpisałem: myBus = new MidiBus(this, “LPD8”, “Saffire 6USB”);Mogłem też wpisać 2 i 2.
I to praktycznie wszystko. Trochę zmodyfikowałem program, żeby zamiast pojedynczej nuty odtwarzał kolejne.
//MIDI_OUT_yar
import themidibus.*; //Import the library
MidiBus myBus; // The MidiBus
void setup() {
size(400, 400);
background(0);
MidiBus.list(); // List all available Midi devices on STDOUT. This will show each device's index and name.
myBus = new MidiBus(this, "LPD8", "Saffire 6USB"); // Create a new MidiBus object
// On mac you will need to use MMJ since Apple's MIDI subsystem doesn't properly support SysEx.
// However MMJ doesn't support sending timestamps so you have to turn off timestamps.
// myBus.sendTimestamps(false);
}
void draw() {
int channel = 0;
int pitch = 64;
int velocity = 110;
for(int i=32; i<98; i=i++){
myBus.sendNoteOn(channel, i, velocity); // Send a Midi noteOn
delay(50);
myBus.sendNoteOff(channel, i, velocity); // Send a Midi nodeOff
delay(50);}
delay(5);
}
void delay(int time) {
int current = millis();
while (millis () < current+time) Thread.yield();
}