📄 xltwavplay.c
字号:
/* * This function extracts the Record sampling rate from the text input widget: */static UInt32GetRecRate(void) { char *pText = XmTextGetString(wRecRate); /* Get contents */ unsigned long ul; if ( sscanf(pText,"%lu",&ul) != 1 ) { /* Convert to u_long */ if ( !*pText ) ReportErrorf("No sampling rate has been specified."); else ReportErrorf("Record sampling rate '%s' must be an integer.",pText); XtFree(pText); /* Release this now */ return 0UL; /* Return no sampling rate */ } XtFree(pText); /* Release this now */ XmSprintfText(wRecRate,"%lu",ul); /* Reformat what we think we got */ return (UInt32) ul; /* Return sampling rate */}/* * This callback is called when the Record Sampling Rate input text widget gets * the focus. When this happens, we turn off the toggle that takes the sampling * rate from the slider. */static voidRecRateFocus_CB(Widget w,XtPointer client_data,XtPointer call_data) { XtVaSetValues(wRecRateTgl,XmNset,False,NULL); /* Disable toggle */ RecRateTgl_value = 0; /* And tracking value */ XmTextSetInsertionPosition(wRecRate,0); /* Cursor at start of field */}/* * This callback is called when the Record Sampling Rate toggle gets altered. */static voidRecRateTgl_CB(Widget w,XtPointer client_data,XtPointer call_data) { XmToggleButtonCallbackStruct *ptr = (XmToggleButtonCallbackStruct *)call_data; if ( (RecRateTgl_value = ptr->set) != 0 ) /* Toggle set? */ XmSprintfText(wRecRate,"%d",SampRate_value); /* Yes, show rate from slider */}/* * This callback is entered when the [Play] button is pressed. */static voidPlay_CB(Widget w,XtPointer client_data,XtPointer call_data) { tosvr_play(0,v_erf); /* Tell server to play */}/* * This callback is entered when the [Pause] button is pressed. */static voidPause_CB(Widget w,XtPointer client_data,XtPointer call_data) { tosvr_pause(0,v_erf); /* Tell server to pause */}/* * This callback is entered when the [Stop] button is pressed. */static voidStop_CB(Widget w,XtPointer client_data,XtPointer call_data) { tosvr_stop(0,v_erf); /* Tell the server to stop */}/* * This is the [Restore] settings button callback: */static voidRestore_CB(Widget w,XtPointer client_data,XtPointer call_data) { tosvr_restore(0,v_erf); /* Tell server to "restore" */ XtVaSetValues(wTimeScrollBar,XmNvalue,0,NULL); /* Fix time slider */ time_display.sample_num = 0; XmSprintfLabel(wTimeDisplayLbl1,"00:00:00.00"); XtVaSetValues(wRateScrollBar,XmNvalue,0,NULL); /* Fix slider */ SampleRateChg_Show(0); /* Update sampling rate etc. */}/* * The [Record] button callback: */static voidRecord_CB(Widget w,XtPointer client_data,XtPointer call_data) { Arg al[20]; /* Arg list */ Cardinal ac; /* Args count */ UInt32 RecRate = GetRecRate(); /* Sampling Rate */ Chan chan_mode; /* Stereo / Mono */ UInt16 data_bits = curBits < 8 ? 8 : curBits; /* Data bits */ Boolean b; /* Current setting of Stereo toggle */ if ( RecRate < 1 ) { /* We must have a sampling rate */ ReportErrorf("Please set a Sampling Rate\nand try again."); return; } ac = 0; XtSetArg(al[ac],XmNset,&b); ++ac; XtGetValues(wStereoCB,al,ac); /* Get Stereo toggle setting */ chan_mode = b ? Stereo : Mono; /* Channels now known */ time_display.sampling_rate = RecRate; /* Store for use during record */ sprintf(time_display.sample_info_str,"%u-bit %s", data_bits, chan_mode == Stereo ? "stereo" : "mono"); /* Update a few fields */ XmSprintfLabel(wDateLbl1,""); /* Don't need for rec; blank if help msg still there */ XmSprintfLabel(wSamplingRateLbl1,"%lu Hz", (unsigned long)RecRate); tosvr_record(0,v_erf,chan_mode,RecRate,data_bits); /* Tell server to start recording */}/* * This callback is entered when a selection has been made from the list box. */static voidPathSelected_CB(Widget w,XtPointer client_data,XtPointer call_data) { XmListCallbackStruct *ptr = (XmListCallbackStruct *)call_data; char *path; /* C string copy */ XmStringGetLtoR(ptr->item,XmSTRING_DEFAULT_CHARSET,&path); /* Get C string pathname */ tosvr_path(path,0,v_erf); /* Tell server the new path */ XtFree(path); /* Release this string */}/* * Internal routine for updating the sampling rate display fields: */static voidSampleRateChg_Show(int newValue) { if ( newValue < (int) DSP_MIN ) { /* * If the value is less than the minimum, assume no overrides here: */ XmSprintfLabel(wRateLbl,"Sampling Rate Override: NONE"); SampRate_value = 0; } else { /* * Otherwise display the overridden sampling rate: */ XmSprintfLabel(wRateLbl,"Sampling Rate Override: %d Hz",(int)newValue); SampRate_value = (int)newValue; } /* * If the record toggle is set, then text box follows slider's value: */ if ( RecRateTgl_value != 0 ) XmSprintfText(wRecRate,"%d",SampRate_value);}/* * This callback is entered when the time has changed (via scroll bar): */static voidTimeChg_CB(Widget w,XtPointer client_data,XtPointer call_data) { XmScrollBarCallbackStruct *ptr = (XmScrollBarCallbackStruct *)call_data; time_display.sample_num = (UInt32)ptr->value; /* wTimeDisplayLbl1 is updated as a result of the this server msg */ /* (since the server refreshes the client in response */ tosvr_start_sample(0,v_erf,(UInt32)ptr->value);}/* * This callback is entered when the sampling rate has changed (via scroll bar): */static voidSampleRateChg_CB(Widget w,XtPointer client_data,XtPointer call_data) { XmScrollBarCallbackStruct *ptr = (XmScrollBarCallbackStruct *)call_data; SampleRateChg_Show(ptr->value); tosvr_sampling_rate(0,v_erf,(UInt32)ptr->value);}/* * This is the Stereo/Mono toggle callback: */static voidStereoChanged_CB(Widget w,XtPointer client_data,XtPointer call_data) { XmToggleButtonCallbackStruct *ptr = (XmToggleButtonCallbackStruct *)call_data; tosvr_chan(0,v_erf,ptr->set ? Stereo : Mono); /* Tell the server about change */}/* * This internal function is used to set the radio buttons: */static voidBitsShow(void) { Widget wSet, wNot; switch ( curBits ) { default : curBits = 8; case 8 : wSet = w8BitCB; wNot = w16BitCB; break; case 16 : wSet = w16BitCB; wNot = w8BitCB; } XtVaSetValues(wSet,XmNset,True,NULL);#if LessTif_Bug_radioBehavior /* * Unless I've goofed somewhere, LessTif does not properly handle radio buttons: */ XtVaSetValues(wNot,XmNset,False,NULL);#endif}/* * This callback is made when the bits per sample radio buttons have changed: */static voidBitsChanged_CB(Widget w,XtPointer client_data,XtPointer call_data) { int bits = (int) (long) client_data; tosvr_bits(0,v_erf,bits); /* Tell server the new bits setting */}/* * This callback, is for the [OK] button in the About dialog: */static voidAboutDlgOkCB(Widget w,XtPointer client_data,XtPointer call_data) { if ( XtIsManaged(wAboutDlg) ) XtUnmanageChild(wAboutDlg); /* Pop down the About dialog */}/* * This callback is for the toggle in the Options->Debug menu selection: */static voidOptionsDebugCB(Widget w,XtPointer client_data,XtPointer call_data) { Arg al[4]; /* Argument list */ Cardinal ac; /* Argument count */ ac = 0; XtSetArg(al[ac],XmNset,&bOptionsDebug); ++ac; /* Request Get Toggle Value */ XtGetValues(wOptions_DebugTgl,al,ac); /* Get value now */ cmdopt_x = bOptionsDebug != False ? 1 : 0; /* Update cmdopt_x also */ tosvr_debug(0,v_erf,cmdopt_x); /* And tell server the same */}/* * This callback is invoked when menu item Options->Semaphore Reset is activated. */static voidOptionsSemResetCB(Widget w,XtPointer client_data,XtPointer call_data) { tosvr_semreset(0,v_erf); /* Request server semaphore reset */}/* * This callback is invoked by the Help->About menu selection: */static voidAboutCB(Widget w,XtPointer client_data,XtPointer call_data) { if ( XtIsManaged(wAboutDlg) ) /* For safety */ return; /* The dialog is already in use */ XtVaSetValues(wAboutDlg,XmNmessageString,sAboutDlgMessage,NULL);/* Supply message */ XtManageChild(wAboutDlg); /* Pop up the dialog now */}/* * This callback is invoked by Menu File->Select, to pop up the file selections dialog box. */static voidPopupSelectFilesCB(Widget w,XtPointer client_data,XtPointer call_data) { if ( XtIsManaged(wFilesDlg) ) /* Already managed? */ return; /* yes, just return */ XtManageChild(wFilesDlg); /* else, make visible now */}/* * This callback is invoked by menu File->Save As.., to start a dialog to allow * saving the recorded.wav file somewhere else. */static voidPopupSaveAsCB(Widget w,XtPointer client_data,XtPointer call_data) { if ( XtIsManaged(wSaveAsDlg) ) /* Is this already managed? */ return; /* Yes, just exit */ XtManageChild(wSaveAsDlg); /* else manage it now */}/* * This callback is invoked by Menu File->Exit, to do the fatal thing.. */static voidExitCB(Widget w,XtPointer client_data,XtPointer call_data) { exit(0); /* This invokes some atexit() calls */}/* * This callback is called when the user presses [OK] in the error dialog. */static voidExitDlgCB(Widget w,XtPointer client_data,XtPointer call_data) { if ( XtIsManaged(wErrDlg) ) /* Is it still managed? */ XtUnmanageChild(wErrDlg); /* Yes, unmanage it now */}/* * This internal function is used to add a new pathname to the list box: */static voidPutFileSelection(XmString xms_pathname) { if ( XmListItemExists(wSelectionsListBox,xms_pathname) == False ) XmListAddItemUnselected(wSelectionsListBox,xms_pathname,0); /* Append to list */}/* * This callback is invoked by the file selection dialog, to add another pathname to the * list box. */static voidFilesDlgOKCB(Widget w,XtPointer client_data,XtPointer call_data) { XmFileSelectionBoxCallbackStruct *ptr = (XmFileSelectionBoxCallbackStruct *) call_data; if ( !XmStringEmpty(ptr->value) ) PutFileSelection(ptr->value); /* Put this string into the selection box */}/* * This call back pops down the dialog box (for any dialog). The widget used for the pop down * is expected to be passed in the client_data argument. */static voidDialogCancelCB(Widget w,XtPointer client_data,XtPointer call_data) { Widget wDlg = (Widget) client_data; /* Get dialog widget */ if ( XtIsManaged(wDlg) ) /* Is it still managed? */ XtUnmanageChild(wDlg); /* yep, unmanage it now */}/* * This function dispatches wavplay server response messages: */static voidDispatchMsg(SVRMSG *msg) { XmString s; double seconds; /* Erase the help text on receipt of first server message */ if (help_text_showing) { help_text_showing = 0; XmSprintfLabel(wFileLbl1,""); XmSprintfLabel(wTypeLbl1,""); XmSprintfLabel(wDateLbl1,""); XmSprintfLabel(wSizeLbl1,""); } if ( msg->msg_type == ToClnt_Bits ) { /* * Server has responded with a new bits per sample setting: */ if ( msg->u.toclnt_bits.DataBits != 0 ) { /* Ignore if value is zero.. */ curBits = msg->u.toclnt_bits.DataBits; /* Server indicates new setting */ BitsShow(); /* Update our client displays */ } } else if ( msg->msg_type == ToClnt_Settings ) { /* * A bunch of settings have changed, according to the server: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -