📄 xaw_i.c
字号:
/* 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 xaw_i.c - XAW Interface from Tomokazu Harada <harada@prince.pe.u-tokyo.ac.jp> modified by Yoshishige Arai <ryo2@on.rim.or.jp>*/#ifdef HAVE_CONFIG_H#include "config.h"#endif /* HAVE_CONFIG_H */#include <stdio.h>#include <stdlib.h>#include <math.h>#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#ifndef NO_STRING_H#include <string.h>#else#include <strings.h>#endif#include <sys/types.h>#include <pwd.h>#include <sys/stat.h>#include "xaw.h"#include <X11/IntrinsicP.h>#include <X11/StringDefs.h>#include <X11/Xaw/Form.h>#include <X11/Xaw/Box.h>#include <X11/Xaw/Label.h>#include <X11/Xaw/Dialog.h>#include <X11/Xaw/AsciiText.h>#ifdef OFFIX#include <OffiX/DragAndDrop.h>#include <OffiX/DragAndDropTypes.h>#endif#include <X11/Xaw/Toggle.h>#include <X11/Xaw/MenuButton.h>#include <X11/Xaw/SimpleMenu.h>#include <X11/Xaw/SmeLine.h>#include <X11/Xaw/SmeBSB.h>#include <X11/Xaw/Scrollbar.h>#include <X11/Xaw/Cardinals.h>#include <X11/Xaw/Simple.h>#include <X11/Xaw/List.h>#include <X11/Xaw/Viewport.h>#include "check.xbm"#include "arrow.xbm"#include "on.xbm"#include "off.xbm"#include "timidity.h"#include "common.h"#include "instrum.h"#include "playmidi.h"#include "readmidi.h"#include "controls.h"#include "timer.h"#include "strtab.h"#ifndef S_ISDIR#define S_ISDIR(mode) (((mode)&0xF000) == 0x4000)#endif /* S_ISDIR */#define TRACE_WIDTH 627 /* default height of trace_vport */#define TRACEVPORT_WIDTH (TRACE_WIDTH+12)#define TRACE_WIDTH_SHORT 388#define TRACEV_OFS 22#define TRACE_FOOT 16#define TRACEH_OFS 0#define BAR_SPACE 20#define BAR_HEIGHT 16static int VOLUME_LABEL_WIDTH = 80;#define MAX_TRACE_HEIGHT 560#if (MAX_XAW_MIDI_CHANNELS*BAR_SPACE+TRACE_FOOT+14 > MAX_TRACE_HEIGHT)#define TRACE_HEIGHT MAX_TRACE_HEIGHT#else#define TRACE_HEIGHT (MAX_XAW_MIDI_CHANNELS*BAR_SPACE+TRACE_FOOT+14)#endif#define VOICES_NUM_OFS 6#define TTITLE_OFS 120#define FILEVPORT_HEIGHT 336#define FILEVPORT_WIDTH 272#define BARSCALE2 0.31111 /* velocity scale (60-4)/180 */#define BARSCALE3 0.28125 /* volume scale (40-4)/128 */#define BARSCALE4 0.25 /* expression scale (36-4)/128 */#define BARSCALE5 0.385827 /* expression scale (53-4)/128 */static int currwidth = 2;static Dimension rotatewidth[] = {TRACE_WIDTH_SHORT, 592, TRACE_WIDTH+8};typedef struct { int col; /* column number */ char **cap; /* caption strings array */ int *w; /* column width array */ int *ofs; /* column offset array */} Tplane;static int plane = 0;#define TCOLUMN 9#define T2COLUMN 10static char *caption[TCOLUMN] ={"ch"," vel"," vol","expr","prog","pan","pit"," instrument", " keyboard"};static char *caption2[T2COLUMN] ={"ch"," vel"," vol","expr","prog","pan","bnk","reverb","chorus", " keyboard"};static int BARH_SPACE[TCOLUMN]= {22,60,40,36,36,36,30,106,304};#define BARH_OFS0 (TRACEH_OFS)#define BARH_OFS1 (BARH_OFS0+22)#define BARH_OFS2 (BARH_OFS1+60)#define BARH_OFS3 (BARH_OFS2+40)#define BARH_OFS4 (BARH_OFS3+36)#define BARH_OFS5 (BARH_OFS4+36)#define BARH_OFS6 (BARH_OFS5+36)#define BARH_OFS7 (BARH_OFS6+30)#define BARH_OFS8 (BARH_OFS7+106)static int bar0ofs[] = {BARH_OFS0,BARH_OFS1,BARH_OFS2,BARH_OFS3, BARH_OFS4,BARH_OFS5,BARH_OFS6,BARH_OFS7,BARH_OFS8};static int BARH2_SPACE[T2COLUMN]= {22,60,40,36,36,36,30,53,53,304};#define BARH2_OFS0 (TRACEH_OFS)#define BARH2_OFS1 (BARH2_OFS0+22)#define BARH2_OFS2 (BARH2_OFS1+60)#define BARH2_OFS3 (BARH2_OFS2+40)#define BARH2_OFS4 (BARH2_OFS3+36)#define BARH2_OFS5 (BARH2_OFS4+36)#define BARH2_OFS6 (BARH2_OFS5+36)#define BARH2_OFS7 (BARH2_OFS6+30)#define BARH2_OFS8 (BARH2_OFS7+53)#define BARH2_OFS9 (BARH2_OFS8+53)static int bar1ofs[] = {BARH2_OFS0,BARH2_OFS1,BARH2_OFS2,BARH2_OFS3, BARH2_OFS4,BARH2_OFS5,BARH2_OFS6,BARH2_OFS7,BARH2_OFS8,BARH2_OFS9};static Tplane pl[] = { {TCOLUMN, caption, BARH_SPACE, bar0ofs}, {T2COLUMN, caption2, BARH2_SPACE, bar1ofs},};#define CL_C 0 /* column 0 = channel */#define CL_VE 1 /* column 1 = velocity */#define CL_VO 2 /* column 2 = volume */#define CL_EX 3 /* column 3 = expression */#define CL_PR 4 /* column 4 = program */#define CL_PA 5 /* column 5 = panning */#define CL_PI 6 /* column 6 = pitch bend */#define CL_IN 7 /* column 7 = instrument name */#define CL_BA 6 /* column 6 = bank */#define CL_RE 7 /* column 7 = reverb */#define CL_CH 8 /* column 8 = chorus */#define INST_NAME_SIZE 16#define INIT_FLISTNUM MAX_DIRECTORY_ENTRYstatic char *inst_name[MAX_XAW_MIDI_CHANNELS];static int disp_inst_name_len = 13;#define UNTITLED_STR "<No Title>"typedef struct { int id; String name; Boolean trap; Boolean bmflag; Widget widget;} ButtonRec;typedef struct { int id; int bit; Widget widget;} OptionRec;typedef struct { char *dirname; char *basename;} DirPath;void a_print_text(Widget,char *);static void drawProg(int,int,int,int,Boolean),drawPan(int,int,Boolean), draw1Chan(int,int,char),drawVol(int,int),drawExp(int,int),drawPitch(int,int), drawInstname(int,char *),drawDrumPart(int,int),drawBank(int,int), drawReverb(int,int),drawChorus(int,int),drawVoices(void),drawTitle(char *), quitCB(),playCB(),pauseCB(),stopCB(),prevCB(),nextCB(), optionsCB(),optionspopupCB(),optionscloseCB(),chorusCB(),optionsdestroyCB(), flistpopupCB(),flistcloseCB(), forwardCB(),backCB(),repeatCB(),randomCB(),menuCB(),sndspecCB(), volsetCB(),volupdownCB(),tuneslideCB(),filemenuCB(), fselectCB(),fdeleteCB(),fdelallCB(),backspaceCB(),aboutCB(),aboutcloseCB(),#ifndef WIDGET_IS_LABEL_WIDGET deleteTextCB(),#endif toggleMark(),popupLoad(),popdownLoad(),volupdownAction(),tuneslideAction(), tunesetAction(),a_readconfig(),a_saveconfig(),filemenuAction(), setDirAction(),setDirList(), drawBar(),redrawTrace(Boolean),completeDir(),ctl_channel_note(), drawKeyboardAll(),draw1Note(),redrawAction(),redrawCaption(), exchgWidth(),toggletrace(), checkRightAndPopupSubmenu(),popdownSubmenuCB(),popdownSubmenu(),leaveSubmenu(), addOneFile(int,int,char *,Boolean), flistMove(),closeParent(),createOptions(),createFlist();static char *expandDir(),*strmatch();static int configcmp();static void pauseAction(),soundkeyAction(),speedAction(),voiceAction();static Boolean IsTracePlaying(),IsEffectiveFile();extern void a_pipe_write(char *);extern int a_pipe_read(char *,int);extern int a_pipe_nread(char *buf, int n);static void initStatus(void);static void xaw_vendor_setup(void);static void safe_getcwd(char *cwd, int maxlen);static Widget title_mb,title_sm,time_l,popup_load,popup_load_f,load_d,load_t;static Widget load_vport,load_flist,cwd_l,load_info, lyric_t;static Dimension lyric_height, base_height, text_height;static GC gc,gcs,gct,gc_xcopy;static Pixel bgcolor,menubcolor,textcolor,textbgcolor,text2bgcolor,buttonbgcolor, buttoncolor,togglecolor,tracecolor,volcolor,expcolor,pancolor,capcolor,rimcolor, boxcolor,suscolor,playcolor,revcolor,chocolor;static Pixel black,white;static Pixel barcol[MAX_XAW_MIDI_CHANNELS];static Widget toplevel,m_box,base_f,file_mb,file_sm,bsb, quit_b,play_b,pause_b,stop_b,prev_b,next_b,fwd_b,back_b, random_b,repeat_b,b_box,v_box,t_box,vol_l0,vol_l,vol_bar,tune_l0,tune_l,tune_bar, trace_vport,trace,pbox,popup_opt,popup_optbox,popup_oclose, popup_about,popup_abox,popup_aok,about_lbl[5], file_vport,file_list,popup_file,popup_fbox,flist_cmdbox, popup_fplay,popup_fdelete,popup_fdelall,popup_fclose, modul_b,porta_b,nrpnv_b,chpressure_b,txtmeta_b,overlapv_b,reverb_b,chorus_b, modul_l,porta_l,nrpnv_l,chpressure_l,txtmeta_l,overlapv_l,reverb_l,chorus_l, modul_bb,porta_bb,nrpnv_bb,chpressure_bb,txtmeta_bb,overlapv_bb,reverb_bb,chorus_bb;static Widget *psmenu = NULL;static char local_buf[300];static char window_title[300], *w_title;int amplitude = DEFAULT_AMPLIFICATION;#ifndef XAW_BITMAP_DIR#define XAW_BITMAP_DIR PKGLIBDIR "/bitmaps"#endif /* XAW_BITMAP_DIR */String bitmapdir = XAW_BITMAP_DIR;Boolean arrangetitle,savelist;static char **current_flist = NULL;static int voices = 0, last_voice = 0, voices_num_width;static int maxentry_on_a_menu = 0,submenu_n = 0;#define OPTIONS_WINDOW 1#define FLIST_WINDOW 2#define ABOUT_WINDOW 4static int popup_shell_exist = 0;typedef struct { Boolean confirmexit; Boolean repeat; Boolean autostart; Boolean autoexit; Boolean hidetext; Boolean shuffle; Boolean disptrace; int amplitude; int extendopt; int chorusopt;} Config;#define FLAG_NOTE_OFF 1#define FLAG_NOTE_ON 2#define FLAG_BANK 1#define FLAG_PROG 2#define FLAG_PROG_ON 4#define FLAG_PAN 8#define FLAG_SUST 16#define FLAG_BENDT 32typedef struct { int reset_panel; int multi_part; char v_flags[MAX_XAW_MIDI_CHANNELS]; int16 cnote[MAX_XAW_MIDI_CHANNELS]; int16 cvel[MAX_XAW_MIDI_CHANNELS]; int16 ctotal[MAX_XAW_MIDI_CHANNELS]; int16 bank[MAX_XAW_MIDI_CHANNELS]; int16 reverb[MAX_XAW_MIDI_CHANNELS]; char c_flags[MAX_XAW_MIDI_CHANNELS]; Channel channel[MAX_XAW_MIDI_CHANNELS]; int is_drum[MAX_XAW_MIDI_CHANNELS];} PanelInfo;/* Default configuration to execute Xaw interface *//* (confirmexit repeat autostart autoexit hidetext shuffle disptrace amplitude) */Config Cfg = { False, False, True, False, False, False, True, DEFAULT_AMPLIFICATION, DEFAULT_OPTIONS, DEFAULT_CHORUS };static PanelInfo *Panel;typedef struct { int y; int l;} KeyL;typedef struct { KeyL k[3]; int xofs; Pixel col;} ThreeL;static ThreeL *keyG;#define KEY_NUM 111#define MAXBITMAP 10static char *bmfname[] = { "back.xbm","fwrd.xbm","next.xbm","pause.xbm","play.xbm","prev.xbm", "quit.xbm","stop.xbm","random.xbm","repeat.xbm",(char *)NULL};static char *iconname = "timidity.xbm";#define BM_BACK 0#define BM_FWRD 1#define BM_NEXT 2#define BM_PAUSE 3#define BM_PLAY 4#define BM_PREV 5#define BM_QUIT 6#define BM_STOP 7#define BM_RANDOM 8#define BM_REPEAT 9static char *dotfile = NULL;char *cfg_items[]= {"Tracing", "ConfirmExit", "Disp:file", "Disp:volume", "Disp:button", "RepeatPlay", "AutoStart", "Disp:text", "Disp:time", "Disp:trace", "CurVol", "ShufflePlay", "AutoExit", "CurFileMode", "ExtOptions", "ChorusOption","File"};#define S_Tracing 0#define S_ConfirmExit 1#define S_DispFile 2#define S_DispVolume 3 #define S_DispButton 4#define S_RepeatPlay 5#define S_AutoStart 6#define S_DispText 7#define S_DispTime 8#define S_DispTrace 9#define S_CurVol 10#define S_ShufflePlay 11#define S_AutoExit 12#define S_CurFileMode 13#define S_ExtOptions 14#define S_ChorusOption 15#define S_MidiFile 16#define CFGITEMSNUMBER 17#define COMMON_BGCOLOR "gray67"#define COMMANDBUTTON_COLOR "gray78"#define TEXTBG_COLOR "gray82"static Display *disp;static int screen;static Pixmap check_mark, arrow_mark, on_mark, off_mark, layer[2];static int bm_height[MAXBITMAP], bm_width[MAXBITMAP], x_hot,y_hot, root_height, root_width;static Pixmap bm_Pixmap[MAXBITMAP];static int max_files, init_options = 0, init_chorus = 0;static char basepath[PATH_MAX];static String *dirlist = NULL, dirlist_top, *flist = NULL;static Dimension trace_width, trace_height, menu_width;static int total_time = 0, curr_time;static float thumbj;static XFontStruct *labelfont,*volumefont,*tracefont;#ifdef I18Nstatic XFontSet ttitlefont;static XFontStruct *ttitlefont0;static char **ml;static XFontStruct **fs_list;#elsestatic XFontStruct *ttitlefont;#define ttitlefont0 ttitlefont#endifstatic struct _app_resources { String bitmap_dir; Boolean arrange_title,save_list,gradient_bar; Dimension text_height,trace_width,trace_height,menu_width; Pixel common_fgcolor,common_bgcolor,menub_bgcolor,text_bgcolor,text2_bgcolor, toggle_fgcolor,button_fgcolor,button_bgcolor, velocity_color,drumvelocity_color,volume_color,expr_color,pan_color, trace_bgcolor,rim_color,box_color,caption_color,sus_color,white_key_color,black_key_color,play_color, rev_color,cho_color; XFontStruct *label_font,*volume_font,*trace_font; String more_text,file_text;#ifdef I18N XFontSet text_font, ttitle_font;#else XFontStruct *text_font, *ttitle_font;#endif} app_resources;static XtResource xaw_resources[] ={#define offset(entry) XtOffset(struct _app_resources*, entry) {"bitmapDir", "BitmapDir", XtRString, sizeof(String), offset(bitmap_dir), XtRString, XAW_BITMAP_DIR }, {"arrangeTitle", "ArrangeTitle", XtRBoolean, sizeof(Boolean), offset(arrange_title), XtRImmediate, (XtPointer)False}, {"saveList", "SaveList", XtRBoolean, sizeof(Boolean), offset(save_list), XtRImmediate, (XtPointer)True}, {"gradientBar", "GradientBar", XtRBoolean, sizeof(Boolean), offset(gradient_bar), XtRImmediate, (XtPointer)False},#ifdef WIDGET_IS_LABEL_WIDGET {"textLHeight", "TextLHeight", XtRShort, sizeof(short), offset(text_height), XtRImmediate, (XtPointer)30},#else {"textHeight", "TextHeight", XtRShort, sizeof(short), offset(text_height), XtRImmediate, (XtPointer)120},#endif {"traceWidth", "TraceWidth", XtRShort, sizeof(short), offset(trace_width), XtRImmediate, (XtPointer)TRACE_WIDTH}, {"traceHeight", "TraceHeight", XtRShort, sizeof(short), offset(trace_height), XtRImmediate, (XtPointer)TRACE_HEIGHT}, {"menuWidth", "MenuWidth", XtRShort, sizeof(Dimension), offset(menu_width), XtRImmediate, (XtPointer)200},#if 0 /* FIXME: this will paint the file-selection list with all blacks.. */ {"foreground", XtCForeground, XtRPixel, sizeof(Pixel), offset(common_fgcolor), XtRString, "black"},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -