/******************************************************************************/
// Print all the instruments available to the default soundbank.
//
// Roy Vanegas: rvanegas@hunter.cuny.edu
/******************************************************************************/
import javax.sound.midi.*;

public class ShowAllInstrumentsForDefaultSoundbank
{
   public static void main( String[] args ) throws Exception
   {
      Synthesizer synthesizer;
      Soundbank   soundbank;
      Instrument  instruments[];
      int line = 0;

      /**
       * Line 1: Get the default synthsizer.
       * Line 2: We need to open the synthesizer before we can perform any
       *         functions on it.
       * Line 3: If a default soundbank for the synthesizer exists, get it.
       *         According to Sun Microsystems, "If a synthesizer doesn't have
       *         a default soundbank, instruments must be loaded explicitly
       *         from an external soundbank."
       * Line 4: The current soundbank will have zero or more instruments.
       *         Method getInstruments will return an array of Instrument
       *         objects of either 0 or more for this soundbank
       * Line 5: Print our findings
       */

      try
      {

/* 1 */  synthesizer = MidiSystem.getSynthesizer();
/* 2 */  synthesizer.open();
/* 3 */  soundbank = synthesizer.getDefaultSoundbank();
/* 4 */  instruments = soundbank.getInstruments();

/* 5 */  for( int index = 0; index < instruments.length; index++ )
            System.out.println( line++ + " " + instruments[ index ] );

      }
      catch( Exception ex ) { ex.printStackTrace(); }

      System.exit( 0 );
   }
}
