/*
	TiMidity++ -- MIDI to WAVE converter and player
	Copyright (C) 1999-2001 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., 675 Mass Ave, Cambridge, MA 02139, USA.

	w32g2_pref.c: Written by Daisuke Aoki <dai@y7.net>
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include <stddef.h>
#include <windows.h>
#undef RC_NONE
// #include <prsht.h>

#if defined(__CYGWIN32__) || defined(__MINGW32__)
#include <commdlg.h>
#else
#include <commctrl.h>
#endif /* __CYGWIN32__ */



#include <commctrl.h>
#ifndef NO_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
//#include <dir.h>
#ifdef AU_GOGO
#include <musenc.h>		/* for gogo */
#endif

#include "timidity.h"
#include "common.h"
#include "instrum.h"
#include "playmidi.h"
#include "readmidi.h"
#include "output.h"
#include "controls.h"
#include "tables.h"
#include "miditrace.h"
#include "reverb.h"
#ifdef SUPPORT_SOUNDSPEC
#include "soundspec.h"
#endif /* SUPPORT_SOUNDSPEC */
#include "recache.h"
#include "arc.h"
#include "strtab.h"
#include "wrd.h"
#include "mid.defs"

#include "w32g.h"
#include "w32g_res.h"
#include "w32g_utl.h"
#include "w32g_pref.h"
#ifdef AU_GOGO
#include "gogo_a.h"
#endif

/* TiMidity Win32GUI preference / PropertySheet */

extern void w32g_restart(void);
extern void set_gogo_opts_use_commandline_options(char *commandline);

extern void restore_voices(int save_voices);

volatile int PrefWndDoing = 0;

static volatile int PrefWndSetOK = 0;
static HPROPSHEETPAGE hPrefWnd;
static int CALLBACK PrefWndPropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam);
static BOOL APIENTRY PrefPlayerDialogProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam);
static BOOL APIENTRY PrefTiMidity1DialogProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam);
static BOOL APIENTRY PrefTiMidity2DialogProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam);
static BOOL APIENTRY PrefTiMidity3DialogProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam);
static BOOL APIENTRY PrefTiMidity4DialogProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam);
static int DlgOpenConfigFile(char *Filename, HWND hwnd);
static int DlgOpenOutputFile(char *Filename, HWND hwnd);

static int vorbisCofigDialog(void);
static int gogoCofigDialog(void);

//#if defined(__CYGWIN32__) || defined(__MINGW32__)
#if 0 /* New version of mingw */
//#define pszTemplate	u1.pszTemplate
//#define pszIcon		u2.pszIcon
#ifndef NONAMELESSUNION
#define NONAMELESSUNION
#endif
#ifndef DUMMYUNIONNAME
#define DUMMYUNIONNAME	u1
#endif
#ifndef DUMMYUNIONNAME2
#define DUMMYUNIONNAME2	u2
#endif
#ifndef DUMMYUNIONNAME3
#define DUMMYUNIONNAME3	u3
#endif
#endif

#define PREFWND_NPAGES 5
void PrefWndCreate(HWND hwnd)
{
	int res;
	PROPSHEETPAGE psp[PREFWND_NPAGES];
	PROPSHEETHEADER psh;

	VOLATILE_TOUCH(PrefWndDoing);
	if(PrefWndDoing)
		return;
	PrefWndDoing = 1;
	PrefWndSetOK = 1;
//	Player page.
	psp[0].dwSize = sizeof(PROPSHEETPAGE);
	psp[0].dwFlags = PSP_USETITLE;
	psp[0].hInstance = hInst;
#if defined (__cplusplus)
	psp[0].pszTemplate = MAKEINTRESOURCE(IDD_PREF_PLAYER);
	psp[0].pszIcon = NULL;
#else
#ifdef NONAMELESSUNION
	psp[0].DUMMYUNIONNAME.pszTemplate = MAKEINTRESOURCE(IDD_PREF_PLAYER);
	psp[0].DUMMYUNIONNAME2.pszIcon = NULL;
#else
	switch(PlayerLanguage) {	// 言語切替
		case LANGUAGE_JAPANESE:
			psp[0].pszTemplate = MAKEINTRESOURCE(IDD_PREF_PLAYER);
			break;
		default:
		case LANGUAGE_ENGLISH:
			psp[0].pszTemplate = MAKEINTRESOURCE(IDD_PREF_PLAYER_EN);
			break;
	}
	psp[0].pszIcon = NULL;
#endif
#endif
	psp[0].pfnDlgProc = PrefPlayerDialogProc;
	switch(PlayerLanguage) {	// 言語切替
		case LANGUAGE_JAPANESE:
			psp[0].pszTitle = (LPSTR)TEXT("プレイヤー");
			break;
		default:
		case LANGUAGE_ENGLISH:
			psp[0].pszTitle = (LPSTR)TEXT("Player");
			break;
	}
	psp[0].lParam = 0;
	psp[0].pfnCallback = NULL;

// TiMidity page1.
	psp[1].dwSize = sizeof(PROPSHEETPAGE);
	psp[1].dwFlags = PSP_USETITLE;
	psp[1].hInstance = hInst;
#if defined (__cplusplus)
	psp[1].pszTemplate = MAKEINTRESOURCE(IDD_PREF_TIMIDITY1);
	psp[1].pszIcon = NULL;
#else
#ifdef NONAMELESSUNION
	psp[1].DUMMYUNIONNAME.pszTemplate = MAKEINTRESOURCE(IDD_PREF_TIMIDITY1);
	psp[1].DUMMYUNIONNAME2.pszIcon = NULL;
#else
	switch(PlayerLanguage) {	// 言語切替
		case LANGUAGE_JAPANESE:
			psp[1].pszTemplate = MAKEINTRESOURCE(IDD_PREF_TIMIDITY1);
			break;
		default:
		case LANGUAGE_ENGLISH:
			psp[1].pszTemplate = MAKEINTRESOURCE(IDD_PREF_TIMIDITY1_EN);
			break;
	}
	psp[1].pszIcon = NULL;
#endif
#endif
	psp[1].pfnDlgProc = PrefTiMidity1DialogProc;
	switch(PlayerLanguage) {	// 言語切替
		case LANGUAGE_JAPANESE:
			psp[1].pszTitle = (LPSTR)TEXT("エフェクト");
			break;
		default:
		case LANGUAGE_ENGLISH:
			psp[1].pszTitle = (LPSTR)TEXT("Effect");
			break;
	}
	psp[1].lParam = 0;
	psp[1].pfnCallback = NULL;
// TiMidity page2.
	psp[2].dwSize = sizeof(PROPSHEETPAGE);
	psp[2].dwFlags = PSP_USETITLE;
	psp[2].hInstance = hInst;
#if defined (__cplusplus)
	psp[2].pszTemplate = MAKEINTRESOURCE(IDD_PREF_TIMIDITY2);
	psp[2].pszIcon = NULL;
#else
#ifdef NONAMELESSUNION
	psp[2].DUMMYUNIONNAME.pszTemplate = MAKEINTRESOURCE(IDD_PREF_TIMIDITY2);
	psp[2].DUMMYUNIONNAME2.pszIcon = NULL;
#else
	switch(PlayerLanguage) {	// 言語切替
		case LANGUAGE_JAPANESE:
			psp[2].pszTemplate = MAKEINTRESOURCE(IDD_PREF_TIMIDITY2);
			break;
		default:
		case LANGUAGE_ENGLISH:
			psp[2].pszTemplate = MAKEINTRESOURCE(IDD_PREF_TIMIDITY2_EN);
			break;
	}
	psp[2].pszIcon = NULL;
#endif
#endif
	psp[2].pfnDlgProc = PrefTiMidity2DialogProc;
	switch(PlayerLanguage) {	// 言語切替
		case LANGUAGE_JAPANESE:
			psp[2].pszTitle = (LPSTR)TEXT("その他");
			break;
		default:
		case LANGUAGE_ENGLISH:
			psp[2].pszTitle = (LPSTR)TEXT("Misc");
			break;
	}
	psp[2].lParam = 0;
	psp[2].pfnCallback = NULL;
// TiMidity page3.
	psp[3].dwSize = sizeof(PROPSHEETPAGE);
	psp[3].dwFlags = PSP_USETITLE;
	psp[3].hInstance = hInst;
#if defined (__cplusplus)
	psp[3].pszTemplate = MAKEINTRESOURCE(IDD_PREF_TIMIDITY3);
	psp[3].pszIcon = NULL;
#else
#ifdef NONAMELESSUNION
	psp[3].DUMMYUNIONNAME.pszTemplate = MAKEINTRESOURCE(IDD_PREF_TIMIDITY3);
	psp[3].DUMMYUNIONNAME2.pszIcon = NULL;
#else
	switch(PlayerLanguage) {	// 言語切替
		case LANGUAGE_JAPANESE:
			psp[3].pszTemplate = MAKEINTRESOURCE(IDD_PREF_TIMIDITY3);
			break;
		default:
		case LANGUAGE_ENGLISH:
			psp[3].pszTemplate = MAKEINTRESOURCE(IDD_PREF_TIMIDITY3_EN);
			break;
	}
	psp[3].pszIcon = NULL;
#endif
#endif
	psp[3].pfnDlgProc = PrefTiMidity3DialogProc;
	switch(PlayerLanguage) {	// 言語切替
		case LANGUAGE_JAPANESE:
			psp[3].pszTitle = (LPSTR)TEXT("出力");
			break;
		default:
		case LANGUAGE_ENGLISH:
			psp[3].pszTitle = (LPSTR)TEXT("Output");
			break;
	}
	psp[3].lParam = 0;
	psp[3].pfnCallback = NULL;
// TiMidity page4.
	psp[4].dwSize = sizeof(PROPSHEETPAGE);
	psp[4].dwFlags = PSP_USETITLE;
	psp[4].hInstance = hInst;
#if defined (__cplusplus)
	psp[4].pszTemplate = MAKEINTRESOURCE(IDD_PREF_TIMIDITY4);
	psp[4].pszIcon = NULL;
#else
#ifdef NONAMELESSUNION
	psp[4].DUMMYUNIONNAME.pszTemplate = MAKEINTRESOURCE(IDD_PREF_TIMIDITY4);
	psp[4].DUMMYUNIONNAME2.pszIcon = NULL;
#else
	switch(PlayerLanguage) {	// 言語切替
		case LANGUAGE_JAPANESE:
			psp[4].pszTemplate = MAKEINTRESOURCE(IDD_PREF_TIMIDITY4);
			break;
		default:
		case LANGUAGE_ENGLISH:
			psp[4].pszTemplate = MAKEINTRESOURCE(IDD_PREF_TIMIDITY4_EN);
			break;
	}
	psp[4].pszIcon = NULL;
#endif
#endif
	psp[4].pfnDlgProc = PrefTiMidity4DialogProc;
	switch(PlayerLanguage) {	// 言語切替
		case LANGUAGE_JAPANESE:
			psp[4].pszTitle = (LPSTR)TEXT("チャンネル");
			break;
		default:
		case LANGUAGE_ENGLISH:
			psp[4].pszTitle = (LPSTR)TEXT("Channel");
			break;
	}
	psp[4].lParam = 0;
	psp[4].pfnCallback = NULL;
// Propsheetheader
	psh.dwSize = sizeof(PROPSHEETHEADER);
//	  psh.dwFlags = PSH_USEHICON | PSH_PROPSHEETPAGE | PSH_USECALLBACK | PSH_NOAPPLYNOW;
	psh.dwFlags = PSH_USEHICON | PSH_PROPSHEETPAGE | PSH_USECALLBACK;
	psh.hwndParent = hwnd;
	psh.hInstance = hInst;
	switch(PlayerLanguage) {	// 言語切替
		case LANGUAGE_JAPANESE:
			psh.pszCaption = (LPSTR)TEXT("TiMidity++ Win32GUI - 詳細設定");
			break;
		default:
		case LANGUAGE_ENGLISH:
			psh.pszCaption = (LPSTR)TEXT("TiMidity++ Win32GUI - Preference");
			break;
	}
	psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
#if defined (__cplusplus)
	psh.nStartPage = 0;
	psh.ppsp = (LPCPROPSHEETPAGE)&psp;
#else
#ifdef NONAMELESSUNION
	psh.DUMMYUNIONNAME.hIcon = NULL;
	psh.DUMMYUNIONNAME2.nStartPage = 0;
	psh.DUMMYUNIONNAME3.ppsp = (LPCPROPSHEETPAGE)&psp;
#else
	psh.hIcon = NULL;
	psh.nStartPage = 0;
	psh.ppsp = (LPCPROPSHEETPAGE)&psp;
#endif
#endif
	psh.pfnCallback = PrefWndPropSheetProc;

	res = PropertySheet(&psh);

	PrefWndSetOK = 0;
	PrefWndDoing = 0;
	return;
}

static HFONT hFontPrefWnd = NULL;
#define PREFWND_XSIZE	240*3
#define PREFWND_YSIZE	180*4
static int CALLBACK PrefWndPropSheetProc(HWND hwnd, UINT uMsg, LPARAM lParam)
{
	if(uMsg==PSCB_INITIALIZED){
		PrefWndSetOK = 1;
		hPrefWnd = (HPROPSHEETPAGE)hwnd;
		PropSheet_Changed(hwnd,0);
		if(hFontPrefWnd==NULL){
			char FontLang[256];
			switch(PlayerLanguage){
			  case LANGUAGE_ENGLISH:
				strcpy(FontLang,"Times New Roman");
				break;
			  default:
			  case LANGUAGE_JAPANESE:
				strcpy(FontLang,"ＭＳ Ｐ明朝");
				break;
			}
			hFontPrefWnd = CreateFont(18,0,0,0,FW_DONTCARE,FALSE,FALSE,FALSE,
									  DEFAULT_CHARSET,
									  OUT_DEFAULT_PRECIS,
									  CLIP_DEFAULT_PRECIS,
									  DEFAULT_QUALITY,
									  DEFAULT_PITCH | FF_DONTCARE,FontLang);
		}
	}
	return 0;
}

#define DLG_CHECKBUTTON_TO_FLAG(hwnd,ctlid,x)	\
	((SendDlgItemMessage((hwnd),(ctlid),BM_GETCHECK,0,0))?((x)=1):((x)=0))
#define DLG_FLAG_TO_CHECKBUTTON(hwnd,ctlid,x)	\
	((x)?(SendDlgItemMessage((hwnd),(ctlid),BM_SETCHECK,1,0)):\
	(SendDlgItemMessage((hwnd),(ctlid),BM_SETCHECK,0,0)))


/*
	プロパティシート
	WM_NOTIFY の PSN_KILLACTIVE
		ページが非アクティブになる時
		カレントページでプロパティシートが OK or CLOSE される時
	WM_NOTIFY の PSN_SETACTIVE
		ページがアクティブになる時
	WM_NOTIFY の PSN_RESET
		キャンセルされたとき
		PrefWndSetOK = 0 とする
*/

/* st_temp, sp_temp を適用する
 * 注意: MainThread からの呼び出し禁止、危険！
 */
void PrefSettingApplyReally(void)
{
	int restart;
	extern int IniFileAutoSave;

	free_instruments(1);
	if(play_mode->fd != -1)
		play_mode->close_output();

	restart = (PlayerLanguage != sp_temp->PlayerLanguage);
	if(sp_temp->PlayerLanguage == LANGUAGE_JAPANESE)
		strcpy(st_temp->output_text_code, "SJIS");
	else
		strcpy(st_temp->output_text_code, "ASCII");
	ApplySettingPlayer(sp_temp);
	ApplySettingTiMidity(st_temp);
	SaveSettingPlayer(sp_current);
	SaveSettingTiMidity(st_current);
	memcpy(sp_temp, sp_current, sizeof(SETTING_PLAYER));
	memcpy(st_temp, st_current, sizeof(SETTING_TIMIDITY));
	restore_voices(1);
	PrefWndSetOK = 0;
	if(IniFileAutoSave)
		SaveIniFile(sp_current, st_current);
	if(restart &&
	   MessageBox(hListWnd,"Restart TiMidity?", "TiMidity",
				  MB_YESNO)==IDYES)
	{
		if(hFontPrefWnd)
		{
			DeleteObject(hFontPrefWnd);
			hFontPrefWnd = 0;
		}

		w32g_restart();
		PrefWndDoing = 0;
	}
}

static void PrefSettingApply(void)
{
	 w32g_send_rc(RC_EXT_APPLY_SETTING, 0);
}

