001package ca.bc.webarts.widgets;
002
003import java.util.*;
004import javax.sound.sampled.*;
005
006
007/**
008 *  Iterates throught the available sound mixers and shows the capabilities
009 *
010 * @author    Sing Li @ vsj
011 */
012public class JQueryMixers
013{
014  /**  Constructor for the JQueryMixers object */
015  public JQueryMixers() { }
016
017
018  /**
019   *  The main program for the JQueryMixers class
020   *
021   * @param  args           The command line arguments
022   * @exception  Exception  Description of the Exception
023   */
024  public static void main( String[] args )
025    throws Exception
026  {
027    showMixers();
028    disp("\n\n-------------------\n");
029    probePort();
030  }
031
032
033  /**  Description of the Method */
034  public static void showMixers()
035  {
036    ArrayList<Mixer.Info>
037        mixInfos = new ArrayList<Mixer.Info>(
038        Arrays.asList(
039        AudioSystem.getMixerInfo(
040        ) ) );
041    Line.Info sourceDLInfo = new Line.Info( SourceDataLine.class );
042    Line.Info targetDLInfo = new Line.Info( TargetDataLine.class );
043    Line.Info clipInfo = new Line.Info( Clip.class );
044    Line.Info portInfo = new Line.Info( Port.class );
045    String support;
046    for ( Mixer.Info mixInfo : mixInfos )
047    {
048      Mixer mixer = AudioSystem.getMixer( mixInfo );
049      support = ", supports ";
050      if ( mixer.isLineSupported( sourceDLInfo ) )
051      {
052        support += "SourceDataLine ";
053      }
054      if ( mixer.isLineSupported( clipInfo ) )
055      {
056        support += "Clip ";
057      }
058      if ( mixer.isLineSupported( targetDLInfo ) )
059      {
060        support += "TargetDataLine ";
061      }
062      if ( mixer.isLineSupported( portInfo ) )
063      {
064        support += "Port ";
065      }
066      disp( "Mixer: " + mixInfo.getName() + support + ", " + mixInfo.getDescription() );
067    }
068  }
069
070
071  /**
072   *  Description of the Method
073   *
074   * @exception  Exception  Description of the Exception
075   */
076  public static void probePort() throws Exception
077  {
078    ArrayList<Mixer.Info> mixerInfos = new ArrayList<Mixer.Info>(
079        Arrays.asList( AudioSystem.getMixerInfo() ) );
080    Line.Info portInfo = new Line.Info( Port.class );
081    for ( Mixer.Info mixerInfo : mixerInfos )
082    {
083      Mixer mixer = AudioSystem.getMixer( mixerInfo );
084      if ( mixer.isLineSupported(portInfo) )
085      {
086        // found a Port Mixer
087        disp( "Found mixer: " + mixerInfo.getName() );
088        disp( "\t" + mixerInfo.getDescription() );
089        disp( "Source Lines Supported:" );
090        ArrayList<Line.Info> srcInfos =
091            new ArrayList<Line.Info>(Arrays.asList( mixer.getSourceLineInfo() ) );
092
093        for ( Line.Info srcInfo : srcInfos )
094        {
095          Port.Info pi = (Port.Info)srcInfo;
096          disp( "\t" + pi.getName() + ", " + ( pi.isSource() ? "source" : "target" ) );
097          showControls( mixer.getLine(srcInfo) );
098        }// of for Line.Info
099
100        disp( "Target Lines Supported:" );
101        ArrayList<Line.Info> targetInfos =
102            new ArrayList<Line.Info>(Arrays.asList(mixer.getTargetLineInfo()) );
103
104        for ( Line.Info targetInfo : targetInfos )
105        {
106          Port.Info pi = (Port.Info)targetInfo;
107          disp( "\t" + pi.getName() + ", " +( pi.isSource() ?"source" : "target" ) );
108          showControls( mixer.getLine(targetInfo ) );
109        }
110      }// of if
111      // (mixer.isLineSupported)
112    }// of for (Mixer.Info)
113  }
114
115
116  /**
117   *  Description of the Method
118   *
119   * @param  inLine         Description of the Parameter
120   * @exception  Exception  Description of the Exception
121   */
122  private static void showControls(
123                                    Line inLine )
124    throws Exception
125  {
126    // must open the line to get
127    // at controls
128    inLine.open();
129    disp( "\t\tAvailable controls:" );
130    ArrayList<Control> ctrls =  new ArrayList<Control>(
131        Arrays.asList(inLine.getControls() ) );
132    for ( Control ctrl : ctrls )
133    {
134      disp( "\t\t\t" + ctrl.toString() );
135      if ( ctrl instanceof CompoundControl )
136      {
137        CompoundControl cc = ( (CompoundControl)ctrl );
138        ArrayList<Control> ictrls = new ArrayList<Control>( Arrays.asList(cc.getMemberControls() ) );
139        for ( Control ictrl : ictrls )
140        {
141          disp( "\t\t\t\t" + ictrl.toString() );
142        }
143      }// of if (ctrl instanceof)
144    }// of for(Control ctrl)
145    inLine.close();
146  }
147
148
149  /**
150   *  Description of the Method
151   *
152   * @param  msg  Description of the Parameter
153   */
154  private static void disp( String msg )
155  {
156    System.out.println( msg );
157  }
158}
159