001         package com.croftsoft.core.media.sound.midi;
002    
003         import javax.sound.midi.*;
004    
005         /*********************************************************************
006         * Tests all MIDI Instruments.
007         *
008         * <P>
009         *
010         * @author
011         *   <a href="http://www.CroftSoft.com/">David Wallace Croft</a>
012         * @version
013         *   2001-05-29
014         * @version
015         *   1999-11-07
016         *********************************************************************/
017         public final class  MidiTest
018         //////////////////////////////////////////////////////////////////////
019         //////////////////////////////////////////////////////////////////////
020         {
021    
022         private  MidiTest ( ) { }
023    
024         //////////////////////////////////////////////////////////////////////
025         // Static methods
026         //////////////////////////////////////////////////////////////////////
027    
028         public static void  main ( String [ ]  args )
029           throws MidiUnavailableException
030         //////////////////////////////////////////////////////////////////////
031         {
032           Sequencer  sequencer = MidiSystem.getSequencer ( );
033    
034           Synthesizer  synthesizer = MidiSystem.getSynthesizer ( );
035    
036           synthesizer.open ( );
037    
038           Instrument [ ]  instruments
039             = synthesizer.getDefaultSoundbank ( ).getInstruments ( );
040    
041           MidiChannel [ ]  midiChannels = synthesizer.getChannels ( );
042    
043           for ( int  instrumentIndex = 0;
044                 instrumentIndex < instruments.length;
045                 instrumentIndex++ )
046           {
047             Instrument  instrument = instruments [ instrumentIndex ];
048    
049             System.out.println ( instrument.getName ( ) );
050    
051             synthesizer.loadInstrument ( instrument );
052    
053             midiChannels [ 0 ].programChange ( instrumentIndex );
054    
055             int  velocity = 64;
056    
057             for ( int  noteNumber = 0; noteNumber < 128; noteNumber++ )
058             {
059               midiChannels [ 0 ].noteOn ( noteNumber, velocity );
060    
061               try
062               {
063                 Thread.sleep ( 100 );
064               }
065               catch ( InterruptedException  e )
066               {
067               }
068    
069               midiChannels [ 0 ].noteOff ( noteNumber );
070    
071               try
072               {
073                 Thread.sleep ( 100 );
074               }
075               catch ( InterruptedException  e )
076               {
077               }
078    
079             }
080           }
081    
082           synthesizer.close ( );
083    
084           sequencer.close ( );
085         }
086    
087         //////////////////////////////////////////////////////////////////////
088         //////////////////////////////////////////////////////////////////////
089         }