|
ASX Version4.20.14
|
This is an example of how to use the ASX Mixer functions.
/* $Header: /home/eliot/asi/repo/cvsrepo/Repository/apps/asx/examples/mixer/main.c,v 1.8 2011/03/01 14:26:48 as-age Exp $ */ #include "stdio.h" #include "stdlib.h" #include "asx.h" #include "asxstring.h" int CheckError(ASX_HANDLE hObj, int nLine); int CheckErrorNonTerminal(ASX_HANDLE hObj, int nLine); void PrintNodeName(ASX_HANDLE hNode); void PrintControlName(ASX_HANDLE hControl); ASX_HANDLE hSystem=0; int main(int argc, char* argv[]) { char *pszName; char szString[256]; ASX_HANDLE hAdapter; ASX_HANDLE hMixer; ASX_HANDLE hNode,hSrcNode,hDestNode; ASX_HANDLE hControl; ASX_ERROR asxError; int nAdapterToUse=0; int i,j,nLen,nNodes,nControls; // create the system ASX_System_Create(ASX_SYSTEM_TYPE_HPI,&hSystem); CheckError(hSystem, __LINE__); // get the adapter asxError = ASX_System_GetAdapter(hSystem,nAdapterToUse,&hAdapter); CheckError(hSystem, __LINE__); ASX_Adapter_GetName(hAdapter,0,0,&nLen); CheckError(hAdapter, __LINE__); pszName = (char *)malloc(nLen); ASX_Adapter_GetName(hAdapter,pszName,nLen,&nLen); CheckError(hAdapter, __LINE__); printf("Adapter [%d] is %s \n", nAdapterToUse,pszName); // get the MAC address (only supported on some adapters) asxError = ASX_Adapter_GetMacAddress(hAdapter,szString); if(asxError==asxERROR_NO_ERROR) { printf("\tMAC address is %s \n", szString); } // get the mixer handle asxError = ASX_Adapter_GetMixer( hAdapter, &hMixer ); CheckError(hAdapter, __LINE__); // dump source lines ASX_Mixer_GetSourceNodeCount(hMixer,&nNodes); printf("Source nodes\n"); for(j=0;j<nNodes;j++) { ASX_Mixer_GetSourceNode(hMixer,j,&hNode); PrintNodeName(hNode); } // dump destination lines ASX_Mixer_GetDestinationNodeCount(hMixer,&nNodes); printf("Destination nodes\n"); for(j=0;j<nNodes;j++) { ASX_Mixer_GetDestinationNode(hMixer,j,&hNode); PrintNodeName(hNode); } // find all LineIn nodes (for exmaple) asxError = ASX_Mixer_GetNodeTypeCount(hMixer,asxNODE_LINE_IN,&nNodes); CheckError(hMixer, __LINE__); printf("Total of %d asxNODE_LINE_IN nodes found.\n",nNodes); for(i=0;i<nNodes;i++) { asxError = ASX_Mixer_GetNodeByType(hMixer,asxNODE_LINE_IN,i,&hNode); CheckError(hMixer, __LINE__); PrintNodeName(hNode); } // dump all controls asxError = ASX_Mixer_GetControlCount(hMixer,&nControls); CheckError(hMixer, __LINE__); printf("Retrieved controls\n"); for(i=0;i<nControls;i++) { ASX_Mixer_GetControl(hMixer,i,&hControl); PrintControlName(hControl); printf("On node(s) "); ASX_Control_GetSourceNode(hControl,&hNode); if( hNode ) PrintNodeName(hNode); ASX_Control_GetDestinationNode(hControl,&hNode); if( hNode ) PrintNodeName(hNode); printf("\n"); } // *************** Using ASX_Mixer_GetControlByNode() printf("ASX_Mixer_GetControlByNode() examples\n"); // ------------ get a peak meter on node Play 0 printf("Finding a peak meter control of node Player 0\n"); // first get the Player node asxError = ASX_Mixer_GetNodeByType(hMixer,asxNODE_PLAYER,0,&hNode); if(!CheckErrorNonTerminal(hMixer, __LINE__)) { // now get the control asxError = ASX_Mixer_GetControlByNode(hMixer,hNode,0, asxCONTROL_METER,&hControl); if(!CheckErrorNonTerminal(hMixer, __LINE__)) { // print out some controldetails PrintControlName(hControl); } } // ------------ get a trim/level control on Line Out 0 printf("Finding a level/trim control of node Line Out 0\n"); // first get the Line Out node asxError = ASX_Mixer_GetNodeByType(hMixer,asxNODE_LINE_OUT,0,&hNode); if(!CheckErrorNonTerminal(hMixer, __LINE__)) { // now get the control asxError = ASX_Mixer_GetControlByNode(hMixer,0,hNode,asxCONTROL_LEVEL,&hControl); if(!CheckErrorNonTerminal(hMixer, __LINE__)) { // print out some controldetails PrintControlName(hControl); } } // ------------ get a volume control between Play 0 and Line Out 0 printf("Finding a volume control between Play 0 and Line Out 0\n"); // first get the Line Out destination node asxError = ASX_Mixer_GetNodeByType(hMixer,asxNODE_LINE_OUT,0,&hDestNode); if(!CheckErrorNonTerminal(hMixer, __LINE__)) { // second get the Play source node node asxError = ASX_Mixer_GetNodeByType(hMixer,asxNODE_PLAYER,0,&hSrcNode); if(!CheckErrorNonTerminal(hMixer, __LINE__)) { // now get the control asxError = ASX_Mixer_GetControlByNode(hMixer,hSrcNode,hDestNode,asxCONTROL_VOLUME,&hControl); if(!CheckErrorNonTerminal(hMixer, __LINE__)) { // print out some controldetails PrintControlName(hControl); } } } // *************** Using ASX_Mixer_GetControlByNodeTypeAndIndex() printf("ASX_Mixer_GetControlByNodeTypeAndIndex() examples\n"); // ------------ get a peak meter on node Play 0 printf("Finding a peak meter control of node Player 0\n"); asxError = ASX_Mixer_GetControlByNodeTypeAndIndex( hMixer, asxNODE_PLAYER,0, 0,0, asxCONTROL_METER, &hControl); if(!CheckErrorNonTerminal(hMixer, __LINE__)) { // print out some control details PrintControlName(hControl); } // ------------ get a trim/level control on Line Out 0 printf("Finding a level/trim control of node Line Out 0\n"); asxError = ASX_Mixer_GetControlByNodeTypeAndIndex( hMixer, 0,0, asxNODE_LINE_OUT,0, asxCONTROL_LEVEL, &hControl); if(!CheckErrorNonTerminal(hMixer, __LINE__)) { // print out some control details PrintControlName(hControl); } // ------------ get a volume control between Play 0 and Line Out 0 printf("Finding a volume control between Play 0 and Line Out 0\n"); asxError = ASX_Mixer_GetControlByNodeTypeAndIndex( hMixer, asxNODE_PLAYER,0, asxNODE_LINE_OUT,0, asxCONTROL_VOLUME, &hControl); if(!CheckErrorNonTerminal(hMixer, __LINE__)) { // print out some control details PrintControlName(hControl); } printf("Press ENTER to exit\n"); getchar(); ASX_System_Delete(hSystem); return 0; } void PrintControlName(ASX_HANDLE hControl) { char *pszName; int nLen; enum asxCONTROL eControl; ASX_Control_GetType(hControl, &eControl); ASXSTRING_EnumToString(eControl,0,0,&nLen); pszName=(char *)malloc(nLen); ASXSTRING_EnumToString(eControl,pszName,nLen,&nLen); printf("Control : %s\n",pszName); free(pszName); } void PrintNodeName(ASX_HANDLE hNode) { char *pszName; int nLen,nIndex; enum asxNODE eNode; ASX_Node_GetType(hNode, &eNode); ASX_Node_GetIndex(hNode, &nIndex); ASXSTRING_EnumToString(eNode,0,0,&nLen); pszName=(char *)malloc(nLen); ASXSTRING_EnumToString(eNode,pszName,nLen,&nLen); printf("Node : %s_%d\n",pszName,nIndex); free(pszName); } int CheckError(ASX_HANDLE hObj, int nLine) { ASX_ERROR nError; int asxSubSystemErrorCode=0; char *pszAsxErrorString; char *pszAsxSubSystemErrorString; int nLen1,nLen2; ASX_Error_GetLast( hObj, &nError, &asxSubSystemErrorCode); if(!nError) return 0; ASX_Error_GetLastString( hObj, 0,0,&nLen1,0,0,&nLen2); pszAsxErrorString = (char *)malloc(nLen1); pszAsxSubSystemErrorString = (char *)malloc(nLen2); ASX_Error_GetLastString( hObj, pszAsxErrorString,nLen1,&nLen1,pszAsxSubSystemErrorString,nLen2,&nLen2); printf("Error: #%d, %s - Subsystem Error: #%ld, %s \n", nError, pszAsxErrorString, asxSubSystemErrorCode, pszAsxSubSystemErrorString ); printf("When called from source %s line %d\n",__FILE__,nLine); printf("Press ENTER to exit\n"); getchar(); free(pszAsxErrorString); free(pszAsxSubSystemErrorString); ASX_System_Delete(hSystem); exit(1); return 1; } int CheckErrorNonTerminal(ASX_HANDLE hObj, int nLine) { ASX_ERROR nError; int asxSubSystemErrorCode=0; char *pszAsxErrorString; char *pszAsxSubSystemErrorString; int nLen1,nLen2; ASX_Error_GetLast( hObj, &nError, &asxSubSystemErrorCode); if(!nError) return 0; ASX_Error_GetLastString( hObj, 0,0,&nLen1,0,0,&nLen2); pszAsxErrorString = (char *)malloc(nLen1); pszAsxSubSystemErrorString = (char *)malloc(nLen2); ASX_Error_GetLastString( hObj, pszAsxErrorString,nLen1,&nLen1,pszAsxSubSystemErrorString,nLen2,&nLen2); printf("WARNING: #%d, %s - Skipping.\n\n", nError, pszAsxErrorString); ASX_Error_Clear( hObj ); return 1; }
1.7.3