Java Code Examples for javax.sound.midi.Synthesizer#open()
The following examples show how to use
javax.sound.midi.Synthesizer#open() .
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: Dialogs.java From Pixelitor with GNU General Public License v3.0 | 7 votes |
public static void playWarningSound() { try { int maxVolume = 90; int sound = 65; Synthesizer synthesizer = MidiSystem.getSynthesizer(); synthesizer.open(); MidiChannel channel = synthesizer.getChannels()[9]; // drums channel. for (int i = 0; i < 10; i++) { Thread.sleep(100); channel.noteOn(sound + i, maxVolume); Thread.sleep(100); channel.noteOff(sound + i); } } catch (MidiUnavailableException | InterruptedException e1) { e1.printStackTrace(); } }
Example 2
Source File: ExtraCharInSoundbank.java From openjdk-jdk9 with GNU General Public License v2.0 | 7 votes |
public static void main(String[] args) throws Exception { // the internal synthesizer needs a soundcard to work properly if (!isSoundcardInstalled()) { return; } Synthesizer theSynth = MidiSystem.getSynthesizer(); System.out.println("Got synth: "+theSynth); theSynth.open(); try { Soundbank theSoundbank = theSynth.getDefaultSoundbank(); System.out.println("Got soundbank: "+theSoundbank); theSynth.loadAllInstruments(theSoundbank); try { if (!checkInstrumentNames(theSynth)) { throw new Exception("Test failed"); } } finally { theSynth.unloadAllInstruments(theSoundbank); } } finally { theSynth.close(); } System.out.println("Test passed."); }
Example 3
Source File: MidiApp.java From FXTutorials with MIT License | 6 votes |
private void loadChannel() { try { Synthesizer synth = MidiSystem.getSynthesizer(); synth.open(); synth.loadInstrument(synth.getDefaultSoundbank().getInstruments()[5]); channel = synth.getChannels()[0]; } catch (MidiUnavailableException e) { System.out.println("Cannot get synth"); e.printStackTrace(); } }
Example 4
Source File: AsynchronousMidiChannel.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void doIt(String args[]) { Synthesizer synth = null; MidiChannel mChanArr[]; MidiChannel chan = null; boolean failed = false; int i = 0; int chanNum = 0; int val = 1; int contr = 0; Soundbank sBank; Instrument[] insArr; Instrument instr = null; Object ev = new Object(); try { synth = MidiSystem.getSynthesizer(); System.out.println("Got synth: "+synth); synth.open(); int latency = (int) synth.getLatency(); System.out.println(" -> latency: " +latency +" microseconds"); mChanArr = synth.getChannels(); while ((i < mChanArr.length) && (chan == null)) { chanNum = i; chan = mChanArr[i++]; } if (chan == null) { System.out.println("No channels in " +"this synthesizer!"); return; } System.out.println("Got MidiChannel: "+chan); sBank = synth.getDefaultSoundbank(); if (sBank == null) { System.out.println("No default sound bank!"); return; } insArr = sBank.getInstruments(); for (int j = 0; j < insArr.length; j++) { if (insArr[j].getPatch().getBank() == val) { instr = insArr[j]; synth.loadInstrument(instr); } } if (instr == null) { System.out.println("No instr. with this bank!"); return; } chan.controlChange(contr, val); // need to respect the synthesizer's latency if (latency > 0) { try { Thread.sleep(latency/1000); } catch (InterruptedException inEx) { } } if (chan.getController(contr) != val) { failed = true; System.err.println("getController() does not " +"return proper value: " + chan.getController(contr)); } else { System.out.println("getController(" + contr + ") returns proper value: " + chan.getController(contr)); } } catch (MidiUnavailableException mue) { System.err.println("MidiUnavailableException was " +"thrown: " + mue); System.out.println("could not test."); return; } catch(SecurityException se) { se.printStackTrace(); System.err.println("Sound access is not denied but " + "SecurityException was thrown!"); return; } finally { if (synth != null) synth.close(); } if (failed == true) { System.out.println("test failed"); } else { System.out.println("OKAY"); } return; }
Example 5
Source File: SynthesizerGetLatency.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String args[]) throws Exception { Synthesizer synth = null; boolean failed = false; boolean notexec = false; try { synth = MidiSystem.getSynthesizer(); System.out.println("Got synth: "+synth); synth.open(); int latency = (int) synth.getLatency(); System.out.println(" -> latency: " +latency +" microseconds"); if (latency < 5000 && latency > 0) { System.out.println("## This latency is VERY small, probably due to this bug."); System.out.println("## This causes failure of this test."); failed = true; } } catch (MidiUnavailableException mue) { System.err.println("MidiUnavailableException was " +"thrown: " + mue); System.out.println("could not test."); notexec = true; } catch(SecurityException se) { se.printStackTrace(); System.err.println("Sound access is not denied but " + "SecurityException was thrown!"); notexec = true; } finally { if (synth != null) synth.close(); } if (failed) { throw new Exception("Test FAILED!"); } if (notexec) { System.out.println("Test not failed."); } else { System.out.println("Test Passed."); } }
Example 6
Source File: ImplicitOpenClose.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Field f = SoftSynthesizer.class.getDeclaredField("testline"); f.setAccessible(true); f.set(null, new DummySourceDataLine()); Synthesizer synth = new SoftSynthesizer(); ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth; // Test single open/close cycle Receiver recv = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test using 2 receiver cycle Receiver recv1 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); Receiver recv2 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv2.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); recv1.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for explicit,implicit conflict synth.open(); Receiver recv3 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for implicit,explicit conflict recv3 = rcd.getReceiverReferenceCounting(); synth.open(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); }
Example 7
Source File: ImplicitOpenClose.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Field f = SoftSynthesizer.class.getDeclaredField("testline"); f.setAccessible(true); f.set(null, new DummySourceDataLine()); Synthesizer synth = new SoftSynthesizer(); ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth; // Test single open/close cycle Receiver recv = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test using 2 receiver cycle Receiver recv1 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); Receiver recv2 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv2.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); recv1.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for explicit,implicit conflict synth.open(); Receiver recv3 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for implicit,explicit conflict recv3 = rcd.getReceiverReferenceCounting(); synth.open(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); }
Example 8
Source File: ImplicitOpenClose.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Field f = SoftSynthesizer.class.getDeclaredField("testline"); f.setAccessible(true); f.set(null, new DummySourceDataLine()); Synthesizer synth = new SoftSynthesizer(); ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth; // Test single open/close cycle Receiver recv = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test using 2 receiver cycle Receiver recv1 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); Receiver recv2 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv2.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); recv1.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for explicit,implicit conflict synth.open(); Receiver recv3 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for implicit,explicit conflict recv3 = rcd.getReceiverReferenceCounting(); synth.open(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); }
Example 9
Source File: ImplicitOpenClose.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Field f = SoftSynthesizer.class.getDeclaredField("testline"); f.setAccessible(true); f.set(null, new DummySourceDataLine()); Synthesizer synth = new SoftSynthesizer(); ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth; // Test single open/close cycle Receiver recv = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test using 2 receiver cycle Receiver recv1 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); Receiver recv2 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv2.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); recv1.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for explicit,implicit conflict synth.open(); Receiver recv3 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for implicit,explicit conflict recv3 = rcd.getReceiverReferenceCounting(); synth.open(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); }
Example 10
Source File: ImplicitOpenClose.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Field f = SoftSynthesizer.class.getDeclaredField("testline"); f.setAccessible(true); f.set(null, new DummySourceDataLine()); Synthesizer synth = new SoftSynthesizer(); ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth; // Test single open/close cycle Receiver recv = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test using 2 receiver cycle Receiver recv1 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); Receiver recv2 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv2.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); recv1.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for explicit,implicit conflict synth.open(); Receiver recv3 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for implicit,explicit conflict recv3 = rcd.getReceiverReferenceCounting(); synth.open(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); }
Example 11
Source File: ImplicitOpenClose.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Field f = SoftSynthesizer.class.getDeclaredField("testline"); f.setAccessible(true); f.set(null, new DummySourceDataLine()); Synthesizer synth = new SoftSynthesizer(); ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth; // Test single open/close cycle Receiver recv = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test using 2 receiver cycle Receiver recv1 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); Receiver recv2 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv2.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); recv1.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for explicit,implicit conflict synth.open(); Receiver recv3 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for implicit,explicit conflict recv3 = rcd.getReceiverReferenceCounting(); synth.open(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); }
Example 12
Source File: ImplicitOpenClose.java From hottub with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Field f = SoftSynthesizer.class.getDeclaredField("testline"); f.setAccessible(true); f.set(null, new DummySourceDataLine()); Synthesizer synth = new SoftSynthesizer(); ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth; // Test single open/close cycle Receiver recv = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test using 2 receiver cycle Receiver recv1 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); Receiver recv2 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv2.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); recv1.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for explicit,implicit conflict synth.open(); Receiver recv3 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for implicit,explicit conflict recv3 = rcd.getReceiverReferenceCounting(); synth.open(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); }
Example 13
Source File: ImplicitOpenClose.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Field f = SoftSynthesizer.class.getDeclaredField("testline"); f.setAccessible(true); f.set(null, new DummySourceDataLine()); Synthesizer synth = new SoftSynthesizer(); ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth; // Test single open/close cycle Receiver recv = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test using 2 receiver cycle Receiver recv1 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); Receiver recv2 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv2.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); recv1.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for explicit,implicit conflict synth.open(); Receiver recv3 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for implicit,explicit conflict recv3 = rcd.getReceiverReferenceCounting(); synth.open(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); }
Example 14
Source File: ImplicitOpenClose.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Field f = SoftSynthesizer.class.getDeclaredField("testline"); f.setAccessible(true); f.set(null, new DummySourceDataLine()); Synthesizer synth = new SoftSynthesizer(); ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth; // Test single open/close cycle Receiver recv = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test using 2 receiver cycle Receiver recv1 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); Receiver recv2 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv2.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); recv1.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for explicit,implicit conflict synth.open(); Receiver recv3 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for implicit,explicit conflict recv3 = rcd.getReceiverReferenceCounting(); synth.open(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); }
Example 15
Source File: ImplicitOpenClose.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Field f = SoftSynthesizer.class.getDeclaredField("testline"); f.setAccessible(true); f.set(null, new DummySourceDataLine()); Synthesizer synth = new SoftSynthesizer(); ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth; // Test single open/close cycle Receiver recv = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test using 2 receiver cycle Receiver recv1 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); Receiver recv2 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv2.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); recv1.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for explicit,implicit conflict synth.open(); Receiver recv3 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for implicit,explicit conflict recv3 = rcd.getReceiverReferenceCounting(); synth.open(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); }
Example 16
Source File: ImplicitOpenClose.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Field f = SoftSynthesizer.class.getDeclaredField("testline"); f.setAccessible(true); f.set(null, new DummySourceDataLine()); Synthesizer synth = new SoftSynthesizer(); ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth; // Test single open/close cycle Receiver recv = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test using 2 receiver cycle Receiver recv1 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); Receiver recv2 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv2.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); recv1.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for explicit,implicit conflict synth.open(); Receiver recv3 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for implicit,explicit conflict recv3 = rcd.getReceiverReferenceCounting(); synth.open(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); }
Example 17
Source File: ImplicitOpenClose.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Field f = SoftSynthesizer.class.getDeclaredField("testline"); f.setAccessible(true); f.set(null, new DummySourceDataLine()); Synthesizer synth = new SoftSynthesizer(); ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth; // Test single open/close cycle Receiver recv = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test using 2 receiver cycle Receiver recv1 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); Receiver recv2 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv2.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); recv1.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for explicit,implicit conflict synth.open(); Receiver recv3 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for implicit,explicit conflict recv3 = rcd.getReceiverReferenceCounting(); synth.open(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); }
Example 18
Source File: ImplicitOpenClose.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Field f = SoftSynthesizer.class.getDeclaredField("testline"); f.setAccessible(true); f.set(null, new DummySourceDataLine()); Synthesizer synth = new SoftSynthesizer(); ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth; // Test single open/close cycle Receiver recv = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test using 2 receiver cycle Receiver recv1 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); Receiver recv2 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv2.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); recv1.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for explicit,implicit conflict synth.open(); Receiver recv3 = rcd.getReceiverReferenceCounting(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); // Test for implicit,explicit conflict recv3 = rcd.getReceiverReferenceCounting(); synth.open(); if(!synth.isOpen()) throw new Exception("Synthesizer not open!"); recv3.close(); if(!synth.isOpen()) throw new Exception("Synthesizer was closed!"); synth.close(); if(synth.isOpen()) throw new Exception("Synthesizer not closed!"); }