Java Code Examples for javax.sound.midi.MidiSystem#getReceiver()

The following examples show how to use javax.sound.midi.MidiSystem#getReceiver() . 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: ClosedReceiver.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute Receiver.send() and expect that there is no exception.
 */
private static boolean testReceiverSend() {
    boolean result = true;

    Receiver receiver;
    ShortMessage shMsg = new ShortMessage();

    try {
        receiver = MidiSystem.getReceiver();
        shMsg.setMessage(ShortMessage.NOTE_ON, 0,60, 93);
        try {
            receiver.send( shMsg, -1 );
        } catch(IllegalStateException ilEx) {
            ilEx.printStackTrace(System.out);
            out("IllegalStateException was thrown incorrectly!");
            result = false;
        }
        receiver.close();
    } catch(MidiUnavailableException e) {
        out("Midi unavailable, cannot test.");
    } catch(InvalidMidiDataException ine) {
        out("InvalidMidiDataException, cannot test.");
    }
    return result;
}
 
Example 2
Source File: RTMidiIn.java    From jmg with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Initialise the input source
 */
  	private boolean init() {
  		if (trans == null) {
     		try {
        		if (MidiSystem.getReceiver() == null) {
           			System.err.println("MidiSystem Receiver Unavailable");
             			 return false;
         		}
		MidiDevice.Info[] mdi=MidiSystem.getMidiDeviceInfo();
		for(int i=0;i<mdi.length;i++){
			System.out.println(mdi[i]);
		}
		trans = MidiSystem.getTransmitter();
		trans.setReceiver(this);
       	}catch (MidiUnavailableException e) {
        		System.err.println("Midi System Unavailable:" + e);
          		return false;
        	}
  	}
    		return true;
}
 
Example 3
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 4
Source File: InitializationHang.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] argv) {
    try {
        MidiSystem.getReceiver();
        Toolkit.getDefaultToolkit();
    } catch (final MidiUnavailableException ignored) {
        // the test is not applicable
    }
}
 
Example 5
Source File: MidiModule.java    From stagedisplayviewer with MIT License 5 votes vote down vote up
public MidiModule() {
    Receiver tempReceiver = null;

    if (Property.MIDI.isTrue()) {
        try {
            tempReceiver = MidiSystem.getReceiver();
            log.info("Midi module loaded");
        } catch (MidiUnavailableException e) {
            log.error("Midi module failed to load {}", e);
        }
    }
    receiver = tempReceiver;
}
 
Example 6
Source File: InitializationHang.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] argv) throws Exception {
    MidiSystem.getReceiver();
    Toolkit.getDefaultToolkit();
}
 
Example 7
Source File: InitializationHang.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] argv) throws Exception {
    MidiSystem.getReceiver();
    Toolkit.getDefaultToolkit();
}
 
Example 8
Source File: InitializationHang.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] argv) throws Exception {
    MidiSystem.getReceiver();
    Toolkit.getDefaultToolkit();
}
 
Example 9
Source File: InitializationHang.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] argv) throws Exception {
    MidiSystem.getReceiver();
    Toolkit.getDefaultToolkit();
}
 
Example 10
Source File: InitializationHang.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] argv) throws Exception {
    MidiSystem.getReceiver();
    Toolkit.getDefaultToolkit();
}
 
Example 11
Source File: OpenClose.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void fetchObjectMidiSystem() throws MidiUnavailableException {
    receiverMidiSystem = MidiSystem.getReceiver();
}
 
Example 12
Source File: InitializationHang.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] argv) throws Exception {
    MidiSystem.getReceiver();
    Toolkit.getDefaultToolkit();
}
 
Example 13
Source File: InitializationHang.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] argv) throws Exception {
    MidiSystem.getReceiver();
    Toolkit.getDefaultToolkit();
}
 
Example 14
Source File: InitializationHang.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] argv) throws Exception {
    MidiSystem.getReceiver();
    Toolkit.getDefaultToolkit();
}