shithub: aacdec

Download patch

ref: 7fdb7f1ee9faa796a2a615fe2450273c6340ef53
parent: 6f3fe7ef4467047775b03ee52671d73c82b5cdec
author: menno <menno>
date: Wed Sep 3 16:19:07 EDT 2003

in_mp4: title formatting

--- a/plugins/in_mp4/config.c
+++ b/plugins/in_mp4/config.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: config.c,v 1.5 2003/08/03 18:00:14 menno Exp $
+** $Id: config.c,v 1.6 2003/09/03 20:19:07 menno Exp $
 **/
 
 #define WIN32_LEAN_AND_MEAN
@@ -37,6 +37,7 @@
 int m_use_for_aac = 1;
 int m_downmix = 0;
 int m_vbr_display = 0;
+char titleformat[MAX_PATH];
 
 void _r_s(char *name,char *data, int mlen)
 {
--- a/plugins/in_mp4/config.h
+++ b/plugins/in_mp4/config.h
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: config.h,v 1.5 2003/08/03 18:00:15 menno Exp $
+** $Id: config.h,v 1.6 2003/09/03 20:19:07 menno Exp $
 **/
 
 char app_name[];
@@ -33,6 +33,7 @@
 int m_use_for_aac;
 int m_downmix;
 int m_vbr_display;
+char titleformat[MAX_PATH];
 
 #define RS(x) (_r_s(#x,x,sizeof(x)))
 #define WS(x) (WritePrivateProfileString(app_name,#x,x,INI_FILE))
--- a/plugins/in_mp4/in_mp4.c
+++ b/plugins/in_mp4/in_mp4.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: in_mp4.c,v 1.38 2003/08/03 18:00:15 menno Exp $
+** $Id: in_mp4.c,v 1.39 2003/09/03 20:19:07 menno Exp $
 **/
 
 //#define DEBUG_OUTPUT
@@ -181,6 +181,7 @@
     strcpy(use_for_aac, "1");
     strcpy(downmix, "0");
     strcpy(vbr_display, "1");
+    strcpy(titleformat, "%7");
 
     RS(priority);
     RS(resolution);
@@ -188,6 +189,7 @@
     RS(use_for_aac);
     RS(downmix);
     RS(vbr_display);
+    RS(titleformat);
 
     m_priority = atoi(priority);
     m_resolution = atoi(resolution);
@@ -219,6 +221,7 @@
     WS(use_for_aac);
     WS(downmix);
     WS(vbr_display);
+    WS(titleformat);
 }
 
 void init()
@@ -538,7 +541,119 @@
 
     return 0;
 }
