Builder_20
Builder_20

Reputation: 31

How can i send a Midi Message to a specific Midi Port

I want to send Note_On Message to a virtual Midi Interface called LoopBe (Link to Site). How do i get the Receiver object (Java)? I tried the Code below but I get a NullPointerException on rcvr.send().

public class test {

public static Receiver rcvr;

public static void main(String[] args) throws InvalidMidiDataException, MidiUnavailableException {
    String scene = "Test";
    getReceiver();
    ShortMessage myMsg = new ShortMessage();
    // Nachricht Channel Note Lautstärke
    myMsg.setMessage(ShortMessage.NOTE_ON, 0, 1, 127);
    rcvr.send(myMsg, -1);
    System.out.println("Szene " + scene + " ausgelöst");
}

public static void getReceiver() throws MidiUnavailableException {
    MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
    for(Info devices : infos )
    {
        System.out.println(devices.getName() + " : " + devices.getDescription());
        if(devices.getName() == "LoopBe Internal MIDI" && devices.getDescription() == "No details available") {
            MidiDevice device = MidiSystem.getMidiDevice(devices); 
            rcvr =  device.getReceiver();
            System.out.println("Receiver: " + rcvr.toString());
        }
    }
  }
}

I tried rcvr = MidiSystem.getReceiver() and it worked, but it sends the message to com.sun.media.sound.MidiOutDevice$MidiOutReceiver@404b9385.

Upvotes: 0

Views: 350

Answers (1)

CL.
CL.

Reputation: 180230

You should open the device before using it.

Upvotes: 4

Related Questions