mixer/main.c

This is an example of how to use the ASX Mixer functions.

00001 /* $Header: /Repository/apps/asx/examples/mixer/main.c,v 1.6 2006/05/23 02:07:46 as-ewb Exp $ */
00002 #include "stdio.h"
00003 #include "stdlib.h"
00004 #include "asx.h"
00005 #include "asxstring.h"
00006 
00007 int CheckError(ASX_HANDLE hObj, int nLine);
00008 int CheckErrorNonTerminal(ASX_HANDLE hObj, int nLine);
00009 void PrintNodeName(ASX_HANDLE hNode);
00010 void PrintControlName(ASX_HANDLE hControl);
00011 
00012 ASX_HANDLE hSystem=0;
00013 
00014 int main(int argc, char* argv[])
00015 {
00016 
00017     char *pszName;
00018     ASX_HANDLE hAdapter;
00019     ASX_HANDLE hMixer;
00020     ASX_HANDLE hNode,hSrcNode,hDestNode;
00021     ASX_HANDLE hControl;
00022     ASX_ERROR asxError;
00023     int nAdapterToUse=0;
00024     int i,j,nLen,nNodes,nControls;
00025 
00026     // create the system
00027     ASX_System_Create(ASX_SYSTEM_TYPE_HPI,&hSystem);
00028     CheckError(hSystem, __LINE__);
00029 
00030     // get the adapter
00031     asxError = ASX_System_GetAdapter(hSystem,nAdapterToUse,&hAdapter);
00032     CheckError(hSystem, __LINE__);
00033 
00034     ASX_Adapter_GetName(hAdapter,0,0,&nLen);
00035     CheckError(hAdapter, __LINE__);
00036     pszName = (char *)malloc(nLen);
00037     ASX_Adapter_GetName(hAdapter,pszName,nLen,&nLen);
00038     CheckError(hAdapter, __LINE__);
00039     printf("Adapter [%d] is %s \n", nAdapterToUse,pszName);
00040 
00041     // get the mixer handle
00042     asxError = ASX_Adapter_GetMixer( hAdapter, &hMixer );
00043     CheckError(hAdapter, __LINE__);
00044 
00045     // dump source lines
00046     ASX_Mixer_GetSourceNodeCount(hMixer,&nNodes);
00047     printf("Source nodes\n");
00048     for(j=0;j<nNodes;j++)
00049     {
00050         ASX_Mixer_GetSourceNode(hMixer,j,&hNode);
00051         PrintNodeName(hNode);
00052     }
00053     // dump destination lines
00054     ASX_Mixer_GetDestinationNodeCount(hMixer,&nNodes);
00055     printf("Destination nodes\n");
00056     for(j=0;j<nNodes;j++)
00057     {
00058         ASX_Mixer_GetDestinationNode(hMixer,j,&hNode);
00059         PrintNodeName(hNode);
00060     }
00061 
00062     // find all LineIn nodes (for exmaple)
00063     asxError = ASX_Mixer_GetNodeTypeCount(hMixer,asxNODE_LINE_IN,&nNodes);
00064     CheckError(hMixer, __LINE__);
00065     printf("Total of %d asxNODE_LINE_IN nodes found.\n",nNodes);
00066 
00067     for(i=0;i<nNodes;i++)
00068     {
00069         asxError = ASX_Mixer_GetNodeByType(hMixer,asxNODE_LINE_IN,i,&hNode);
00070         CheckError(hMixer, __LINE__);
00071         PrintNodeName(hNode);
00072     }
00073 
00074 
00075     // dump all controls
00076     asxError = ASX_Mixer_GetControlCount(hMixer,&nControls);
00077     CheckError(hMixer, __LINE__);
00078 
00079     printf("Retrieved controls\n");
00080     for(i=0;i<nControls;i++)
00081     {
00082         ASX_Mixer_GetControl(hMixer,i,&hControl);
00083         PrintControlName(hControl);
00084 
00085         printf("On node(s) ");
00086         ASX_Control_GetSourceNode(hControl,&hNode);
00087         if( hNode )
00088             PrintNodeName(hNode);
00089         ASX_Control_GetDestinationNode(hControl,&hNode);
00090         if( hNode )
00091             PrintNodeName(hNode);
00092         printf("\n");
00093 
00094     }
00095 
00096     //  *************** Using ASX_Mixer_GetControlByNode()
00097     printf("ASX_Mixer_GetControlByNode() examples\n");
00098     
00099     // ------------ get a peak meter on node Play 0
00100     printf("Finding a peak meter control of node Player 0\n");
00101     // first get the Player node
00102     asxError = ASX_Mixer_GetNodeByType(hMixer,asxNODE_PLAYER,0,&hNode);
00103     if(!CheckErrorNonTerminal(hMixer, __LINE__))
00104     {
00105         // now get the control
00106         asxError = ASX_Mixer_GetControlByNode(hMixer,hNode,0, asxCONTROL_METER,&hControl);
00107         if(!CheckErrorNonTerminal(hMixer, __LINE__))
00108         {
00109             // print out some controldetails
00110             PrintControlName(hControl);
00111         }
00112     }
00113 
00114     // ------------ get a trim/level control on Line Out 0
00115     printf("Finding a level/trim control of node Line Out 0\n");
00116     // first get the Line Out node
00117     asxError = ASX_Mixer_GetNodeByType(hMixer,asxNODE_LINE_OUT,0,&hNode);
00118     if(!CheckErrorNonTerminal(hMixer, __LINE__))
00119     {
00120         // now get the control
00121         asxError = ASX_Mixer_GetControlByNode(hMixer,0,hNode,asxCONTROL_LEVEL,&hControl);
00122         if(!CheckErrorNonTerminal(hMixer, __LINE__))
00123         {
00124             // print out some controldetails
00125             PrintControlName(hControl);
00126         }
00127     }
00128 
00129     // ------------ get a volume control between Play 0 and Line Out 0
00130     printf("Finding a volume control between Play 0 and Line Out 0\n");
00131     // first get the Line Out destination node
00132     asxError = ASX_Mixer_GetNodeByType(hMixer,asxNODE_LINE_OUT,0,&hDestNode);
00133     if(!CheckErrorNonTerminal(hMixer, __LINE__))
00134     {
00135         // second get the Play source node  node
00136         asxError = ASX_Mixer_GetNodeByType(hMixer,asxNODE_PLAYER,0,&hSrcNode);
00137         if(!CheckErrorNonTerminal(hMixer, __LINE__))
00138         {
00139             // now get the control
00140             asxError = ASX_Mixer_GetControlByNode(hMixer,hSrcNode,hDestNode,asxCONTROL_VOLUME,&hControl);
00141             if(!CheckErrorNonTerminal(hMixer, __LINE__))
00142             {
00143                 // print out some controldetails
00144                 PrintControlName(hControl);
00145             }
00146         }
00147     }
00148 
00149     // *************** Using ASX_Mixer_GetControlByNodeTypeAndIndex()
00150     printf("ASX_Mixer_GetControlByNodeTypeAndIndex() examples\n");
00151     // ------------ get a peak meter on node Play 0
00152     printf("Finding a peak meter control of node Player 0\n");
00153     asxError = ASX_Mixer_GetControlByNodeTypeAndIndex(
00154         hMixer,
00155         asxNODE_PLAYER,0,
00156         0,0,
00157         asxCONTROL_METER,
00158         &hControl);
00159     if(!CheckErrorNonTerminal(hMixer, __LINE__))
00160     {
00161         // print out some control details
00162         PrintControlName(hControl);
00163     }
00164 
00165     // ------------ get a trim/level control on Line Out 0
00166     printf("Finding a level/trim control of node Line Out 0\n");
00167     asxError = ASX_Mixer_GetControlByNodeTypeAndIndex(
00168         hMixer,
00169         0,0,
00170         asxNODE_LINE_OUT,0,
00171         asxCONTROL_LEVEL,
00172         &hControl);
00173     if(!CheckErrorNonTerminal(hMixer, __LINE__))
00174     {
00175         // print out some control details
00176         PrintControlName(hControl);
00177     }
00178 
00179     // ------------ get a volume control between Play 0 and Line Out 0
00180     printf("Finding a volume control between Play 0 and Line Out 0\n");
00181     asxError = ASX_Mixer_GetControlByNodeTypeAndIndex(
00182         hMixer,
00183         asxNODE_PLAYER,0,
00184         asxNODE_LINE_OUT,0,
00185         asxCONTROL_VOLUME,
00186         &hControl);
00187     if(!CheckErrorNonTerminal(hMixer, __LINE__))
00188     {
00189         // print out some control details
00190         PrintControlName(hControl);
00191     }
00192 
00193     printf("Press ENTER to exit\n");
00194     getchar();
00195     ASX_System_Delete(hSystem);
00196     return 0;
00197 }
00198 
00199 void PrintControlName(ASX_HANDLE hControl)
00200 {
00201     char *pszName;
00202     int nLen;
00203     enum asxCONTROL eControl;
00204 
00205     ASX_Control_GetType(hControl, &eControl);
00206     ASXSTRING_EnumToString(eControl,0,0,&nLen);
00207     pszName=(char *)malloc(nLen);
00208     ASXSTRING_EnumToString(eControl,pszName,nLen,&nLen);
00209     printf("Control : %s\n",pszName);
00210 
00211     free(pszName);
00212 }
00213 
00214 void PrintNodeName(ASX_HANDLE hNode)
00215 {
00216     char *pszName;
00217     int nLen,nIndex;
00218     enum asxNODE eNode;
00219 
00220     ASX_Node_GetType(hNode, &eNode);
00221     ASX_Node_GetIndex(hNode, &nIndex);
00222     ASXSTRING_EnumToString(eNode,0,0,&nLen);
00223     pszName=(char *)malloc(nLen);
00224     ASXSTRING_EnumToString(eNode,pszName,nLen,&nLen);
00225     printf("Node : %s_%d\n",pszName,nIndex);
00226     free(pszName);
00227 }
00228 
00229 int CheckError(ASX_HANDLE hObj, int nLine)
00230 {
00231     int nError;
00232     int asxSubSystemErrorCode=0;
00233     char *pszAsxErrorString;
00234     char *pszAsxSubSystemErrorString;
00235     int nLen1,nLen2;
00236 
00237     ASX_Error_GetLast( hObj, &nError, &asxSubSystemErrorCode);
00238     if(!nError)
00239         return 0;
00240     ASX_Error_GetLastString( hObj, 0,0,&nLen1,0,0,&nLen2);
00241     pszAsxErrorString = (char *)malloc(nLen1);
00242     pszAsxSubSystemErrorString = (char *)malloc(nLen2);
00243     ASX_Error_GetLastString( hObj, pszAsxErrorString,nLen1,&nLen1,pszAsxSubSystemErrorString,nLen2,&nLen2);
00244     printf("Error: #%d, %s - Subsystem Error: #%ld, %s \n",
00245         nError,
00246         pszAsxErrorString,
00247         asxSubSystemErrorCode,
00248         pszAsxSubSystemErrorString );
00249     printf("When called from source %s line %d\n",__FILE__,nLine);
00250 
00251     printf("Press ENTER to exit\n");
00252     getchar();
00253     free(pszAsxErrorString);
00254     free(pszAsxSubSystemErrorString);
00255     ASX_System_Delete(hSystem);
00256     exit(1);
00257     return 1;
00258 }
00259 
00260 int CheckErrorNonTerminal(ASX_HANDLE hObj, int nLine)
00261 {
00262     int nError;
00263     int asxSubSystemErrorCode=0;
00264     char *pszAsxErrorString;
00265     char *pszAsxSubSystemErrorString;
00266     int nLen1,nLen2;
00267 
00268     ASX_Error_GetLast( hObj, &nError, &asxSubSystemErrorCode);
00269     if(!nError)
00270         return 0;
00271     ASX_Error_GetLastString( hObj, 0,0,&nLen1,0,0,&nLen2);
00272     pszAsxErrorString = (char *)malloc(nLen1);
00273     pszAsxSubSystemErrorString = (char *)malloc(nLen2);
00274     ASX_Error_GetLastString( hObj, pszAsxErrorString,nLen1,&nLen1,pszAsxSubSystemErrorString,nLen2,&nLen2);
00275     printf("WARNING: #%d, %s - Skipping.\n\n",
00276         nError,
00277         pszAsxErrorString);
00278     ASX_Error_Clear( hObj );
00279     return 1;
00280 }

Generated on Tue Nov 18 13:03:40 2008 for ASX by  doxygen 1.4.6-NO