/* TiMidity++ -- MIDI to WAVE converter and player Copyright (C) 1999-2002 Masanao Izumo Copyright (C) 1995 Tuukka Toivonen 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 */ #ifdef HAVE_CONFIG_H #include "config.h" #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include "timidity.h" #include "common.h" #include "instrum.h" #include "playmidi.h" #include "readmidi.h" #include "output.h" #include "controls.h" #include "recache.h" #ifdef SUPPORT_SOUNDSPEC #include "soundspec.h" #endif /* SUPPORT_SOUNDSPEC */ #include "wrd.h" #include "w32g.h" #include "w32g_ut2.h" char *timidity_window_inifile; // **************************************************************************** // DlgChooseFont // hwnd: Owner Window of This Dialog // hwndFontChange: Window to Change Font // hFontPre: Previous Font of hwndFontChange (Call CloseHandle()) int DlgChooseFontAndApply(HWND hwnd, HWND hwndFontChange, HFONT hFontPre, char *fontname, int *fontheight, int *fontwidth) { LOGFONT lf; CHOOSEFONT cf; HFONT hFont; memset(&lf,0,sizeof(LOGFONT)); memset(&cf,0,sizeof(CHOOSEFONT)); // lf.lfHeight = 16; // lf.lfWidth = 8; strcpy(lf.lfFaceName,"MS 明朝"); cf.lStructSize = sizeof(CHOOSEFONT); cf.hwndOwner = hwnd; // cf.hDC = NULL; cf.lpLogFont = &lf; // cf.iPointSize = 16; // cf.Flags = CF_ANSIONLY | CF_FORCEFONTEXIST ; cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT;; // cf.rgbColors = RGB(0,0,0); // cf.lCustData = NULL; // cf.lpfnHook = NULL; // cf.lpTemplateName = NULL; // cf.hInstance = 0; // cf.lpszStyle = NULL; cf.nFontType = SCREEN_FONTTYPE; // cf.nSizeMin = 4; // cf.nSizeMax = 72; ChooseFont(&cf); // if(ChooseFont(&cf)==TRUE) // return -1; if(hFontPre!=NULL) CloseHandle(hFontPre); hFont = CreateFontIndirect(&lf); SendMessage(hwndFontChange,WM_SETFONT,(WPARAM)hFont,(LPARAM)MAKELPARAM(TRUE,0)); if(fontname!=NULL) strcpy(fontname,lf.lfFaceName); if(fontheight!=NULL) *fontheight = lf.lfHeight; if(fontwidth!=NULL) *fontwidth = lf.lfWidth; return 0; } int DlgChooseFont(HWND hwnd, char *fontName, int *fontHeight, int *fontWidth) { LOGFONT lf; CHOOSEFONT cf; memset(&lf,0,sizeof(LOGFONT)); if(fontHeight!=NULL) lf.lfHeight = *fontHeight; if(fontWidth!=NULL) lf.lfWidth = *fontWidth; if(fontName!=NULL) strcpy(lf.lfFaceName,fontName); memset(&cf,0,sizeof(CHOOSEFONT)); cf.lStructSize = sizeof(CHOOSEFONT); cf.hwndOwner = hwnd; // cf.hDC = NULL; cf.lpLogFont = &lf; // cf.iPointSize = 16; // cf.Flags = CF_ANSIONLY | CF_FORCEFONTEXIST ; cf.Flags = CF_ANSIONLY | CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT; // cf.rgbColors = RGB(0,0,0); // cf.lCustData = NULL; // cf.lpfnHook = NULL; // cf.lpTemplateName = NULL; // cf.hInstance = 0; // cf.lpszStyle = NULL; cf.nFontType = SCREEN_FONTTYPE; // cf.nSizeMin = 4; // cf.nSizeMax = 72; if(ChooseFont(&cf)!=TRUE) return -1; if(fontName!=NULL) strcpy(fontName,lf.lfFaceName); if(fontHeight!=NULL) *fontHeight = abs(lf.lfHeight); if(fontWidth!=NULL) *fontWidth = lf.lfWidth; return 0; } /**********************************************************************/ void SetWindowPosSize ( HWND parent_hwnd, HWND hwnd, int x, int y ) { RECT rc1, rc2; int width1, height1; int width2, height2; if ( GetWindowRect ( hwnd, &rc1 ) ) { width1 = rc1.right - rc1.left; height1 = rc1.bottom - rc1.top; if ( x >= 0 ) { rc1.right = rc1.right - rc1.left + x; rc1.left = x; } else { // rc1.right = rc1.right - rc1.left; // rc1.left = 0; } if ( y >= 0 ) { rc1.bottom = rc1.bottom - rc1.top + y; rc1.top = y; } else { // rc1.bottom = rc1.bottom - rc1.top; // rc1.top = 0; } if ( GetClientRect ( parent_hwnd, &rc2 ) ) { width2 = rc2.right - rc2.left; height2 = rc2.bottom - rc2.top; if ( rc1.left < rc2.left ) rc1.left = rc2.left; if ( rc1.left > rc2.right ) rc1.left = rc2.right; if ( rc1.top < rc2.top ) rc1.top = rc2.top; if ( rc1.top > rc2.bottom ) rc1.top = rc2.bottom; if ( width1 > width2 ) width1 = width2; if ( height1 > height2 ) height1 = height2; MoveWindow ( hwnd, rc1.left, rc1.top, width1, height1, TRUE ); } } } /**********************************************************************/ BOOL PosSizeSave = TRUE; #define SEC_MAINWND "MainWnd" int INISaveMainWnd(void) { char *section = SEC_MAINWND; char *inifile = TIMIDITY_WINDOW_INI_FILE; char buffer[256]; if ( PosSizeSave ) { sprintf(buffer,"%d",MainWndInfo.PosX); if ( MainWndInfo.PosX >= 0 || MainWndInfo.PosY >= 0 ) { if ( MainWndInfo.PosX < 0 ) MainWndInfo.PosX = 0; if ( MainWndInfo.PosY < 0 ) MainWndInfo.PosY = 0; } if ( MainWndInfo.PosX >= 0 ) WritePrivateProfileString(section,"PosX",buffer,inifile); sprintf(buffer,"%d",MainWndInfo.PosY); if ( MainWndInfo.PosY >= 0 ) WritePrivateProfileString(section,"PosY",buffer,inifile); } sprintf(buffer,"%d",MainWndInfo.CanvasMode); WritePrivateProfileString(section,"CanvasMode",buffer,inifile); WritePrivateProfileString(NULL,NULL,NULL,inifile); // Write Flush return 0; } int INILoadMainWnd(void) { char *section = SEC_MAINWND; char *inifile = TIMIDITY_WINDOW_INI_FILE; int num; num = GetPrivateProfileInt(section,"PosX",-1,inifile); MainWndInfo.PosX = num; num = GetPrivateProfileInt(section,"PosY",-1,inifile); MainWndInfo.PosY = num; num = GetPrivateProfileInt(section,"CanvasMode",-1,inifile); MainWndInfo.CanvasMode = num; return 0; } #define SEC_LISTWND "ListWnd" int INISaveListWnd(void) { char *section = SEC_LISTWND; char *inifile = TIMIDITY_WINDOW_INI_FILE; char buffer[256]; if ( PosSizeSave ) { if ( ListWndInfo.PosX >= 0 || ListWndInfo.PosY >= 0 ) { if ( ListWndInfo.PosX < 0 ) ListWndInfo.PosX = 0; if ( ListWndInfo.PosY < 0 ) ListWndInfo.PosY = 0; } sprintf(buffer,"%d",ListWndInfo.PosX); if ( ListWndInfo.PosX >= 0 ) WritePrivateProfileString(section,"PosX",buffer,inifile); sprintf(buffer,"%d",ListWndInfo.PosY); if ( ListWndInfo.PosY >= 0 ) WritePrivateProfileString(section,"PosY",buffer,inifile); sprintf(buffer,"%d",ListWndInfo.Width); WritePrivateProfileString(section,"Width",buffer,inifile); sprintf(buffer,"%d",ListWndInfo.Height); WritePrivateProfileString(section,"Height",buffer,inifile); } WritePrivateProfileString(section,"fontNameEN",ListWndInfo.fontNameEN,inifile); WritePrivateProfileString(section,"fontNameJA",ListWndInfo.fontNameJA,inifile); sprintf(buffer,"%d",ListWndInfo.fontWidth); WritePrivateProfileString(section,"fontWidth",buffer,inifile); sprintf(buffer,"%d",ListWndInfo.fontHeight); WritePrivateProfileString(section,"fontHeight",buffer,inifile); sprintf(buffer,"%d",ListWndInfo.fontFlags); WritePrivateProfileString(section,"fontFlags",buffer,inifile); WritePrivateProfileString(NULL,NULL,NULL,inifile); // Write Flush return 0; } int INILoadListWnd(void) { char *section = SEC_LISTWND; char *inifile = TIMIDITY_WINDOW_INI_FILE; int num; char buffer[64]; num = GetPrivateProfileInt(section,"PosX",-1,inifile); ListWndInfo.PosX = num; num = GetPrivateProfileInt(section,"PosY",-1,inifile); ListWndInfo.PosY = num; num = GetPrivateProfileInt(section,"Width",-1,inifile); if(num!=-1) ListWndInfo.Width = num; num = GetPrivateProfileInt(section,"Height",-1,inifile); if(num!=-1) ListWndInfo.Height = num; GetPrivateProfileString(section,"fontNameEN","",buffer,32,inifile); if(buffer[0]!=0) strcpy(ListWndInfo.fontNameEN,buffer); GetPrivateProfileString(section,"fontNameJA","",buffer,32,inifile); if(buffer[0]!=0) strcpy(ListWndInfo.fontNameJA,buffer); num = GetPrivateProfileInt(section,"fontWidth",-1,inifile); if(num!=-1) ListWndInfo.fontWidth = num; num = GetPrivateProfileInt(section,"fontHeight",-1,inifile); if(num!=-1) ListWndInfo.fontHeight = num; num = GetPrivateProfileInt(section,"fontFlags",-1,inifile); if(num!=-1) ListWndInfo.fontFlags = num; return 0; } #define SEC_DOCWND "DocWnd" int INISaveDocWnd(void) { char *section = SEC_DOCWND; char *inifile = TIMIDITY_WINDOW_INI_FILE; char buffer[256]; if ( PosSizeSave ) { if ( DocWndInfo.PosX >= 0 || DocWndInfo.PosY >= 0 ) { if ( DocWndInfo.PosX < 0 ) DocWndInfo.PosX = 0; if ( DocWndInfo.PosY < 0 ) DocWndInfo.PosY = 0; } sprintf(buffer,"%d",DocWndInfo.PosX); if ( DocWndInfo.PosX >= 0 ) WritePrivateProfileString(section,"PosX",buffer,inifile); sprintf(buffer,"%d",DocWndInfo.PosY); if ( DocWndInfo.PosY >= 0 ) WritePrivateProfileString(section,"PosY",buffer,inifile); sprintf(buffer,"%d",DocWndInfo.Width); WritePrivateProfileString(section,"Width",buffer,inifile); sprintf(buffer,"%d",DocWndInfo.Height); WritePrivateProfileString(section,"Height",buffer,inifile); } WritePrivateProfileString(section,"fontNameEN",DocWndInfo.fontNameEN,inifile); WritePrivateProfileString(section,"fontNameJA",DocWndInfo.fontNameJA,inifile); sprintf(buffer,"%d",DocWndInfo.fontWidth); WritePrivateProfileString(section,"fontWidth",buffer,inifile); sprintf(buffer,"%d",DocWndInfo.fontHeight); WritePrivateProfileString(section,"fontHeight",buffer,inifile); sprintf(buffer,"%d",DocWndInfo.fontFlags); WritePrivateProfileString(section,"fontFlags",buffer,inifile); WritePrivateProfileString(NULL,NULL,NULL,inifile); // Write Flush return 0; } int INILoadDocWnd(void) { char *section = SEC_DOCWND; char *inifile = TIMIDITY_WINDOW_INI_FILE; int num; char buffer[64]; num = GetPrivateProfileInt(section,"PosX",-1,inifile); DocWndInfo.PosX = num; num = GetPrivateProfileInt(section,"PosY",-1,inifile); DocWndInfo.PosY = num; num = GetPrivateProfileInt(section,"Width",-1,inifile); if(num!=-1) DocWndInfo.Width = num; num = GetPrivateProfileInt(section,"Height",-1,inifile); if(num!=-1) DocWndInfo.Height = num; GetPrivateProfileString(section,"fontNameEN","",buffer,32,inifile); if(buffer[0]!=0) strcpy(DocWndInfo.fontNameEN,buffer); GetPrivateProfileString(section,"fontNameJA","",buffer,32,inifile); if(buffer[0]!=0) strcpy(DocWndInfo.fontNameJA,buffer); num = GetPrivateProfileInt(section,"fontWidth",-1,inifile); if(num!=-1) DocWndInfo.fontWidth = num; num = GetPrivateProfileInt(section,"fontHeight",-1,inifile); if(num!=-1) DocWndInfo.fontHeight = num; num = GetPrivateProfileInt(section,"fontFlags",-1,inifile); if(num!=-1) DocWndInfo.fontFlags = num; return 0; } #define SEC_CONSOLEWND "ConsoleWnd" int INISaveConsoleWnd(void) { char *section = SEC_CONSOLEWND; char *inifile = TIMIDITY_WINDOW_INI_FILE; char buffer[256]; if ( PosSizeSave ) { if ( ConsoleWndInfo.PosX >= 0 || ConsoleWndInfo.PosY >= 0 ) { if ( ConsoleWndInfo.PosX < 0 ) ConsoleWndInfo.PosX = 0; if ( ConsoleWndInfo.PosY < 0 ) ConsoleWndInfo.PosY = 0; } sprintf(buffer,"%d",ConsoleWndInfo.PosX); if ( ConsoleWndInfo.PosX >= 0 ) WritePrivateProfileString(section,"PosX",buffer,inifile); sprintf(buffer,"%d",ConsoleWndInfo.PosY); if ( ConsoleWndInfo.PosY >= 0 ) WritePrivateProfileString(section,"PosY",buffer,inifile); } WritePrivateProfileString(NULL,NULL,NULL,inifile); // Write Flush return 0; } int INILoadConsoleWnd(void) { char *section = SEC_CONSOLEWND; char *inifile = TIMIDITY_WINDOW_INI_FILE; int num; num = GetPrivateProfileInt(section,"PosX",-1,inifile); ConsoleWndInfo.PosX = num; num = GetPrivateProfileInt(section,"PosY",-1,inifile); ConsoleWndInfo.PosY = num; return 0; } /**********************************************************************/ // プロセス間通信用にメールスロットのサーバースレッドを用意する #define TIMIDITY_MAILSLOT "\\\\.\\mailslot\\timiditypp_mailslot_ver_1_0" // メールスロットに渡される形式 // ヘッダ // コマンド名 // オプション数 // オプション1 // オプション2 // ... // ヘッダ #define MC_HEADER "TiMidity++Win32GUI Mailslot-1.0" // コマンド名 // TiMidity の終了 #define MC_TERMINATE "Terminate" // ファイルを指定 #define MC_FILES "Files Argc Argv" // オプション1 : ファイル名1 // ... // プレイリストのクリア #define MC_PLAYLIST_CLEAR "Playlist Clear" // 演奏開始 #define MC_PLAY "Play" // 次のファイルの演奏 #define MC_PLAY_NEXT "Play Next" // 前のファイルの演奏 #define MC_PLAY_PREV "Play Prev" // 演奏停止 #define MC_STOP "Stop" // 演奏一時停止 #define MC_PAUSE "Pause" // TiMidity の状態を指定メールスロットに送信 #define MC_SEND_TIMIDITY_INFO "Send TiMidity Info" // オプション1 : メールスロット名 // オプション2 : 状態1 // ... // 状態 // "PlayFileName:〜" : 演奏ファイル名 // "PlayTile:〜" : 演奏タイトル名 // "PlayStatus:〜" : 演奏状態(〜:PLAY,STOP,PAUSE) static HANDLE hMailslot = NULL; void w32gMailslotThread(void); int w32gStartMailslotThread(void) { DWORD dwThreadID; HANDLE hThread; hThread = (HANDLE)crt_beginthreadex(NULL,0,(LPTHREAD_START_ROUTINE)w32gMailslotThread,NULL,0,&dwThreadID); if((unsigned long)hThread==-1){ return FALSE; // Error! } return TRUE; } int ReadFromMailslot(HANDLE hmailslot, char *buffer, int *size) { DWORD dwMessageSize, dwMessageNum, dwMessageReadSize; BOOL bRes; int i; bRes = GetMailslotInfo(hmailslot,NULL,&dwMessageSize,&dwMessageNum,(LPDWORD)NULL); if(bRes==FALSE || dwMessageSize==MAILSLOT_NO_MESSAGE) return FALSE; for(i=0;i<10;i++){ bRes = ReadFile(hMailslot,buffer,dwMessageSize,&dwMessageReadSize,(LPOVERLAPPED)NULL); #ifdef W32GUI_DEBUG PrintfDebugWnd("[%s]\n",buffer); #endif if(bRes==TRUE){ break; } Sleep(300); } if(bRes==TRUE){ *size = (int)dwMessageSize; return TRUE; } else return FALSE; } // 無視する版 void ReadFromMailslotIgnore(HANDLE hmailslot, int num) { int i; char buffer[10240]; int size; for(i=0;i 0 ? argc-1 : 0, argv+1); return FALSE; } else { if(TryUniqTiMidity(20)==TRUE){ w32gStartMailslotThread(); return TRUE; } return FALSE; } case 2: if(ExistOldTiMidity()==TRUE){ for(i=0;i<=20;i++){ TerminateOldTiMidity(); if(UniqTiMidity()==TRUE){ w32gStartMailslotThread(); return TRUE; } Sleep(1000); } } else { if(TryUniqTiMidity(20)==TRUE){ w32gStartMailslotThread(); return TRUE; } } return FALSE; case 3: return FALSE; case 4: if(ExistOldTiMidity()==TRUE){ for(i=0;i<=20;i++){ TerminateOldTiMidity(); if(ExistOldTiMidity()==FALSE){ return FALSE; } Sleep(1000); } } return FALSE; case 5: return TRUE; default: return FALSE; } } // w32gSecondTiMidity() の後処理 int w32gSecondTiMidityExit(void) { MailslotThreadTeminateFlag = TRUE; Sleep(300); if(hMailslot!=NULL) CloseHandle(hMailslot); ReleaseMutex(hMutexTiMidity); CloseHandle(hMutexTiMidity); return 0; } // Before it call timidity_start_initialize() int isURLFile(char *filename) { if(strncasecmp(filename,"http://",7)==0 || strncasecmp(filename,"ftp://",6)==0 || strncasecmp(filename,"news://",7)==0 || strncasecmp(filename,"file:",5)==0 || strncasecmp(filename,"dir:",4)==0){ return TRUE; } else { return FALSE; } }