static BOOL APIENTRY
PrefPlayerDialogProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam)
{
	switch (uMess){
   case WM_INITDIALOG:
//		SendMessage(hwnd,WM_SETFONT,(WPARAM)hFontPrefWnd,MAKELPARAM(TRUE,0));
		SendDlgItemMessage(hwnd,IDC_EDIT_CONFIG_FILE,
		WM_SETFONT,(WPARAM)hFontPrefWnd,MAKELPARAM(TRUE,0));
		break;
	case WM_COMMAND:
	switch (LOWORD(wParam)) {
		case IDC_BUTTON_CONFIG_FILE:
			{
				char filename[MAXPATH+1];
				filename[0] = '\0';
				SendDlgItemMessage(hwnd,IDC_EDIT_CONFIG_FILE,WM_GETTEXT,
					(WPARAM)MAX_PATH,(LPARAM)TEXT(filename));
				if(!DlgOpenConfigFile(filename,hwnd))
				if(filename[0]!='\0')
						SetDlgItemText(hwnd,IDC_EDIT_CONFIG_FILE,TEXT(filename));
	   }
			break;
		case IDC_RADIOBUTTON_JAPANESE:
		case IDC_RADIOBUTTON_ENGLISH:
			break;
		default:
		break;
	  }
		PrefWndSetOK = 1;
		PropSheet_Changed((HWND)hPrefWnd,hwnd);
		break;
	case WM_NOTIFY:
		switch (((NMHDR FAR *) lParam)->code){
		case PSN_KILLACTIVE:
		SendDlgItemMessage(hwnd,IDC_EDIT_CONFIG_FILE,WM_GETTEXT,
			(WPARAM)MAX_PATH,(LPARAM)TEXT(sp_temp->ConfigFile));
			if(SendDlgItemMessage(hwnd,IDC_RADIOBUTTON_ENGLISH,BM_GETCHECK,0,0)){
				sp_temp->PlayerLanguage = LANGUAGE_ENGLISH;
			} else if(SendDlgItemMessage(hwnd,IDC_RADIOBUTTON_JAPANESE,BM_GETCHECK,0,0)){
				sp_temp->PlayerLanguage = LANGUAGE_JAPANESE;
			}
		 {
		 int flag;

			SettingCtlFlag(st_temp, 'x',
								DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_AUTOQUIT,flag));
			SettingCtlFlag(st_temp, 'u',
								DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_AUTOUNIQ,flag));
			SettingCtlFlag(st_temp, 'R',
								DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_AUTOREFINE,flag));
			SettingCtlFlag(st_temp, 'a',
								DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_AUTOSTART,flag));
			SettingCtlFlag(st_temp, 'C',
								DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_NOT_CONTINUE,flag));
			SettingCtlFlag(st_temp, 'd',
								!DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_NOT_DRAG_START,flag));
			SettingCtlFlag(st_temp, 'l',
								!DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_NOT_LOOPING,flag));
			SettingCtlFlag(st_temp, 'r',
								DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_RANDOM,flag));
			}
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECK_SEACHDIRRECURSIVE,
				sp_temp->SeachDirRecursive);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECK_DOCWNDINDEPENDENT,
				sp_temp->DocWndIndependent);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECK_DOCWNDAUTOPOPUP,
				sp_temp->DocWndAutoPopup);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECK_INIFILE_AUTOSAVE,
				sp_temp->IniFileAutoSave);
			SetWindowLong(hwnd,DWL_MSGRESULT,FALSE);
			return TRUE;
		case PSN_RESET:
			PrefWndSetOK = 0;
			SetWindowLong(hwnd,	DWL_MSGRESULT, FALSE);
			break;
		case PSN_APPLY:
			PrefSettingApply();
			PropSheet_UnChanged((HWND)hPrefWnd,hwnd);
			break;
		case PSN_SETACTIVE:
			SetDlgItemText(hwnd,IDC_EDIT_CONFIG_FILE,TEXT(sp_temp->ConfigFile));
			switch(sp_temp->PlayerLanguage){
		 case LANGUAGE_ENGLISH:
				CheckRadioButton(hwnd,IDC_RADIOBUTTON_JAPANESE,IDC_RADIOBUTTON_ENGLISH,
				IDC_RADIOBUTTON_ENGLISH);
				break;
			default:
		 case LANGUAGE_JAPANESE:
				CheckRadioButton(hwnd,IDC_RADIOBUTTON_JAPANESE,IDC_RADIOBUTTON_ENGLISH,
				IDC_RADIOBUTTON_JAPANESE);
				break;
			}
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_AUTOQUIT,
									strchr(st_temp->opt_ctl + 1, 'x'));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_AUTOUNIQ,
									strchr(st_temp->opt_ctl + 1, 'u'));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_AUTOREFINE,
									strchr(st_temp->opt_ctl + 1, 'R'));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_AUTOSTART,
									strchr(st_temp->opt_ctl + 1, 'a'));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_NOT_CONTINUE,
									strchr(st_temp->opt_ctl + 1, 'C'));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_NOT_DRAG_START,
									!strchr(st_temp->opt_ctl + 1, 'd'));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_NOT_LOOPING,
									!strchr(st_temp->opt_ctl + 1, 'l'));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_RANDOM,
									strchr(st_temp->opt_ctl + 1, 'r'));

			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECK_SEACHDIRRECURSIVE,
									sp_temp->SeachDirRecursive);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECK_DOCWNDINDEPENDENT,
									sp_temp->DocWndIndependent);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECK_DOCWNDAUTOPOPUP,
									sp_temp->DocWndAutoPopup);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECK_INIFILE_AUTOSAVE,
									sp_temp->IniFileAutoSave);
			break;
		default:
			return FALSE;
		}
   case WM_SIZE:
		return FALSE;
	case WM_CLOSE:
		break;
	default:
	  break;
	}
	return FALSE;
}

static BOOL APIENTRY
PrefTiMidity1DialogProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam)
{
	switch (uMess){
	case WM_INITDIALOG:
		break;
	case WM_COMMAND:
	switch (LOWORD(wParam)) {
	  case IDCLOSE:
		break;
		case IDC_CHECKBOX_CHORUS:
		case IDC_CHECKBOX_CHORUS_LEVEL:
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_CHORUS,BM_GETCHECK,0,0)){
				EnableWindow(GetDlgItem(hwnd,IDC_CHECKBOX_CHORUS_LEVEL),TRUE);
				if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_CHORUS_LEVEL,BM_GETCHECK,0,0)){
					EnableWindow(GetDlgItem(hwnd,IDC_EDIT_CHORUS),TRUE);
			} else {
					EnableWindow(GetDlgItem(hwnd,IDC_EDIT_CHORUS),FALSE);
				}
			} else {
				EnableWindow(GetDlgItem(hwnd,IDC_CHECKBOX_CHORUS_LEVEL),FALSE);
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT_CHORUS),FALSE);
			}
			break;
		case IDC_CHECKBOX_REVERB:
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_REVERB,BM_GETCHECK,0,0)){
				EnableWindow(GetDlgItem(hwnd,IDC_CHECKBOX_GLOBAL_REVERB),TRUE);
				EnableWindow(GetDlgItem(hwnd,IDC_CHECKBOX_REVERB_LEVEL),TRUE);
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_REVERB_LEVEL,BM_GETCHECK,0,0)){
					EnableWindow(GetDlgItem(hwnd,IDC_EDIT_REVERB),TRUE);
			} else {
					EnableWindow(GetDlgItem(hwnd,IDC_EDIT_REVERB),FALSE);
				}
			} else {
				EnableWindow(GetDlgItem(hwnd,IDC_CHECKBOX_GLOBAL_REVERB),FALSE);
				EnableWindow(GetDlgItem(hwnd,IDC_CHECKBOX_REVERB_LEVEL),FALSE);
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT_REVERB),FALSE);
			}
			break;
		case IDC_CHECKBOX_GLOBAL_REVERB:
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_GLOBAL_REVERB,BM_GETCHECK,0,0)){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_REVERB_LEVEL,BM_SETCHECK,0,0);
			}
			SendMessage(hwnd,WM_COMMAND,IDC_CHECKBOX_REVERB,0);
			break;
		case IDC_CHECKBOX_REVERB_LEVEL:
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_REVERB_LEVEL,BM_GETCHECK,0,0)){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_GLOBAL_REVERB,BM_SETCHECK,0,0);
			}
			SendMessage(hwnd,WM_COMMAND,IDC_CHECKBOX_REVERB,0);
			break;
	 case IDC_CHECKBOX_DELAY:
		case IDC_RADIOBUTTON_DELAY_LEFT:
		case IDC_RADIOBUTTON_DELAY_RIGHT:
		case IDC_RADIOBUTTON_DELAY_CENTER:
			if(!SendDlgItemMessage(hwnd,IDC_RADIOBUTTON_DELAY_LEFT,BM_GETCHECK,0,0))
			if(!SendDlgItemMessage(hwnd,IDC_RADIOBUTTON_DELAY_RIGHT,BM_GETCHECK,0,0))
			if(!SendDlgItemMessage(hwnd,IDC_RADIOBUTTON_DELAY_CENTER,BM_GETCHECK,0,0))
				CheckRadioButton(hwnd,IDC_RADIOBUTTON_DELAY_LEFT,IDC_RADIOBUTTON_DELAY_CENTER,IDC_RADIOBUTTON_DELAY_CENTER);
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_DELAY,BM_GETCHECK,0,0)){
				EnableWindow(GetDlgItem(hwnd,IDC_RADIOBUTTON_DELAY_LEFT),TRUE);
				EnableWindow(GetDlgItem(hwnd,IDC_RADIOBUTTON_DELAY_RIGHT),TRUE);
				EnableWindow(GetDlgItem(hwnd,IDC_RADIOBUTTON_DELAY_CENTER),TRUE);
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT_DELAY),TRUE);
		 } else {
				EnableWindow(GetDlgItem(hwnd,IDC_RADIOBUTTON_DELAY_LEFT),FALSE);
				EnableWindow(GetDlgItem(hwnd,IDC_RADIOBUTTON_DELAY_RIGHT),FALSE);
				EnableWindow(GetDlgItem(hwnd,IDC_RADIOBUTTON_DELAY_CENTER),FALSE);
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT_DELAY),FALSE);
		 }
			break;
		default:
		PrefWndSetOK = 1;
		return FALSE;
		break;
	  }
		PrefWndSetOK = 1;
		PropSheet_Changed((HWND)hPrefWnd,hwnd);
		break;
	case WM_NOTIFY:
		switch (((NMHDR FAR *) lParam)->code){
		case PSN_KILLACTIVE:
			// CHORUS
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_CHORUS,BM_GETCHECK,0,0)){
				if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_CHORUS_LEVEL,BM_GETCHECK,0,0)){
					st_temp->opt_chorus_control = -(int)GetDlgItemInt(hwnd,IDC_EDIT_CHORUS,NULL,TRUE);
				} else {
					st_temp->opt_chorus_control = 1;
				}
			} else {
				st_temp->opt_chorus_control = 0;
			}
		 // REVERB
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_REVERB,BM_GETCHECK,0,0)){
				if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_GLOBAL_REVERB,BM_GETCHECK,0,0)){
					st_temp->opt_reverb_control = 2;
				} else if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_REVERB_LEVEL,BM_GETCHECK,0,0)){
					st_temp->opt_reverb_control = -(int)GetDlgItemInt(hwnd,IDC_EDIT_REVERB,NULL,TRUE);
				} else {
					st_temp->opt_reverb_control = 1;
				}
			} else {
				st_temp->opt_reverb_control = 0;
			}
		 // DELAY
			st_temp->effect_lr_delay_msec = GetDlgItemInt(hwnd,IDC_EDIT_DELAY,NULL,FALSE);
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_DELAY,BM_GETCHECK,0,0)){
				if(SendDlgItemMessage(hwnd,IDC_RADIOBUTTON_DELAY_LEFT,BM_GETCHECK,0,0)){
					st_temp->effect_lr_mode = 0;
				} else if(SendDlgItemMessage(hwnd,IDC_RADIOBUTTON_DELAY_RIGHT,BM_GETCHECK,0,0)){
					st_temp->effect_lr_mode = 1;
				} else {
					st_temp->effect_lr_mode = 2;
			}
			} else {
				st_temp->effect_lr_mode = -1;
		 }
			// NOISESHARPING
		 st_temp->noise_sharp_type = GetDlgItemInt(hwnd,IDC_EDIT_NOISESHARPING,NULL,FALSE);
		 st_temp->opt_env_attack = GetDlgItemInt(hwnd,IDC_EDIT_ENV_ATTACK,NULL,FALSE);
		 st_temp->opt_velocity_table = GetDlgItemInt(hwnd,IDC_EDIT_VELOCITYTABLE,NULL,FALSE);
			// Misc
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_MODWHEEL,st_temp->opt_modulation_wheel);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_PORTAMENTO,st_temp->opt_portamento);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_NRPNVIB,st_temp->opt_nrpn_vibrato);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_CHPRESS,st_temp->opt_channel_pressure);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_OVOICE,st_temp->opt_overlap_voice_allow);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_TRACETEXT,st_temp->opt_trace_text_meta_event);
		 st_temp->modify_release = GetDlgItemInt(hwnd,IDC_EDIT_MODIFY_RELEASE,NULL,FALSE);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_TVAA,st_temp->opt_tva_attack);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_TVAD,st_temp->opt_tva_decay);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_TVAR,st_temp->opt_tva_release);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_PDELAY,st_temp->opt_delay_control);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_RESONANCE,st_temp->opt_resonance);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_SRCHORUS,st_temp->opt_surround_chorus);
			SetWindowLong(hwnd,DWL_MSGRESULT,FALSE);
			return TRUE;
		case PSN_RESET:
			PrefWndSetOK = 0;
			SetWindowLong(hwnd,	DWL_MSGRESULT, FALSE);
			break;
		case PSN_APPLY:
			PrefSettingApply();
			break;
		case PSN_SETACTIVE:
			// CHORUS
			if(GetDlgItemInt(hwnd,IDC_EDIT_CHORUS,NULL,FALSE)==0)
				SetDlgItemInt(hwnd,IDC_EDIT_CHORUS,1,TRUE);
			if(st_temp->opt_chorus_control==0){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_CHORUS,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_CHORUS_LEVEL,BM_SETCHECK,0,0);
			} else if(st_temp->opt_chorus_control>0){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_CHORUS,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_CHORUS_LEVEL,BM_SETCHECK,0,0);
			} else {
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_CHORUS,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_CHORUS_LEVEL,BM_SETCHECK,1,0);
				SetDlgItemInt(hwnd,IDC_EDIT_CHORUS,-st_temp->opt_chorus_control,TRUE);
			}
			SendMessage(hwnd,WM_COMMAND,IDC_CHECKBOX_CHORUS,0);
			// REVERB
			if(GetDlgItemInt(hwnd,IDC_EDIT_REVERB,NULL,FALSE)==0)
				SetDlgItemInt(hwnd,IDC_EDIT_REVERB,1,TRUE);
			if(st_temp->opt_reverb_control==0){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_REVERB,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_GLOBAL_REVERB,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_REVERB_LEVEL,BM_SETCHECK,0,0);
			} else if(st_temp->opt_reverb_control==1){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_REVERB,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_GLOBAL_REVERB,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_REVERB_LEVEL,BM_SETCHECK,0,0);
			} else if(st_temp->opt_reverb_control>=2){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_REVERB,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_GLOBAL_REVERB,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_REVERB_LEVEL,BM_SETCHECK,0,0);
			} else {
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_REVERB,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_GLOBAL_REVERB,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_REVERB_LEVEL,BM_SETCHECK,1,0);
				SetDlgItemInt(hwnd,IDC_EDIT_REVERB,-st_temp->opt_reverb_control,TRUE);
		 }
			SendMessage(hwnd,WM_COMMAND,IDC_CHECKBOX_REVERB,0);
			// DELAY
			SetDlgItemInt(hwnd,IDC_EDIT_DELAY,st_temp->effect_lr_delay_msec,TRUE);
			if(st_temp->effect_lr_mode<0){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_DELAY,BM_SETCHECK,0,0);
			} else {
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_DELAY,BM_SETCHECK,1,0);
				switch(st_temp->effect_lr_mode){
			case 0:
					CheckRadioButton(hwnd,IDC_RADIOBUTTON_DELAY_LEFT,IDC_RADIOBUTTON_DELAY_CENTER,
				IDC_RADIOBUTTON_DELAY_LEFT);
					break;
				case 1:
					CheckRadioButton(hwnd,IDC_RADIOBUTTON_DELAY_LEFT,IDC_RADIOBUTTON_DELAY_CENTER,
				IDC_RADIOBUTTON_DELAY_RIGHT);
					break;
				case 2:
			default:
					CheckRadioButton(hwnd,IDC_RADIOBUTTON_DELAY_LEFT,IDC_RADIOBUTTON_DELAY_CENTER,
				IDC_RADIOBUTTON_DELAY_CENTER);
					break;
			 }
		 }
			SendMessage(hwnd,WM_COMMAND,IDC_CHECKBOX_DELAY,0);
			// NOISESHARPING
		 SetDlgItemInt(hwnd,IDC_EDIT_NOISESHARPING,st_temp->noise_sharp_type,TRUE);
		 SetDlgItemInt(hwnd,IDC_EDIT_ENV_ATTACK,st_temp->opt_env_attack,TRUE);
		 SetDlgItemInt(hwnd,IDC_EDIT_VELOCITYTABLE,st_temp->opt_velocity_table,TRUE);
			// Misc
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_MODWHEEL,st_temp->opt_modulation_wheel);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_PORTAMENTO,st_temp->opt_portamento);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_NRPNVIB,st_temp->opt_nrpn_vibrato);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CHPRESS,st_temp->opt_channel_pressure);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_OVOICE,st_temp->opt_overlap_voice_allow);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_TRACETEXT,st_temp->opt_trace_text_meta_event);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_TVAA,st_temp->opt_tva_attack);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_TVAD,st_temp->opt_tva_decay);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_TVAR,st_temp->opt_tva_release);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_PDELAY,st_temp->opt_delay_control);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_RESONANCE,st_temp->opt_resonance);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_SRCHORUS,st_temp->opt_surround_chorus);
			SetDlgItemInt(hwnd,IDC_EDIT_MODIFY_RELEASE,st_temp->modify_release,TRUE);
			break;
		default:
			return FALSE;
		}
		break;
   case WM_SIZE:
		return FALSE;
	case WM_CLOSE:
		break;
	default:
	  break;
	}
	return FALSE;
}

static int char_count(char *s, int c)
{
	 int n = 0;
	 while(*s)
		  n += (*s++ == c);
	 return n;
}

