1 /*
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
63 * contain standard MIDI file data or soundbanks. You can query the
64 * <code>MidiSystem</code> for the format of a specified MIDI file.
65 * <p>
66 * You cannot instantiate a <code>MidiSystem</code>; all the methods are
67 * static.
68 *
69 * <p>Properties can be used to specify default MIDI devices.
70 * Both system properties and a properties file are considered.
71 * The <code>sound.properties</code> properties file is read from
72 * an implementation-specific location (typically it is the <code>lib</code>
73 * directory in the Java installation directory).
74 * If a property exists both as a system property and in the
75 * properties file, the system property takes precedence. If none is
76 * specified, a suitable default is chosen among the available devices.
77 * The syntax of the properties file is specified in
78 * {@link java.util.Properties#load(InputStream) Properties.load}. The
79 * following table lists the available property keys and which methods
80 * consider them:
81 *
82 * <table border=0>
83 * <tr>
84 * <th>Property Key</th>
85 * <th>Interface</th>
86 * <th>Affected Method</th>
87 * </tr>
88 * <tr>
89 * <td><code>javax.sound.midi.Receiver</code></td>
90 * <td>{@link Receiver}</td>
91 * <td>{@link #getReceiver}</td>
92 * </tr>
93 * <tr>
94 * <td><code>javax.sound.midi.Sequencer</code></td>
95 * <td>{@link Sequencer}</td>
96 * <td>{@link #getSequencer}</td>
97 * </tr>
98 * <tr>
99 * <td><code>javax.sound.midi.Synthesizer</code></td>
100 * <td>{@link Synthesizer}</td>
101 * <td>{@link #getSynthesizer}</td>
102 * </tr>
408 * by {@link #getReceiver}.
409 * The connection is made by retrieving a <code>Transmitter</code>
410 * instance from the <code>Sequencer</code> and setting its
411 * <code>Receiver</code>.
412 * Closing and re-opening the sequencer will restore the
413 * connection to the default device.
414 *
415 * <p>If <code>connected</code> is false, the returned
416 * <code>Sequencer</code> instance is not connected, it
417 * has no open <code>Transmitters</code>. In order to
418 * play the sequencer on a MIDI device, or a <code>Synthesizer</code>,
419 * it is necessary to get a <code>Transmitter</code> and set its
420 * <code>Receiver</code>.
421 *
422 * <p>If the system property
423 * <code>javax.sound.midi.Sequencer</code>
424 * is defined or it is defined in the file "sound.properties",
425 * it is used to identify the default sequencer.
426 * For details, refer to the {@link MidiSystem class description}.
427 *
428 * @return the default sequencer
429 * @throws MidiUnavailableException if the sequencer is not
430 * available due to resource restrictions,
431 * or no sequencer is installed in the system,
432 * or if <code>connected</code> is true, and there is
433 * no <code>Receiver</code> available by any installed
434 * <code>MidiDevice</code>
435 * @see #getSynthesizer
436 * @see #getReceiver
437 * @since 1.5
438 */
439 public static Sequencer getSequencer(boolean connected)
440 throws MidiUnavailableException {
441 Sequencer seq = (Sequencer) getDefaultDeviceWrapper(Sequencer.class);
442
443 if (connected) {
444 // IMPORTANT: this code needs to be synch'ed with
445 // all AutoConnectSequencer instances,
446 // (e.g. RealTimeSequencer) because the
447 // same algorithm for synth retrieval
|
1 /*
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
63 * contain standard MIDI file data or soundbanks. You can query the
64 * <code>MidiSystem</code> for the format of a specified MIDI file.
65 * <p>
66 * You cannot instantiate a <code>MidiSystem</code>; all the methods are
67 * static.
68 *
69 * <p>Properties can be used to specify default MIDI devices.
70 * Both system properties and a properties file are considered.
71 * The <code>sound.properties</code> properties file is read from
72 * an implementation-specific location (typically it is the <code>lib</code>
73 * directory in the Java installation directory).
74 * If a property exists both as a system property and in the
75 * properties file, the system property takes precedence. If none is
76 * specified, a suitable default is chosen among the available devices.
77 * The syntax of the properties file is specified in
78 * {@link java.util.Properties#load(InputStream) Properties.load}. The
79 * following table lists the available property keys and which methods
80 * consider them:
81 *
82 * <table border=0>
83 * <caption>MIDI System Property Keys</caption>
84 * <tr>
85 * <th>Property Key</th>
86 * <th>Interface</th>
87 * <th>Affected Method</th>
88 * </tr>
89 * <tr>
90 * <td><code>javax.sound.midi.Receiver</code></td>
91 * <td>{@link Receiver}</td>
92 * <td>{@link #getReceiver}</td>
93 * </tr>
94 * <tr>
95 * <td><code>javax.sound.midi.Sequencer</code></td>
96 * <td>{@link Sequencer}</td>
97 * <td>{@link #getSequencer}</td>
98 * </tr>
99 * <tr>
100 * <td><code>javax.sound.midi.Synthesizer</code></td>
101 * <td>{@link Synthesizer}</td>
102 * <td>{@link #getSynthesizer}</td>
103 * </tr>
409 * by {@link #getReceiver}.
410 * The connection is made by retrieving a <code>Transmitter</code>
411 * instance from the <code>Sequencer</code> and setting its
412 * <code>Receiver</code>.
413 * Closing and re-opening the sequencer will restore the
414 * connection to the default device.
415 *
416 * <p>If <code>connected</code> is false, the returned
417 * <code>Sequencer</code> instance is not connected, it
418 * has no open <code>Transmitters</code>. In order to
419 * play the sequencer on a MIDI device, or a <code>Synthesizer</code>,
420 * it is necessary to get a <code>Transmitter</code> and set its
421 * <code>Receiver</code>.
422 *
423 * <p>If the system property
424 * <code>javax.sound.midi.Sequencer</code>
425 * is defined or it is defined in the file "sound.properties",
426 * it is used to identify the default sequencer.
427 * For details, refer to the {@link MidiSystem class description}.
428 *
429 * @param connected whether or not the returned {@code Sequencer}
430 * is connected to the default {@code Synthesizer}
431 * @return the default sequencer
432 * @throws MidiUnavailableException if the sequencer is not
433 * available due to resource restrictions,
434 * or no sequencer is installed in the system,
435 * or if <code>connected</code> is true, and there is
436 * no <code>Receiver</code> available by any installed
437 * <code>MidiDevice</code>
438 * @see #getSynthesizer
439 * @see #getReceiver
440 * @since 1.5
441 */
442 public static Sequencer getSequencer(boolean connected)
443 throws MidiUnavailableException {
444 Sequencer seq = (Sequencer) getDefaultDeviceWrapper(Sequencer.class);
445
446 if (connected) {
447 // IMPORTANT: this code needs to be synch'ed with
448 // all AutoConnectSequencer instances,
449 // (e.g. RealTimeSequencer) because the
450 // same algorithm for synth retrieval
|