public void setInputDevice(MidiDevice device) {
        //close existing connection, if there is one
        try {
            inputDevice.close();
        } catch (NullPointerException npe) {

        }

        inputDevice = device;

        System.out.println("Trying to open " + inputDevice.getDeviceInfo().getName() + "...");
        try {
            Transmitter trans = inputDevice.getTransmitter();
            trans.setReceiver(new MidiInputHandler(this));
            inputDevice.open();
            System.out.println("Device opened successfully!\n");
        } catch (MidiUnavailableException mue) {
            System.out.println("Couldn't open this device!");
            System.out.println("\tException thrown: " + mue.toString());
        }
    }