-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtk-column-taglib-samplingrate.c
95 lines (79 loc) · 2.71 KB
/
gtk-column-taglib-samplingrate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* gtk-column-taglib-samplingrate.c
*
* Copyright (C) 2016 Alessandro Grassi <alessandro.g89@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include <libfm/fm.h>
#include <libfm/fm-gtk.h>
#include <taglib/tag_c.h>
FM_DEFINE_MODULE(gtk_folder_col, taglib_samplingrate)
GType get_type() { return G_TYPE_STRING; };
void get_value(FmFileInfo *fi, GValue *value){
char* filename;
int samplingrate;
char samplingrate_string[15];
TagLib_File *TL_file;
filename = fm_path_to_str( fm_file_info_get_path(fi) );
TL_file = taglib_file_new( filename );
free( filename );
if (TL_file != NULL) {
if(taglib_file_is_valid(TL_file)){
const TagLib_AudioProperties *TL_props = taglib_file_audioproperties( TL_file );
samplingrate = taglib_audioproperties_samplerate( TL_props );
sprintf( samplingrate_string, "%d Hz", samplingrate );
g_value_set_string( value, samplingrate_string );
taglib_tag_free_strings();
taglib_file_free( TL_file );
}
}
};
gint sort(FmFileInfo *fi1, FmFileInfo *fi2){
char *filename1, *filename2;
int samplingrate1 = 0, samplingrate2 = 0;
TagLib_File *TL_file1, *TL_file2;
filename1 = fm_path_to_str( fm_file_info_get_path(fi1) );
filename2 = fm_path_to_str( fm_file_info_get_path(fi2) );
TL_file1 = taglib_file_new( filename1 );
TL_file2 = taglib_file_new( filename2 );
free( filename1 );
free( filename2 );
if (TL_file1 != NULL) {
if(taglib_file_is_valid(TL_file1)){
const TagLib_AudioProperties *TL_props = taglib_file_audioproperties( TL_file1 );
samplingrate1 = taglib_audioproperties_samplerate( TL_props );
taglib_tag_free_strings();
taglib_file_free( TL_file1 );
}
}
if (TL_file2 != NULL) {
if(taglib_file_is_valid(TL_file2)){
const TagLib_AudioProperties *TL_props = taglib_file_audioproperties( TL_file2 );
samplingrate2 = taglib_audioproperties_samplerate( TL_props );
taglib_tag_free_strings();
taglib_file_free( TL_file2 );
}
}
return samplingrate1 - samplingrate2;
}
FmFolderModelColumnInit fm_module_init_gtk_folder_col = {
"Sampling rate",
0,
&get_type,
&get_value,
&sort
};