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 "monkeyaudio_header.h"
28 #include "libapetag/info_mac.h"
29 
30 gboolean
et_mac_header_read_file_info(GFile * file,ET_File_Info * ETFileInfo,GError ** error)31 et_mac_header_read_file_info (GFile *file,
32                               ET_File_Info *ETFileInfo,
33                               GError **error)
34 {
35     StreamInfoMac 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_mac_read (file, &Info, error))
41     {
42         return FALSE;
43     }
44 
45     ETFileInfo->mpc_profile   = g_strdup(Info.CompresionName);
46     ETFileInfo->version       = Info.Version;
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 
53     return TRUE;
54 }
55 
56 EtFileHeaderFields *
et_mac_header_display_file_info_to_ui(const ET_File * ETFile)57 et_mac_header_display_file_info_to_ui (const ET_File *ETFile)
58 {
59     EtFileHeaderFields *fields;
60     ET_File_Info *info;
61     gchar *time  = NULL;
62     gchar *time1 = NULL;
63     gchar *size  = NULL;
64     gchar *size1 = NULL;
65 
66     info = ETFile->ETFileInfo;
67     fields = g_slice_new (EtFileHeaderFields);
68 
69     fields->description = _("Monkey's Audio File");
70 
71     /* Mode changed to profile name  */
72     fields->mode_label = _("Profile:");
73     fields->mode = info->mpc_profile;
74 
75     /* Bitrate */
76     fields->bitrate = g_strdup_printf (_("%d kb/s"), info->bitrate);
77 
78     /* Samplerate */
79     fields->samplerate = g_strdup_printf (_("%d Hz"), info->samplerate);
80 
81     /* Version changed to encoder version */
82     fields->version_label = _("Encoder:");
83     fields->version = g_strdup_printf ("%i.%i", info->version / 1000,
84                                        info->version % 1000);
85 
86     /* Size */
87     size = g_format_size (info->size);
88     size1 = g_format_size (ETCore->ETFileDisplayedList_TotalSize);
89     fields->size = g_strdup_printf ("%s (%s)", size, size1);
90     g_free (size);
91     g_free (size1);
92 
93     /* Duration */
94     time = Convert_Duration (info->duration);
95     time1 = Convert_Duration (ETCore->ETFileDisplayedList_TotalDuration);
96     fields->duration = g_strdup_printf ("%s (%s)", time, time1);
97     g_free (time);
98     g_free (time1);
99 
100     return fields;
101 }
102 
103 void
et_mac_file_header_fields_free(EtFileHeaderFields * fields)104 et_mac_file_header_fields_free (EtFileHeaderFields *fields)
105 {
106     g_return_if_fail (fields != NULL);
107 
108     g_free (fields->bitrate);
109     g_free (fields->samplerate);
110     g_free (fields->version);
111     g_free (fields->size);
112     g_free (fields->duration);
113     g_slice_free (EtFileHeaderFields, fields);
114 }
115