+/* Get the title from the file */
+void ConstructTitle(MP4FileHandle file, char *filename, char *title, char *format)
+{
+    int some_info = 0;
+    char *in = format;
+    char *out = title;
+    char *bound = out + (MAX_PATH - 10 - 1);
+    char *pVal, dummy1[1024];
+    short dummy, dummy2;
 
+
+    while (*in && out < bound)
+    {
+        switch (*in)
+        {
+        case '%':
+            ++in;
+            break;
+
+        default:
+            *out++ = *in++;
+            continue;
+        }
+
+        /* handle % escape sequence */
+        switch (*in++)
+        {
+        case '0':
+            dummy = 0; dummy2 = 0;
+            if (MP4GetMetadataTrack(file, &dummy, &dummy2))
+            {
+                wsprintf(dummy1, "%d", dummy);
+                lstrcpy(out, dummy1); out += lstrlen(dummy1);
+                some_info = 1;
+            }
+            break;
+
+        case '1':
+            pVal = NULL;
+            if (MP4GetMetadataArtist(file, &pVal))
+            {
+                lstrcpy(out, pVal); out += lstrlen(pVal);
+                some_info = 1;
+            }
+            break;
+
+        case '2':
+            pVal = NULL;
+            if (MP4GetMetadataName(file, &pVal))
+            {
+                lstrcpy(out, pVal); out += lstrlen(pVal);
+                some_info = 1;
+            }
+            break;
+
+        case '3':
+            pVal = NULL;
+            if (MP4GetMetadataAlbum(file, &pVal))
+            {
+                lstrcpy(out, pVal); out += lstrlen(pVal);
+                some_info = 1;
+            }
+            break;
+
+        case '4':
+            pVal = NULL;
+            if (MP4GetMetadataYear(file, &pVal))
+            {
+                lstrcpy(out, pVal); out += lstrlen(pVal);
+                some_info = 1;
+            }
+            break;
+
+        case '5':
+            pVal = NULL;
+            if (MP4GetMetadataComment(file, &pVal))
+            {
+                lstrcpy(out, pVal); out += lstrlen(pVal);
+                some_info = 1;
+            }
+            break;
+
+        case '6':
+            pVal = NULL;
+            if (MP4GetMetadataGenre(file, &pVal))
+            {
+                lstrcpy(out, pVal); out += lstrlen(pVal);
+                some_info = 1;
+            }
+            break;
+
+        case '7':
+            {
+                char *p=filename+lstrlen(filename);
+                int len = 0;
+                while (*p != '\\' && p >= filename) { p--; len++; }
+                lstrcpy(out, ++p); out += len;
+                some_info = 1;
+                break;
+            }
+        }
+    }
+
+    *out = '\0';
+
+    if (!some_info)
+    {
+        char *p=filename+lstrlen(filename);
+        while (*p != '\\' && p >= filename) p--;
+        lstrcpy(title,++p);
+    }
+}
+
 BOOL CALLBACK config_dialog_proc(HWND hwndDlg, UINT message,
                                  WPARAM wParam, LPARAM lParam)
 {
@@ -557,6 +672,7 @@
             SendMessage(GetDlgItem(hwndDlg, IDC_DOWNMIX), BM_SETCHECK, BST_CHECKED, 0);
         if (m_vbr_display)
             SendMessage(GetDlgItem(hwndDlg, IDC_VBR), BM_SETCHECK, BST_CHECKED, 0);
+        SetDlgItemText(hwndDlg, IDC_TITLEFORMAT, titleformat);
         return TRUE;
 
     case WM_COMMAND:
@@ -569,6 +685,7 @@
             m_use_for_aac = SendMessage(GetDlgItem(hwndDlg, IDC_USEFORAAC), BM_GETCHECK, 0, 0);
             m_downmix = SendMessage(GetDlgItem(hwndDlg, IDC_DOWNMIX), BM_GETCHECK, 0, 0);
             m_vbr_display = SendMessage(GetDlgItem(hwndDlg, IDC_VBR), BM_GETCHECK, 0, 0);
+            GetDlgItemText(hwndDlg, IDC_TITLEFORMAT, titleformat, MAX_PATH);
 
             m_priority = SendMessage(GetDlgItem(hwndDlg, IDC_PRIORITY), TBM_GETPOS, 0, 0);
             for (i = 0; i < 6; i++)
@@ -1266,11 +1383,16 @@
 
         if (title)
         {
-            char *tmp2;
-            char *tmp = PathFindFileName(mp4state.filename);
-            strcpy(title, tmp);
-            tmp2 = strrchr(title, '.');
-            tmp2[0] = '\0';
+            if (mp4state.filetype == 0)
+            {
+                ConstructTitle(mp4state.mp4file, mp4state.filename, title, titleformat);
+            } else {
+                char *tmp2;
+                char *tmp = PathFindFileName(mp4state.filename);
+                strcpy(title, tmp);
+                tmp2 = strrchr(title, '.');
+                tmp2[0] = '\0';
+            }
         }
     } else {
         if (length_in_ms)
@@ -1278,11 +1400,18 @@
 
         if (title)
         {
-            char *tmp2;
-            char *tmp = PathFindFileName(filename);
-            strcpy(title, tmp);
-            tmp2 = strrchr(title, '.');
-            tmp2[0] = '\0';
+            MP4FileHandle file = MP4_INVALID_FILE_HANDLE;
+            if (!(file = MP4Read(filename, 0)))
+            {
+                char *tmp2;
+                char *tmp = PathFindFileName(filename);
+                strcpy(title, tmp);
+                tmp2 = strrchr(title, '.');
+                tmp2[0] = '\0';
+            } else {
+                ConstructTitle(file, filename, title, titleformat);
+                MP4Close(file);
+            }
         }
     }
 }
