launchpad icon indicating copy to clipboard operation
launchpad copied to clipboard

Better Device Finding

Open jocopa3 opened this issue 8 years ago • 1 comments

I know this library is infrequently updated, but there are better ways to find available devices than guessing from a pre-written list of device names. It looks like an attempt to improve device searching was made (i.e. calling midiBus.availableInputs() is there, but not used), so I decided to expand on that:

//Guess the Launchpad type
public Launchpad() {
    this.connected = false;

    System.out.println("Guessing Launchpad...");

    midiBus = new MidiBus();
    String[] deviceNames = midiBus.availableInputs();

    for(int i = 0; i < deviceNames.length && !connected; i++) {
        if (deviceNames[i].toLowerCase().contains("launchpad") && midiBus.addInput(deviceNames[i]) && midiBus.addOutput(deviceNames[i])) {
            System.out.println("Launchpad named \""+deviceNames[i]+"\" was found!");
            midiBus.addMidiListener(this);

            listeners = new Vector<LaunchpadListener>();
            addListener(new MonomeLaunchpad(this));
            reset();
            this.connected = true;
            break;
        }
    }
}

In the code above, I removed all Processing references since I don't use Processing, but it should work the same with or without Processing. I'm not aware of any Novation products that use the "Launchpad" name but aren't actually launchpads, so it should work fine with all devices.

I'm also updating the library for Launchpad Pro support, even though I don't own one (occasionally borrowing from a friend who wanted custom software for it), so a lot of the code is a shot in the dark trying to follow its programmers reference.

jocopa3 avatar Aug 15 '15 07:08 jocopa3