static BOOL APIENTRY
PrefTiMidity2DialogProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam)
{
	switch (uMess){
   case WM_INITDIALOG:
		break;
	case WM_COMMAND:
	switch (LOWORD(wParam)) {
	  case IDCLOSE:
		break;
		case IDC_CHECKBOX_SPECIAL_TONEBANK:
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_SPECIAL_TONEBANK,BM_GETCHECK,0,0)){
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT_SPECIAL_TONEBANK),TRUE);
			} else {
				EnableWindow(GetDlgItem(hwnd,IDC_EDIT_SPECIAL_TONEBANK),FALSE);
			}
		default:
		break;
	  }
		PrefWndSetOK = 1;
		PropSheet_Changed((HWND)hPrefWnd,hwnd);
		break;
	case WM_NOTIFY:
		switch (((NMHDR FAR *) lParam)->code){
		case PSN_KILLACTIVE: {
			int i;
			char *p;
			st_temp->voices = GetDlgItemInt(hwnd,IDC_EDIT_VOICES,NULL,FALSE);
			st_temp->amplification = GetDlgItemInt(hwnd,IDC_EDIT_AMPLIFICATION,NULL,FALSE);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_FREE_INST,st_temp->free_instruments_afterwards);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_ANTIALIAS,st_temp->antialiasing_allowed);
			DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_LOADINST_PLAYING,st_temp->opt_realtime_playing);
			st_temp->allocate_cache_size = GetDlgItemInt(hwnd,IDC_EDIT_CACHE_SIZE,NULL,FALSE);
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_REDUCE_VOICE,BM_GETCHECK,0,0))
			{
				st_temp->reduce_voice_threshold = -1;
				st_temp->auto_reduce_polyphony = 1;
			}
			else
			{
				st_temp->reduce_voice_threshold = 0;
				st_temp->auto_reduce_polyphony = 0;
			}

			st_temp->default_tonebank = GetDlgItemInt(hwnd,IDC_EDIT_DEFAULT_TONEBANK,NULL,FALSE);
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_SPECIAL_TONEBANK,BM_GETCHECK,0,0)){
				st_temp->special_tonebank = GetDlgItemInt(hwnd,IDC_EDIT_SPECIAL_TONEBANK,NULL,TRUE);
		 } else {
				st_temp->special_tonebank = -1;
		 }
			if(SendDlgItemMessage(hwnd,IDC_RADIOBUTTON_GS,BM_GETCHECK,0,0)){
			st_temp->opt_default_mid = 0x41;
			} else if(SendDlgItemMessage(hwnd,IDC_RADIOBUTTON_XG,BM_GETCHECK,0,0)){
			st_temp->opt_default_mid = 0x43;
		 } else
			st_temp->opt_default_mid = 0x7e;

			SettingCtlFlag(st_temp, 't',
								DLG_CHECKBUTTON_TO_FLAG(hwnd,IDC_CHECKBOX_CTL_TRACE_PLAYING,i));

			/* remove 'v' and 'q' from st_temp->opt_ctl */
			while(strchr(st_temp->opt_ctl + 1, 'v'))
				 SettingCtlFlag(st_temp, 'v', 0);
			while(strchr(st_temp->opt_ctl + 1, 'q'))
				 SettingCtlFlag(st_temp, 'q', 0);

			/* append 'v' or 'q' */
			p = st_temp->opt_ctl + strlen(st_temp->opt_ctl);
			i = GetDlgItemInt(hwnd,IDC_EDIT_CTL_VEBOSITY,NULL,TRUE);
			while(i > 1) { *p++ = 'v'; i--; }
			while(i < 1) { *p++ = 'q'; i++; }

			st_temp->control_ratio = GetDlgItemInt(hwnd,IDC_EDIT_CONTROL_RATIO,NULL,FALSE);
			SetWindowLong(hwnd,DWL_MSGRESULT,FALSE);
			}
			return TRUE;
		case PSN_RESET:
			PrefWndSetOK = 0;
			SetWindowLong(hwnd,	DWL_MSGRESULT, FALSE);
			break;
		case PSN_APPLY:
			PrefSettingApply();
			break;
		case PSN_SETACTIVE:
			SetDlgItemInt(hwnd,IDC_EDIT_VOICES,st_temp->voices,FALSE);
			SetDlgItemInt(hwnd,IDC_EDIT_AMPLIFICATION,st_temp->amplification,FALSE);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_FREE_INST,st_temp->free_instruments_afterwards);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_ANTIALIAS,st_temp->antialiasing_allowed);
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_LOADINST_PLAYING,st_temp->opt_realtime_playing);
			SetDlgItemInt(hwnd,IDC_EDIT_CACHE_SIZE,st_temp->allocate_cache_size,FALSE);

			SetDlgItemInt(hwnd,IDC_EDIT_REDUCE_VOICE,st_temp->reduce_voice_threshold,TRUE);
			SendDlgItemMessage(hwnd,IDC_CHECKBOX_REDUCE_VOICE,BM_SETCHECK,st_temp->reduce_voice_threshold,0);
			SetDlgItemInt(hwnd,IDC_EDIT_DEFAULT_TONEBANK,st_temp->default_tonebank,FALSE);
			SetDlgItemInt(hwnd,IDC_EDIT_SPECIAL_TONEBANK,st_temp->special_tonebank,TRUE);
			if(st_temp->special_tonebank<0){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_SPECIAL_TONEBANK,BM_SETCHECK,0,0);
			} else {
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_SPECIAL_TONEBANK,BM_SETCHECK,1,0);
			}
			SendMessage(hwnd,WM_COMMAND,IDC_CHECKBOX_SPECIAL_TONEBANK,0);
			switch(st_temp->opt_default_mid){
		 case 0x41:
				CheckRadioButton(hwnd,IDC_RADIOBUTTON_GM,IDC_RADIOBUTTON_XG,IDC_RADIOBUTTON_GS);
				break;
		 case 0x43:
				CheckRadioButton(hwnd,IDC_RADIOBUTTON_GM,IDC_RADIOBUTTON_XG,IDC_RADIOBUTTON_XG);
				break;
			default:
		 case 0x7e:
				CheckRadioButton(hwnd,IDC_RADIOBUTTON_GM,IDC_RADIOBUTTON_XG,IDC_RADIOBUTTON_GM);
				break;
			}

			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CTL_TRACE_PLAYING,
											strchr(st_temp->opt_ctl + 1, 't'));
			SetDlgItemInt(hwnd,IDC_EDIT_CTL_VEBOSITY,
							  char_count(st_temp->opt_ctl + 1, 'v') -
							  char_count(st_temp->opt_ctl + 1, 'q') + 1, TRUE);
			SetDlgItemInt(hwnd,IDC_EDIT_CONTROL_RATIO,st_temp->control_ratio,FALSE);
			break;
		default:
			return FALSE;
		}
		break;
   case WM_SIZE:
		return FALSE;
	case WM_CLOSE:
		break;
	default:
	  break;
	}
	return FALSE;
}


// IDC_COMBO_OUTPUT_MODE
static char *cb_info_IDC_COMBO_OUTPUT_MODE_jp[]= {
	"以下のファイルに出力",(char *)0,
#if defined(__CYGWIN32__) || defined(__MINGW32__)
	"ファイル名を自動で決定し、ソ\ースと同じフォルダに出力",(char *)1,
#else
	"ファイル名を自動で決定し、ソースと同じフォルダに出力",(char *)1,
#endif

	"ファイル名を自動で決定し、以下のフォルダに出力",(char *)2,
	"ファイル名を自動で決定し、以下のフォルダに出力(フォルダ名付き)",(char *)3,
	NULL
};
static char *cb_info_IDC_COMBO_OUTPUT_MODE_en[]= {
	"next output file",(char *)0,
	"auto filename",(char *)1,
	"auto filename and output in next dir",(char *)2,
	"auto filename and output in next dir",(char *)3,
	NULL
};
static char **cb_info_IDC_COMBO_OUTPUT_MODE;

static BOOL APIENTRY
PrefTiMidity3DialogProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam)
{
	switch (uMess){
   case WM_INITDIALOG:
		{
			int i;
			SendDlgItemMessage(hwnd,IDC_EDIT_OUTPUT_FILE,WM_SETFONT,(WPARAM)hFontPrefWnd,MAKELPARAM(TRUE,0));
			SendDlgItemMessage(hwnd,IDC_COMBO_OUTPUT,CB_RESETCONTENT,(WPARAM)0,(LPARAM)0);
			for(i=0;play_mode_list[i]!=0;i++){
				SendDlgItemMessage(hwnd,IDC_COMBO_OUTPUT,CB_INSERTSTRING,(WPARAM)-1,(LPARAM)play_mode_list[i]->id_name);
			}
			if (PlayerLanguage == LANGUAGE_JAPANESE)
			  cb_info_IDC_COMBO_OUTPUT_MODE = cb_info_IDC_COMBO_OUTPUT_MODE_jp;
			else
			  cb_info_IDC_COMBO_OUTPUT_MODE = cb_info_IDC_COMBO_OUTPUT_MODE_en;
			for(i=0;cb_info_IDC_COMBO_OUTPUT_MODE[i];i+=2){
				SendDlgItemMessage(hwnd,IDC_COMBO_OUTPUT_MODE,CB_INSERTSTRING,(WPARAM)-1,(LPARAM)cb_info_IDC_COMBO_OUTPUT_MODE[i]);
			}
			{
				int cb_num;
				for(cb_num=0;(int)cb_info_IDC_COMBO_OUTPUT_MODE[cb_num];cb_num+=2){
					SendDlgItemMessage(hwnd,IDC_COMBO_OUTPUT_MODE,CB_SETCURSEL,(WPARAM)0,(LPARAM)0);
					if(st_temp->auto_output_mode==(int)cb_info_IDC_COMBO_OUTPUT_MODE[cb_num+1]){
						SendDlgItemMessage(hwnd,IDC_COMBO_OUTPUT_MODE,CB_SETCURSEL,(WPARAM)cb_num/2,(LPARAM)0);
						break;
					}
				}
			}
		}
		break;
	case WM_COMMAND:
	switch (LOWORD(wParam)) {
	  case IDCLOSE:
		break;
		case IDC_BUTTON_OUTPUT_FILE:
			{
				char filename[MAXPATH+1];
				filename[0] = '\0';
				SendDlgItemMessage(hwnd,IDC_EDIT_OUTPUT_FILE,WM_GETTEXT,
					(WPARAM)MAX_PATH,(LPARAM)TEXT(filename));
				if(!DlgOpenOutputFile(filename,hwnd))
				if(filename[0]!='\0')
						SetDlgItemText(hwnd,IDC_EDIT_OUTPUT_FILE,TEXT(filename));
	   }
		break;
		case IDC_BUTTON_OUTPUT_FILE_DEL:
			{
			char filename[MAXPATH+1];
			DWORD res;
			if(st_temp->auto_output_mode>0){
				break;
			}
			GetDlgItemText(hwnd,IDC_EDIT_OUTPUT_FILE,filename,(WPARAM)MAX_PATH);
		 res = GetFileAttributes(filename);
		 if(res!=0xFFFFFFFF && !(res & FILE_ATTRIBUTE_DIRECTORY)){
				if(DeleteFile(filename)!=TRUE){
				char buffer[MAXPATH + 1024];
			   sprintf(buffer,"Can't delete file %s !",filename);
					MessageBox(NULL,buffer,"Error!", MB_OK);
				} else {
				char buffer[MAXPATH + 1024];
			   sprintf(buffer,"Delete file %s !",filename);
					MessageBox(NULL,buffer,"Delete!", MB_OK);
			}
			}
		 }
			break;
		case IDC_BUTTON_LOW:
			SetDlgItemInt(hwnd,IDC_EDIT_SAMPLE_RATE,11025,FALSE);
		break;
		case IDC_BUTTON_MIDDLE:
			SetDlgItemInt(hwnd,IDC_EDIT_SAMPLE_RATE,22050,FALSE);
		break;
		case IDC_BUTTON_HIGH:
			SetDlgItemInt(hwnd,IDC_EDIT_SAMPLE_RATE,44100,FALSE);
		break;
		case IDC_BUTTON_4:
			SetDlgItemInt(hwnd,IDC_EDIT_SAMPLE_RATE,4000,FALSE);
		break;
		case IDC_BUTTON_8:
			SetDlgItemInt(hwnd,IDC_EDIT_SAMPLE_RATE,8000,FALSE);
		break;
		case IDC_BUTTON_16:
			SetDlgItemInt(hwnd,IDC_EDIT_SAMPLE_RATE,16000,FALSE);
		break;
		case IDC_BUTTON_24:
			SetDlgItemInt(hwnd,IDC_EDIT_SAMPLE_RATE,24000,FALSE);
		break;
		case IDC_BUTTON_32:
			SetDlgItemInt(hwnd,IDC_EDIT_SAMPLE_RATE,32000,FALSE);
		break;
		case IDC_BUTTON_40:
			SetDlgItemInt(hwnd,IDC_EDIT_SAMPLE_RATE,40000,FALSE);
		break;
		case IDC_BUTTON_48:
			SetDlgItemInt(hwnd,IDC_EDIT_SAMPLE_RATE,48000,FALSE);
		break;
		case IDC_CHECKBOX_ULAW:
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_GETCHECK,0,0)){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_8BITS,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_16BITS,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_SIGNED,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_UNSIGNED,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_BYTESWAP,BM_SETCHECK,0,0);
		 } else {
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,1,0);
		 }
			break;
		case IDC_CHECKBOX_ALAW:
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_GETCHECK,0,0)){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_8BITS,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_16BITS,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_SIGNED,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_UNSIGNED,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_BYTESWAP,BM_SETCHECK,0,0);
		 } else {
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,1,0);
		 }
			break;
		case IDC_CHECKBOX_LINEAR:
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_GETCHECK,0,0)){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,1,0);
		 } else {
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,1,0);
		 }
			break;
		case IDC_CHECKBOX_8BITS:
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_8BITS,BM_GETCHECK,0,0)){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_8BITS,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_16BITS,BM_SETCHECK,0,0);
		 } else {
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_8BITS,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_16BITS,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,1,0);
		 }
			break;
		case IDC_CHECKBOX_16BITS:
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_16BITS,BM_GETCHECK,0,0)){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_8BITS,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_16BITS,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,1,0);
		 } else {
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_8BITS,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_16BITS,BM_SETCHECK,0,0);
		 }
			break;
		case IDC_CHECKBOX_SIGNED:
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_SIGNED,BM_GETCHECK,0,0)){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_SIGNED,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_UNSIGNED,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,1,0);
		 } else {
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_SIGNED,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_UNSIGNED,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,1,0);
		 }
			break;
		case IDC_CHECKBOX_UNSIGNED:
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_UNSIGNED,BM_GETCHECK,0,0)){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_SIGNED,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_UNSIGNED,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,1,0);
		 } else {
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_SIGNED,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_UNSIGNED,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,1,0);
		 }
			break;
		case IDC_CHECKBOX_BYTESWAP:
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_BYTESWAP,BM_GETCHECK,0,0)){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_BYTESWAP,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,1,0);
		 } else {
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_BYTESWAP,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,1,0);
		 }
			break;
		case IDC_RADIO_STEREO:
			if(SendDlgItemMessage(hwnd,IDC_RADIO_STEREO,BM_GETCHECK,0,0)){
				SendDlgItemMessage(hwnd,IDC_RADIO_STEREO,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_RADIO_MONO,BM_SETCHECK,0,0);
		 } else {
				SendDlgItemMessage(hwnd,IDC_RADIO_STEREO,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_RADIO_MONO,BM_SETCHECK,1,0);
		 }
			break;
		case IDC_RADIO_MONO:
			if(SendDlgItemMessage(hwnd,IDC_RADIO_MONO,BM_GETCHECK,0,0)){
				SendDlgItemMessage(hwnd,IDC_RADIO_STEREO,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_RADIO_MONO,BM_SETCHECK,1,0);
		 } else {
				SendDlgItemMessage(hwnd,IDC_RADIO_STEREO,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_RADIO_MONO,BM_SETCHECK,0,0);
		 }
			break;
		case IDC_BUTTON_OUTPUT_OPTIONS:
			{
				int num;
				num = SendDlgItemMessage(hwnd,IDC_COMBO_OUTPUT,CB_GETCURSEL,(WPARAM)0,(LPARAM)0);
				if(num>=0){
					st_temp->opt_playmode[0]=play_mode_list[num]->id_character;
				} else {
					st_temp->opt_playmode[0]='d';
				}
				if(st_temp->opt_playmode[0]=='v'){
					vorbisConfigDialog();
				} else if(st_temp->opt_playmode[0]=='g'){
					gogoConfigDialog();
				}
			}
			break;
		case IDC_COMBO_OUTPUT_MODE:
			{
				int cb_num1, cb_num2;
				cb_num1 = SendDlgItemMessage(hwnd,IDC_COMBO_OUTPUT_MODE,CB_GETCURSEL,(WPARAM)0,(LPARAM)0);
				if (PlayerLanguage == LANGUAGE_JAPANESE)
				  cb_info_IDC_COMBO_OUTPUT_MODE = cb_info_IDC_COMBO_OUTPUT_MODE_jp;
				else
				  cb_info_IDC_COMBO_OUTPUT_MODE = cb_info_IDC_COMBO_OUTPUT_MODE_en;
				for(cb_num2=0;(int)cb_info_IDC_COMBO_OUTPUT_MODE[cb_num2];cb_num2+=2){
					if(cb_num1*2==cb_num2){
						st_temp->auto_output_mode = (int)cb_info_IDC_COMBO_OUTPUT_MODE[cb_num2+1];
						break;
					}
				}
				if (PlayerLanguage == LANGUAGE_JAPANESE) {
				  if(st_temp->auto_output_mode>0){
				    SendDlgItemMessage(hwnd,IDC_BUTTON_OUTPUT_FILE,WM_SETTEXT,0,(LPARAM)"出力先");
				    SetDlgItemText(hwnd,IDC_EDIT_OUTPUT_FILE,st_temp->OutputDirName);
				  } else {
				    SendDlgItemMessage(hwnd,IDC_BUTTON_OUTPUT_FILE,WM_SETTEXT,0,(LPARAM)"出力ファイル");
				    SetDlgItemText(hwnd,IDC_EDIT_OUTPUT_FILE,st_temp->OutputName);
				  }
				} else {
				  if(st_temp->auto_output_mode>0){
				    SendDlgItemMessage(hwnd,IDC_BUTTON_OUTPUT_FILE,WM_SETTEXT,0,(LPARAM)"Output File");
				    SetDlgItemText(hwnd,IDC_EDIT_OUTPUT_FILE,st_temp->OutputDirName);
				  } else {
				    SendDlgItemMessage(hwnd,IDC_BUTTON_OUTPUT_FILE,WM_SETTEXT,0,(LPARAM)"Output File");
				    SetDlgItemText(hwnd,IDC_EDIT_OUTPUT_FILE,st_temp->OutputName);
				  }
				}
			}
			break;
		default:
		break;
	  }
		PrefWndSetOK = 1;
		PropSheet_Changed((HWND)hPrefWnd,hwnd);
		break;
	case WM_NOTIFY:
		switch (((NMHDR FAR *) lParam)->code){
		case PSN_KILLACTIVE: {
			int i = 0;
			int num;
			num = SendDlgItemMessage(hwnd,IDC_COMBO_OUTPUT,CB_GETCURSEL,(WPARAM)0,(LPARAM)0);
			if(num>=0){
				st_temp->opt_playmode[i]=play_mode_list[num]->id_character;
			} else {
				st_temp->opt_playmode[i]='d';
			}
			i++;
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_GETCHECK,0,0))
				st_temp->opt_playmode[i++] = 'U';
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_GETCHECK,0,0))
				st_temp->opt_playmode[i++] = 'A';
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_GETCHECK,0,0))
				st_temp->opt_playmode[i++] = 'l';
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_8BITS,BM_GETCHECK,0,0))
				st_temp->opt_playmode[i++] = '8';
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_16BITS,BM_GETCHECK,0,0))
				st_temp->opt_playmode[i++] = '1';
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_SIGNED,BM_GETCHECK,0,0))
				st_temp->opt_playmode[i++] = 's';
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_UNSIGNED,BM_GETCHECK,0,0))
				st_temp->opt_playmode[i++] = 'u';
			if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_BYTESWAP,BM_GETCHECK,0,0))
				st_temp->opt_playmode[i++] = 'x';
			if(SendDlgItemMessage(hwnd,IDC_RADIO_STEREO,BM_GETCHECK,0,0))
				st_temp->opt_playmode[i++] = 'S';
			if(SendDlgItemMessage(hwnd,IDC_RADIO_MONO,BM_GETCHECK,0,0))
				st_temp->opt_playmode[i++] = 'M';
			st_temp->opt_playmode[i] = '\0';
			st_temp->output_rate = GetDlgItemInt(hwnd,IDC_EDIT_SAMPLE_RATE,NULL,FALSE);
 			if(st_temp->auto_output_mode==0)
				GetDlgItemText(hwnd,IDC_EDIT_OUTPUT_FILE,st_temp->OutputName,(WPARAM)sizeof(st_temp->OutputName));
			else
				GetDlgItemText(hwnd,IDC_EDIT_OUTPUT_FILE,st_temp->OutputDirName,(WPARAM)sizeof(st_temp->OutputDirName));

			SetWindowLong(hwnd,DWL_MSGRESULT,FALSE);
			}
			return TRUE;
		case PSN_RESET:
			PrefWndSetOK = 0;
			SetWindowLong(hwnd,	DWL_MSGRESULT, FALSE);
			break;
		case PSN_APPLY:
			PrefSettingApply();
			break;
		case PSN_SETACTIVE: {
			char *opt;
			int num = 0;
			int i;
			for(i=0;play_mode_list[i]!=0;i++){
				if(st_temp->opt_playmode[0]==play_mode_list[i]->id_character){
					num = i;
				break;
			}
			}
			SendDlgItemMessage(hwnd,IDC_COMBO_OUTPUT,CB_SETCURSEL,(WPARAM)num,(LPARAM)0);
			if(st_temp->auto_output_mode==0){
			if(st_temp->OutputName[0]=='\0')
				SetDlgItemText(hwnd,IDC_EDIT_OUTPUT_FILE,TEXT("output.wav"));
			else
				SetDlgItemText(hwnd,IDC_EDIT_OUTPUT_FILE,TEXT(st_temp->OutputName));
			} else
				SetDlgItemText(hwnd,IDC_EDIT_OUTPUT_FILE,st_temp->OutputDirName);

			opt = st_temp->opt_playmode + 1;
			if(strchr(opt, 'U')){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,0,0);
		 } else if(strchr(opt, 'A')){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,0,0);
		 } else {
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ULAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_ALAW,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_LINEAR,BM_SETCHECK,1,0);
		 }
			if(strchr(opt, '1')){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_8BITS,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_16BITS,BM_SETCHECK,1,0);
			} else {
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_8BITS,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_16BITS,BM_SETCHECK,0,0);
		 }
			if(strchr(opt, 's')){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_SIGNED,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_UNSIGNED,BM_SETCHECK,0,0);
			} else {
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_SIGNED,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_UNSIGNED,BM_SETCHECK,1,0);
		 }
			if(strchr(opt, 'x')){
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_BYTESWAP,BM_SETCHECK,1,0);
			} else {
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_BYTESWAP,BM_SETCHECK,0,0);
		 }
			if(strchr(opt, 'M')){
				SendDlgItemMessage(hwnd,IDC_RADIO_STEREO,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_RADIO_MONO,BM_SETCHECK,1,0);
			} else {
				SendDlgItemMessage(hwnd,IDC_RADIO_STEREO,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_RADIO_MONO,BM_SETCHECK,0,0);
		 }
			SetDlgItemInt(hwnd,IDC_EDIT_SAMPLE_RATE,st_temp->output_rate,FALSE);