--- a/plugins/in_mp4/in_mp4.rc
+++ b/plugins/in_mp4/in_mp4.rc
@@ -94,7 +94,7 @@
     LTEXT           "of",IDC_STATIC11,257,127,8,14,SS_CENTERIMAGE
 END
 
-IDD_CONFIG DIALOG DISCARDABLE  0, 0, 233, 95
+IDD_CONFIG DIALOG DISCARDABLE  0, 0, 233, 166
 STYLE DS_MODALFRAME | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Configuration"
 FONT 8, "MS Sans Serif"
@@ -117,13 +117,23 @@
                     WS_TABSTOP,152,39,55,10
     CONTROL         "Show errors",IDC_ERROR,"Button",BS_AUTOCHECKBOX | 
                     WS_TABSTOP,152,52,53,10
-    DEFPUSHBUTTON   "OK",IDOK,122,74,50,14
-    PUSHBUTTON      "Cancel",IDCANCEL,61,74,50,14
+    EDITTEXT        IDC_TITLEFORMAT,14,86,121,14,ES_AUTOHSCROLL
+    DEFPUSHBUTTON   "OK",IDOK,176,145,50,14
+    PUSHBUTTON      "Cancel",IDCANCEL,176,125,50,14
     GROUPBOX        "Priority",IDC_STATIC,7,7,57,58
     LTEXT           "Highest",IDC_STATIC,34,18,25,8
     LTEXT           "Normal",IDC_STATIC,34,35,23,8
     LTEXT           "Lowest",IDC_STATIC,34,52,24,8
     GROUPBOX        "Resolution",IDC_STATIC,71,7,73,58
+    GROUPBOX        "Title format",IDC_STATIC,7,72,137,87
+    LTEXT           "%0 - Track",IDC_STATIC,17,109,35,8
+    LTEXT           "%1 - Artist",IDC_STATIC,17,120,32,8
+    LTEXT           "%2 - Title",IDC_STATIC,17,131,30,8
+    LTEXT           "%3 - Album",IDC_STATIC,17,142,36,8
+    LTEXT           "%4 - Year",IDC_STATIC,68,109,31,8
+    LTEXT           "%5 - Comment",IDC_STATIC,68,120,46,8
+    LTEXT           "%6 - Genre",IDC_STATIC,68,131,36,8
+    LTEXT           "%7 - Filename",IDC_STATIC,68,142,44,8
 END
 
 
@@ -148,7 +158,7 @@
         LEFTMARGIN, 7
         RIGHTMARGIN, 226
         TOPMARGIN, 7
-        BOTTOMMARGIN, 88
+        BOTTOMMARGIN, 159
     END
 END
 #endif    // APSTUDIO_INVOKED
--- a/plugins/in_mp4/resource.h
+++ b/plugins/in_mp4/resource.h
@@ -54,6 +54,7 @@
 #define IDC_STATIC12                    1036
 #define IDC_DOWNMIX                     1038
 #define IDC_VBR                         1039
+#define IDC_TITLEFORMAT                 1040
 
 // Next default values for new objects
 // 
@@ -61,7 +62,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        103
 #define _APS_NEXT_COMMAND_VALUE         40001
-#define _APS_NEXT_CONTROL_VALUE         1040
+#define _APS_NEXT_CONTROL_VALUE         1041
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif