1 /* EasyTAG - Tag editor for audio files
2  * Copyright (C) 2014  David King <amigadave@amigadave.com>
3  * Copyright (C) 2001-2003  Jerome Couderc <easytag@gmail.com>
4  * Copyright (C) 2002-2003  Artur Polaczyñski <artii@o2.pl>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "config.h"
22 
23 #include <glib/gi18n.h>
24 
25 #include "et_core.h"
26 #include "misc.h"
27 #include "musepack_header.h"
28 #include "libapetag/info_mpc.h"
29 
30 gboolean
et_mpc_header_read_file_info(GFile * file,ET_File_Info * ETFileInfo,GError ** error)31 et_mpc_header_read_file_info (GFile *file,
32                               ET_File_Info *ETFileInfo,
33                               GError **error)
34 {
35     StreamInfoMpc Info;
36 
37     g_return_val_if_fail (file != NULL && ETFileInfo != NULL, FALSE);
38     g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
39 
40     if (!info_mpc_read (file, &Info, error))
41     {
42         return FALSE;
43     }
44 
45     ETFileInfo->mpc_profile = g_strdup(Info.ProfileName);
46     ETFileInfo->version     = Info.StreamVersion;
47     ETFileInfo->bitrate     = Info.Bitrate/1000.0;
48     ETFileInfo->samplerate  = Info.SampleFreq;
49     ETFileInfo->mode        = Info.Channels;
50     ETFileInfo->size        = Info.FileSize;
51     ETFileInfo->duration    = Info.Duration/1000;
52     ETFileInfo->mpc_version = g_strdup_printf("%s",Info.Encoder);
53 
54     return TRUE;
55 }
56 
57 EtFileHeaderFields *
et_mpc_header_display_file_info_to_ui(const ET_File * ETFile)58 et_mpc_header_display_file_info_to_ui (const ET_File *ETFile)
59 {
60     EtFileHeaderFields *fields;
61     ET_File_Info *info;
62     gchar *time  = NULL;
63     gchar *time1 = NULL;
64     gchar *size  = NULL;
65     gchar *size1 = NULL;
66 
67     info = ETFile->ETFileInfo;
68     fields = g_slice_new (EtFileHeaderFields);
69 
70     fields->description = _("MusePack File");
71 
72     /* Mode changed to profile name  */
73     fields->mode_label = _("Profile:");
74     fields->mode = g_strdup_printf ("%s (SV%d)", info->mpc_profile,
75                                     info->version);
76 
77     /* Bitrate */
78     fields->bitrate = g_strdup_printf (_("%d kb/s"), info->bitrate);
79 
80     /* Samplerate */
81     fields->samplerate = g_strdup_printf (_("%d Hz"), info->samplerate);
82 
83     /* Version changed to encoder version */
84     fields->version_label = _("Encoder:");
85     fields->version = info->mpc_version;
86 
87     /* Size */
88     size = g_format_size (info->size);
89     size1 = g_format_size (ETCore->ETFileDisplayedList_TotalSize);
90     fields->size = g_strdup_printf ("%s (%s)", size, size1);
91     g_free (size);
92     g_free (size1);
93 
94     /* Duration */
95     time = Convert_Duration (info->duration);
96     time1 = Convert_Duration (ETCore->ETFileDisplayedList_TotalDuration);
97     fields->duration = g_strdup_printf ("%s (%s)", time, time1);
98     g_free (time);
99     g_free (time1);
100 
101     return fields;
102 }
103 
104 void
et_mpc_file_header_fields_free(EtFileHeaderFields * fields)105 et_mpc_file_header_fields_free (EtFileHeaderFields *fields)
106 {
107     g_return_if_fail (fields != NULL);
108 
109     g_free (fields->mode);
110     g_free (fields->bitrate);
111     g_free (fields->samplerate);
112     g_free (fields->size);
113     g_free (fields->duration);
114     g_slice_free (EtFileHeaderFields, fields);
115 }
116