⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 motif_i.c

📁 MIDI解码程序(用VC编写)
💻 C
📖 第 1 页 / 共 3 页
字号:
/*    TiMidity++ -- MIDI to WAVE converter and player    Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>    Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    motif_interface.c: written by Vincent Pagel (pagel@loria.fr) 10/4/95    Policy : I choose to make a separate process for a TIMIDITY motif    interface for TIMIDITY (if the interface was in the same process    X redrawings would interfere with the audio computation. Besides    XtAppAddWorkProc mechanism is not easily controlable)    The solution : I create a pipe between Timidity and the forked interface    and use XtAppAddInput to watch the data arriving on the pipe.    10/4/95      - Initial working version with prev, next, and quit button and a        text display    17/5/95      - Add timidity icon with filename displaying to play midi while        I work without having that big blue window in the corner of        my screen :)      - Solve the problem of concurent scale value modification    21/5/95      - Add menus, file selection box    14/6/95      - Make the visible part of file list follow the selection   */#ifdef HAVE_CONFIG_H#include "config.h"#endif /* HAVE_CONFIG_H */#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <stdarg.h>#include <Xm/Xm.h>#include <Xm/Form.h>#include <Xm/Text.h>#include <Xm/PushB.h>#include <Xm/Label.h>#include <Xm/Scale.h>#include <Xm/List.h>#include <Xm/Frame.h>#include <Xm/RowColumn.h>#include <Xm/CascadeB.h>#include <Xm/FileSB.h>#include <Xm/FileSB.h>#include <Xm/ToggleB.h>#include "timidity.h"#include "common.h"#include "instrum.h"#include "playmidi.h"#include "output.h"#include "controls.h"#include "motif.h"static XtAppContext context;static XmStringCharSet char_set=XmSTRING_DEFAULT_CHARSET;static Widget toplevel;static Widget text;static XmTextPosition wpr_position=0;static Widget mainForm;static Widget menu_bar, open_option, quit_option, auto_next_option;static Widget open_dialog , add_all_button;static Widget btnForm, backBtn,fwdBtn, restartBtn, pauseBtn, quitBtn,	      nextBtn, prevBtn;static Pixmap backPixmap, fwdPixmap, pausePixmap , restartPixmap,	      prevPixmap, nextPixmap, quitPixmap,	      timidityPixmap;static Widget countFrame, countForm, counterlbl, totlbl , count_headlbl;static int last_sec=0;static int max_sec=0;static Widget file_namelbl, file_headlbl;static Widget volume_scale , locator_scale ;static Boolean locator_scale_button= ButtonRelease;static Widget file_list;static int file_number_to_play; /* Number of the file we're playing in the list *//* * CREATE PIXMAPS FOR THE BUTONS */static void CreatePixmaps(Widget parent){  /*   *   * BITMAPS   */#include "motif_bitmaps/back.xbm"#include "motif_bitmaps/next.xbm"#include "motif_bitmaps/prev.xbm"#include "motif_bitmaps/restart.xbm"#include "motif_bitmaps/fwd.xbm"#include "motif_bitmaps/pause.xbm"#include "motif_bitmaps/quit.xbm"#include "motif_bitmaps/timidity.xbm"    Display *disp;    Drawable d;    Pixel fg,bg;    int ac;    Arg al[20];    unsigned int depth=DefaultDepthOfScreen(XtScreen(toplevel));    ac = 0;    XtSetArg(al[ac], XmNbackground, &bg); ac++;    XtSetArg(al[ac], XmNforeground, &fg); ac++;    XtGetValues(parent, al, ac);    disp=XtDisplay(toplevel);    d=RootWindowOfScreen(XtScreen(toplevel));    backPixmap = XCreatePixmapFromBitmapData(disp, d,					     back_bits, back_width, back_height,					     fg, bg,depth);    fwdPixmap = XCreatePixmapFromBitmapData( disp, d,					     fwd_bits, fwd_width, fwd_height,					     fg, bg,depth);    pausePixmap = XCreatePixmapFromBitmapData(disp, d,					pause_bits, pause_width, pause_height,					fg, bg,depth);    restartPixmap = XCreatePixmapFromBitmapData(disp, d,					  restart_bits, restart_width, restart_height,					  fg, bg,depth);    nextPixmap  = XCreatePixmapFromBitmapData(disp, d,					next_bits, next_width, next_height,					fg, bg,depth);    prevPixmap  = XCreatePixmapFromBitmapData(disp, d,					prev_bits, prev_width, prev_height,					fg, bg,depth);    quitPixmap  = XCreatePixmapFromBitmapData(disp, d,					quit_bits, quit_width, quit_height,					fg, bg,depth);    timidityPixmap  = XCreatePixmapFromBitmapData(disp, d,						  timidity_bits, timidity_width, timidity_height,						  WhitePixelOfScreen(XtScreen(toplevel)),						  BlackPixelOfScreen(XtScreen(toplevel)),depth);}/************************************ *                                  * * ALL THE INTERFACE'S CALLBACKS    * *                                  * ************************************//* * Generic buttons callbacks ( Transport Buttons ) *//*ARGSUSED*/static void  GenericCB(Widget widget, int data, XtPointer call_data){	if(data != MOTIF_QUIT && data != MOTIF_NEXT && data != MOTIF_PREV)	{		Arg al[10];		int ac, nbfile;		ac=0;		XtSetArg(al[ac], XmNitemCount, &nbfile); ac++;		XtGetValues(file_list, al, ac);		if(file_number_to_play==0||file_number_to_play>nbfile)			return;	}    m_pipe_int_write( data );}/* *  Generic scales callbacks : VOLUME and LOCATOR *//*ARGSUSED*/static void Generic_scaleCB(Widget widget, int data, XtPointer call_data){    XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct *) call_data;	if(data == MOTIF_CHANGE_LOCATOR)	{		Arg al[10];		int ac, nbfile;		ac=0;		XtSetArg(al[ac], XmNitemCount, &nbfile); ac++;		XtGetValues(file_list, al, ac);		if(file_number_to_play<=0||file_number_to_play>nbfile)		{			XmScaleSetValue(locator_scale,0);			return;		}	}    m_pipe_int_write(  data );    m_pipe_int_write(cbs->value);}/* * Detect when a mouse button is pushed or released in a scale area to * avoid concurent scale value modification while holding it with the mouse *//*ARGSUSED*/static void Locator_btn(Widget w,XtPointer client_data,XEvent *event,Boolean *cont){    /* Type = ButtonPress or ButtonRelease */    locator_scale_button= event->xbutton.type;}/* * File List selection CALLBACK *//*ARGSUSED*/static void File_ListCB(Widget widget, int data, XtPointer call_data){    XmListCallbackStruct *cbs= (XmListCallbackStruct *) call_data;    char *text;    int nbvisible, first_visible ;    Arg al[10];    int ac;    /* First, check that the selected file is really visible in the list */    ac=0;    XtSetArg(al[ac],XmNtopItemPosition,&first_visible); ac++;    XtSetArg(al[ac],XmNvisibleItemCount,&nbvisible); ac++;    XtGetValues(widget, al, ac);    if ( ( first_visible > cbs->item_position) ||         ((first_visible+nbvisible) <= cbs->item_position))	XmListSetPos(widget, cbs->item_position);    /* Tell the application to play the requested file */    XmStringGetLtoR(cbs->item,char_set,&text);    m_pipe_int_write(MOTIF_PLAY_FILE);    m_pipe_string_write(text);    file_number_to_play=cbs->item_position;    XtFree(text);}/* * Generic menu callback *//*ARGSUSED*/static void menuCB(Widget w,int client_data,XmAnyCallbackStruct *call_data){    switch (client_data)	{	case MENU_OPEN:	{	    XtManageChild(open_dialog);	}	break;	case MENU_QUIT : {	    m_pipe_int_write(MOTIF_QUIT);	}	    break;	case MENU_TOGGLE : {	    /* Toggle modified : for the moment , nothing to do ! */	    /* if (XmToggleButtonGetState(w)) TRUE else FALSE */	    }	    break;	}}/* * File selection box callback *//*ARGSUSED*/static void openCB(Widget w,int client_data,XmFileSelectionBoxCallbackStruct *call_data){    if (client_data==DIALOG_CANCEL)	{ /* do nothing if cancel is selected. */	    XtUnmanageChild(open_dialog);	    return;	}    else if (client_data==DIALOG_ALL)	{ /* Add all the listed files  */	    Arg al[10];	    int ac;	    Widget the_list;	    int nbfile;	    XmStringTable files;		char *text;	    int i;	    the_list=XmFileSelectionBoxGetChild(open_dialog,XmDIALOG_LIST);	    if (!XmIsList(the_list))		{		    fprintf(stderr, "PANIC: List are not what they used to be"			    NLS);		    exit(1);		}	    ac=0;	    XtSetArg(al[ac], XmNitemCount, &nbfile); ac++;	    XtSetArg(al[ac], XmNitems, &files); ac++;	    XtGetValues(the_list, al, ac);	    m_pipe_int_write(MOTIF_EXPAND);	    m_pipe_int_write(nbfile);	    for (i=0;i<nbfile;i++)		{			XmStringGetLtoR(files[i],char_set,&text);			m_pipe_string_write(text);			XtFree(text);		}	    XtUnmanageChild(open_dialog);	}    else	{   /* get filename from file selection box and add it to the list*/		char *text;	    m_pipe_int_write(MOTIF_EXPAND);	    m_pipe_int_write(1);		XmStringGetLtoR(call_data->value,char_set,&text);	    m_pipe_string_write(text);		XtFree(text);	    XtUnmanageChild(open_dialog);	}}/******************************************************** *                                                      * * Receive DATA sent by the application on the pipe     * *                                                      * ********************************************************//*ARGSUSED*/static void handle_input(client_data, source, id)    XtPointer client_data;    int *source;    XtInputId *id;{    int message;    m_pipe_int_read(&message);    switch (message)	{	case REFRESH_MESSAGE : {	    fprintf(stderr, "REFRESH MESSAGE IS OBSOLETE !!!" NLS);	}	    break;	case TOTALTIME_MESSAGE : {	    int tseconds;	    int minutes,seconds;	    char local_string[20];	    Arg al[10];	    int ac;	    m_pipe_int_read(&tseconds);	    seconds=tseconds;	    minutes=seconds/60;	    seconds-=minutes*60;	    sprintf(local_string,"/ %02d:%02d",minutes,seconds);	    ac=0;	    XtSetArg(al[ac], XmNlabelString,		     XmStringCreate(local_string, char_set)); ac++;	    XtSetValues(totlbl, al, ac);	    /* Readjust the time scale */	    XmScaleSetValue(locator_scale,0);	    ac=0;	    XtSetArg(al[ac], XmNmaximum, tseconds); ac++;	    XtSetValues(locator_scale, al, ac);	    max_sec=tseconds;	}	    break;	case MASTERVOL_MESSAGE: {	    int volume;	    m_pipe_int_read(&volume);	    XmScaleSetValue(volume_scale,volume);	}	    break;	case FILENAME_MESSAGE : {	    char filename[255], separator[255];	    Arg al[10];	    char *pc;	    int ac, i;	    short nbcol;	    m_pipe_string_read(filename);	    /* Extract basename of the file */	    pc=strrchr(filename,'/');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -