001 002package bradleyross.coremidi4j.samples; 003 004/** 005 * Obtains a list of devices and tests for changes in configuration. 006 * 007 * <p>This is part of the demonstration code contained in the 008 * documentation for the DerekCook/CoreMidi4J.</p> 009 * 010 * @author Derek Cook 011 * 012 */ 013 014public class Available { 015 016 public static void main(String[] args) throws Exception { 017 try { 018 /* 019 * The following statement previously read Class deviceProviderClass = Class.forName(... 020 * However, since the returned object is never used, this results in a warning message 021 * in Eclipse. The statement does not require returning a value, and I removed the 022 * storage of the returned value. 023 */ 024 Class.forName( 025 "uk.co.xfactorylibrarians.coremidi4j.CoreMidiDeviceProvider"); 026 System.out.println("CoreMIDI4J Java classes are available."); 027 System.out.println("Working MIDI Devices:"); 028 for (javax.sound.midi.MidiDevice.Info device : Example.getWorkingDeviceInfo()) { 029 System.out.println(" " + device); 030 } 031 if (Example.isCoreMidiLoaded()) { 032 System.out.println("CoreMIDI4J native library is running."); 033 Example.watchForMidiChanges(); 034 /* 035 * If the sleep method throws InterruptedException, it does not mean 036 * that the CoreMIDI4J classes are not loaded. For that reason, the 037 * exception is trapped locally to avoid erroneous messages. 038 */ 039 try { 040 System.out.println("Watching for MIDI environment changes for thirty seconds."); 041 Thread.sleep(30000); 042 } catch (InterruptedException e) { 043 e.printStackTrace(); 044 } 045 } else { 046 System.out.println("CoreMIDI4J native library is not available."); 047 } 048 } catch (Exception e) { 049 System.out.println("CoreMIDI4J Java classes are not available."); 050 e.printStackTrace(); 051 } 052 } 053}