#if 0		// Buggy
			EnableWindow(GetDlgItem(hwnd,IDC_RADIOBUTTON_LIST_MIDI_EVENT),FALSE);
#endif
			break;
			}
		default:
			return FALSE;
		}
		break;
   case WM_SIZE:
		return FALSE;
	case WM_CLOSE:
		break;
	default:
	  break;
	}
	return FALSE;
}

#define PREF_CHANNEL_MODE_DRUM_CHANNEL		1
#define PREF_CHANNEL_MODE_DRUM_CHANNEL_MASK	2
#define PREF_CHANNEL_MODE_QUIET_CHANNEL		3
static BOOL APIENTRY
PrefTiMidity4DialogProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam)
{
	static int pref_channel_mode;
	switch (uMess){
   case WM_INITDIALOG:
		pref_channel_mode = PREF_CHANNEL_MODE_DRUM_CHANNEL;
		break;
	case WM_COMMAND:
	switch (LOWORD(wParam)) {
	  case IDCLOSE:
		break;
		case IDC_CHECKBOX_DRUM_CHANNEL:
			{
			NMHDR nmhdr;
		 nmhdr.code = PSN_KILLACTIVE;
			SendMessage(hwnd,WM_NOTIFY,0,(LPARAM)&nmhdr);
			pref_channel_mode = PREF_CHANNEL_MODE_DRUM_CHANNEL;
			SendDlgItemMessage(hwnd,IDC_CHECKBOX_DRUM_CHANNEL,BM_SETCHECK,1,0);
			SendDlgItemMessage(hwnd,IDC_CHECKBOX_DRUM_CHANNEL_MASK,BM_SETCHECK,0,0);
			SendDlgItemMessage(hwnd,IDC_CHECKBOX_QUIET_CHANNEL,BM_SETCHECK,0,0);
		 nmhdr.code = PSN_SETACTIVE;
			SendMessage(hwnd,WM_NOTIFY,0,(LPARAM)&nmhdr);
			}
		break;
		case IDC_CHECKBOX_DRUM_CHANNEL_MASK:
			{
			NMHDR nmhdr;
		 nmhdr.code = PSN_KILLACTIVE;
			SendMessage(hwnd,WM_NOTIFY,0,(LPARAM)&nmhdr);
			pref_channel_mode = PREF_CHANNEL_MODE_DRUM_CHANNEL_MASK;
			SendDlgItemMessage(hwnd,IDC_CHECKBOX_DRUM_CHANNEL,BM_SETCHECK,0,0);
			SendDlgItemMessage(hwnd,IDC_CHECKBOX_DRUM_CHANNEL_MASK,BM_SETCHECK,1,0);
			SendDlgItemMessage(hwnd,IDC_CHECKBOX_QUIET_CHANNEL,BM_SETCHECK,0,0);
		 nmhdr.code = PSN_SETACTIVE;
			SendMessage(hwnd,WM_NOTIFY,0,(LPARAM)&nmhdr);
			}
		break;
		case IDC_CHECKBOX_QUIET_CHANNEL:
			{
			NMHDR nmhdr;
		 nmhdr.code = PSN_KILLACTIVE;
			SendMessage(hwnd,WM_NOTIFY,0,(LPARAM)&nmhdr);
			pref_channel_mode = PREF_CHANNEL_MODE_QUIET_CHANNEL;
			SendDlgItemMessage(hwnd,IDC_CHECKBOX_DRUM_CHANNEL,BM_SETCHECK,0,0);
			SendDlgItemMessage(hwnd,IDC_CHECKBOX_DRUM_CHANNEL_MASK,BM_SETCHECK,0,0);
			SendDlgItemMessage(hwnd,IDC_CHECKBOX_QUIET_CHANNEL,BM_SETCHECK,1,0);
		 nmhdr.code = PSN_SETACTIVE;
			SendMessage(hwnd,WM_NOTIFY,0,(LPARAM)&nmhdr);
			}
		break;
		case IDC_BUTTON_REVERSE:
			{
			NMHDR nmhdr;
			nmhdr.code = PSN_KILLACTIVE;
			SendMessage(hwnd,WM_NOTIFY,0,(LPARAM)&nmhdr);
			switch(pref_channel_mode){
			case PREF_CHANNEL_MODE_DRUM_CHANNEL_MASK:
				st_temp->default_drumchannel_mask = ~st_temp->default_drumchannel_mask;
				break;
			case PREF_CHANNEL_MODE_QUIET_CHANNEL:
				st_temp->quietchannels = ~st_temp->quietchannels;
				break;
			default:
			case PREF_CHANNEL_MODE_DRUM_CHANNEL:
				st_temp->default_drumchannels = ~st_temp->default_drumchannels;
				break;
			}
			nmhdr.code = PSN_SETACTIVE;
			SendMessage(hwnd,WM_NOTIFY,0,(LPARAM)&nmhdr);
			}
			break;
		default:
		break;
	  }
		PrefWndSetOK = 1;
		PropSheet_Changed((HWND)hPrefWnd,hwnd);
		break;
	case WM_NOTIFY:
		switch (((NMHDR FAR *) lParam)->code){
		case PSN_KILLACTIVE:
			{
			ChannelBitMask channelbitmask;
			int tmp;
#define PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,ctlid,channelbitmask,ch,tmp) \
{	if(DLG_CHECKBUTTON_TO_FLAG((hwnd),(ctlid),(tmp))) SET_CHANNELMASK((channelbitmask),(ch)); \
	else UNSET_CHANNELMASK((channelbitmask),(ch)); }
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH01,channelbitmask,0,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH02,channelbitmask,1,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH03,channelbitmask,2,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH04,channelbitmask,3,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH05,channelbitmask,4,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH06,channelbitmask,5,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH07,channelbitmask,6,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH08,channelbitmask,7,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH09,channelbitmask,8,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH10,channelbitmask,9,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH11,channelbitmask,10,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH12,channelbitmask,11,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH13,channelbitmask,12,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH14,channelbitmask,13,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH15,channelbitmask,14,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH16,channelbitmask,15,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH17,channelbitmask,16,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH18,channelbitmask,17,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH19,channelbitmask,18,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH20,channelbitmask,19,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH21,channelbitmask,20,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH22,channelbitmask,21,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH23,channelbitmask,22,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH24,channelbitmask,23,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH25,channelbitmask,24,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH26,channelbitmask,25,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH27,channelbitmask,26,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH28,channelbitmask,27,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH29,channelbitmask,28,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH30,channelbitmask,29,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH31,channelbitmask,30,tmp);
			PREF_CHECKBUTTON_SET_CHANNELMASK(hwnd,IDC_CHECKBOX_CH32,channelbitmask,31,tmp);
			switch(pref_channel_mode){
			case PREF_CHANNEL_MODE_DRUM_CHANNEL_MASK:
				st_temp->default_drumchannel_mask = channelbitmask;
				break;
			case PREF_CHANNEL_MODE_QUIET_CHANNEL:
				st_temp->quietchannels = channelbitmask;
				break;
			default:
			case PREF_CHANNEL_MODE_DRUM_CHANNEL:
				st_temp->default_drumchannels = channelbitmask;
				break;
			}
			}
			SetWindowLong(hwnd,DWL_MSGRESULT,FALSE);
			return TRUE;
		case PSN_RESET:
			PrefWndSetOK = 0;
			SetWindowLong(hwnd,	DWL_MSGRESULT, FALSE);
			break;
		case PSN_APPLY:
			PrefSettingApply();
			break;
		case PSN_SETACTIVE:
			{
			ChannelBitMask channelbitmask;
			switch(pref_channel_mode){
			case PREF_CHANNEL_MODE_DRUM_CHANNEL_MASK:
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_DRUM_CHANNEL,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_DRUM_CHANNEL_MASK,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_QUIET_CHANNEL,BM_SETCHECK,0,0);
				channelbitmask = st_temp->default_drumchannel_mask;
				break;
			case PREF_CHANNEL_MODE_QUIET_CHANNEL:
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_DRUM_CHANNEL,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_DRUM_CHANNEL_MASK,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_QUIET_CHANNEL,BM_SETCHECK,1,0);
				channelbitmask = st_temp->quietchannels;
				break;
			default:
			case PREF_CHANNEL_MODE_DRUM_CHANNEL:
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_DRUM_CHANNEL,BM_SETCHECK,1,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_DRUM_CHANNEL_MASK,BM_SETCHECK,0,0);
				SendDlgItemMessage(hwnd,IDC_CHECKBOX_QUIET_CHANNEL,BM_SETCHECK,0,0);
				channelbitmask = st_temp->default_drumchannels;
				break;
			}
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH01,IS_SET_CHANNELMASK(channelbitmask,0));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH02,IS_SET_CHANNELMASK(channelbitmask,1));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH03,IS_SET_CHANNELMASK(channelbitmask,2));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH04,IS_SET_CHANNELMASK(channelbitmask,3));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH05,IS_SET_CHANNELMASK(channelbitmask,4));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH06,IS_SET_CHANNELMASK(channelbitmask,5));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH07,IS_SET_CHANNELMASK(channelbitmask,6));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH08,IS_SET_CHANNELMASK(channelbitmask,7));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH09,IS_SET_CHANNELMASK(channelbitmask,8));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH10,IS_SET_CHANNELMASK(channelbitmask,9));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH11,IS_SET_CHANNELMASK(channelbitmask,10));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH12,IS_SET_CHANNELMASK(channelbitmask,11));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH13,IS_SET_CHANNELMASK(channelbitmask,12));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH14,IS_SET_CHANNELMASK(channelbitmask,13));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH15,IS_SET_CHANNELMASK(channelbitmask,14));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH16,IS_SET_CHANNELMASK(channelbitmask,15));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH17,IS_SET_CHANNELMASK(channelbitmask,16));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH18,IS_SET_CHANNELMASK(channelbitmask,17));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH19,IS_SET_CHANNELMASK(channelbitmask,18));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH20,IS_SET_CHANNELMASK(channelbitmask,19));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH21,IS_SET_CHANNELMASK(channelbitmask,20));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH22,IS_SET_CHANNELMASK(channelbitmask,21));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH23,IS_SET_CHANNELMASK(channelbitmask,22));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH24,IS_SET_CHANNELMASK(channelbitmask,23));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH25,IS_SET_CHANNELMASK(channelbitmask,24));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH26,IS_SET_CHANNELMASK(channelbitmask,25));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH27,IS_SET_CHANNELMASK(channelbitmask,26));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH28,IS_SET_CHANNELMASK(channelbitmask,27));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH29,IS_SET_CHANNELMASK(channelbitmask,28));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH30,IS_SET_CHANNELMASK(channelbitmask,29));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH31,IS_SET_CHANNELMASK(channelbitmask,30));
			DLG_FLAG_TO_CHECKBUTTON(hwnd,IDC_CHECKBOX_CH32,IS_SET_CHANNELMASK(channelbitmask,31));
			}
		 break;
		default:
			return FALSE;
		}
		break;
   case WM_SIZE:
		return FALSE;
	case WM_CLOSE:
		break;
	default:
	  break;
	}
	return FALSE;
}

static int DlgOpenConfigFile(char *Filename, HWND hwnd)
{
	OPENFILENAME ofn;
   char filename[MAXPATH + 256];
   char dir[MAXPATH + 256];
   int res;

   strncpy(dir,ConfigFileOpenDir,MAXPATH);
   dir[MAXPATH-1] = '\0';
   strncpy(filename,Filename,MAXPATH);
   filename[MAXPATH-1] = '\0';

	memset(&ofn, 0, sizeof(OPENFILENAME));
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = hwnd;
	ofn.hInstance = hInst ;
	ofn.lpstrFilter =
		"config file\0*.cfg;*.config\0"
		"all files\0*.*\0"
		"\0\0";
	ofn.lpstrCustomFilter = NULL;
	ofn.nMaxCustFilter = 0;
	ofn.nFilterIndex = 1 ;
	ofn.lpstrFile = filename;
	ofn.nMaxFile = 256;
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = 0;
	if(dir[0] != '\0')
		ofn.lpstrInitialDir	= dir;
	else
		ofn.lpstrInitialDir	= 0;
	ofn.lpstrTitle	= "Open Config File";
	ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER
	| OFN_READONLY | OFN_HIDEREADONLY;
	ofn.lpstrDefExt = 0;
	ofn.lCustData = 0;
	ofn.lpfnHook = 0;
	ofn.lpTemplateName= 0;

	res = GetOpenFileName(&ofn);
   strncpy(ConfigFileOpenDir,dir,MAXPATH);
   ConfigFileOpenDir[MAXPATH-1] = '\0';
   if(res==TRUE){
	strncpy(Filename,filename,MAXPATH);
	Filename[MAXPATH-1] = '\0';
	return 0;
	}
   else {
	Filename[0] = '\0';
	return -1;
	}
}

