📄 w32g_syn.c
字号:
/* TiMidity++ -- MIDI to WAVE converter and player Copyright (C) 1999-2004 Masanao Izumo <iz@onicos.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 w32g_syn.c: Written by Daisuke Aoki <dai@y7.net>*/#ifdef HAVE_CONFIG_H#include "config.h"#endif /* HAVE_CONFIG_H */#include "interface.h"#include <stdio.h>#include <stdlib.h>#include <process.h>#include <stddef.h>#include <windows.h>#undef RC_NONE#include <shlobj.h>#if defined(__CYGWIN32__) || defined(__MINGW32__)#ifndef HAVE_NEW_MMSYSTEM#include <commdlg.h>#ifndef TPM_TOPALIGN#define TPM_TOPALIGN 0x0000L /* for old version of cygwin */#endif#define TIME_ONESHOT 0#define TIME_PERIODIC 1int WINAPI timeSetEvent(UINT uDelay, UINT uResolution, void *fptc, DWORD dwUser, UINT fuEvent);int WINAPI timeKillEvent(UINT uTimerID);#endif#else#include <commctrl.h>#endif /* __CYGWIN32__ */#include <commctrl.h>#ifndef NO_STRING_H#include <string.h>#else#include <strings.h>#endif#include <shlobj.h>#include <windowsx.h> /* There is no <windowsx.h> on CYGWIN. * Edit_* and ListBox_* are defined in * <windowsx.h> */#ifdef TWSYNSRV#include <winsvc.h>//#include <lmcons.h>#include <stdarg.h>#endif#include "timidity.h"#include "common.h"#include "instrum.h"#include "playmidi.h"#include "readmidi.h"#include "output.h"#include "controls.h"#if defined(__CYGWIN32__) || defined(__MINGW32__)#define WIN32GCCWINAPI void InitCommonControls(void);#endif#include "w32g.h"#include "w32g_utl.h"#include "w32g_pref.h"#include "w32g_res.h"#ifdef IA_W32G_SYNtypedef struct w32g_syn_t_ { UINT nid_uID;#ifndef TWSYNSRV HWND nid_hWnd; HICON hIcon;#endif int argc; char **argv; HANDLE gui_hThread; DWORD gui_dwThreadId; HANDLE syn_hThread; DWORD syn_dwThreadId;// int syn_ThreadPriority; HANDLE hMutex; int volatile quit_state;} w32g_syn_t;static w32g_syn_t w32g_syn;// 奺庬曄悢 (^^;;;HINSTANCE hInst = NULL;int PlayerLanguage = LANGUAGE_ENGLISH;int IniFileAutoSave = 1;char *IniFile;char *ConfigFile;char *PlaylistFile;char *PlaylistHistoryFile;char *MidiFileOpenDir;char *ConfigFileOpenDir;char *PlaylistFileOpenDir;int SecondMode = 0;BOOL PosSizeSave = TRUE;int DocMaxSize;char *DocFileExt;int AutoloadPlaylist = 0;int AutosavePlaylist = 0;int SeachDirRecursive = 0;int DocWndIndependent = 0;int DocWndAutoPopup = 0;int TraceGraphicFlag;int PlayerThreadPriority;int MidiPlayerThreadPriority;int MainThreadPriority;int GUIThreadPriority;int TracerThreadPriority;int WrdThreadPriority;int SubWindowMax = 5;int InitMinimizeFlag = 0;int DebugWndStartFlag = 1;int ConsoleWndStartFlag = 0;int ListWndStartFlag = 0;int TracerWndStartFlag = 0;int DocWndStartFlag = 0;int WrdWndStartFlag = 0;int DebugWndFlag = 1;int ConsoleWndFlag = 1;int ListWndFlag = 1;int TracerWndFlag = 0;int DocWndFlag = 1;int WrdWndFlag = 0;int SoundSpecWndFlag = 0;int WrdGraphicFlag;int TraceGraphicFlag;int w32g_auto_output_mode = 0;char *w32g_output_dir = NULL;extern void CmdLineToArgv(LPSTR lpCmdLine, int *argc, CHAR ***argv);static int start_syn_thread ( void );static void WINAPI syn_thread ( void );#ifndef TWSYNSRV// Task tray version herestatic LRESULT CALLBACK SynWinProc ( HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam );static void VersionWnd(HWND hParentWnd);static void TiMidityWnd(HWND hParentWnd);static int w32g_syn_create_win ( void );#define HAVE_SYN_CONSOLE#define MYWM_NOTIFYICON (WM_USER+501)#define MYWM_QUIT (WM_USER+502)#define W32G_SYNWIN_CLASSNAME "TWSYNTH GUI"#define W32G_SYN_TIP "TWSYNTH GUI"// 億僢僾傾僢僾儊僯儏乕#define IDM_NOTHING 100#define IDM_QUIT 101#define IDM_START 102// #define IDM_STOP 103#define IDM_SYSTEM_RESET 104#define IDM_GM_SYSTEM_RESET 105#define IDM_GS_SYSTEM_RESET 106#define IDM_XG_SYSTEM_RESET 107#define IDM_CHANGE_GM_SYSTEM 108#define IDM_CHANGE_GS_SYSTEM 109#define IDM_CHANGE_XG_SYSTEM 110#define IDM_CHANGE_DEFAULT_SYSTEM 111#define IDM_PREFERENCE 112#define IDM_CONSOLE_WND 113#define IDM_PROCESS_PRIORITY_LOWEST 131#define IDM_PROCESS_PRIORITY_BELOW_NORMAL 132#define IDM_PROCESS_PRIORITY_NORMAL 133#define IDM_PROCESS_PRIORITY_ABOVE_NORMAL 134#define IDM_PROCESS_PRIORITY_HIGHEST 135#define IDM_PROCESS_PRIORITY_REALTIME 136#define IDM_SYN_THREAD_PRIORITY_LOWEST 121#define IDM_SYN_THREAD_PRIORITY_BELOW_NORMAL 122#define IDM_SYN_THREAD_PRIORITY_NORMAL 123#define IDM_SYN_THREAD_PRIORITY_ABOVE_NORMAL 124#define IDM_SYN_THREAD_PRIORITY_HIGHEST 125#define IDM_SYN_THREAD_PRIORITY_TIMECRITICAL 137#define IDM_VERSION 126#define IDM_TIMIDITY 127#ifdef HAVE_SYN_CONSOLEstatic HWND hConsoleWnd;void InitConsoleWnd(HWND hParentWnd);#endif // HAVE_SYN_CONSOLE#else // !TWSYNSRV// Windows service version here#undef HAVE_SYN_CONSOLEstatic SERVICE_STATUS_HANDLE serviceStatusHandle;static DWORD currentServiceStatus;static const char *serviceName = "Timidity";static const char *serviceDescription = "Realtime synthesize midi message";static const char *regKeyTwSynSrv = "SYSTEM\\CurrentControlSet\\Services\\Timidity";static BOOL InstallService();static BOOL UninstallService();#endif // !TWSYNSRV#define W32G_SYN_NID_UID 12301#define W32G_MUTEX_NAME "TWSYNTH MUTEX"#define W32G_SYN_MESSAGE_MAX 100#define W32G_SYN_NONE 0#define W32G_SYN_QUIT 10#define W32G_SYN_START 11 // 墘憈忬懺傊堏峴#define W32G_SYN_STOP 12 // 墘憈掆巭忬懺傊堏峴#define W32G_SYN_GS_SYSTEM_RESET 21#define W32G_SYN_XG_SYSTEM_RESET 22#define W32G_SYN_SYSTEM_RESET 23#define W32G_SYN_GM_SYSTEM_RESET 24#define W32G_SYN_CHANGE_GS_SYSTEM 25#define W32G_SYN_CHANGE_XG_SYSTEM 26#define W32G_SYN_CHANGE_GM_SYSTEM 27#define W32G_SYN_CHANGE_DEFAULT_SYSTEM 28typedef struct w32g_syn_message_t_ { int cmd;} w32g_syn_message_t;static volatile enum { stop, run, quit, none } w32g_syn_status, w32g_syn_status_prev; #ifndef MAX_PORT#define MAX_PORT 4#endifint w32g_syn_id_port[MAX_PORT];int w32g_syn_port_num = 2;extern int win_main(int argc, char **argv);extern int ctl_pass_playing_list2(int n, char *args[]);extern void winplaymidi(void);w32g_syn_message_t msg_loopbuf[W32G_SYN_MESSAGE_MAX];int msg_loopbuf_start = -1;int msg_loopbuf_end = -1;extern int rtsyn_system_mode;HANDLE msg_loopbuf_hMutex = NULL; // 攔懠張棟梡int syn_AutoStart; // 僔儞僙帺摦婲摦DWORD processPriority; // 僾儘僙僗偺僾儔僀僆儕僥傿DWORD syn_ThreadPriority; // 僔儞僙僗儗僢僪偺僾儔僀僆儕僥傿extern int volatile stream_max_compute; // play_event() 偺 compute_data() 偱寁嶼傪嫋偡嵟戝帪娫丅static int w32g_syn_main ( void );static int start_syn_thread ( void );static void WINAPI syn_thread ( void );static void terminate_syn_thread ( void );static int wait_for_termination_of_syn_thread ( void );int w32g_message_set ( int cmd );int w32g_message_get ( w32g_syn_message_t *msg );void w32g_syn_ctl_pass_playing_list ( int n_, char *args_[] );int w32g_syn_do_before_pref_apply ( void );int w32g_syn_do_after_pref_apply ( void );/* 峔憿 丂儊僀儞僗儗僢僪丗GUI偺儊僢僙乕僕儖乕僾 丂僔儞僙僒僀僓乕僗儗僢僪丗敪壒晹暘*/int WINAPIWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ HANDLE hMutex; int i; // 崱偺偲偙傠俀廳婲摦偼偱偒側偄傛偆偵偟偲偔丅 hMutex = OpenMutex ( 0, FALSE, W32G_MUTEX_NAME ); if ( hMutex != NULL ) { CloseHandle ( hMutex ); return 0; } w32g_syn.hMutex = CreateMutex ( NULL, TRUE, W32G_MUTEX_NAME ); if ( w32g_syn.hMutex == NULL ) { return 0; } CmdLineToArgv(lpCmdLine, &w32g_syn.argc, &w32g_syn.argv);#ifdef TWSYNSRV // Service install and uninstall handling for (i = 1; i < w32g_syn.argc; i++) { if (stricmp(w32g_syn.argv[i], "/INSTALL") == 0) { InstallService(); ReleaseMutex ( w32g_syn.hMutex ); CloseHandle ( w32g_syn.hMutex ); return 0; } else if (stricmp(w32g_syn.argv[i], "/UNINSTALL") == 0) { UninstallService(); ReleaseMutex ( w32g_syn.hMutex ); CloseHandle ( w32g_syn.hMutex ); return 0; } }#endif// wrdt=wrdt_list[0]; hInst = hInstance; w32g_syn.gui_hThread = GetCurrentThread(); w32g_syn.gui_dwThreadId = GetCurrentThreadId(); w32g_syn.quit_state = 0; w32g_syn_main (); ReleaseMutex ( w32g_syn.hMutex ); CloseHandle ( w32g_syn.hMutex ); return 0;}#ifndef TWSYNSRV// Task tray version herestatic int w32g_syn_create_win ( void ){ WNDCLASSEX wndclass ; wndclass.cbSize = sizeof(WNDCLASSEX); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = SynWinProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInst ; wndclass.hIcon = w32g_syn.hIcon; wndclass.hIconSm = w32g_syn.hIcon; wndclass.hCursor = LoadCursor(0,IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH)(COLOR_SCROLLBAR + 1); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = W32G_SYNWIN_CLASSNAME; RegisterClassEx(&wndclass); w32g_syn.nid_hWnd = CreateWindowEx ( WS_EX_TOOLWINDOW, W32G_SYNWIN_CLASSNAME, 0, WS_CLIPCHILDREN, CW_USEDEFAULT,0, 10, 10,0,0,hInst,0 ); if ( w32g_syn.nid_hWnd == NULL ) { return -1; } ShowWindow ( w32g_syn.nid_hWnd, SW_HIDE ); UpdateWindow ( w32g_syn.nid_hWnd ); // 昁梫側偄偲巚偆傫偩偗偳丅 return 0;}// return// 0 : OK// -1 : FATAL ERRORstatic int w32g_syn_main ( void ){ int i; MSG msg; InitCommonControls(); w32g_syn.nid_uID = W32G_SYN_NID_UID; w32g_syn.nid_hWnd = NULL; w32g_syn.hIcon = LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_TIMIDITY), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); processPriority = NORMAL_PRIORITY_CLASS; syn_ThreadPriority = THREAD_PRIORITY_NORMAL; for ( i = 0; i <= MAX_PORT; i ++ ) { w32g_syn_id_port[i] = i + 1; } if ( w32g_syn_create_win() ) { MessageBox ( NULL, "Fatal Error", "ERROR", MB_OK ); return -1; } while( GetMessage(&msg,NULL,0,0) ){ if ( msg.message == MYWM_QUIT ) { if ( w32g_syn.quit_state < 1 ) w32g_syn.quit_state = 1; if ( hConsoleWnd != NULL ) { DestroyWindow ( hConsoleWnd ); hConsoleWnd = NULL; } DestroyWindow ( w32g_syn.nid_hWnd ); w32g_syn.nid_hWnd = NULL; } TranslateMessage(&msg); DispatchMessage(&msg); } while ( w32g_syn.quit_state < 2 ) { Sleep ( 300 ); } return 0;}static VOID CALLBACK forced_exit ( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime ){ exit ( 0 );}// Add the icon into the status area of the task bar.BOOL AddTasktrayIcon(HWND hwnd){ BOOL bRes; NOTIFYICONDATA nid; nid.cbSize = sizeof ( NOTIFYICONDATA ); nid.hWnd = w32g_syn.nid_hWnd = hwnd; nid.uID = w32g_syn.nid_uID; nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; nid.uCallbackMessage = MYWM_NOTIFYICON; nid.hIcon = w32g_syn.hIcon; strcpy ( nid.szTip, W32G_SYN_TIP ); bRes = Shell_NotifyIcon ( NIM_ADD, &nid ); return bRes;}// Delete the icon from the status area of the task bar.void DeleteTasktrayIcon(HWND hwnd){ BOOL bRes; NOTIFYICONDATA nid; int i; nid.cbSize = sizeof ( NOTIFYICONDATA ); nid.hWnd = w32g_syn.nid_hWnd; nid.uID = w32g_syn.nid_uID; for ( i = 1; i <= 10; i ++ ) { bRes = Shell_NotifyIcon ( NIM_DELETE, &nid ); if ( bRes == TRUE ) break; if ( i >= 10 ) { MessageBox ( NULL, "Fatal Error", "ERROR", MB_OK ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -