Java Code Examples for javax.sound.midi.MidiDevice#getTransmitter()

The following examples show how to use javax.sound.midi.MidiDevice#getTransmitter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MidiReciever.java    From Panako with GNU Affero General Public License v3.0 5 votes vote down vote up
public MidiReciever()
    {
        MidiDevice device;
        MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
        for (int i = 0; i < infos.length; i++) {
            try {
            device = MidiSystem.getMidiDevice(infos[i]);
            //does the device have any transmitters?
            //if it does, add it to the device list
            System.out.println(infos[i]);

            //get all transmitters
            List<Transmitter> transmitters = device.getTransmitters();
            //and for each transmitter

            for(int j = 0; j<transmitters.size();j++) {
                //create a new receiver
                transmitters.get(j).setReceiver(
                        //using my own MidiInputReceiver
                        new MidiInputReceiver(device.getDeviceInfo().toString())
                );
            }

            Transmitter trans = device.getTransmitter();
            trans.setReceiver(new MidiInputReceiver(device.getDeviceInfo().toString()));

            //open each device
            device.open();
            //if code gets this far without throwing an exception
            //print a success message
            System.out.println(device.getDeviceInfo()+" Was Opened");


        } catch (MidiUnavailableException e) {}
    }


}
 
Example 2
Source File: DefaultDevices.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean testDevice(MidiDevice device, Class type,
        String providerClassName, String instanceName,
        boolean expectedResult) {
    boolean allOk = true;

    try {
        String propertyName = type.getName();
        String propertyValue = (providerClassName != null) ? providerClassName: "" ;
        propertyValue += "#" + instanceName;
        out("property: " + propertyName + "="+ propertyValue);
        System.setProperty(propertyName, propertyValue);
        Object reference = null;
        Object result = null;
        if (type == SEQUENCER_CLASS) {
            reference = device;
            result = MidiSystem.getSequencer();
        } else if (type == SYNTHESIZER_CLASS) {
            reference = device;
            result = MidiSystem.getSynthesizer();
        } else if (type == RECEIVER_CLASS) {
            reference = device.getReceiver();
            result = MidiSystem.getReceiver();
        } else if (type == TRANSMITTER_CLASS) {
            reference = device.getTransmitter();
            result = MidiSystem.getTransmitter();
        }
        out("result: " + result);
        boolean rightDevice = (reference.getClass() == result.getClass());
        if (rightDevice != expectedResult) {
            out("\nERROR: type " + type + " failed:"
                    + " class should" + (expectedResult ? "" : " NOT") + " be '"
                    + reference.getClass()
                    + "' but is '" + result.getClass() + "'!\n");
            allOk = false;
        }
        if (expectedResult
                && reference instanceof MidiDevice
                && result instanceof MidiDevice) {
            MidiDevice referenceDevice = (MidiDevice)reference;
            MidiDevice resultDevice = (MidiDevice)result;
            if (!referenceDevice.getDeviceInfo().getName().equals(
                                resultDevice.getDeviceInfo().getName())) {
                out("\nERROR: type " + type + " failed: name should be '"
                        + referenceDevice.getDeviceInfo().getName()
                        + "' but is '"
                        + resultDevice.getDeviceInfo().getName() + "'!\n");
                allOk = false;
            }
        }
        if (result instanceof Receiver) {
            ((Receiver)result).close();
        } else if (result instanceof Transmitter) {
            ((Transmitter)result).close();
        } else if (result instanceof Synthesizer) {
            ((Synthesizer)result).close();
        } else if (result instanceof Sequencer) {
            ((Sequencer)result).close();
        }
    } catch (Exception e) {
        out("Exception thrown; Test NOT failed.");
        e.printStackTrace(System.out);
        out("");
    }
    return allOk;
}
 
Example 3
Source File: MidiCommunication.java    From jmg with GNU General Public License v2.0 5 votes vote down vote up
private void setMidiInputSelection(int inputDeviceID, MidiDevice.Info[] info) {
    try {
        // inut setup
        MidiDevice inputPort = MidiSystem.getMidiDevice (info [inputDeviceID]);
        //System.out.println (inputPort);
        inputPort.open ();
        Transmitter t = inputPort.getTransmitter ();
        t.setReceiver(this);
    } catch (Exception e) {
        // Oops! Should never get here
        System.out.println ("Exception in PlumStone main ()");
        System.out.println (e);
        System.exit (0);
    }
}