static int DlgOpenOutputFile(char *Filename, HWND hwnd)
{
	OPENFILENAME ofn;
   char filename[MAXPATH + 256];
   char dir[MAXPATH + 256];
   int res;
	static char OutputFileOpenDir[MAXPATH+256];
   static int initflag = 1;

   if(initflag){
	OutputFileOpenDir[0] = '\0';
	  initflag = 0;
   }
   strncpy(dir,OutputFileOpenDir,MAXPATH);
   dir[MAXPATH-1] = '\0';
   strncpy(filename,Filename,MAXPATH);
   filename[MAXPATH-1] = '\0';

	memset(&ofn, 0, sizeof(OPENFILENAME));
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = hwnd;
	ofn.hInstance = hInst ;
	ofn.lpstrFilter =
		"wave file\0*.wav;*.wave;*.aif;*.aiff;*.aifc;*.au;*.snd;*.audio\0"
		"all files\0*.*\0"
		"\0\0";
	ofn.lpstrCustomFilter = NULL;
	ofn.nMaxCustFilter = 0;
	ofn.nFilterIndex = 1 ;
	ofn.lpstrFile = filename;
	ofn.nMaxFile = 256;
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = 0;
	if(dir[0] != '\0')
		ofn.lpstrInitialDir	= dir;
	else
		ofn.lpstrInitialDir	= 0;
	ofn.lpstrTitle	= "Output File";
	ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY;
	ofn.lpstrDefExt = 0;
	ofn.lCustData = 0;
	ofn.lpfnHook = 0;
	ofn.lpTemplateName= 0;

	res = GetSaveFileName(&ofn);
   strncpy(OutputFileOpenDir,dir,MAXPATH);
   OutputFileOpenDir[MAXPATH-1] = '\0';
   if(res==TRUE){
	strncpy(Filename,filename,MAXPATH);
	Filename[MAXPATH-1] = '\0';
	return 0;
	} else {
	Filename[0] = '\0';
	return -1;
	}
}

volatile int w32g_interactive_id3_tag_set = 0;
int w32g_gogo_id3_tag_dialog(void)
{
	return 0;
}


#ifdef AU_GOGO
///////////////////////////////////////////////////////////////////////
//
// gogo ConfigDialog
//
///////////////////////////////////////////////////////////////////////

// id のコンボボックスの情報の定義
#define CB_INFO_TYPE1_BEGIN(id) static int cb_info_ ## id [] = {
#define CB_INFO_TYPE1_END };
#define CB_INFO_TYPE2_BEGIN(id) static char * cb_info_ ## id [] = {
#define CB_INFO_TYPE2_END };

// cb_info_type1_ＩＤ  cb_info_type2_ＩＤ というふうになる。

// IDC_COMBO_OUTPUT_FORMAT
CB_INFO_TYPE2_BEGIN(IDC_COMBO_OUTPUT_FORMAT)
	"MP3+TAG",(char *)MC_OUTPUT_NORMAL,
	"RIFF/WAVE",(char *)MC_OUTPUT_RIFF_WAVE,
	"RIFF/RMP",(char *)MC_OUTPUT_RIFF_RMP,
	NULL
CB_INFO_TYPE2_END

// IDC_COMBO_MPEG1_AUDIO_BITRATE
CB_INFO_TYPE1_BEGIN(IDC_COMBO_MPEG1_AUDIO_BITRATE)
	32,40,48,56,64,80,96,112,128,160,192,224,256,320,-1
CB_INFO_TYPE1_END

// IDC_COMBO_MPEG2_AUDIO_BITRATE
CB_INFO_TYPE1_BEGIN(IDC_COMBO_MPEG2_AUDIO_BITRATE)
	8,16,24,32,40,48,56,64,80,96,112,128,144,160,-1
CB_INFO_TYPE1_END

// IDC_COMBO_ENCODE_MODE
CB_INFO_TYPE2_BEGIN(IDC_COMBO_ENCODE_MODE)
	"monoral",(char *)MC_MODE_MONO,
	"stereo",(char *)MC_MODE_STEREO,
	"joint stereo",(char *)MC_MODE_JOINT,
	"mid/side stereo",(char *)MC_MODE_MSSTEREO,
	"dual channel",(char *)MC_MODE_DUALCHANNEL,
	NULL
CB_INFO_TYPE2_END

// IDC_COMBO_EMPHASIS_TYPE
CB_INFO_TYPE2_BEGIN(IDC_COMBO_EMPHASIS_TYPE)
	"NONE",(char *)MC_EMP_NONE,
	"50/15ms (normal CD-DA emphasis)",(char *)MC_EMP_5015MS,
	"CCITT",(char *)MC_EMP_CCITT,
	NULL
CB_INFO_TYPE2_END

// IDC_COMBO_VBR_BITRATE_LOW
CB_INFO_TYPE1_BEGIN(IDC_COMBO_VBR_BITRATE_LOW)
	32,40,48,56,64,80,96,112,128,160,192,224,256,320,-1
CB_INFO_TYPE1_END

// IDC_COMBO_VBR_BITRATE_HIGH
CB_INFO_TYPE1_BEGIN(IDC_COMBO_VBR_BITRATE_HIGH)
	32,40,48,56,64,80,96,112,128,160,192,224,256,320,-1
CB_INFO_TYPE1_END

// IDC_COMBO_VBR
CB_INFO_TYPE2_BEGIN(IDC_COMBO_VBR)
	"Quality 0 (320 - 32 kbps)",(char *)0,
	"Quality 1 (256 - 32 kbps)",(char *)1,
	"Quality 2 (256 - 32 kbps)",(char *)2,
	"Quality 3 (256 - 32 kbps)",(char *)3,
	"Quality 4 (256 - 32 kbps)",(char *)4,
	"Quality 5 (224 - 32 kbps)",(char *)5,
	"Quality 6 (192 - 32 kbps)",(char *)6,
	"Quality 7 (160 - 32 kbps)",(char *)7,
	"Quality 8 (128 - 32 kbps)",(char *)8,
	"Quality 9 (128 - 32 kbps)",(char *)9,
	NULL
CB_INFO_TYPE2_END

