fixes to get winamp2 plugin to build on win32 again
This commit is contained in:
parent
77d8e7fe28
commit
c2a9bbb0dc
@ -39,6 +39,20 @@ static char ini_name[MAX_PATH];
|
||||
static const char default_format[] = "[%artist% - ]$if2(%title%,%filename%)";
|
||||
static const char default_sep[] = ", ";
|
||||
|
||||
static wchar_t *convert_ansi_to_wide_(const char *src)
|
||||
{
|
||||
int len;
|
||||
wchar_t *dest;
|
||||
|
||||
FLAC__ASSERT(0 != src);
|
||||
|
||||
len = strlen(src) + 1;
|
||||
/* copy */
|
||||
dest = malloc(len*sizeof(wchar_t));
|
||||
if (dest) mbstowcs(dest, src, len);
|
||||
return dest;
|
||||
}
|
||||
|
||||
void InitConfig()
|
||||
{
|
||||
char *p;
|
||||
@ -56,7 +70,7 @@ void ReadConfig()
|
||||
RS(flac_cfg.title.tag_format, sizeof(flac_cfg.title.tag_format), default_format);
|
||||
if (flac_cfg.title.tag_format_w)
|
||||
free(flac_cfg.title.tag_format_w);
|
||||
flac_cfg.title.tag_format_w = FLAC_plugin__convert_ansi_to_wide(flac_cfg.title.tag_format);
|
||||
flac_cfg.title.tag_format_w = convert_ansi_to_wide_(flac_cfg.title.tag_format);
|
||||
/* @@@ FIXME: trailing spaces */
|
||||
RS(flac_cfg.title.sep, sizeof(flac_cfg.title.sep), default_sep);
|
||||
RI(flac_cfg.tag.reserve_space, 1);
|
||||
@ -129,7 +143,7 @@ static INT_PTR CALLBACK GeneralProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l
|
||||
if (flac_cfg.title.tag_format_w)
|
||||
free(flac_cfg.title.tag_format_w);
|
||||
GetDlgItemText(hwnd, IDC_SEP, flac_cfg.title.sep, sizeof(flac_cfg.title.sep));
|
||||
flac_cfg.title.tag_format_w = FLAC_plugin__convert_ansi_to_wide(flac_cfg.title.tag_format);
|
||||
flac_cfg.title.tag_format_w = convert_ansi_to_wide_(flac_cfg.title.tag_format);
|
||||
|
||||
/*! flac_cfg.tag.reserve_space = GetCheck(IDC_RESERVE); */
|
||||
flac_cfg.display.show_bps = GetCheck(IDC_BPS);
|
||||
|
@ -265,35 +265,59 @@ static DWORD WINAPI DecodeThread(void *unused)
|
||||
* title formatting
|
||||
*/
|
||||
|
||||
static const T_CHAR *get_tag(const T_CHAR *tag, void *param)
|
||||
static T_CHAR *get_tag(const T_CHAR *tag, void *param)
|
||||
{
|
||||
FLAC__StreamMetadata *tags = (FLAC__StreamMetadata*)param;
|
||||
const T_CHAR *val = FLAC_plugin__tags_get_tag_ucs2(tags, tag);
|
||||
char *tagname, *p;
|
||||
T_CHAR *val;
|
||||
|
||||
if (!tag)
|
||||
return 0;
|
||||
/* Vorbis comment names must be ASCII, so convert 'tag' first */
|
||||
tagname = malloc(wcslen(tag)+1);
|
||||
for(p=tagname;*tag;) {
|
||||
if(*tag > 0x7d) {
|
||||
free(tagname);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
*p++ = (char)(*tag++);
|
||||
}
|
||||
*p++ = '\0';
|
||||
/* now get it */
|
||||
val = FLAC_plugin__tags_get_tag_ucs2(tags, tagname);
|
||||
free(tagname);
|
||||
/* some "user friendly cheavats" */
|
||||
if (!val)
|
||||
{
|
||||
if (!wcsicmp(tag, L"ARTIST"))
|
||||
{
|
||||
val = FLAC_plugin__tags_get_tag_ucs2(tags, "PERFORMER");
|
||||
if (!val) val = FLAC_plugin__tags_get_tag_ucs2(tags, L"COMPOSER");
|
||||
if (!val) val = FLAC_plugin__tags_get_tag_ucs2(tags, "COMPOSER");
|
||||
}
|
||||
else if (!wcsicmp(tag, L"YEAR") || !wcsicmp(tag, L"DATE"))
|
||||
{
|
||||
val = FLAC_plugin__tags_get_tag_ucs2(tags, L"YEAR_RECORDED");
|
||||
if (!val) val = FLAC_plugin__tags_get_tag_ucs2(tags, L"YEAR_PERFORMED");
|
||||
val = FLAC_plugin__tags_get_tag_ucs2(tags, "YEAR_RECORDED");
|
||||
if (!val) val = FLAC_plugin__tags_get_tag_ucs2(tags, "YEAR_PERFORMED");
|
||||
}
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static void free_tag(T_CHAR *tag, void *param)
|
||||
{
|
||||
(void)param;
|
||||
free(tag);
|
||||
}
|
||||
|
||||
static void format_title(const char *filename, WCHAR *title, unsigned max_size)
|
||||
{
|
||||
FLAC__StreamMetadata *tags;
|
||||
|
||||
ReadTags(filename, &tags, /*forDisplay=*/true);
|
||||
|
||||
tagz_format(flac_cfg.title.tag_format_w, get_tag, free, tags, title, max_size);
|
||||
tagz_format(flac_cfg.title.tag_format_w, get_tag, free_tag, tags, title, max_size);
|
||||
|
||||
FLAC_plugin__tags_destroy(&tags);
|
||||
}
|
||||
@ -327,7 +351,8 @@ static void getfileinfo(char *filename, char *title, int *length_in_msec)
|
||||
}
|
||||
|
||||
if (length_in_msec)
|
||||
*length_in_msec = (int)((double)streaminfo.data.stream_info.total_samples / (double)streaminfo.data.stream_info.sample_rate * 1000.0 + 0.5);
|
||||
/* with VC++ you have to spoon feed it the casting from uint64->int64->double */
|
||||
*length_in_msec = (int)((double)(FLAC__int64)streaminfo.data.stream_info.total_samples / (double)streaminfo.data.stream_info.sample_rate * 1000.0 + 0.5);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -28,7 +28,7 @@
|
||||
typedef struct
|
||||
{
|
||||
char filename[MAX_PATH];
|
||||
FLAC__StreamMetadata tags;
|
||||
FLAC__StreamMetadata *tags;
|
||||
} LOCALDATA;
|
||||
|
||||
static char buffer[8192];
|
||||
@ -201,7 +201,7 @@ static wchar_t *AnsiToWide(const char *src)
|
||||
if (*buffer) { ucs2 = AnsiToWide(buffer); FLAC_plugin__tags_set_tag_ucs2(data->tags, y, ucs2, /*replace_all=*/false); free(ucs2); } \
|
||||
else FLAC_plugin__tags_delete_tag(data->tags, y)
|
||||
|
||||
#define SetTextW(x,y) ucs2 = FLAC_plugin__tags_get_tag_ucs2(data->tags, y)); \
|
||||
#define SetTextW(x,y) ucs2 = FLAC_plugin__tags_get_tag_ucs2(data->tags, y); \
|
||||
SetDlgItemTextW(hwnd, x, ucs2); \
|
||||
free(ucs2)
|
||||
|
||||
@ -232,8 +232,8 @@ static BOOL InitInfoboxInfo(HWND hwnd, const char *file)
|
||||
length = (DWORD)(streaminfo.data.stream_info.total_samples / streaminfo.data.stream_info.sample_rate);
|
||||
bps = (DWORD)(filesize / (125*streaminfo.data.stream_info.total_samples/streaminfo.data.stream_info.sample_rate));
|
||||
ratio = bps*1000000 / (streaminfo.data.stream_info.sample_rate*streaminfo.data.stream_info.channels*streaminfo.data.stream_info.bits_per_sample);
|
||||
rg = FLAC_plugin__tags_get_tag_utf8(data->tags, L"REPLAYGAIN_TRACK_GAIN") ? 1 : 0;
|
||||
rg |= FLAC_plugin__tags_get_tag_utf8(data->tags, L"REPLAYGAIN_ALBUM_GAIN") ? 2 : 0;
|
||||
rg = FLAC_plugin__tags_get_tag_utf8(data->tags, "REPLAYGAIN_TRACK_GAIN") ? 1 : 0;
|
||||
rg |= FLAC_plugin__tags_get_tag_utf8(data->tags, "REPLAYGAIN_ALBUM_GAIN") ? 2 : 0;
|
||||
|
||||
sprintf(buffer, "Sample rate: %d Hz\nChannels: %d\nBits per sample: %d\nMin block size: %d\nMax block size: %d\n"
|
||||
"File size: %I64d bytes\nTotal samples: %I64d\nLength: %d:%02d\nAvg. bitrate: %d\nCompression ratio: %d.%d%%\n"
|
||||
@ -414,7 +414,7 @@ static __inline char *GetFileName(const char *fullname)
|
||||
|
||||
void ReadTags(const char *fileName, FLAC__StreamMetadata **tags, BOOL forDisplay)
|
||||
{
|
||||
if(FLAC_plugin__tags_get(fileName, tags, forDisplay ? flac_cfg.title.sep : NULL)) {
|
||||
if(FLAC_plugin__tags_get(fileName, tags)) {
|
||||
|
||||
/* add file name */
|
||||
if (forDisplay)
|
||||
@ -422,13 +422,13 @@ void ReadTags(const char *fileName, FLAC__StreamMetadata **tags, BOOL forDisplay
|
||||
char *c;
|
||||
wchar_t *ucs2;
|
||||
ucs2 = AnsiToWide(fileName);
|
||||
FLAC_plugin__tags_set_tag_ucs2(*tags, "filepath", ucs2);
|
||||
FLAC_plugin__tags_set_tag_ucs2(*tags, "filepath", ucs2, /*replace_all=*/true);
|
||||
free(ucs2);
|
||||
|
||||
strcpy(buffer, GetFileName(fileName));
|
||||
if (c = strrchr(buffer, '.')) *c = 0;
|
||||
ucs2 = AnsiToWide(buffer);
|
||||
FLAC_plugin__tags_set_tag_ucs2(*tags, "filename", ucs2);
|
||||
FLAC_plugin__tags_set_tag_ucs2(*tags, "filename", ucs2, /*replace_all=*/true);
|
||||
free(ucs2);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
ULONGLONG FileSize(const char *fileName);
|
||||
void ReadTags(const char *fileName, FLAC_Plugin__CanonicalTag *tag, BOOL forDisplay);
|
||||
void ReadTags(const char *fileName, FLAC__StreamMetadata **tags, BOOL forDisplay);
|
||||
|
||||
void InitInfobox();
|
||||
void DeinitInfobox();
|
||||
|
@ -737,7 +737,7 @@ private:
|
||||
while(*s1 && *s1!='%') s1++;
|
||||
if (!*s1) {Error();break;}
|
||||
*s1=0;
|
||||
const T_CHAR * tag=f(spec,fp);
|
||||
T_CHAR * tag=f(spec,fp);
|
||||
*s1='%';
|
||||
/*if (!tag) tag=tag_unknown; */
|
||||
if (tag && tag[0])
|
||||
|
@ -14,8 +14,8 @@ typedef unsigned short T_CHAR;
|
||||
#define T_CHAR char
|
||||
#endif
|
||||
|
||||
typedef const T_CHAR* (*TAGFUNC)(const T_CHAR *tag,void *p); /* return 0 if not found */
|
||||
typedef void (*TAGFREEFUNC)(const T_CHAR *tag,void *p);
|
||||
typedef T_CHAR* (*TAGFUNC)(const T_CHAR *tag,void *p); /* return 0 if not found */
|
||||
typedef void (*TAGFREEFUNC)(T_CHAR *tag,void *p);
|
||||
|
||||
|
||||
UINT tagz_format(const T_CHAR * spec,TAGFUNC f,TAGFREEFUNC ff,void *fp,T_CHAR * out,UINT max);
|
||||
|
Loading…
x
Reference in New Issue
Block a user