fixes to get winamp2 plugin to build on win32 again
authorJosh Coalson <jcoalson@users.sourceforce.net>
Sun, 30 Jan 2005 18:18:08 +0000 (18:18 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Sun, 30 Jan 2005 18:18:08 +0000 (18:18 +0000)
src/plugin_winamp2/config.c
src/plugin_winamp2/in_flac.c
src/plugin_winamp2/infobox.c
src/plugin_winamp2/infobox.h
src/plugin_winamp2/tagz.cpp
src/plugin_winamp2/tagz.h

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