// id のコンボボックスを選択の設定する。
#define CB_SETCURSEL_TYPE1(id) \
{ \
	int cb_num; \
	for(cb_num=0;(int)cb_info_ ## id [cb_num]>=0;cb_num++){ \
		SendDlgItemMessage(hwnd,id,CB_SETCURSEL,(WPARAM)0,(LPARAM)0); \
		if(gogo_ConfigDialogInfo.opt ## id == (int) cb_info_ ## id [cb_num]){ \
			SendDlgItemMessage(hwnd,id,CB_SETCURSEL,(WPARAM)cb_num,(LPARAM)0); \
			break; \
		} \
	} \
}
#define CB_SETCURSEL_TYPE2(id) \
{ \
	int cb_num; \
	for(cb_num=0;(int)cb_info_ ## id [cb_num];cb_num+=2){ \
		SendDlgItemMessage(hwnd,id,CB_SETCURSEL,(WPARAM)0,(LPARAM)0); \
	    if(gogo_ConfigDialogInfo.opt ## id == (int) cb_info_ ## id [cb_num+1]){ \
			SendDlgItemMessage(hwnd,id,CB_SETCURSEL,(WPARAM)cb_num/2,(LPARAM)0); \
			break; \
		} \
	} \
}
// id のコンボボックスの選択を変数に代入する。
#define CB_GETCURSEL_TYPE1(id) \
{ \
	int cb_num1, cb_num2; \
	cb_num1 = SendDlgItemMessage(hwnd,id,CB_GETCURSEL,(WPARAM)0,(LPARAM)0); \
	for(cb_num2=0;(int)cb_info_ ## id [cb_num2]>=0;cb_num2++) \
		if(cb_num1==cb_num2){ \
			gogo_ConfigDialogInfo.opt ## id = (int)cb_info_ ## id [cb_num2]; \
			break; \
		} \
}
#define CB_GETCURSEL_TYPE2(id) \
{ \
	int cb_num1, cb_num2; \
	cb_num1 = SendDlgItemMessage(hwnd,id,CB_GETCURSEL,(WPARAM)0,(LPARAM)0); \
	for(cb_num2=0;(int)cb_info_ ## id [cb_num2];cb_num2+=2) \
		if(cb_num1*2==cb_num2){ \
			gogo_ConfigDialogInfo.opt ## id = (int)cb_info_ ## id [cb_num2+1]; \
			break; \
		} \
}
// チェックされているか。
#define IS_CHECK(id) SendDlgItemMessage(hwnd,id,BM_GETCHECK,0,0)
// チェックする。
#define CHECK(id) SendDlgItemMessage(hwnd,id,BM_SETCHECK,1,0)
// チェックをはずす。
#define UNCHECK(id) SendDlgItemMessage(hwnd,id,BM_SETCHECK,0,0)
// id のチェックボックスを設定する。
#define CHECKBOX_SET(id) \
	if(gogo_ConfigDialogInfo.opt ## id>0) \
		SendDlgItemMessage(hwnd,id,BM_SETCHECK,1,0); \
	else \
		SendDlgItemMessage(hwnd,id,BM_SETCHECK,0,0); \
// id のチェックボックスを変数に代入する。
#define CHECKBOX_GET(id) \
	if(SendDlgItemMessage(hwnd,id,BM_GETCHECK,0,0)) \
		gogo_ConfigDialogInfo.opt ## id = 1; \
	else \
		gogo_ConfigDialogInfo.opt ## id = 0; \
// id のエディットを設定する。
#define EDIT_SET(id) SendDlgItemMessage(hwnd,id,WM_SETTEXT,0,(LPARAM)gogo_ConfigDialogInfo.opt ## id);
// id のエディットを変数に代入する。
#define EDIT_GET(id,size) SendDlgItemMessage(hwnd,id,WM_GETTEXT,(WPARAM)size,(LPARAM)gogo_ConfigDialogInfo.opt ## id);
#define EDIT_GET_RANGE(id,size,min,max) \
{ \
	char tmpbuf[64]; \
	int value; \
	SendDlgItemMessage(hwnd,id,WM_GETTEXT,(WPARAM)size,(LPARAM)gogo_ConfigDialogInfo.opt ## id); \
	value = atoi((char *)gogo_ConfigDialogInfo.opt ## id); \
	if(value<min) value = min; \
	if(value>max) value = max; \
	sprintf(tmpbuf,"%d",value); \
	strncpy((char *)gogo_ConfigDialogInfo.opt ## id,tmpbuf,size); \
	(gogo_ConfigDialogInfo.opt ## id)[size] = '\0'; \
}
// コントロールの有効化
#define ENABLE_CONTROL(id) EnableWindow(GetDlgItem(hwnd,id),TRUE);
// コントロールの無効化
#define DISABLE_CONTROL(id) EnableWindow(GetDlgItem(hwnd,id),FALSE);

static void gogoConfigDialogProcControlEnableDisable(HWND hwnd);
static void gogoConfigDialogProcControlApply(HWND hwnd);
static void gogoConfigDialogProcControlReset(HWND hwnd);
static int gogo_ConfigDialogInfoLock();
static int gogo_ConfigDialogInfoUnLock();
static HANDLE hgogoConfigDailog = NULL;
static BOOL APIENTRY gogoConfigDialogProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam)
{
	char buff[1024];
	switch (uMess){
	case WM_INITDIALOG:
	{
		int i;
		// コンボボックスの初期化
		for(i=0;cb_info_IDC_COMBO_OUTPUT_FORMAT[i];i+=2){
			SendDlgItemMessage(hwnd,IDC_COMBO_OUTPUT_FORMAT,CB_INSERTSTRING,(WPARAM)-1,(LPARAM)cb_info_IDC_COMBO_OUTPUT_FORMAT[i]);
		}
		for(i=0;cb_info_IDC_COMBO_MPEG1_AUDIO_BITRATE[i]>=0;i++){
			sprintf(buff,"%d kbit/sec",cb_info_IDC_COMBO_MPEG1_AUDIO_BITRATE[i]);
			SendDlgItemMessage(hwnd,IDC_COMBO_MPEG1_AUDIO_BITRATE,CB_INSERTSTRING,(WPARAM)-1,(LPARAM)buff);
		}
		for(i=0;cb_info_IDC_COMBO_MPEG2_AUDIO_BITRATE[i]>=0;i++){
			sprintf(buff,"%d kbit/sec",cb_info_IDC_COMBO_MPEG2_AUDIO_BITRATE[i]);
			SendDlgItemMessage(hwnd,IDC_COMBO_MPEG2_AUDIO_BITRATE,CB_INSERTSTRING,(WPARAM)-1,(LPARAM)buff);
		}
		for(i=0;cb_info_IDC_COMBO_ENCODE_MODE[i];i+=2){
			SendDlgItemMessage(hwnd,IDC_COMBO_ENCODE_MODE,CB_INSERTSTRING,(WPARAM)-1,(LPARAM)cb_info_IDC_COMBO_ENCODE_MODE[i]);
		}
		for(i=0;cb_info_IDC_COMBO_EMPHASIS_TYPE[i];i+=2){
			SendDlgItemMessage(hwnd,IDC_COMBO_EMPHASIS_TYPE,CB_INSERTSTRING,(WPARAM)-1,(LPARAM)cb_info_IDC_COMBO_EMPHASIS_TYPE[i]);
		}
		for(i=0;cb_info_IDC_COMBO_VBR_BITRATE_LOW[i]>=0;i++){
			sprintf(buff,"%d kbit/sec",cb_info_IDC_COMBO_VBR_BITRATE_LOW[i]);
			SendDlgItemMessage(hwnd,IDC_COMBO_VBR_BITRATE_LOW,CB_INSERTSTRING,(WPARAM)-1,(LPARAM)buff);
		}
		for(i=0;cb_info_IDC_COMBO_VBR_BITRATE_HIGH[i]>=0;i++){
			sprintf(buff,"%d kbit/sec",cb_info_IDC_COMBO_VBR_BITRATE_HIGH[i]);
			SendDlgItemMessage(hwnd,IDC_COMBO_VBR_BITRATE_HIGH,CB_INSERTSTRING,(WPARAM)-1,(LPARAM)buff);
		}
		for(i=0;cb_info_IDC_COMBO_VBR[i];i+=2){
			SendDlgItemMessage(hwnd,IDC_COMBO_VBR,CB_INSERTSTRING,(WPARAM)-1,(LPARAM)cb_info_IDC_COMBO_VBR[i]);
		}
		// 設定
		gogoConfigDialogProcControlReset(hwnd);
	}
		break;
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDCLOSE:
			SendMessage(hwnd,WM_CLOSE,(WPARAM)0,(LPARAM)0);
			break;
		case IDOK:
			gogoConfigDialogProcControlApply(hwnd);
			SendMessage(hwnd,WM_CLOSE,(WPARAM)0,(LPARAM)0);
			break;
		case IDCANCEL:
			SendMessage(hwnd,WM_CLOSE,(WPARAM)0,(LPARAM)0);
			break;
		case IDC_BUTTON_APPLY:
			gogoConfigDialogProcControlApply(hwnd);
			break;
		case IDC_CHECK_DEFAULT:
			gogoConfigDialogProcControlEnableDisable(hwnd);
			break;
		case IDC_CHECK_COMMANDLINE_OPTS:
			gogoConfigDialogProcControlEnableDisable(hwnd);
			break;
		case IDC_EDIT_COMMANDLINE_OPTION:
			break;
		case IDC_CHECK_OUTPUT_FORMAT:
			gogoConfigDialogProcControlEnableDisable(hwnd);
			break;
		case IDC_COMBO_OUTPUT_FORMAT:
			break;
		case IDC_CHECK_MPEG1AUDIOBITRATE:
			if(IS_CHECK(IDC_CHECK_MPEG1AUDIOBITRATE)){
				CHECK(IDC_CHECK_MPEG2AUDIOBITRATE);
				UNCHECK(IDC_CHECK_VBR);
				UNCHECK(IDC_CHECK_VBR_BITRATE);
			} else {
				UNCHECK(IDC_CHECK_MPEG2AUDIOBITRATE);
			}
			gogoConfigDialogProcControlEnableDisable(hwnd);
			break;
		case IDC_COMBO_MPEG1_AUDIO_BITRATE:
			break;
		case IDC_CHECK_MPEG2AUDIOBITRATE:
			if(IS_CHECK(IDC_CHECK_MPEG2AUDIOBITRATE)){
				CHECK(IDC_CHECK_MPEG1AUDIOBITRATE);
				UNCHECK(IDC_CHECK_VBR);
				UNCHECK(IDC_CHECK_VBR_BITRATE);
			} else {
				UNCHECK(IDC_CHECK_MPEG1AUDIOBITRATE);
			}
			gogoConfigDialogProcControlEnableDisable(hwnd);
			break;
		case IDC_COMBO_MPEG2_AUDIO_BITRATE:
			break;
		case IDC_CHECK_ENHANCED_LOW_PASS_FILTER:
			if(IS_CHECK(IDC_CHECK_ENHANCED_LOW_PASS_FILTER)){
				UNCHECK(IDC_CHECK_16KHZ_LOW_PASS_FILTER);
			}
			gogoConfigDialogProcControlEnableDisable(hwnd);
			break;
		case IDC_EDIT_LPF_PARA1:
			break;
		case IDC_EDIT_LPF_PARA2:
			break;
		case IDC_CHECK_ENCODE_MODE:
			gogoConfigDialogProcControlEnableDisable(hwnd);
			break;
		case IDC_COMBO_ENCODE_MODE:
			break;
		case IDC_CHECK_EMPHASIS_TYPE:
			gogoConfigDialogProcControlEnableDisable(hwnd);
			break;
		case IDC_COMBO_EMPHASIS_TYPE:
			break;
		case IDC_CHECK_OUTFREQ:
			gogoConfigDialogProcControlEnableDisable(hwnd);
			break;
		case IDC_EDIT_OUTFREQ:
			break;
		case IDC_CHECK_MSTHRESHOLD:
			gogoConfigDialogProcControlEnableDisable(hwnd);
			break;
		case IDC_EDIT_MSTHRESHOLD_THRESHOLD:
			break;
		case IDC_EDIT_MSTHRESHOLD_MSPOWER:
			break;
		case IDC_CHECK_USE_CPU_OPTS:
			gogoConfigDialogProcControlEnableDisable(hwnd);
			break;
		case IDC_CHECK_CPUMMX:
			break;
		case IDC_CHECK_CPUSSE:
			break;
		case IDC_CHECK_CPU3DNOW:
			break;
		case IDC_CHECK_CPUE3DNOW:
			break;
		case IDC_CHECK_VBR:
			if(IS_CHECK(IDC_CHECK_VBR)){
				UNCHECK(IDC_COMBO_MPEG1_AUDIO_BITRATE);
				UNCHECK(IDC_COMBO_MPEG2_AUDIO_BITRATE);
			}
			gogoConfigDialogProcControlEnableDisable(hwnd);
			break;
		case IDC_COMBO_VBR:
			break;
		case IDC_CHECK_VBR_BITRATE:
			if(IS_CHECK(IDC_CHECK_VBR_BITRATE)){
				CHECK(IDC_CHECK_VBR);
				UNCHECK(IDC_COMBO_MPEG1_AUDIO_BITRATE);
				UNCHECK(IDC_COMBO_MPEG2_AUDIO_BITRATE);
			}
			gogoConfigDialogProcControlEnableDisable(hwnd);
			break;
		case IDC_COMBO_VBR_BITRATE_LOW:
			break;
		case IDC_COMBO_VBR_BITRATE_HIGH:
			break;
		case IDC_CHECK_USEPSY:
			break;
		case IDC_CHECK_VERIFY:
			break;
		case IDC_CHECK_16KHZ_LOW_PASS_FILTER:
			if(IS_CHECK(IDC_CHECK_16KHZ_LOW_PASS_FILTER)){
				UNCHECK(IDC_CHECK_ENHANCED_LOW_PASS_FILTER);
			}
			gogoConfigDialogProcControlEnableDisable(hwnd);
			break;
		default:
			break;
		}
		break;
	case WM_NOTIFY:
		break;
	case WM_SIZE:
		return FALSE;
	case WM_CLOSE:
		gogo_ConfigDialogInfoSaveINI();
//MessageBox(NULL,"CLOSE","CLOSE",MB_OK);
		DestroyWindow(hwnd);
		break;
	case WM_DESTROY:
		hgogoConfigDailog = NULL;
//MessageBox(NULL,"DESTROY","DESTROY",MB_OK);
		break;
	default:
		break;
	}
	return FALSE;
}

// コントロールの有効 / 無効化
static void gogoConfigDialogProcControlEnableDisable(HWND hwnd)
{
	ENABLE_CONTROL(IDC_CHECK_DEFAULT);
	if(IS_CHECK(IDC_CHECK_DEFAULT)){
		DISABLE_CONTROL(IDC_CHECK_COMMANDLINE_OPTS);
		DISABLE_CONTROL(IDC_EDIT_COMMANDLINE_OPTION);
		DISABLE_CONTROL(IDC_CHECK_OUTPUT_FORMAT);
		DISABLE_CONTROL(IDC_COMBO_OUTPUT_FORMAT);
		DISABLE_CONTROL(IDC_CHECK_MPEG1AUDIOBITRATE);
		DISABLE_CONTROL(IDC_COMBO_MPEG1_AUDIO_BITRATE);
		DISABLE_CONTROL(IDC_CHECK_MPEG2AUDIOBITRATE);
		DISABLE_CONTROL(IDC_COMBO_MPEG2_AUDIO_BITRATE);
		DISABLE_CONTROL(IDC_CHECK_ENHANCED_LOW_PASS_FILTER);
		DISABLE_CONTROL(IDC_EDIT_LPF_PARA1);
		DISABLE_CONTROL(IDC_EDIT_LPF_PARA2);
		DISABLE_CONTROL(IDC_CHECK_ENCODE_MODE);
		DISABLE_CONTROL(IDC_COMBO_ENCODE_MODE);
		DISABLE_CONTROL(IDC_CHECK_EMPHASIS_TYPE);
		DISABLE_CONTROL(IDC_COMBO_EMPHASIS_TYPE);
		DISABLE_CONTROL(IDC_CHECK_OUTFREQ);
		DISABLE_CONTROL(IDC_EDIT_OUTFREQ);
		DISABLE_CONTROL(IDC_CHECK_MSTHRESHOLD);
		DISABLE_CONTROL(IDC_EDIT_MSTHRESHOLD_THRESHOLD);
		DISABLE_CONTROL(IDC_EDIT_MSTHRESHOLD_MSPOWER);
		DISABLE_CONTROL(IDC_CHECK_USE_CPU_OPTS);
		DISABLE_CONTROL(IDC_CHECK_CPUMMX);
		DISABLE_CONTROL(IDC_CHECK_CPUSSE);
		DISABLE_CONTROL(IDC_CHECK_CPU3DNOW);
		DISABLE_CONTROL(IDC_CHECK_CPUE3DNOW);
		DISABLE_CONTROL(IDC_CHECK_VBR);
		DISABLE_CONTROL(IDC_COMBO_VBR);
		DISABLE_CONTROL(IDC_CHECK_VBR_BITRATE);
		DISABLE_CONTROL(IDC_COMBO_VBR_BITRATE_LOW);
		DISABLE_CONTROL(IDC_COMBO_VBR_BITRATE_HIGH);
		DISABLE_CONTROL(IDC_CHECK_USEPSY);
		DISABLE_CONTROL(IDC_CHECK_VERIFY);
		DISABLE_CONTROL(IDC_CHECK_16KHZ_LOW_PASS_FILTER);
	} else {
		ENABLE_CONTROL(IDC_CHECK_COMMANDLINE_OPTS);
		if(IS_CHECK(IDC_CHECK_COMMANDLINE_OPTS)){
			ENABLE_CONTROL(IDC_EDIT_COMMANDLINE_OPTION);
			DISABLE_CONTROL(IDC_CHECK_OUTPUT_FORMAT);
			DISABLE_CONTROL(IDC_COMBO_OUTPUT_FORMAT);
			DISABLE_CONTROL(IDC_CHECK_MPEG1AUDIOBITRATE);
			DISABLE_CONTROL(IDC_COMBO_MPEG1_AUDIO_BITRATE);
			DISABLE_CONTROL(IDC_CHECK_MPEG2AUDIOBITRATE);
			DISABLE_CONTROL(IDC_COMBO_MPEG2_AUDIO_BITRATE);
			DISABLE_CONTROL(IDC_CHECK_ENHANCED_LOW_PASS_FILTER);
			DISABLE_CONTROL(IDC_EDIT_LPF_PARA1);
			DISABLE_CONTROL(IDC_EDIT_LPF_PARA2);
			DISABLE_CONTROL(IDC_CHECK_ENCODE_MODE);
			DISABLE_CONTROL(IDC_COMBO_ENCODE_MODE);
			DISABLE_CONTROL(IDC_CHECK_EMPHASIS_TYPE);
			DISABLE_CONTROL(IDC_COMBO_EMPHASIS_TYPE);
			DISABLE_CONTROL(IDC_CHECK_OUTFREQ);
			DISABLE_CONTROL(IDC_EDIT_OUTFREQ);
			DISABLE_CONTROL(IDC_CHECK_MSTHRESHOLD);
			DISABLE_CONTROL(IDC_EDIT_MSTHRESHOLD_THRESHOLD);
			DISABLE_CONTROL(IDC_EDIT_MSTHRESHOLD_MSPOWER);
			DISABLE_CONTROL(IDC_CHECK_USE_CPU_OPTS);
			DISABLE_CONTROL(IDC_CHECK_CPUMMX);
			DISABLE_CONTROL(IDC_CHECK_CPUSSE);
			DISABLE_CONTROL(IDC_CHECK_CPU3DNOW);
			DISABLE_CONTROL(IDC_CHECK_CPUE3DNOW);
			DISABLE_CONTROL(IDC_CHECK_VBR);
			DISABLE_CONTROL(IDC_COMBO_VBR);
			DISABLE_CONTROL(IDC_CHECK_VBR_BITRATE);
			DISABLE_CONTROL(IDC_COMBO_VBR_BITRATE_LOW);
			DISABLE_CONTROL(IDC_COMBO_VBR_BITRATE_HIGH);
			DISABLE_CONTROL(IDC_CHECK_USEPSY);
			DISABLE_CONTROL(IDC_CHECK_VERIFY);
			DISABLE_CONTROL(IDC_CHECK_16KHZ_LOW_PASS_FILTER);
		} else {
			DISABLE_CONTROL(IDC_EDIT_COMMANDLINE_OPTION);
			ENABLE_CONTROL(IDC_CHECK_OUTPUT_FORMAT);
			if(IS_CHECK(IDC_CHECK_OUTPUT_FORMAT)){
				ENABLE_CONTROL(IDC_COMBO_OUTPUT_FORMAT);
			} else {
				DISABLE_CONTROL(IDC_COMBO_OUTPUT_FORMAT);
			}
			ENABLE_CONTROL(IDC_CHECK_16KHZ_LOW_PASS_FILTER);
			ENABLE_CONTROL(IDC_CHECK_ENHANCED_LOW_PASS_FILTER);
			if(IS_CHECK(IDC_CHECK_16KHZ_LOW_PASS_FILTER)){
				UNCHECK(IDC_CHECK_ENHANCED_LOW_PASS_FILTER);
				DISABLE_CONTROL(IDC_EDIT_LPF_PARA1);
				DISABLE_CONTROL(IDC_EDIT_LPF_PARA2);
			} else {
				if(IS_CHECK(IDC_CHECK_ENHANCED_LOW_PASS_FILTER)){
					UNCHECK(IDC_CHECK_16KHZ_LOW_PASS_FILTER);
					ENABLE_CONTROL(IDC_EDIT_LPF_PARA1);
					ENABLE_CONTROL(IDC_EDIT_LPF_PARA2);
				} else {
					DISABLE_CONTROL(IDC_EDIT_LPF_PARA1);
					DISABLE_CONTROL(IDC_EDIT_LPF_PARA2);
				}
			}
			ENABLE_CONTROL(IDC_CHECK_ENCODE_MODE);
			if(IS_CHECK(IDC_CHECK_ENCODE_MODE)){
				ENABLE_CONTROL(IDC_COMBO_ENCODE_MODE);
			} else {
				DISABLE_CONTROL(IDC_COMBO_ENCODE_MODE);
			}
			ENABLE_CONTROL(IDC_CHECK_EMPHASIS_TYPE);
			if(IS_CHECK(IDC_CHECK_EMPHASIS_TYPE)){
				ENABLE_CONTROL(IDC_COMBO_EMPHASIS_TYPE);
			} else {
				DISABLE_CONTROL(IDC_COMBO_EMPHASIS_TYPE);
			}
			ENABLE_CONTROL(IDC_CHECK_OUTFREQ);
			if(IS_CHECK(IDC_CHECK_OUTFREQ)){
				ENABLE_CONTROL(IDC_EDIT_OUTFREQ);
			} else {
				DISABLE_CONTROL(IDC_EDIT_OUTFREQ);
			}
			ENABLE_CONTROL(IDC_CHECK_MSTHRESHOLD);
			if(IS_CHECK(IDC_CHECK_MSTHRESHOLD)){
				ENABLE_CONTROL(IDC_EDIT_MSTHRESHOLD_THRESHOLD);
				ENABLE_CONTROL(IDC_EDIT_MSTHRESHOLD_MSPOWER);
			} else {
				DISABLE_CONTROL(IDC_EDIT_MSTHRESHOLD_THRESHOLD);
				DISABLE_CONTROL(IDC_EDIT_MSTHRESHOLD_MSPOWER);
			}
			ENABLE_CONTROL(IDC_CHECK_USE_CPU_OPTS);
			if(IS_CHECK(IDC_CHECK_USE_CPU_OPTS)){
				ENABLE_CONTROL(IDC_CHECK_CPUMMX);
				ENABLE_CONTROL(IDC_CHECK_CPUSSE);
				ENABLE_CONTROL(IDC_CHECK_CPU3DNOW);
				ENABLE_CONTROL(IDC_CHECK_CPUE3DNOW);
			} else {
				DISABLE_CONTROL(IDC_CHECK_CPUMMX);
				DISABLE_CONTROL(IDC_CHECK_CPUSSE);
				DISABLE_CONTROL(IDC_CHECK_CPU3DNOW);
				DISABLE_CONTROL(IDC_CHECK_CPUE3DNOW);
			}
			ENABLE_CONTROL(IDC_CHECK_VBR);
			ENABLE_CONTROL(IDC_CHECK_MPEG1AUDIOBITRATE);
			ENABLE_CONTROL(IDC_CHECK_MPEG2AUDIOBITRATE);
			if(IS_CHECK(IDC_CHECK_VBR)){
				ENABLE_CONTROL(IDC_COMBO_VBR);
				ENABLE_CONTROL(IDC_CHECK_VBR_BITRATE);
				if(IS_CHECK(IDC_CHECK_VBR_BITRATE)){
					ENABLE_CONTROL(IDC_COMBO_VBR_BITRATE_LOW);
					ENABLE_CONTROL(IDC_COMBO_VBR_BITRATE_HIGH);
				} else {
					DISABLE_CONTROL(IDC_COMBO_VBR_BITRATE_LOW);
					DISABLE_CONTROL(IDC_COMBO_VBR_BITRATE_HIGH);
				}
				UNCHECK(IDC_CHECK_MPEG1AUDIOBITRATE);
				UNCHECK(IDC_CHECK_MPEG2AUDIOBITRATE);
				DISABLE_CONTROL(IDC_COMBO_MPEG1_AUDIO_BITRATE);
				DISABLE_CONTROL(IDC_COMBO_MPEG2_AUDIO_BITRATE);
			} else {
				UNCHECK(IDC_CHECK_VBR_BITRATE);
				DISABLE_CONTROL(IDC_COMBO_VBR);
				DISABLE_CONTROL(IDC_CHECK_VBR_BITRATE);
				DISABLE_CONTROL(IDC_COMBO_VBR_BITRATE_LOW);
				DISABLE_CONTROL(IDC_COMBO_VBR_BITRATE_HIGH);
				if(IS_CHECK(IDC_CHECK_MPEG1AUDIOBITRATE)){
					ENABLE_CONTROL(IDC_COMBO_MPEG1_AUDIO_BITRATE);
				} else {
					DISABLE_CONTROL(IDC_COMBO_MPEG1_AUDIO_BITRATE);
				}
				if(IS_CHECK(IDC_CHECK_MPEG2AUDIOBITRATE)){
					ENABLE_CONTROL(IDC_COMBO_MPEG2_AUDIO_BITRATE);
				} else {
					DISABLE_CONTROL(IDC_COMBO_MPEG2_AUDIO_BITRATE);
				}
			}
			ENABLE_CONTROL(IDC_CHECK_USEPSY);
			ENABLE_CONTROL(IDC_CHECK_VERIFY);
		}
	}
}

static void gogoConfigDialogProcControlReset(HWND hwnd)
{
	// コンボボックスの選択設定
	CB_SETCURSEL_TYPE2(IDC_COMBO_OUTPUT_FORMAT)
	CB_SETCURSEL_TYPE1(IDC_COMBO_MPEG1_AUDIO_BITRATE)
	CB_SETCURSEL_TYPE1(IDC_COMBO_MPEG2_AUDIO_BITRATE)
	CB_SETCURSEL_TYPE2(IDC_COMBO_ENCODE_MODE)
	CB_SETCURSEL_TYPE2(IDC_COMBO_EMPHASIS_TYPE)
	CB_SETCURSEL_TYPE1(IDC_COMBO_VBR_BITRATE_LOW)
	CB_SETCURSEL_TYPE1(IDC_COMBO_VBR_BITRATE_HIGH)
	CB_SETCURSEL_TYPE2(IDC_COMBO_VBR)
	// チェックボックスの設定
	CHECKBOX_SET(IDC_CHECK_DEFAULT)
	CHECKBOX_SET(IDC_CHECK_COMMANDLINE_OPTS)
	CHECKBOX_SET(IDC_CHECK_OUTPUT_FORMAT)
	CHECKBOX_SET(IDC_CHECK_MPEG1AUDIOBITRATE)
	CHECKBOX_SET(IDC_CHECK_MPEG2AUDIOBITRATE)
	CHECKBOX_SET(IDC_CHECK_ENHANCED_LOW_PASS_FILTER)
	CHECKBOX_SET(IDC_CHECK_ENCODE_MODE)
	CHECKBOX_SET(IDC_CHECK_EMPHASIS_TYPE)
	CHECKBOX_SET(IDC_CHECK_OUTFREQ)
	CHECKBOX_SET(IDC_CHECK_MSTHRESHOLD)
	CHECKBOX_SET(IDC_CHECK_USE_CPU_OPTS)
	CHECKBOX_SET(IDC_CHECK_CPUMMX)
	CHECKBOX_SET(IDC_CHECK_CPUSSE)
	CHECKBOX_SET(IDC_CHECK_CPU3DNOW)
	CHECKBOX_SET(IDC_CHECK_CPUE3DNOW)
	CHECKBOX_SET(IDC_CHECK_VBR)
	CHECKBOX_SET(IDC_CHECK_VBR_BITRATE)
	CHECKBOX_SET(IDC_CHECK_USEPSY)
	CHECKBOX_SET(IDC_CHECK_VERIFY)
	CHECKBOX_SET(IDC_CHECK_16KHZ_LOW_PASS_FILTER)
	// エディットの設定
	EDIT_SET(IDC_EDIT_OUTFREQ)
	EDIT_SET(IDC_EDIT_MSTHRESHOLD_THRESHOLD)
	EDIT_SET(IDC_EDIT_MSTHRESHOLD_MSPOWER)
	EDIT_SET(IDC_EDIT_COMMANDLINE_OPTION)
	EDIT_SET(IDC_EDIT_LPF_PARA1)
	EDIT_SET(IDC_EDIT_LPF_PARA2)
	// コントロールの有効 / 無効化
	gogoConfigDialogProcControlEnableDisable(hwnd);
}

static void gogoConfigDialogProcControlApply(HWND hwnd)
{
	// コンボボックスの選択設定
	CB_GETCURSEL_TYPE2(IDC_COMBO_OUTPUT_FORMAT)
	CB_GETCURSEL_TYPE1(IDC_COMBO_MPEG1_AUDIO_BITRATE)
	CB_GETCURSEL_TYPE1(IDC_COMBO_MPEG2_AUDIO_BITRATE)
	CB_GETCURSEL_TYPE2(IDC_COMBO_ENCODE_MODE)
	CB_GETCURSEL_TYPE2(IDC_COMBO_EMPHASIS_TYPE)
	CB_GETCURSEL_TYPE1(IDC_COMBO_VBR_BITRATE_LOW)
	CB_GETCURSEL_TYPE1(IDC_COMBO_VBR_BITRATE_HIGH)
	CB_GETCURSEL_TYPE2(IDC_COMBO_VBR)
	// チェックボックスの設定
	CHECKBOX_GET(IDC_CHECK_DEFAULT)
	CHECKBOX_GET(IDC_CHECK_COMMANDLINE_OPTS)
	CHECKBOX_GET(IDC_CHECK_OUTPUT_FORMAT)
	CHECKBOX_GET(IDC_CHECK_MPEG1AUDIOBITRATE)
	CHECKBOX_GET(IDC_CHECK_MPEG2AUDIOBITRATE)
	CHECKBOX_GET(IDC_CHECK_ENHANCED_LOW_PASS_FILTER)
	CHECKBOX_GET(IDC_CHECK_ENCODE_MODE)
	CHECKBOX_GET(IDC_CHECK_EMPHASIS_TYPE)
	CHECKBOX_GET(IDC_CHECK_OUTFREQ)
	CHECKBOX_GET(IDC_CHECK_MSTHRESHOLD)
	CHECKBOX_GET(IDC_CHECK_USE_CPU_OPTS)
	CHECKBOX_GET(IDC_CHECK_CPUMMX)
	CHECKBOX_GET(IDC_CHECK_CPUSSE)
	CHECKBOX_GET(IDC_CHECK_CPU3DNOW)
	CHECKBOX_GET(IDC_CHECK_CPUE3DNOW)
	CHECKBOX_GET(IDC_CHECK_VBR)
	CHECKBOX_GET(IDC_CHECK_VBR_BITRATE)
	CHECKBOX_GET(IDC_CHECK_USEPSY)
	CHECKBOX_GET(IDC_CHECK_VERIFY)
	CHECKBOX_GET(IDC_CHECK_16KHZ_LOW_PASS_FILTER)
	// エディットの設定
	EDIT_GET_RANGE(IDC_EDIT_OUTFREQ,6,4000,65000)
	EDIT_GET_RANGE(IDC_EDIT_MSTHRESHOLD_THRESHOLD,4,0,100)
	EDIT_GET_RANGE(IDC_EDIT_MSTHRESHOLD_MSPOWER,4,0,100)
	EDIT_GET(IDC_EDIT_COMMANDLINE_OPTION,1024)
	EDIT_GET_RANGE(IDC_EDIT_LPF_PARA1,4,0,100)
	EDIT_GET_RANGE(IDC_EDIT_LPF_PARA2,4,0,100)
	// コントロールの有効 / 無効化
	gogoConfigDialogProcControlEnableDisable(hwnd);
	// リセット
	gogoConfigDialogProcControlReset(hwnd);
}

#undef CB_INFO_TYPE1_BEGIN
#undef CB_INFO_TYPE1_END
#undef CB_INFO_TYPE2_BEGIN
#undef CB_INFO_TYPE2_END
#undef CB_SETCURSEL_TYPE1
#undef CB_SETCURSEL_TYPE2
#undef CB_GETCURSEL_TYPE1
#undef CB_GETCURSEL_TYPE2
#undef CHECKBOX_SET
#undef CHECKBOX_GET
#undef EDIT_SET
#undef EDIT_GET
#undef EDIT_GET_RANGE

#endif

int gogoConfigDialog(void)
{
#ifdef AU_GOGO
  if(!IsWindow(hgogoConfigDailog)) {
    if (PlayerLanguage == LANGUAGE_JAPANESE)
      hgogoConfigDailog = CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG_GOGO),(HWND)hPrefWnd,gogoConfigDialogProc);
    else
      hgogoConfigDailog = CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG_GOGO_EN),(HWND)hPrefWnd,gogoConfigDialogProc);
  }
  ShowWindow(hgogoConfigDailog,SW_SHOW);
#endif
  return 0;
}

#ifdef AU_GOGO

static int gogo_ConfigDialogInfoLock()
{
	return 0;
}
static int gogo_ConfigDialogInfoUnLock()
{
	return 0;
}

volatile gogo_ConfigDialogInfo_t gogo_ConfigDialogInfo;

int gogo_ConfigDialogInfoInit(void)
{
	gogo_ConfigDialogInfo.optIDC_CHECK_DEFAULT = 1;
	gogo_ConfigDialogInfo.optIDC_CHECK_COMMANDLINE_OPTS = 0;
	gogo_ConfigDialogInfo.optIDC_EDIT_COMMANDLINE_OPTION[0] = '\0';
	gogo_ConfigDialogInfo.optIDC_CHECK_OUTPUT_FORMAT = 1;
	gogo_ConfigDialogInfo.optIDC_COMBO_OUTPUT_FORMAT = MC_OUTPUT_NORMAL;
	gogo_ConfigDialogInfo.optIDC_CHECK_MPEG1AUDIOBITRATE = 1;
	gogo_ConfigDialogInfo.optIDC_COMBO_MPEG1_AUDIO_BITRATE = 160;
	gogo_ConfigDialogInfo.optIDC_CHECK_MPEG2AUDIOBITRATE = 1;
	gogo_ConfigDialogInfo.optIDC_COMBO_MPEG2_AUDIO_BITRATE = 80;
	gogo_ConfigDialogInfo.optIDC_CHECK_ENHANCED_LOW_PASS_FILTER = 0;
	strcpy((char *)gogo_ConfigDialogInfo.optIDC_EDIT_LPF_PARA1,"55");
	strcpy((char *)gogo_ConfigDialogInfo.optIDC_EDIT_LPF_PARA2,"70");
	gogo_ConfigDialogInfo.optIDC_CHECK_ENCODE_MODE = 1;
	gogo_ConfigDialogInfo.optIDC_COMBO_ENCODE_MODE = MC_MODE_STEREO;
	gogo_ConfigDialogInfo.optIDC_CHECK_EMPHASIS_TYPE = 1;
	gogo_ConfigDialogInfo.optIDC_COMBO_EMPHASIS_TYPE = MC_EMP_NONE;
	gogo_ConfigDialogInfo.optIDC_CHECK_OUTFREQ = 0;
	strcpy((char *)gogo_ConfigDialogInfo.optIDC_EDIT_OUTFREQ,"44100");
	gogo_ConfigDialogInfo.optIDC_CHECK_MSTHRESHOLD = 0;
	strcpy((char *)gogo_ConfigDialogInfo.optIDC_EDIT_MSTHRESHOLD_THRESHOLD,"75");
	strcpy((char *)gogo_ConfigDialogInfo.optIDC_EDIT_MSTHRESHOLD_MSPOWER,"66");
	gogo_ConfigDialogInfo.optIDC_CHECK_USE_CPU_OPTS = 0;
	gogo_ConfigDialogInfo.optIDC_CHECK_CPUMMX = 0;
	gogo_ConfigDialogInfo.optIDC_CHECK_CPUSSE = 0;
	gogo_ConfigDialogInfo.optIDC_CHECK_CPU3DNOW = 0;
	gogo_ConfigDialogInfo.optIDC_CHECK_CPUE3DNOW = 0;
	gogo_ConfigDialogInfo.optIDC_CHECK_VBR = 0;
	gogo_ConfigDialogInfo.optIDC_COMBO_VBR = 0;
	gogo_ConfigDialogInfo.optIDC_CHECK_VBR_BITRATE = 0;
	gogo_ConfigDialogInfo.optIDC_COMBO_VBR_BITRATE_LOW = 32;
	gogo_ConfigDialogInfo.optIDC_COMBO_VBR_BITRATE_HIGH = 320;
	gogo_ConfigDialogInfo.optIDC_CHECK_USEPSY = 1;
	gogo_ConfigDialogInfo.optIDC_CHECK_VERIFY = 0;
	gogo_ConfigDialogInfo.optIDC_CHECK_16KHZ_LOW_PASS_FILTER = 1;
	return 0;
}

int gogo_ConfigDialogInfoApply(void)
{
	gogo_ConfigDialogInfoLock();
	if(gogo_ConfigDialogInfo.optIDC_CHECK_DEFAULT>0){
		gogo_opts_reset();
		gogo_ConfigDialogInfoUnLock();
		return 0;
	}
	if(gogo_ConfigDialogInfo.optIDC_CHECK_COMMANDLINE_OPTS>0){
		gogo_opts_reset();
		set_gogo_opts_use_commandline_options((char *)gogo_ConfigDialogInfo.optIDC_EDIT_COMMANDLINE_OPTION);
		gogo_ConfigDialogInfoUnLock();
		return 0;
	}
	if(gogo_ConfigDialogInfo.optIDC_CHECK_OUTPUT_FORMAT>0){
		gogo_opts.optOUTPUT_FORMAT = gogo_ConfigDialogInfo.optIDC_COMBO_OUTPUT_FORMAT;
	}
	if(gogo_ConfigDialogInfo.optIDC_CHECK_MPEG1AUDIOBITRATE>0){
		gogo_opts.optBITRATE1 = gogo_ConfigDialogInfo.optIDC_COMBO_MPEG1_AUDIO_BITRATE;
	}
	if(gogo_ConfigDialogInfo.optIDC_CHECK_MPEG2AUDIOBITRATE>0){
		gogo_opts.optBITRATE2 = gogo_ConfigDialogInfo.optIDC_COMBO_MPEG2_AUDIO_BITRATE;
	}
	if(gogo_ConfigDialogInfo.optIDC_CHECK_ENHANCED_LOW_PASS_FILTER>0){
		gogo_opts.optENHANCEDFILTER_A = atoi((char *)gogo_ConfigDialogInfo.optIDC_EDIT_LPF_PARA1);
		gogo_opts.optENHANCEDFILTER_B = atoi((char *)gogo_ConfigDialogInfo.optIDC_EDIT_LPF_PARA2);
	}
	if(gogo_ConfigDialogInfo.optIDC_CHECK_ENCODE_MODE>0){
		gogo_opts.optENCODEMODE = gogo_ConfigDialogInfo.optIDC_COMBO_ENCODE_MODE;
	}
	if(gogo_ConfigDialogInfo.optIDC_CHECK_EMPHASIS_TYPE>0){
		gogo_opts.optEMPHASIS = gogo_ConfigDialogInfo.optIDC_COMBO_EMPHASIS_TYPE;
	}
	if(gogo_ConfigDialogInfo.optIDC_CHECK_OUTFREQ>0){
		gogo_opts.optOUTFREQ = atoi((char *)gogo_ConfigDialogInfo.optIDC_EDIT_OUTFREQ);
	}
	if(gogo_ConfigDialogInfo.optIDC_CHECK_MSTHRESHOLD>0){
		gogo_opts.optMSTHRESHOLD_threshold = atoi((char *)gogo_ConfigDialogInfo.optIDC_EDIT_MSTHRESHOLD_THRESHOLD);
		gogo_opts.optMSTHRESHOLD_mspower = atoi((char *)gogo_ConfigDialogInfo.optIDC_EDIT_MSTHRESHOLD_MSPOWER);
	}
	if(gogo_ConfigDialogInfo.optIDC_CHECK_USE_CPU_OPTS>0){
		gogo_opts.optUSEMMX = gogo_ConfigDialogInfo.optIDC_CHECK_CPUMMX;
		gogo_opts.optUSEKNI = gogo_ConfigDialogInfo.optIDC_CHECK_CPUSSE;
		gogo_opts.optUSE3DNOW = gogo_ConfigDialogInfo.optIDC_CHECK_CPU3DNOW;
		gogo_opts.optUSEE3DNOW = gogo_ConfigDialogInfo.optIDC_CHECK_CPUE3DNOW;
	}
	if(gogo_ConfigDialogInfo.optIDC_CHECK_VBR>0){
		gogo_opts.optVBR = gogo_ConfigDialogInfo.optIDC_COMBO_VBR;
	}
	if(gogo_ConfigDialogInfo.optIDC_CHECK_VBR_BITRATE>0){
		gogo_opts.optVBRBITRATE_low = gogo_ConfigDialogInfo.optIDC_COMBO_VBR_BITRATE_LOW;
		gogo_opts.optVBRBITRATE_high = gogo_ConfigDialogInfo.optIDC_COMBO_VBR_BITRATE_HIGH;
	}
	if(gogo_ConfigDialogInfo.optIDC_CHECK_USEPSY>0){
		gogo_opts.optUSEPSY = TRUE;
	}
	if(gogo_ConfigDialogInfo.optIDC_CHECK_VERIFY>0){
		gogo_opts.optVERIFY = TRUE;
	}
	if(gogo_ConfigDialogInfo.optIDC_CHECK_16KHZ_LOW_PASS_FILTER>0){
		gogo_opts.optUSELPF16 = TRUE;
	}
//	gogo_opts.optINPFREQ;			// SYSTEM USE(システムで使用するから指定できない)
//	gogo_opts.optSTARTOFFSET;	// SYSTEM USE
//	gogo_opts.optADDTAGnum;		// SYSTEM USE
//	gogo_opts.optADDTAG_len[64];	// SYSTEM USE
//	gogo_opts.optADDTAG_buf[64];	// SYSTEM USE
//	gogo_opts.optCPU;					// PREPAIRING(準備中)
//	gogo_opts.optBYTE_SWAP;			// SYSTEM USE
//	gogo_opts.opt8BIT_PCM;			// SYSTEM USE
//	gogo_opts.optMONO_PCM;		// SYSTEM USE
//	gogo_opts.optTOWNS_SND;			// SYSTEM USE
//	gogo_opts.optTHREAD_PRIORITY;	// PREPARING
//	gogo_opts.optREADTHREAD_PRIORITY;	// PREPARING
//	gogo_opts.optOUTPUTDIR[1024];			// SYSTEM USE
//	gogo_opts.output_name[1024];				// SYSTEM USE
	gogo_ConfigDialogInfoUnLock();
	return 0;
}

#define SEC_GOGO	"gogo"
int gogo_ConfigDialogInfoSaveINI(void)
{
	char *section = SEC_GOGO;
	char *inifile = timidity_output_inifile;
	char buffer[1024];
#define NUMSAVE(name) \
		sprintf(buffer,"%d",gogo_ConfigDialogInfo. ## name ); \
		WritePrivateProfileString(section, #name ,buffer,inifile);
#define STRSAVE(name) \
		WritePrivateProfileString(section,(char *) #name ,(char *)gogo_ConfigDialogInfo. ## name ,inifile);
	NUMSAVE(optIDC_CHECK_DEFAULT)
	NUMSAVE(optIDC_CHECK_COMMANDLINE_OPTS)
	STRSAVE(optIDC_EDIT_COMMANDLINE_OPTION)
	NUMSAVE(optIDC_CHECK_OUTPUT_FORMAT)
	NUMSAVE(optIDC_COMBO_OUTPUT_FORMAT)
	NUMSAVE(optIDC_CHECK_MPEG1AUDIOBITRATE)
	NUMSAVE(optIDC_COMBO_MPEG1_AUDIO_BITRATE)
	NUMSAVE(optIDC_CHECK_MPEG2AUDIOBITRATE)
	NUMSAVE(optIDC_COMBO_MPEG2_AUDIO_BITRATE)
	NUMSAVE(optIDC_CHECK_ENHANCED_LOW_PASS_FILTER)
	STRSAVE(optIDC_EDIT_LPF_PARA1)
	STRSAVE(optIDC_EDIT_LPF_PARA2)
	NUMSAVE(optIDC_CHECK_ENCODE_MODE)
	NUMSAVE(optIDC_COMBO_ENCODE_MODE)
	NUMSAVE(optIDC_CHECK_EMPHASIS_TYPE)
	NUMSAVE(optIDC_COMBO_EMPHASIS_TYPE)
	NUMSAVE(optIDC_CHECK_OUTFREQ)
	STRSAVE(optIDC_EDIT_OUTFREQ)
	NUMSAVE(optIDC_CHECK_MSTHRESHOLD)
	STRSAVE(optIDC_EDIT_MSTHRESHOLD_THRESHOLD)
	STRSAVE(optIDC_EDIT_MSTHRESHOLD_MSPOWER)
	NUMSAVE(optIDC_CHECK_USE_CPU_OPTS)
	NUMSAVE(optIDC_CHECK_CPUMMX)
	NUMSAVE(optIDC_CHECK_CPUSSE)
	NUMSAVE(optIDC_CHECK_CPU3DNOW)
	NUMSAVE(optIDC_CHECK_CPUE3DNOW)
	NUMSAVE(optIDC_CHECK_VBR)
	NUMSAVE(optIDC_COMBO_VBR)
	NUMSAVE(optIDC_CHECK_VBR_BITRATE)
	NUMSAVE(optIDC_COMBO_VBR_BITRATE_LOW)
	NUMSAVE(optIDC_COMBO_VBR_BITRATE_HIGH)
	NUMSAVE(optIDC_CHECK_USEPSY)
	NUMSAVE(optIDC_CHECK_VERIFY)
	NUMSAVE(optIDC_CHECK_16KHZ_LOW_PASS_FILTER)
	WritePrivateProfileString(NULL,NULL,NULL,inifile);		// Write Flush
#undef NUMSAVE
#undef STRSAVE
	return 0;
}
int gogo_ConfigDialogInfoLoadINI(void)
{
	char *section = SEC_GOGO;
	char *inifile = timidity_output_inifile;
	int num;
	char buffer[1024];
#define NUMLOAD(name) \
		num = GetPrivateProfileInt(section, #name ,-1,inifile); \
		if(num!=-1) gogo_ConfigDialogInfo. ## name = num;
#define STRLOAD(name,len) \
		GetPrivateProfileString(section,(char *) #name ,"",buffer,len,inifile); \
		buffer[len-1] = '\0'; \
		if(buffer[0]!=0) \
			strcpy((char *)gogo_ConfigDialogInfo. ## name ,buffer);
	gogo_ConfigDialogInfoLock();
	NUMLOAD(optIDC_CHECK_DEFAULT)
	NUMLOAD(optIDC_CHECK_COMMANDLINE_OPTS)
	STRLOAD(optIDC_EDIT_COMMANDLINE_OPTION,1024)
	NUMLOAD(optIDC_CHECK_OUTPUT_FORMAT)
	NUMLOAD(optIDC_COMBO_OUTPUT_FORMAT)
	NUMLOAD(optIDC_CHECK_MPEG1AUDIOBITRATE)
	NUMLOAD(optIDC_COMBO_MPEG1_AUDIO_BITRATE)
	NUMLOAD(optIDC_CHECK_MPEG2AUDIOBITRATE)
	NUMLOAD(optIDC_COMBO_MPEG2_AUDIO_BITRATE)
	NUMLOAD(optIDC_CHECK_ENHANCED_LOW_PASS_FILTER)
	STRLOAD(optIDC_EDIT_LPF_PARA1,4)
	STRLOAD(optIDC_EDIT_LPF_PARA2,4)
	NUMLOAD(optIDC_CHECK_ENCODE_MODE)
	NUMLOAD(optIDC_COMBO_ENCODE_MODE)
	NUMLOAD(optIDC_CHECK_EMPHASIS_TYPE)
	NUMLOAD(optIDC_COMBO_EMPHASIS_TYPE)
	NUMLOAD(optIDC_CHECK_OUTFREQ)
	STRLOAD(optIDC_EDIT_OUTFREQ,6)
	NUMLOAD(optIDC_CHECK_MSTHRESHOLD)
	STRLOAD(optIDC_EDIT_MSTHRESHOLD_THRESHOLD,4)
	STRLOAD(optIDC_EDIT_MSTHRESHOLD_MSPOWER,4)
	NUMLOAD(optIDC_CHECK_USE_CPU_OPTS)
	NUMLOAD(optIDC_CHECK_CPUMMX)
	NUMLOAD(optIDC_CHECK_CPUSSE)
	NUMLOAD(optIDC_CHECK_CPU3DNOW)
	NUMLOAD(optIDC_CHECK_CPUE3DNOW)
	NUMLOAD(optIDC_CHECK_VBR)
	NUMLOAD(optIDC_COMBO_VBR)
	NUMLOAD(optIDC_CHECK_VBR_BITRATE)
	NUMLOAD(optIDC_COMBO_VBR_BITRATE_LOW)
	NUMLOAD(optIDC_COMBO_VBR_BITRATE_HIGH)
	NUMLOAD(optIDC_CHECK_USEPSY)
	NUMLOAD(optIDC_CHECK_VERIFY)
	NUMLOAD(optIDC_CHECK_16KHZ_LOW_PASS_FILTER)
#undef NUMLOAD
#undef STRLOAD
	gogo_ConfigDialogInfoUnLock();
	return 0;
}

#endif	// AU_GOGO


#ifdef AU_VORBIS
///////////////////////////////////////////////////////////////////////
//
// vorbis ConfigDialog
//
///////////////////////////////////////////////////////////////////////

volatile vorbis_ConfigDialogInfo_t vorbis_ConfigDialogInfo;

// id のコンボボックスの情報の定義
#define CB_INFO_TYPE1_BEGIN(id) static int cb_info_ ## id [] = {
#define CB_INFO_TYPE1_END };
#define CB_INFO_TYPE2_BEGIN(id) static char * cb_info_ ## id [] = {
#define CB_INFO_TYPE2_END };

// cb_info_type1_ＩＤ  cb_info_type2_ＩＤ というふうになる。

// IDC_COMBO_MODE_jp
CB_INFO_TYPE2_BEGIN(IDC_COMBO_MODE_jp)
	"デフォルト(約128kbps VBR)",(char *)0,
	"約112kbps VBR",(char *)1,
	"約128kbps VBR",(char *)2,
	"約160kbps VBR",(char *)3,
	"約192kbps VBR",(char *)4,
	"約256kbps VBR",(char *)5,
	"約350kbps VBR",(char *)6,
	NULL
CB_INFO_TYPE2_END

// IDC_COMBO_MODE_en
CB_INFO_TYPE2_BEGIN(IDC_COMBO_MODE_en)
	"Default (About 128kbps VBR)",(char *)0,
	"About 112kbps VBR",(char *)1,
	"About 128kbps VBR",(char *)2,
	"About 160kbps VBR",(char *)3,
	"About 192kbps VBR",(char *)4,
	"About 256kbps VBR",(char *)5,
	"About 350kbps VBR",(char *)6,
	NULL
CB_INFO_TYPE2_END

static char **cb_info_IDC_COMBO_MODE;

// id のコンボボックスを選択の設定する。
#define CB_SETCURSEL_TYPE1(id) \
{ \
	int cb_num; \
	for(cb_num=0;(int)cb_info_ ## id [cb_num]>=0;cb_num++){ \
		SendDlgItemMessage(hwnd,id,CB_SETCURSEL,(WPARAM)0,(LPARAM)0); \
		if(vorbis_ConfigDialogInfo.opt ## id == (int) cb_info_ ## id [cb_num]){ \
			SendDlgItemMessage(hwnd,id,CB_SETCURSEL,(WPARAM)cb_num,(LPARAM)0); \
			break; \
		} \
	} \
}
#define CB_SETCURSEL_TYPE2(id) \
{ \
	int cb_num; \
	for(cb_num=0;(int)cb_info_ ## id [cb_num];cb_num+=2){ \
		SendDlgItemMessage(hwnd,id,CB_SETCURSEL,(WPARAM)0,(LPARAM)0); \
	    if(vorbis_ConfigDialogInfo.opt ## id == (int) cb_info_ ## id [cb_num+1]){ \
			SendDlgItemMessage(hwnd,id,CB_SETCURSEL,(WPARAM)cb_num/2,(LPARAM)0); \
			break; \
		} \
	} \
}
// id のコンボボックスの選択を変数に代入する。
#define CB_GETCURSEL_TYPE1(id) \
{ \
	int cb_num1, cb_num2; \
	cb_num1 = SendDlgItemMessage(hwnd,id,CB_GETCURSEL,(WPARAM)0,(LPARAM)0); \
	for(cb_num2=0;(int)cb_info_ ## id [cb_num2]>=0;cb_num2++) \
		if(cb_num1==cb_num2){ \
			vorbis_ConfigDialogInfo.opt ## id = (int)cb_info_ ## id [cb_num2]; \
			break; \
		} \
}
#define CB_GETCURSEL_TYPE2(id) \
{ \
	int cb_num1, cb_num2; \
	cb_num1 = SendDlgItemMessage(hwnd,id,CB_GETCURSEL,(WPARAM)0,(LPARAM)0); \
	for(cb_num2=0;(int)cb_info_ ## id [cb_num2];cb_num2+=2) \
		if(cb_num1*2==cb_num2){ \
			vorbis_ConfigDialogInfo.opt ## id = (int)cb_info_ ## id [cb_num2+1]; \
			break; \
		} \
}
// チェックされているか。
#define IS_CHECK(id) SendDlgItemMessage(hwnd,id,BM_GETCHECK,0,0)
// チェックする。
#define CHECK(id) SendDlgItemMessage(hwnd,id,BM_SETCHECK,1,0)
// チェックをはずす。
#define UNCHECK(id) SendDlgItemMessage(hwnd,id,BM_SETCHECK,0,0)
// id のチェックボックスを設定する。
#define CHECKBOX_SET(id) \
	if(vorbis_ConfigDialogInfo.opt ## id>0) \
		SendDlgItemMessage(hwnd,id,BM_SETCHECK,1,0); \
	else \
		SendDlgItemMessage(hwnd,id,BM_SETCHECK,0,0); \
// id のチェックボックスを変数に代入する。
#define CHECKBOX_GET(id) \
	if(SendDlgItemMessage(hwnd,id,BM_GETCHECK,0,0)) \
		vorbis_ConfigDialogInfo.opt ## id = 1; \
	else \
		vorbis_ConfigDialogInfo.opt ## id = 0; \
// id のエディットを設定する。
#define EDIT_SET(id) SendDlgItemMessage(hwnd,id,WM_SETTEXT,0,(LPARAM)vorbis_ConfigDialogInfo.opt ## id);
// id のエディットを変数に代入する。
#define EDIT_GET(id,size) SendDlgItemMessage(hwnd,id,WM_GETTEXT,(WPARAM)size,(LPARAM)vorbis_ConfigDialogInfo.opt ## id);
#define EDIT_GET_RANGE(id,size,min,max) \
{ \
	char tmpbuf[64]; \
	int value; \
	SendDlgItemMessage(hwnd,id,WM_GETTEXT,(WPARAM)size,(LPARAM)vorbis_ConfigDialogInfo.opt ## id); \
	value = atoi((char *)vorbis_ConfigDialogInfo.opt ## id); \
	if(value<min) value = min; \
	if(value>max) value = max; \
	sprintf(tmpbuf,"%d",value); \
	strncpy((char *)vorbis_ConfigDialogInfo.opt ## id,tmpbuf,size); \
	(vorbis_ConfigDialogInfo.opt ## id)[size] = '\0'; \
}
// コントロールの有効化
#define ENABLE_CONTROL(id) EnableWindow(GetDlgItem(hwnd,id),TRUE);
// コントロールの無効化
#define DISABLE_CONTROL(id) EnableWindow(GetDlgItem(hwnd,id),FALSE);


static void vorbisConfigDialogProcControlEnableDisable(HWND hwnd);
static void vorbisConfigDialogProcControlApply(HWND hwnd);
static void vorbisConfigDialogProcControlReset(HWND hwnd);
static int vorbis_ConfigDialogInfoLock();
static int vorbis_ConfigDialogInfoUnLock();
static HANDLE hvorbisConfigDailog = NULL;
static BOOL APIENTRY vorbisConfigDialogProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam)
{
	switch (uMess){
	case WM_INITDIALOG:
	{
		int i;
		// コンボボックスの初期化
		if (PlayerLanguage == LANGUAGE_JAPANESE)
		  cb_info_IDC_COMBO_MODE = cb_info_IDC_COMBO_MODE_jp;
		else
		  cb_info_IDC_COMBO_MODE = cb_info_IDC_COMBO_MODE_en;

		for(i=0;cb_info_IDC_COMBO_MODE[i];i+=2){
			SendDlgItemMessage(hwnd,IDC_COMBO_MODE,CB_INSERTSTRING,(WPARAM)-1,(LPARAM)cb_info_IDC_COMBO_MODE[i]);
		}
		// 設定
		vorbisConfigDialogProcControlReset(hwnd);
	}
		break;
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDCLOSE:
			SendMessage(hwnd,WM_CLOSE,(WPARAM)0,(LPARAM)0);
			break;
		case IDOK:
			vorbisConfigDialogProcControlApply(hwnd);
			SendMessage(hwnd,WM_CLOSE,(WPARAM)0,(LPARAM)0);
			break;
		case IDCANCEL:
			SendMessage(hwnd,WM_CLOSE,(WPARAM)0,(LPARAM)0);
			break;
		case IDC_BUTTON_APPLY:
			vorbisConfigDialogProcControlApply(hwnd);
			break;
		case IDC_CHECK_DEFAULT:
			vorbisConfigDialogProcControlEnableDisable(hwnd);
			break;
		case IDC_COMBO_MODE:
			break;
		default:
			break;
		}
		break;
	case WM_NOTIFY:
		break;
	case WM_SIZE:
		return FALSE;
	case WM_CLOSE:
		vorbis_ConfigDialogInfoSaveINI();
		DestroyWindow(hwnd);
		break;
	case WM_DESTROY:
		hvorbisConfigDailog = NULL;
		break;
	default:
		break;
	}
	return FALSE;
}

// コントロールの有効 / 無効化
static void vorbisConfigDialogProcControlEnableDisable(HWND hwnd)
{
	ENABLE_CONTROL(IDC_CHECK_DEFAULT);
	if(IS_CHECK(IDC_CHECK_DEFAULT)){
		DISABLE_CONTROL(IDC_COMBO_MODE);
	} else {
		ENABLE_CONTROL(IDC_COMBO_MODE);
	}
}

static void vorbisConfigDialogProcControlReset(HWND hwnd)
{
	// コンボボックスの選択設定
	CB_SETCURSEL_TYPE2(IDC_COMBO_MODE)
	// チェックボックスの設定
	CHECKBOX_SET(IDC_CHECK_DEFAULT)
	// エディットの設定
	// コントロールの有効 / 無効化
	vorbisConfigDialogProcControlEnableDisable(hwnd);
}

static void vorbisConfigDialogProcControlApply(HWND hwnd)
{
	// コンボボックスの選択設定
	CB_GETCURSEL_TYPE2(IDC_COMBO_MODE)
	// チェックボックスの設定
	CHECKBOX_GET(IDC_CHECK_DEFAULT)
	// エディットの設定
	// コントロールの有効 / 無効化
	vorbisConfigDialogProcControlEnableDisable(hwnd);
	// リセット
	vorbisConfigDialogProcControlReset(hwnd);
}

#undef CB_INFO_TYPE1_BEGIN
#undef CB_INFO_TYPE1_END
#undef CB_INFO_TYPE2_BEGIN
#undef CB_INFO_TYPE2_END
#undef CB_SETCURSEL_TYPE1
#undef CB_SETCURSEL_TYPE2
#undef CB_GETCURSEL_TYPE1
#undef CB_GETCURSEL_TYPE2
#undef CHECKBOX_SET
#undef CHECKBOX_GET
#undef EDIT_SET
#undef EDIT_GET
#undef EDIT_GET_RANGE

#endif

int vorbisConfigDialog(void)
{
#ifdef AU_VORBIS
  if(!IsWindow(hvorbisConfigDailog)) {
    if (PlayerLanguage == LANGUAGE_JAPANESE)
      hvorbisConfigDailog = CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG_VORBIS),(HWND)hPrefWnd,vorbisConfigDialogProc);
    else
      hvorbisConfigDailog = CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG_VORBIS_EN),(HWND)hPrefWnd,vorbisConfigDialogProc);
  }
  ShowWindow(hvorbisConfigDailog,SW_SHOW);
#endif
	return 0;
}

#ifdef AU_VORBIS

static int vorbis_ConfigDialogInfoLock()
{
	return 0;
}
static int vorbis_ConfigDialogInfoUnLock()
{
	return 0;
}

int vorbis_ConfigDialogInfoInit(void)
{
	vorbis_ConfigDialogInfo.optIDC_CHECK_DEFAULT = 1;
	vorbis_ConfigDialogInfo.optIDC_COMBO_MODE = 0;
	return 0;
}

extern volatile int ogg_vorbis_mode;
int vorbis_ConfigDialogInfoApply(void)
{
	vorbis_ConfigDialogInfoLock();
	if(vorbis_ConfigDialogInfo.optIDC_CHECK_DEFAULT>0){
//		vorbis_opts_reset();
		vorbis_ConfigDialogInfoUnLock();
		return 0;
	}
	ogg_vorbis_mode = vorbis_ConfigDialogInfo.optIDC_COMBO_MODE;
	vorbis_ConfigDialogInfoUnLock();
	return 0;
}

#define SEC_VORBIS	"vorbis"
int vorbis_ConfigDialogInfoSaveINI(void)
{
	char *section = SEC_VORBIS;
	char *inifile = timidity_output_inifile;
	char buffer[1024];
//	int len;
#define NUMSAVE(name) \
		sprintf(buffer,"%d",vorbis_ConfigDialogInfo. ## name ); \
		WritePrivateProfileString(section, #name ,buffer,inifile);
//#define STRSAVE(name,len) \
//		WritePrivateProfileString(section,(char *) #name ,(char *)vorbis_ConfigDialogInfo. ## name ,inifile);
	NUMSAVE(optIDC_CHECK_DEFAULT)
	NUMSAVE(optIDC_COMBO_MODE)
	WritePrivateProfileString(NULL,NULL,NULL,inifile);		// Write Flush
#undef NUMSAVE
//#undef STRSAVE
	return 0;
}
int vorbis_ConfigDialogInfoLoadINI(void)
{
	char *section = SEC_VORBIS;
	char *inifile = timidity_output_inifile;
	int num;
//	char buffer[1024];
#define NUMLOAD(name) \
		num = GetPrivateProfileInt(section, #name ,-1,inifile); \
		if(num!=-1) vorbis_ConfigDialogInfo. ## name = num;
//#define STRLOAD(name,len) \
//		GetPrivateProfileString(section,(char *) #name ,"",buffer,len,inifile); \
//		buffer[len-1] = '\0'; \
//		if(buffer[0]!=0) \
//			strcpy((char *)vorbis_ConfigDialogInfo. ## name ,buffer);
	vorbis_ConfigDialogInfoLock();
	NUMLOAD(optIDC_CHECK_DEFAULT)
	NUMLOAD(optIDC_COMBO_MODE)
#undef NUMLOAD
//#undef STRLOAD
	vorbis_ConfigDialogInfoUnLock();
	return 0;
}

#endif	// AU_VORBIS
