I would like to have a program that could do something when it gets a midi input.
For instance when I click button 1 on my controller it should print "You clicked btn 1" and when I click button 2 it should print "You clicked btn 2".
I tried using the javax.sound.midi library but all the examples in forums or on youtube didn't work for.
This worked the most for me. It printed all of the Midi Devices of my PC but it didn't receive anything. Can anybody help?
package de.snke.dev;
import javax.sound.midi.*;;
public class Main extends Object implements Receiver{
static MidiClass myMidi;
public static void main(String[] args) throws Exception {
MidiDevice.Info[] info =
MidiSystem.getMidiDeviceInfo();
for (int i=0; i < info.length; i++) {
System.out.println(i + ") " + info[i]);
System.out.println("Name: " + info[i].getName());
System.out.println("Description: " +
info[i].getDescription());
MidiDevice device =
MidiSystem.getMidiDevice(info[i]);
System.out.println("Device: " + device);
}
}
public void send(MidiMessage msg,
long time) {
System.out.println("Received message " + msg);
}
public void close() {
System.out.println("Closing");
}
}
EDIT: Now I have
Sequencer seq;
Transmitter seqTrans;
Synthesizer synth;
Receiver synthRcvr;
try {
seq = MidiSystem.getSequencer();
seqTrans = seq.getTransmitter();
synth = MidiSystem.getSynthesizer();
synthRcvr = synth.getReceiver();
seqTrans.setReceiver(synthRcvr);
} catch (MidiUnavailableException e) {
// handle or throw exception
}
Have I now connected to my APC Mini? Sorry I'm a beginner... If Yes how can I now read the midi input? And if No what do I have to change?