2003-01-08 07:59:48 +00:00
|
|
|
#include <windows.h>
|
|
|
|
|
#include <commctrl.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "config.h"
|
2003-01-14 09:01:31 +00:00
|
|
|
#include "tagz.h"
|
2003-01-08 07:59:48 +00:00
|
|
|
#include "resource.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char buffer[256];
|
|
|
|
|
|
|
|
|
|
//
|
2003-01-14 09:01:31 +00:00
|
|
|
// Read/write config
|
2003-01-08 07:59:48 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#define RI(x, def) (x = GetPrivateProfileInt("FLAC", #x, def, ini_name))
|
|
|
|
|
#define WI(x) WritePrivateProfileString("FLAC", #x, itoa(x, buffer, 10), ini_name)
|
2003-01-14 09:01:31 +00:00
|
|
|
#define RS(x, n, def) GetPrivateProfileString("FLAC", #x, def, x, n, ini_name)
|
|
|
|
|
#define WS(x) WritePrivateProfileString("FLAC", #x, x, ini_name)
|
2003-01-08 07:59:48 +00:00
|
|
|
|
2003-01-14 09:01:31 +00:00
|
|
|
static const char default_format[] = "[%artist% - ]$if2(%title%,%filename%)";
|
2003-01-08 07:59:48 +00:00
|
|
|
|
|
|
|
|
void ReadConfig()
|
|
|
|
|
{
|
2003-01-14 09:01:31 +00:00
|
|
|
RS(flac_cfg.title.tag_format, sizeof(flac_cfg.title.tag_format), default_format);
|
|
|
|
|
|
2003-01-08 07:59:48 +00:00
|
|
|
RI(flac_cfg.output.replaygain.enable, 1);
|
|
|
|
|
RI(flac_cfg.output.replaygain.album_mode, 0);
|
|
|
|
|
RI(flac_cfg.output.replaygain.hard_limit, 0);
|
|
|
|
|
RI(flac_cfg.output.replaygain.preamp, 0);
|
|
|
|
|
RI(flac_cfg.output.resolution.normal.dither_24_to_16, 0);
|
|
|
|
|
RI(flac_cfg.output.resolution.replaygain.dither, 0);
|
|
|
|
|
RI(flac_cfg.output.resolution.replaygain.noise_shaping, 1);
|
|
|
|
|
RI(flac_cfg.output.resolution.replaygain.bps_out, 16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WriteConfig()
|
|
|
|
|
{
|
2003-01-14 09:01:31 +00:00
|
|
|
WS(flac_cfg.title.tag_format);
|
|
|
|
|
|
2003-01-08 07:59:48 +00:00
|
|
|
WI(flac_cfg.output.replaygain.enable);
|
|
|
|
|
WI(flac_cfg.output.replaygain.album_mode);
|
|
|
|
|
WI(flac_cfg.output.replaygain.hard_limit);
|
|
|
|
|
WI(flac_cfg.output.replaygain.preamp);
|
|
|
|
|
WI(flac_cfg.output.resolution.normal.dither_24_to_16);
|
|
|
|
|
WI(flac_cfg.output.resolution.replaygain.dither);
|
|
|
|
|
WI(flac_cfg.output.resolution.replaygain.noise_shaping);
|
|
|
|
|
WI(flac_cfg.output.resolution.replaygain.bps_out);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
2003-01-14 09:01:31 +00:00
|
|
|
// Dialog
|
2003-01-08 07:59:48 +00:00
|
|
|
//
|
|
|
|
|
|
2003-01-14 09:01:31 +00:00
|
|
|
#define PREAMP_RANGE 24
|
|
|
|
|
|
2003-01-08 07:59:48 +00:00
|
|
|
#define Check(x,y) CheckDlgButton(hwnd, x, y ? BST_CHECKED : BST_UNCHECKED)
|
|
|
|
|
#define GetCheck(x) (IsDlgButtonChecked(hwnd, x)==BST_CHECKED)
|
|
|
|
|
#define GetSel(x) SendDlgItemMessage(hwnd, x, CB_GETCURSEL, 0, 0)
|
|
|
|
|
#define GetPos(x) SendDlgItemMessage(hwnd, x, TBM_GETPOS, 0, 0)
|
2003-01-14 09:01:31 +00:00
|
|
|
#define Enable(x,y) EnableWindow(GetDlgItem(hwnd, x), y)
|
2003-01-08 07:59:48 +00:00
|
|
|
|
2003-01-14 09:01:31 +00:00
|
|
|
|
|
|
|
|
static INT_PTR CALLBACK GeneralProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
{
|
|
|
|
|
switch (msg)
|
|
|
|
|
{
|
|
|
|
|
// init
|
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
|
SetDlgItemText(hwnd, IDC_TITLE, flac_cfg.title.tag_format);
|
|
|
|
|
return TRUE;
|
|
|
|
|
// commands
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
|
{
|
|
|
|
|
// ok
|
|
|
|
|
case IDOK:
|
|
|
|
|
GetDlgItemText(hwnd, IDC_TITLE, flac_cfg.title.tag_format, sizeof(flac_cfg.title.tag_format));
|
|
|
|
|
break;
|
|
|
|
|
// reset
|
|
|
|
|
case IDC_RESET:
|
|
|
|
|
SetDlgItemText(hwnd, IDC_TITLE, default_format);
|
|
|
|
|
break;
|
|
|
|
|
// help
|
|
|
|
|
case IDC_TAGZ_HELP:
|
|
|
|
|
MessageBox(hwnd, tagz_manual, "Help", 0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2003-01-08 07:59:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
static void UpdatePreamp(HWND hwnd, HWND hamp)
|
|
|
|
|
{
|
|
|
|
|
int pos = SendMessage(hamp, TBM_GETPOS, 0, 0) - PREAMP_RANGE;
|
|
|
|
|
sprintf(buffer, "%d dB", pos);
|
|
|
|
|
SetDlgItemText(hwnd, IDC_PA, buffer);
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-14 09:01:31 +00:00
|
|
|
static void UpdateRG(HWND hwnd)
|
|
|
|
|
{
|
|
|
|
|
int on = GetCheck(IDC_ENABLE);
|
|
|
|
|
Enable(IDC_ALBUM, on);
|
|
|
|
|
Enable(IDC_LIMITER, on);
|
|
|
|
|
Enable(IDC_PREAMP, on);
|
|
|
|
|
Enable(IDC_PA, on);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void UpdateDither(HWND hwnd)
|
|
|
|
|
{
|
|
|
|
|
int on = GetCheck(IDC_DITHERRG);
|
|
|
|
|
Enable(IDC_SHAPE, on);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static INT_PTR CALLBACK OutputProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
2003-01-08 07:59:48 +00:00
|
|
|
{
|
|
|
|
|
switch (msg)
|
|
|
|
|
{
|
|
|
|
|
// init
|
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
|
Check(IDC_ENABLE, flac_cfg.output.replaygain.enable);
|
|
|
|
|
Check(IDC_ALBUM, flac_cfg.output.replaygain.album_mode);
|
|
|
|
|
Check(IDC_LIMITER, flac_cfg.output.replaygain.hard_limit);
|
|
|
|
|
Check(IDC_DITHER, flac_cfg.output.resolution.normal.dither_24_to_16);
|
|
|
|
|
Check(IDC_DITHERRG, flac_cfg.output.resolution.replaygain.dither);
|
2003-01-14 09:01:31 +00:00
|
|
|
// prepare preamp slider
|
2003-01-08 07:59:48 +00:00
|
|
|
{
|
|
|
|
|
HWND hamp = GetDlgItem(hwnd, IDC_PREAMP);
|
|
|
|
|
SendMessage(hamp, TBM_SETRANGE, 1, MAKELONG(0, PREAMP_RANGE*2));
|
|
|
|
|
SendMessage(hamp, TBM_SETPOS, 1, flac_cfg.output.replaygain.preamp+PREAMP_RANGE);
|
|
|
|
|
UpdatePreamp(hwnd, hamp);
|
|
|
|
|
}
|
2003-01-14 09:01:31 +00:00
|
|
|
// fill comboboxes
|
2003-01-08 07:59:48 +00:00
|
|
|
{
|
|
|
|
|
HWND hlist = GetDlgItem(hwnd, IDC_TO);
|
|
|
|
|
SendMessage(hlist, CB_ADDSTRING, 0, (LPARAM)"16 bps");
|
|
|
|
|
SendMessage(hlist, CB_ADDSTRING, 0, (LPARAM)"24 bps");
|
|
|
|
|
SendMessage(hlist, CB_SETCURSEL, flac_cfg.output.resolution.replaygain.bps_out/8 - 2, 0);
|
|
|
|
|
|
|
|
|
|
hlist = GetDlgItem(hwnd, IDC_SHAPE);
|
|
|
|
|
SendMessage(hlist, CB_ADDSTRING, 0, (LPARAM)"None");
|
|
|
|
|
SendMessage(hlist, CB_ADDSTRING, 0, (LPARAM)"Low");
|
|
|
|
|
SendMessage(hlist, CB_ADDSTRING, 0, (LPARAM)"Medium");
|
|
|
|
|
SendMessage(hlist, CB_ADDSTRING, 0, (LPARAM)"High");
|
|
|
|
|
SendMessage(hlist, CB_SETCURSEL, flac_cfg.output.resolution.replaygain.noise_shaping, 0);
|
|
|
|
|
}
|
2003-01-14 09:01:31 +00:00
|
|
|
UpdateRG(hwnd);
|
|
|
|
|
UpdateDither(hwnd);
|
2003-01-08 07:59:48 +00:00
|
|
|
return TRUE;
|
|
|
|
|
// commands
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
|
{
|
2003-01-14 09:01:31 +00:00
|
|
|
// ok
|
2003-01-08 07:59:48 +00:00
|
|
|
case IDOK:
|
|
|
|
|
flac_cfg.output.replaygain.enable = GetCheck(IDC_ENABLE);
|
|
|
|
|
flac_cfg.output.replaygain.album_mode = GetCheck(IDC_ALBUM);
|
|
|
|
|
flac_cfg.output.replaygain.hard_limit = GetCheck(IDC_LIMITER);
|
|
|
|
|
flac_cfg.output.replaygain.preamp = GetPos(IDC_PREAMP) - PREAMP_RANGE;
|
|
|
|
|
flac_cfg.output.resolution.normal.dither_24_to_16 = GetCheck(IDC_DITHER);
|
|
|
|
|
flac_cfg.output.resolution.replaygain.dither = GetCheck(IDC_DITHERRG);
|
|
|
|
|
flac_cfg.output.resolution.replaygain.noise_shaping = GetSel(IDC_SHAPE);
|
|
|
|
|
flac_cfg.output.resolution.replaygain.bps_out = (GetSel(IDC_TO)+2)*8;
|
2003-01-14 09:01:31 +00:00
|
|
|
break;
|
|
|
|
|
// reset
|
2003-01-08 07:59:48 +00:00
|
|
|
case IDC_RESET:
|
|
|
|
|
Check(IDC_ENABLE, 1);
|
|
|
|
|
Check(IDC_ALBUM, 0);
|
|
|
|
|
Check(IDC_LIMITER, 0);
|
|
|
|
|
Check(IDC_DITHER, 0);
|
|
|
|
|
Check(IDC_DITHERRG, 0);
|
|
|
|
|
|
|
|
|
|
SendDlgItemMessage(hwnd, IDC_PREAMP, TBM_SETPOS, 1, PREAMP_RANGE);
|
|
|
|
|
SendDlgItemMessage(hwnd, IDC_TO, CB_SETCURSEL, 0, 0);
|
|
|
|
|
SendDlgItemMessage(hwnd, IDC_SHAPE, CB_SETCURSEL, 1, 0);
|
2003-01-14 09:01:31 +00:00
|
|
|
|
|
|
|
|
UpdatePreamp(hwnd, GetDlgItem(hwnd, IDC_PREAMP));
|
|
|
|
|
UpdateRG(hwnd);
|
|
|
|
|
UpdateDither(hwnd);
|
|
|
|
|
break;
|
|
|
|
|
// active check-boxes
|
|
|
|
|
case IDC_ENABLE:
|
|
|
|
|
UpdateRG(hwnd);
|
|
|
|
|
break;
|
|
|
|
|
case IDC_DITHERRG:
|
|
|
|
|
UpdateDither(hwnd);
|
2003-01-08 07:59:48 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
// scroller
|
|
|
|
|
case WM_HSCROLL:
|
|
|
|
|
if (GetDlgCtrlID((HWND)lParam)==IDC_PREAMP)
|
|
|
|
|
UpdatePreamp(hwnd, (HWND)lParam);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-14 09:01:31 +00:00
|
|
|
#define NUM_PAGES 2
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
HWND htab;
|
|
|
|
|
HWND hdlg;
|
|
|
|
|
RECT r;
|
|
|
|
|
HWND all[NUM_PAGES];
|
|
|
|
|
} LOCALDATA;
|
|
|
|
|
|
|
|
|
|
static void ScreenToClientRect(HWND hwnd, RECT *rect)
|
|
|
|
|
{
|
|
|
|
|
POINT pt = { rect->left, rect->top };
|
|
|
|
|
ScreenToClient(hwnd, &pt);
|
|
|
|
|
rect->left = pt.x;
|
|
|
|
|
rect->top = pt.y;
|
|
|
|
|
|
|
|
|
|
pt.x = rect->right;
|
|
|
|
|
pt.y = rect->bottom;
|
|
|
|
|
ScreenToClient(hwnd, &pt);
|
|
|
|
|
rect->right = pt.x;
|
|
|
|
|
rect->bottom = pt.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void SendCommand(HWND hwnd, int command)
|
|
|
|
|
{
|
|
|
|
|
LOCALDATA *data = (LOCALDATA*)GetWindowLong(hwnd, GWL_USERDATA);
|
|
|
|
|
SendMessage(data->hdlg, WM_COMMAND, command, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void BroadcastCommand(HWND hwnd, int command)
|
|
|
|
|
{
|
|
|
|
|
LOCALDATA *data = (LOCALDATA*)GetWindowLong(hwnd, GWL_USERDATA);
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i=0; i<NUM_PAGES; i++)
|
|
|
|
|
SendMessage(data->all[i], WM_COMMAND, command, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void OnSelChange(HWND hwnd)
|
|
|
|
|
{
|
|
|
|
|
LOCALDATA *data = (LOCALDATA*)GetWindowLong(hwnd, GWL_USERDATA);
|
|
|
|
|
int index = TabCtrl_GetCurSel(data->htab);
|
|
|
|
|
if (index < 0) return;
|
|
|
|
|
// hide previous
|
|
|
|
|
if (data->hdlg)
|
|
|
|
|
ShowWindow(data->hdlg, SW_HIDE);
|
|
|
|
|
// display
|
|
|
|
|
data->hdlg = data->all[index];
|
|
|
|
|
SetWindowPos(data->hdlg, HWND_TOP, data->r.left, data->r.top, data->r.right-data->r.left, data->r.bottom-data->r.top, SWP_SHOWWINDOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
{
|
|
|
|
|
static activePage = 0;
|
|
|
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
|
{
|
|
|
|
|
// init
|
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
|
{
|
|
|
|
|
LOCALDATA *data = LocalAlloc(LPTR, sizeof(LOCALDATA));
|
|
|
|
|
HINSTANCE inst = (HINSTANCE)lParam;
|
|
|
|
|
TCITEM item;
|
|
|
|
|
|
|
|
|
|
// init
|
|
|
|
|
SetWindowLong(hwnd, GWL_USERDATA, (LONG)data);
|
|
|
|
|
data->htab = GetDlgItem(hwnd, IDC_TABS);
|
|
|
|
|
data->hdlg = NULL;
|
|
|
|
|
// add pages
|
|
|
|
|
item.mask = TCIF_TEXT;
|
|
|
|
|
data->all[0] = CreateDialog(inst, MAKEINTRESOURCE(IDD_CONFIG_GENERAL), hwnd, GeneralProc);
|
|
|
|
|
item.pszText = "General";
|
|
|
|
|
TabCtrl_InsertItem(data->htab, 0, &item);
|
|
|
|
|
|
|
|
|
|
data->all[1] = CreateDialog(inst, MAKEINTRESOURCE(IDD_CONFIG_OUTPUT), hwnd, OutputProc);
|
|
|
|
|
item.pszText = "Output";
|
|
|
|
|
TabCtrl_InsertItem(data->htab, 1, &item);
|
|
|
|
|
// get rect (after adding pages)
|
|
|
|
|
GetWindowRect(data->htab, &data->r);
|
|
|
|
|
ScreenToClientRect(hwnd, &data->r);
|
|
|
|
|
TabCtrl_AdjustRect(data->htab, 0, &data->r);
|
|
|
|
|
// simulate item change
|
|
|
|
|
TabCtrl_SetCurSel(data->htab, activePage);
|
|
|
|
|
OnSelChange(hwnd);
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
// destory
|
|
|
|
|
case WM_DESTROY:
|
|
|
|
|
{
|
|
|
|
|
LOCALDATA *data = (LOCALDATA*)GetWindowLong(hwnd, GWL_USERDATA);
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
activePage = TabCtrl_GetCurSel(data->htab);
|
|
|
|
|
|
|
|
|
|
for (i=0; i<NUM_PAGES; i++)
|
|
|
|
|
DestroyWindow(data->all[i]);
|
|
|
|
|
|
|
|
|
|
LocalFree(data);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
// commands
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
|
{
|
|
|
|
|
// ok/cancel
|
|
|
|
|
case IDOK:
|
|
|
|
|
BroadcastCommand(hwnd, IDOK);
|
|
|
|
|
/* fall through */
|
|
|
|
|
case IDCANCEL:
|
|
|
|
|
EndDialog(hwnd, LOWORD(wParam));
|
|
|
|
|
return TRUE;
|
|
|
|
|
case IDC_RESET:
|
|
|
|
|
SendCommand(hwnd, IDC_RESET);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
// notification
|
|
|
|
|
case WM_NOTIFY:
|
|
|
|
|
if (LOWORD(wParam) == IDC_TABS)
|
|
|
|
|
{
|
|
|
|
|
NMHDR *hdr = (NMHDR*)lParam;
|
|
|
|
|
|
|
|
|
|
switch (hdr->code)
|
|
|
|
|
{
|
|
|
|
|
case TCN_SELCHANGE:
|
|
|
|
|
OnSelChange(hwnd);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-08 07:59:48 +00:00
|
|
|
|
2003-01-14 09:01:31 +00:00
|
|
|
int DoConfig(HINSTANCE inst, HWND parent)
|
2003-01-08 07:59:48 +00:00
|
|
|
{
|
2003-01-14 09:01:31 +00:00
|
|
|
return DialogBoxParam(inst, MAKEINTRESOURCE(IDD_CONFIG), parent, DialogProc, (LONG)inst) == IDOK;
|
2003-01-08 07:59:48 +00:00
|
|
|
}
|