annotate src/musepack/libmpc.cxx @ 472:69b8baad0b24 trunk

[svn] - stuff from vfs_get_metadata is already strdup'd
author nenolod
date Sun, 21 Jan 2007 02:16:17 -0800
parents a157306caf03
children 1e987b380776
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
1 #include "libmpc.h"
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
2
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
3 #define FORCED_THREAD_STACKSIZE 1024 * 1000
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
4 #define REMOVE_NONEXISTANT_TAG(x) if (!*x) { x = NULL; }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
5
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
6 using TagLib::MPC::File;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
7 using TagLib::Tag;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
8 using TagLib::String;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
9 using TagLib::APE::ItemListMap;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
10
372
a157306caf03 [svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents: 368
diff changeset
11 gchar *mpc_fmts[] = { "mpc", NULL };
a157306caf03 [svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents: 368
diff changeset
12
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
13 InputPlugin MpcPlugin = {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
14 NULL, //File Handle FILE* handle
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
15 NULL, //Filename char* filename
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
16 NULL, //Name of Plugin char* filename
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
17 mpcOpenPlugin, //Open Plugin [CALLBACK]
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
18 mpcAboutBox, //Show About box [CALLBACK]
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
19 mpcConfigBox, //Show Configure box [CALLBACK]
260
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
20 mpcIsOurFile, //Check if it's our file [CALLBACK]
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
21 NULL, //Scan the directory [UNUSED]
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
22 mpcPlay, //Play [CALLBACK]
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
23 mpcStop, //Stop [CALLBACK]
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
24 mpcPause, //Pause [CALLBACK]
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
25 mpcSeek, //Seek [CALLBACK]
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
26 NULL, //Set EQ [CALLBACK]
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
27 mpcGetTime, //Get Time [CALLBACK]
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
28 NULL, //Get Volume [UNUSED]
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
29 NULL, //Set Volume [UNUSED]
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
30 NULL, //Close Plugin [UNUSED]
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
31 NULL, //Obsolete [UNUSED]
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
32 NULL, //Visual plugins add_vis_pcm(int time, AFormat fmt, int nch, int length, void *ptr)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
33 NULL, //Set Info Settings set_info(char *title, int length, int rate, int freq, int nch)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
34 NULL, //set Info Text set_info_text(char* text)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
35 mpcGetSongInfo, //Get Title String callback [CALLBACK]
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
36 mpcFileInfoBox, //Show File Info Box [CALLBACK]
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
37 NULL, //Output Plugin Handle OutputPlugin output
254
cdf9756d1528 [svn] Port to NewVFS file probe.
chainsaw
parents: 232
diff changeset
38 mpcGetSongTuple,//Acquire tuple for song [CALLBACK]
cdf9756d1528 [svn] Port to NewVFS file probe.
chainsaw
parents: 232
diff changeset
39 NULL,
cdf9756d1528 [svn] Port to NewVFS file probe.
chainsaw
parents: 232
diff changeset
40 NULL,
cdf9756d1528 [svn] Port to NewVFS file probe.
chainsaw
parents: 232
diff changeset
41 mpcIsOurFD,
372
a157306caf03 [svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents: 368
diff changeset
42 mpc_fmts
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
43 };
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
44
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
45 extern "C"
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
46 InputPlugin* get_iplugin_info()
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
47 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
48 MpcPlugin.description = g_strdup_printf("Musepack Audio Plugin");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
49 return &MpcPlugin;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
50 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
51
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
52 static PluginConfig pluginConfig = {0};
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
53 static Widgets widgets = {0};
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
54 static MpcDecoder mpcDecoder = {0};
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
55 static TrackInfo track = {0};
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
56
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
57 static GThread *threadHandle;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
58 GStaticMutex threadMutex = G_STATIC_MUTEX_INIT;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
59
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
60 /*
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
61 * VFS callback implementation, adapted from mpc_reader.c.
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
62 * This _IS_ very sick, but it works. -nenolod
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
63 */
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
64 static mpc_int32_t
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
65 vfs_fread_impl(void *data, void *ptr, mpc_int32_t size)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
66 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
67 mpc_reader_file *d = (mpc_reader_file *) data;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
68 VFSFile *file = (VFSFile *) d->file;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
69
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
70 return (mpc_int32_t) vfs_fread(ptr, 1, size, file);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
71 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
72
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
73 static mpc_bool_t
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
74 vfs_fseek_impl(void *data, mpc_int32_t offset)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
75 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
76 mpc_reader_file *d = (mpc_reader_file *) data;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
77 VFSFile *file = (VFSFile *) d->file;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
78
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
79 return d->is_seekable ? vfs_fseek(file, offset, SEEK_SET) == 0 : FALSE;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
80 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
81
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
82 static mpc_int32_t
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
83 vfs_ftell_impl(void *data)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
84 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
85 mpc_reader_file *d = (mpc_reader_file *) data;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
86 VFSFile *file = (VFSFile *) d->file;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
87
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
88 return vfs_ftell(file);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
89 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
90
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
91 static mpc_int32_t
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
92 vfs_getsize_impl(void *data)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
93 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
94 mpc_reader_file *d = (mpc_reader_file *) data;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
95
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
96 return d->file_size;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
97 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
98
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
99 static mpc_bool_t
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
100 vfs_canseek_impl(void *data)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
101 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
102 mpc_reader_file *d = (mpc_reader_file *) data;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
103
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
104 return d->is_seekable;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
105 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
106
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
107 /*
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
108 * This sets up an mpc_reader_file object to read from VFS instead of libc.
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
109 * Essentially, we use this instead of the normal constructor.
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
110 * - nenolod
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
111 */
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
112 void
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
113 mpc_reader_setup_file_vfs(mpc_reader_file *p_reader, VFSFile *input)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
114 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
115 p_reader->reader.seek = vfs_fseek_impl;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
116 p_reader->reader.read = vfs_fread_impl;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
117 p_reader->reader.tell = vfs_ftell_impl;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
118 p_reader->reader.get_size = vfs_getsize_impl;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
119 p_reader->reader.canseek = vfs_canseek_impl;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
120 p_reader->reader.data = p_reader;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
121
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
122 p_reader->file = (FILE *) input; // no worries, it gets cast back -nenolod
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
123 p_reader->is_seekable = TRUE; // XXX streams
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
124
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
125 vfs_fseek(input, 0, SEEK_END);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
126 p_reader->file_size = vfs_ftell(input);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
127 vfs_fseek(input, 0, SEEK_SET);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
128 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
129
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
130 static void mpcOpenPlugin()
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
131 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
132 ConfigDb *cfg;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
133 cfg = bmp_cfg_db_open();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
134 bmp_cfg_db_get_bool(cfg, "musepack", "clipPrevention", &pluginConfig.clipPrevention);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
135 bmp_cfg_db_get_bool(cfg, "musepack", "albumGain", &pluginConfig.albumGain);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
136 bmp_cfg_db_get_bool(cfg, "musepack", "dynamicBitrate", &pluginConfig.dynamicBitrate);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
137 bmp_cfg_db_get_bool(cfg, "musepack", "replaygain", &pluginConfig.replaygain);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
138 bmp_cfg_db_close(cfg);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
139 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
140
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
141 static void mpcAboutBox()
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
142 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
143 GtkWidget* aboutBox = widgets.aboutBox;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
144 if (aboutBox)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
145 gdk_window_raise(aboutBox->window);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
146 else
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
147 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
148 char* titleText = g_strdup_printf("Musepack Decoder Plugin 1.2");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
149 char* contentText = "Plugin code by\nBenoit Amiaux\nMartin Spuler\nKuniklo\n\nGet latest version at http://musepack.net\n";
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
150 char* buttonText = "Nevermind";
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
151 aboutBox = xmms_show_message(titleText, contentText, buttonText, FALSE, NULL, NULL);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
152 widgets.aboutBox = aboutBox;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
153 g_signal_connect(G_OBJECT(aboutBox), "destroy", G_CALLBACK(gtk_widget_destroyed), &widgets.aboutBox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
154 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
155 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
156
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
157 static void mpcConfigBox()
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
158 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
159 GtkWidget* configBox = widgets.configBox;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
160 if(configBox)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
161 gdk_window_raise(configBox->window);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
162 else
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
163 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
164 configBox = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
165 gtk_window_set_type_hint(GTK_WINDOW(configBox), GDK_WINDOW_TYPE_HINT_DIALOG);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
166 widgets.configBox = configBox;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
167 g_signal_connect(G_OBJECT(configBox), "destroy", G_CALLBACK(gtk_widget_destroyed), &widgets.configBox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
168 gtk_window_set_title(GTK_WINDOW(configBox), "Musepack Decoder Configuration");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
169 gtk_window_set_policy(GTK_WINDOW(configBox), FALSE, FALSE, FALSE);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
170 gtk_container_border_width(GTK_CONTAINER(configBox), 10);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
171
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
172 GtkWidget* notebook = gtk_notebook_new();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
173 GtkWidget* vbox = gtk_vbox_new(FALSE, 10);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
174 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
175 gtk_container_add(GTK_CONTAINER(configBox), vbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
176
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
177 //General Settings Tab
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
178 GtkWidget* generalSet = gtk_frame_new("General Settings");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
179 gtk_container_border_width(GTK_CONTAINER(generalSet), 5);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
180
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
181 GtkWidget* gSvbox = gtk_vbox_new(FALSE, 10);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
182 gtk_container_border_width(GTK_CONTAINER(gSvbox), 5);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
183 gtk_container_add(GTK_CONTAINER(generalSet), gSvbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
184
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
185 GtkWidget* bitrateCheck = gtk_check_button_new_with_label("Enable Dynamic Bitrate Display");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
186 widgets.bitrateCheck = bitrateCheck;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
187 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bitrateCheck), pluginConfig.dynamicBitrate);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
188 gtk_box_pack_start(GTK_BOX(gSvbox), bitrateCheck, FALSE, FALSE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
189 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), generalSet, gtk_label_new("Plugin"));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
190
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
191 //ReplayGain Settings Tab
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
192 GtkWidget* replaygainSet = gtk_frame_new("ReplayGain Settings");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
193 gtk_container_border_width(GTK_CONTAINER(replaygainSet), 5);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
194
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
195 GtkWidget* rSVbox = gtk_vbox_new(FALSE, 10);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
196 gtk_container_border_width(GTK_CONTAINER(rSVbox), 5);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
197 gtk_container_add(GTK_CONTAINER(replaygainSet), rSVbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
198
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
199 GtkWidget* clippingCheck = gtk_check_button_new_with_label("Enable Clipping Prevention");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
200 widgets.clippingCheck = clippingCheck;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
201 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(clippingCheck), pluginConfig.clipPrevention);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
202 gtk_box_pack_start(GTK_BOX(rSVbox), clippingCheck, FALSE, FALSE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
203
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
204 GtkWidget* replaygainCheck = gtk_check_button_new_with_label("Enable ReplayGain");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
205 widgets.replaygainCheck = replaygainCheck;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
206 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(replaygainCheck), pluginConfig.replaygain);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
207 gtk_box_pack_start(GTK_BOX(rSVbox), replaygainCheck, FALSE, FALSE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
208
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
209 GtkWidget* replaygainType = gtk_frame_new("ReplayGain Type");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
210 gtk_box_pack_start(GTK_BOX(rSVbox), replaygainType, FALSE, FALSE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
211 g_signal_connect(G_OBJECT(replaygainCheck), "toggled", G_CALLBACK(toggleSwitch), replaygainType);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
212
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
213 GtkWidget* rgVbox = gtk_vbox_new(FALSE, 5);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
214 gtk_container_set_border_width(GTK_CONTAINER(rgVbox), 5);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
215 gtk_container_add(GTK_CONTAINER(replaygainType), rgVbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
216
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
217 GtkWidget* trackCheck = gtk_radio_button_new_with_label(NULL, "Use Track Gain");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
218 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(trackCheck), !pluginConfig.albumGain);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
219 gtk_box_pack_start(GTK_BOX(rgVbox), trackCheck, FALSE, FALSE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
220
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
221 GtkWidget* albumCheck = gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(trackCheck)), "Use Album Gain");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
222 widgets.albumCheck = albumCheck;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
223 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(albumCheck), pluginConfig.albumGain);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
224 gtk_box_pack_start(GTK_BOX(rgVbox), albumCheck, FALSE, FALSE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
225 gtk_widget_set_sensitive(replaygainType, pluginConfig.replaygain);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
226 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), replaygainSet, gtk_label_new("ReplayGain"));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
227
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
228 //Buttons
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
229 GtkWidget* buttonBox = gtk_hbutton_box_new();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
230 gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
231 gtk_button_box_set_spacing(GTK_BUTTON_BOX(buttonBox), 5);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
232 gtk_box_pack_start(GTK_BOX(vbox), buttonBox, FALSE, FALSE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
233
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
234 GtkWidget* okButton = gtk_button_new_with_label("Ok");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
235 g_signal_connect(G_OBJECT(okButton), "clicked", G_CALLBACK(saveConfigBox), NULL);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
236 GTK_WIDGET_SET_FLAGS(okButton, GTK_CAN_DEFAULT);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
237 gtk_box_pack_start(GTK_BOX(buttonBox), okButton, TRUE, TRUE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
238
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
239 GtkWidget* cancelButton = gtk_button_new_with_label("Cancel");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
240 g_signal_connect_swapped(G_OBJECT(cancelButton), "clicked", G_CALLBACK(gtk_widget_destroy), GTK_OBJECT(widgets.configBox));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
241 GTK_WIDGET_SET_FLAGS(cancelButton, GTK_CAN_DEFAULT);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
242 gtk_widget_grab_default(cancelButton);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
243 gtk_box_pack_start(GTK_BOX(buttonBox), cancelButton, TRUE, TRUE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
244
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
245 gtk_widget_show_all(configBox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
246 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
247 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
248
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
249 static void toggleSwitch(GtkWidget* p_Widget, gpointer p_Data)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
250 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
251 gtk_widget_set_sensitive(GTK_WIDGET(p_Data), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_Widget)));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
252 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
253
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
254 static void saveConfigBox(GtkWidget* p_Widget, gpointer p_Data)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
255 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
256 ConfigDb* cfg;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
257 GtkToggleButton* tb;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
258
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
259 tb = GTK_TOGGLE_BUTTON(widgets.replaygainCheck);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
260 pluginConfig.replaygain = gtk_toggle_button_get_active(tb);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
261 tb = GTK_TOGGLE_BUTTON(widgets.clippingCheck);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
262 pluginConfig.clipPrevention = gtk_toggle_button_get_active(tb);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
263 tb = GTK_TOGGLE_BUTTON(widgets.bitrateCheck);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
264 pluginConfig.dynamicBitrate = gtk_toggle_button_get_active(tb);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
265 tb = GTK_TOGGLE_BUTTON(widgets.albumCheck);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
266 pluginConfig.albumGain = gtk_toggle_button_get_active(tb);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
267
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
268 cfg = bmp_cfg_db_open();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
269
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
270 bmp_cfg_db_set_bool(cfg, "musepack", "clipPrevention", pluginConfig.clipPrevention);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
271 bmp_cfg_db_set_bool(cfg, "musepack", "albumGain", pluginConfig.albumGain);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
272 bmp_cfg_db_set_bool(cfg, "musepack", "dynamicBitrate", pluginConfig.dynamicBitrate);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
273 bmp_cfg_db_set_bool(cfg, "musepack", "replaygain", pluginConfig.replaygain);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
274
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
275 bmp_cfg_db_close(cfg);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
276
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
277 gtk_widget_destroy (widgets.configBox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
278 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
279
260
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
280 static int mpcIsOurFile(char* p_Filename)
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
281 {
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
282 VFSFile *file;
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
283 gchar magic[3];
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
284 if ((file = vfs_fopen(p_Filename, "rb"))) {
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
285 vfs_fread(magic, 1, 3, file);
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
286 if (!memcmp(magic, "MP+", 3)) {
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
287 vfs_fclose(file);
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
288 return 1;
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
289 }
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
290 vfs_fclose(file);
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
291 }
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
292 return 0;
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
293 }
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
294
254
cdf9756d1528 [svn] Port to NewVFS file probe.
chainsaw
parents: 232
diff changeset
295 static int mpcIsOurFD(char* p_Filename, VFSFile* file)
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
296 {
254
cdf9756d1528 [svn] Port to NewVFS file probe.
chainsaw
parents: 232
diff changeset
297 gchar magic[3];
cdf9756d1528 [svn] Port to NewVFS file probe.
chainsaw
parents: 232
diff changeset
298 vfs_fread(magic, 1, 3, file);
260
4f7b72c88319 [svn] So input.c wants to have the old-style function available...
chainsaw
parents: 254
diff changeset
299 if (!memcmp(magic, "MP+", 3))
254
cdf9756d1528 [svn] Port to NewVFS file probe.
chainsaw
parents: 232
diff changeset
300 return 1;
cdf9756d1528 [svn] Port to NewVFS file probe.
chainsaw
parents: 232
diff changeset
301 return 0;
232
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
302 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
303
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
304 static void mpcPlay(char* p_Filename)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
305 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
306 mpcDecoder.offset = -1;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
307 mpcDecoder.isAlive = true;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
308 mpcDecoder.isOutput = false;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
309 mpcDecoder.isPause = false;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
310 threadHandle = g_thread_create(GThreadFunc(decodeStream), (void *) g_strdup(p_Filename), TRUE, NULL);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
311 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
312
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
313 static void mpcStop()
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
314 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
315 setAlive(false);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
316 if (threadHandle)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
317 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
318 g_thread_join(threadHandle);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
319 if (mpcDecoder.isOutput)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
320 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
321 MpcPlugin.output->buffer_free();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
322 MpcPlugin.output->close_audio();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
323 mpcDecoder.isOutput = false;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
324 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
325 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
326 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
327
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
328 static void mpcPause(short p_Pause)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
329 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
330 lockAcquire();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
331 mpcDecoder.isPause = p_Pause;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
332 MpcPlugin.output->pause(p_Pause);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
333 lockRelease();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
334 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
335
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
336 static void mpcSeek(int p_Offset)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
337 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
338 lockAcquire();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
339 mpcDecoder.offset = static_cast<double> (p_Offset);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
340 MpcPlugin.output->flush(1000 * p_Offset);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
341 lockRelease();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
342 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
343
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
344 static int mpcGetTime()
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
345 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
346 if(!isAlive())
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
347 return -1;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
348 return MpcPlugin.output->output_time();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
349 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
350
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
351 static TitleInput *mpcGetSongTuple(char* p_Filename)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
352 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
353 VFSFile *input = vfs_fopen(p_Filename, "rb");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
354 TitleInput *tuple = NULL;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
355
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
356 if(input)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
357 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
358 tuple = bmp_title_input_new();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
359 gchar *filename_proxy = g_strdup(p_Filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
360
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
361 tuple->file_name = g_path_get_basename(filename_proxy);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
362 tuple->file_path = g_path_get_dirname(filename_proxy);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
363 tuple->file_ext = "mpc"; // XXX: I can't be assed. -nenolod
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
364
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
365 MpcInfo tags = getTags(p_Filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
366
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
367 tuple->date = g_strdup(tags.date);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
368 tuple->track_name = g_strdup(tags.title);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
369 tuple->performer = g_strdup(tags.artist);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
370 tuple->album_name = g_strdup(tags.album);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
371 tuple->track_number = tags.track;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
372 tuple->year = tags.year;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
373 tuple->genre = g_strdup(tags.genre);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
374 tuple->comment = g_strdup(tags.comment);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
375
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
376 freeTags(tags);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
377
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
378 mpc_streaminfo info;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
379 mpc_reader_file reader;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
380 mpc_reader_setup_file_vfs(&reader, input);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
381 mpc_streaminfo_read(&info, &reader.reader);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
382
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
383 tuple->length = static_cast<int> (1000 * mpc_streaminfo_get_length(&info));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
384 vfs_fclose(input);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
385 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
386 else
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
387 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
388 char* temp = g_strdup_printf("[xmms-musepack] mpcGetSongInfo is unable to open %s\n", p_Filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
389 perror(temp);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
390 free(temp);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
391 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
392
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
393 return tuple;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
394 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
395
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
396 static void mpcGetSongInfo(char* p_Filename, char** p_Title, int* p_Length)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
397 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
398 VFSFile *input = vfs_fopen(p_Filename, "rb");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
399 if(input)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
400 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
401 MpcInfo tags = getTags(p_Filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
402 *p_Title = mpcGenerateTitle(tags, p_Filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
403 freeTags(tags);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
404 mpc_streaminfo info;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
405 mpc_reader_file reader;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
406 mpc_reader_setup_file_vfs(&reader, input);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
407 mpc_streaminfo_read(&info, &reader.reader);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
408 *p_Length = static_cast<int> (1000 * mpc_streaminfo_get_length(&info));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
409 vfs_fclose(input);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
410 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
411 else
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
412 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
413 char* temp = g_strdup_printf("[xmms-musepack] mpcGetSongInfo is unable to open %s\n", p_Filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
414 perror(temp);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
415 free(temp);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
416 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
417 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
418
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
419 static void freeTags(MpcInfo& tags)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
420 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
421 free(tags.title);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
422 free(tags.artist);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
423 free(tags.album);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
424 free(tags.comment);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
425 free(tags.genre);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
426 free(tags.date);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
427 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
428
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
429 static MpcInfo getTags(const char* p_Filename)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
430 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
431 File oFile(p_Filename, false);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
432 Tag* poTag = oFile.tag();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
433 MpcInfo tags = {0};
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
434 tags.title = g_strdup(poTag->title().toCString(true));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
435 REMOVE_NONEXISTANT_TAG(tags.title);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
436 tags.artist = g_strdup(poTag->artist().toCString(true));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
437 REMOVE_NONEXISTANT_TAG(tags.artist);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
438 tags.album = g_strdup(poTag->album().toCString(true));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
439 REMOVE_NONEXISTANT_TAG(tags.album);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
440 tags.genre = g_strdup(poTag->genre().toCString(true));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
441 REMOVE_NONEXISTANT_TAG(tags.genre);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
442 tags.comment = g_strdup(poTag->comment().toCString(true));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
443 REMOVE_NONEXISTANT_TAG(tags.comment);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
444 tags.year = poTag->year();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
445 tags.track = poTag->track();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
446 TagLib::APE::Tag* ape = oFile.APETag(false);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
447 if(ape)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
448 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
449 ItemListMap map = ape->itemListMap();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
450 if(map.contains("YEAR"))
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
451 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
452 tags.date = g_strdup(map["YEAR"].toString().toCString(true));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
453 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
454 else
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
455 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
456 tags.date = g_strdup_printf("%d", tags.year);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
457 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
458 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
459 return tags;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
460 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
461
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
462 static void mpcFileInfoBox(char* p_Filename)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
463 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
464 GtkWidget* infoBox = widgets.infoBox;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
465
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
466 if(infoBox)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
467 gdk_window_raise(infoBox->window);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
468 else
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
469 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
470 infoBox = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
471 gtk_window_set_type_hint(GTK_WINDOW(infoBox), GDK_WINDOW_TYPE_HINT_DIALOG);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
472 widgets.infoBox = infoBox;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
473 gtk_window_set_policy(GTK_WINDOW(infoBox), FALSE, FALSE, FALSE);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
474 g_signal_connect(G_OBJECT(infoBox), "destroy", G_CALLBACK(closeInfoBox), NULL);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
475 gtk_container_set_border_width(GTK_CONTAINER(infoBox), 10);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
476
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
477 GtkWidget* iVbox = gtk_vbox_new(FALSE, 10);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
478 gtk_container_add(GTK_CONTAINER(infoBox), iVbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
479
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
480 GtkWidget* filenameHbox = gtk_hbox_new(FALSE, 5);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
481 gtk_box_pack_start(GTK_BOX(iVbox), filenameHbox, FALSE, TRUE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
482
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
483 GtkWidget* fileLabel = gtk_label_new("Filename:");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
484 gtk_box_pack_start(GTK_BOX(filenameHbox), fileLabel, FALSE, TRUE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
485
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
486 GtkWidget* fileEntry = gtk_entry_new();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
487 widgets.fileEntry = fileEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
488 gtk_editable_set_editable(GTK_EDITABLE(fileEntry), FALSE);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
489 gtk_box_pack_start(GTK_BOX(filenameHbox), fileEntry, TRUE, TRUE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
490
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
491 GtkWidget* iHbox = gtk_hbox_new(FALSE, 10);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
492 gtk_box_pack_start(GTK_BOX(iVbox), iHbox, FALSE, TRUE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
493
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
494 GtkWidget* leftBox = gtk_vbox_new(FALSE, 10);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
495 gtk_box_pack_start(GTK_BOX(iHbox), leftBox, FALSE, FALSE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
496
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
497 //Tag labels
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
498 GtkWidget* tagFrame = gtk_frame_new("Musepack Tag");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
499 gtk_box_pack_start(GTK_BOX(leftBox), tagFrame, FALSE, FALSE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
500 gtk_widget_set_sensitive(tagFrame, TRUE);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
501
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
502 GtkWidget* iTable = gtk_table_new(5, 5, FALSE);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
503 gtk_container_set_border_width(GTK_CONTAINER(iTable), 5);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
504 gtk_container_add(GTK_CONTAINER(tagFrame), iTable);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
505
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
506 mpcGtkTagLabel("Title:", 0, 1, 0, 1, iTable);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
507 GtkWidget* titleEntry = mpcGtkTagEntry(1, 4, 0, 1, 0, iTable);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
508 widgets.titleEntry = titleEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
509
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
510 mpcGtkTagLabel("Artist:", 0, 1, 1, 2, iTable);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
511 GtkWidget* artistEntry = mpcGtkTagEntry(1, 4, 1, 2, 0, iTable);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
512 widgets.artistEntry = artistEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
513
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
514 mpcGtkTagLabel("Album:", 0, 1, 2, 3, iTable);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
515 GtkWidget* albumEntry = mpcGtkTagEntry(1, 4, 2, 3, 0, iTable);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
516 widgets.albumEntry = albumEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
517
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
518 mpcGtkTagLabel("Comment:", 0, 1, 3, 4, iTable);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
519 GtkWidget* commentEntry = mpcGtkTagEntry(1, 4, 3, 4, 0, iTable);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
520 widgets.commentEntry = commentEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
521
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
522 mpcGtkTagLabel("Year:", 0, 1, 4, 5, iTable);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
523 GtkWidget* yearEntry = mpcGtkTagEntry(1, 2, 4, 5, 4, iTable);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
524 widgets.yearEntry = yearEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
525 gtk_widget_set_usize(yearEntry, 4, -1);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
526
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
527 mpcGtkTagLabel("Track:", 2, 3, 4, 5, iTable);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
528 GtkWidget* trackEntry = mpcGtkTagEntry(3, 4, 4, 5, 4, iTable);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
529 widgets.trackEntry = trackEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
530 gtk_widget_set_usize(trackEntry, 3, -1);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
531
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
532 mpcGtkTagLabel("Genre:", 0, 1, 5, 6, iTable);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
533 GtkWidget* genreEntry = mpcGtkTagEntry(1, 4, 5, 6, 0, iTable);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
534 widgets.genreEntry = genreEntry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
535 gtk_widget_set_usize(genreEntry, 20, -1);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
536
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
537 //Buttons
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
538 GtkWidget* buttonBox = gtk_hbutton_box_new();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
539 gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
540 gtk_button_box_set_spacing(GTK_BUTTON_BOX(buttonBox), 5);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
541 gtk_box_pack_start(GTK_BOX(leftBox), buttonBox, FALSE, FALSE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
542
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
543 GtkWidget* saveButton = mpcGtkButton("Save", buttonBox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
544 g_signal_connect(G_OBJECT(saveButton), "clicked", G_CALLBACK(saveTags), NULL);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
545
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
546 GtkWidget* removeButton = mpcGtkButton("Remove Tag", buttonBox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
547 g_signal_connect_swapped(G_OBJECT(removeButton), "clicked", G_CALLBACK(removeTags), NULL);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
548
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
549 GtkWidget* cancelButton = mpcGtkButton("Cancel", buttonBox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
550 g_signal_connect_swapped(G_OBJECT(cancelButton), "clicked", G_CALLBACK(closeInfoBox), NULL);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
551 gtk_widget_grab_default(cancelButton);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
552
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
553 //File information
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
554 GtkWidget* infoFrame = gtk_frame_new("Musepack Info");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
555 gtk_box_pack_start(GTK_BOX(iHbox), infoFrame, FALSE, FALSE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
556
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
557 GtkWidget* infoVbox = gtk_vbox_new(FALSE, 5);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
558 gtk_container_add(GTK_CONTAINER(infoFrame), infoVbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
559 gtk_container_set_border_width(GTK_CONTAINER(infoVbox), 10);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
560 gtk_box_set_spacing(GTK_BOX(infoVbox), 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
561
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
562 GtkWidget* streamLabel = mpcGtkLabel(infoVbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
563 GtkWidget* encoderLabel = mpcGtkLabel(infoVbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
564 GtkWidget* profileLabel = mpcGtkLabel(infoVbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
565 GtkWidget* bitrateLabel = mpcGtkLabel(infoVbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
566 GtkWidget* rateLabel = mpcGtkLabel(infoVbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
567 GtkWidget* channelsLabel = mpcGtkLabel(infoVbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
568 GtkWidget* lengthLabel = mpcGtkLabel(infoVbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
569 GtkWidget* fileSizeLabel = mpcGtkLabel(infoVbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
570 GtkWidget* trackPeakLabel = mpcGtkLabel(infoVbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
571 GtkWidget* trackGainLabel = mpcGtkLabel(infoVbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
572 GtkWidget* albumPeakLabel = mpcGtkLabel(infoVbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
573 GtkWidget* albumGainLabel = mpcGtkLabel(infoVbox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
574
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
575 VFSFile *input = vfs_fopen(p_Filename, "rb");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
576 if(input)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
577 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
578 mpc_streaminfo info;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
579 mpc_reader_file reader;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
580 mpc_reader_setup_file_vfs(&reader, input);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
581 mpc_streaminfo_read(&info, &reader.reader);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
582
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
583 int time = static_cast<int> (mpc_streaminfo_get_length(&info));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
584 int minutes = time / 60;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
585 int seconds = time % 60;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
586
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
587 mpcGtkPrintLabel(streamLabel, "Streamversion %d", info.stream_version);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
588 mpcGtkPrintLabel(encoderLabel, "Encoder: \%s", info.encoder);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
589 mpcGtkPrintLabel(profileLabel, "Profile: \%s", info.profile_name);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
590 mpcGtkPrintLabel(bitrateLabel, "Average bitrate: \%6.1f kbps", info.average_bitrate * 1.e-3);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
591 mpcGtkPrintLabel(rateLabel, "Samplerate: \%d Hz", info.sample_freq);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
592 mpcGtkPrintLabel(channelsLabel, "Channels: \%d", info.channels);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
593 mpcGtkPrintLabel(lengthLabel, "Length: \%d:\%.2d", minutes, seconds);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
594 mpcGtkPrintLabel(fileSizeLabel, "File size: \%d Bytes", info.total_file_length);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
595 mpcGtkPrintLabel(trackPeakLabel, "Track Peak: \%5u", info.peak_title);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
596 mpcGtkPrintLabel(trackGainLabel, "Track Gain: \%-+2.2f dB", 0.01 * info.gain_title);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
597 mpcGtkPrintLabel(albumPeakLabel, "Album Peak: \%5u", info.peak_album);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
598 mpcGtkPrintLabel(albumGainLabel, "Album Gain: \%-+5.2f dB", 0.01 * info.gain_album);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
599
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
600 MpcInfo tags = getTags(p_Filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
601 gtk_entry_set_text(GTK_ENTRY(titleEntry), tags.title);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
602 gtk_entry_set_text(GTK_ENTRY(artistEntry), tags.artist);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
603 gtk_entry_set_text(GTK_ENTRY(albumEntry), tags.album);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
604 gtk_entry_set_text(GTK_ENTRY(commentEntry), tags.comment);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
605 gtk_entry_set_text(GTK_ENTRY(genreEntry), tags.genre);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
606 char* entry = g_strdup_printf ("%d", tags.track);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
607 gtk_entry_set_text(GTK_ENTRY(trackEntry), entry);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
608 free(entry);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
609 entry = g_strdup_printf ("%d", tags.year);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
610 gtk_entry_set_text(GTK_ENTRY(yearEntry), entry);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
611 free(entry);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
612 entry = g_filename_display_name(p_Filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
613 gtk_entry_set_text(GTK_ENTRY(fileEntry), entry);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
614 free(entry);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
615 freeTags(tags);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
616 vfs_fclose(input);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
617 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
618 else
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
619 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
620 char* temp = g_strdup_printf("[xmms-musepack] mpcFileInfoBox is unable to read tags from %s", p_Filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
621 perror(temp);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
622 free(temp);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
623 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
624
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
625 char* name = g_filename_display_basename(p_Filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
626 char* text = g_strdup_printf("File Info - %s", name);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
627 free(name);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
628 gtk_window_set_title(GTK_WINDOW(infoBox), text);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
629 free(text);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
630
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
631 gtk_widget_show_all(infoBox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
632 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
633 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
634
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
635 static void mpcGtkPrintLabel(GtkWidget* widget, char* format,...)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
636 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
637 va_list args;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
638
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
639 va_start(args, format);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
640 char* temp = g_strdup_vprintf(format, args);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
641 va_end(args);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
642
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
643 gtk_label_set_text(GTK_LABEL(widget), temp);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
644 free(temp);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
645 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
646
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
647 static GtkWidget* mpcGtkTagLabel(char* p_Text, int a, int b, int c, int d, GtkWidget* p_Box)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
648 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
649 GtkWidget* label = gtk_label_new(p_Text);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
650 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
651 gtk_table_attach(GTK_TABLE(p_Box), label, a, b, c, d, GTK_FILL, GTK_FILL, 5, 5);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
652 return label;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
653 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
654
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
655 static GtkWidget* mpcGtkTagEntry(int a, int b, int c, int d, int p_Size, GtkWidget* p_Box)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
656 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
657 GtkWidget* entry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
658 if(p_Size == 0)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
659 entry = gtk_entry_new();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
660 else
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
661 entry = gtk_entry_new_with_max_length(p_Size);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
662 gtk_table_attach(GTK_TABLE(p_Box), entry, a, b, c, d,
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
663 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | GTK_SHRINK),
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
664 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | GTK_SHRINK), 0, 5);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
665 return entry;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
666 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
667
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
668 static GtkWidget* mpcGtkLabel(GtkWidget* p_Box)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
669 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
670 GtkWidget* label = gtk_label_new("");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
671 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
672 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
673 gtk_box_pack_start(GTK_BOX(p_Box), label, FALSE, FALSE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
674 return label;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
675 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
676
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
677 static GtkWidget* mpcGtkButton(char* p_Text, GtkWidget* p_Box)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
678 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
679 GtkWidget* button = gtk_button_new_with_label(p_Text);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
680 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
681 gtk_box_pack_start(GTK_BOX(p_Box), button, TRUE, TRUE, 0);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
682 return button;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
683 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
684
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
685 static void removeTags(GtkWidget * w, gpointer data)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
686 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
687 File oFile(gtk_entry_get_text(GTK_ENTRY(widgets.fileEntry)));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
688 oFile.remove();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
689 oFile.save();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
690 closeInfoBox(NULL, NULL);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
691 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
692
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
693 static void saveTags(GtkWidget* w, gpointer data)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
694 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
695 File oFile(gtk_entry_get_text(GTK_ENTRY(widgets.fileEntry)));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
696 Tag* poTag = oFile.tag();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
697
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
698 char* cAlbum = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.albumEntry)));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
699 char* cArtist = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.artistEntry)));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
700 char* cTitle = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.titleEntry)));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
701 char* cGenre = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.genreEntry)));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
702 char* cComment = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.commentEntry)));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
703
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
704 const String album = String(cAlbum, TagLib::String::UTF8);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
705 const String artist = String(cArtist, TagLib::String::UTF8);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
706 const String title = String(cTitle, TagLib::String::UTF8);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
707 const String genre = String(cGenre, TagLib::String::UTF8);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
708 const String comment = String(cComment, TagLib::String::UTF8);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
709
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
710 poTag->setAlbum(album);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
711 poTag->setArtist(artist);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
712 poTag->setTitle(title);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
713 poTag->setGenre(genre);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
714 poTag->setComment(comment);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
715 poTag->setYear(atoi(gtk_entry_get_text(GTK_ENTRY(widgets.yearEntry))));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
716 poTag->setTrack(atoi(gtk_entry_get_text(GTK_ENTRY(widgets.trackEntry))));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
717
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
718 free(cAlbum);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
719 free(cArtist);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
720 free(cTitle);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
721 free(cGenre);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
722 free(cComment);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
723
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
724 oFile.save();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
725 closeInfoBox(NULL, NULL);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
726 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
727
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
728 static void closeInfoBox(GtkWidget* w, gpointer data)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
729 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
730 gtk_widget_destroy(widgets.infoBox);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
731 widgets.infoBox = NULL;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
732 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
733
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
734 static char* mpcGenerateTitle(const MpcInfo& p_Tags, char* p_Filename)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
735 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
736 TitleInput* tuple = mpcGetSongTuple(p_Filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
737
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
738 char* title = xmms_get_titlestring (xmms_get_gentitle_format(), tuple);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
739 if(!title)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
740 title = g_strdup(tuple->file_name);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
741 else if (!*title)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
742 title = g_strdup(tuple->file_name);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
743
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
744 bmp_title_input_free(tuple);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
745 return title;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
746 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
747
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
748 static void* endThread(char* p_FileName, VFSFile * p_FileHandle, bool release)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
749 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
750 free(p_FileName);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
751 if(release)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
752 lockRelease();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
753 if(mpcDecoder.isError)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
754 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
755 perror(mpcDecoder.isError);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
756 free(mpcDecoder.isError);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
757 mpcDecoder.isError = NULL;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
758 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
759 setAlive(false);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
760 if(p_FileHandle)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
761 vfs_fclose(p_FileHandle);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
762 if(track.display)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
763 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
764 free(track.display);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
765 track.display = NULL;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
766 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
767 g_thread_exit(NULL);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
768 return 0;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
769 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
770
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
771 static void* decodeStream(void* data)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
772 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
773 lockAcquire();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
774 char* filename = static_cast<char*> (data);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
775 VFSFile *input = vfs_fopen(filename, "rb");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
776 if (!input)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
777 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
778 mpcDecoder.isError = g_strdup_printf("[xmms-musepack] decodeStream is unable to open %s", filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
779 return endThread(filename, input, true);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
780 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
781
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
782 mpc_reader_file reader;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
783 mpc_reader_setup_file_vfs(&reader, input);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
784
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
785 mpc_streaminfo info;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
786 if (mpc_streaminfo_read(&info, &reader.reader) != ERROR_CODE_OK)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
787 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
788 mpcDecoder.isError = g_strdup_printf("[xmms-musepack] decodeStream is unable to read %s", filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
789 return endThread(filename, input, true);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
790 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
791
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
792 MpcInfo tags = getTags(filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
793 track.display = mpcGenerateTitle(tags, filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
794 track.length = static_cast<int> (1000 * mpc_streaminfo_get_length(&info));
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
795 track.bitrate = static_cast<int> (info.average_bitrate);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
796 track.sampleFreq = info.sample_freq;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
797 track.channels = info.channels;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
798 freeTags(tags);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
799
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
800 MpcPlugin.set_info(track.display, track.length, track.bitrate, track.sampleFreq, track.channels);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
801
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
802 mpc_decoder decoder;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
803 mpc_decoder_setup(&decoder, &reader.reader);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
804 if (!mpc_decoder_initialize(&decoder, &info))
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
805 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
806 mpcDecoder.isError = g_strdup_printf("[xmms-musepack] decodeStream is unable to initialize decoder on %s", filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
807 return endThread(filename, input, true);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
808 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
809
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
810 setReplaygain(info, decoder);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
811
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
812 MPC_SAMPLE_FORMAT sampleBuffer[MPC_DECODER_BUFFER_LENGTH];
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
813 char xmmsBuffer[MPC_DECODER_BUFFER_LENGTH * 4];
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
814
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
815 if (!MpcPlugin.output->open_audio(FMT_S16_LE, track.sampleFreq, track.channels))
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
816 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
817 mpcDecoder.isError = g_strdup_printf("[xmms-musepack] decodeStream is unable to open an audio output");
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
818 return endThread(filename, input, true);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
819 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
820 else
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
821 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
822 mpcDecoder.isOutput = true;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
823 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
824
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
825 lockRelease();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
826
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
827 int counter = 2 * track.sampleFreq / 3;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
828 while (isAlive())
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
829 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
830 if (getOffset() != -1)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
831 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
832 mpc_decoder_seek_seconds(&decoder, mpcDecoder.offset);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
833 setOffset(-1);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
834 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
835
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
836 lockAcquire();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
837 short iPlaying = MpcPlugin.output->buffer_playing()? 1 : 0;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
838 int iFree = MpcPlugin.output->buffer_free();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
839 if (!mpcDecoder.isPause && iFree >= ((1152 * 4) << iPlaying))
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
840 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
841 unsigned status = processBuffer(sampleBuffer, xmmsBuffer, decoder);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
842 if (status == (unsigned) (-1))
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
843 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
844 mpcDecoder.isError = g_strdup_printf("[xmms-musepack] error from internal decoder on %s", filename);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
845 return endThread(filename, input, true);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
846 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
847 if (status == 0 && iPlaying == 0)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
848 return endThread(filename, input, true);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
849
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
850 lockRelease();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
851
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
852 if(pluginConfig.dynamicBitrate)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
853 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
854 counter -= status;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
855 if(counter < 0)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
856 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
857 MpcPlugin.set_info(track.display, track.length, track.bitrate, track.sampleFreq, track.channels);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
858 counter = 2 * track.sampleFreq / 3;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
859 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
860 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
861 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
862 else
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
863 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
864 lockRelease();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
865 xmms_usleep(10000);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
866 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
867 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
868 return endThread(filename, input, false);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
869 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
870
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
871 static int processBuffer(MPC_SAMPLE_FORMAT* sampleBuffer, char* xmmsBuffer, mpc_decoder& decoder)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
872 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
873 mpc_uint32_t vbrAcc = 0;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
874 mpc_uint32_t vbrUpd = 0;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
875
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
876 unsigned status = mpc_decoder_decode(&decoder, sampleBuffer, &vbrAcc, &vbrUpd);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
877 copyBuffer(sampleBuffer, xmmsBuffer, status);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
878
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
879 if (pluginConfig.dynamicBitrate)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
880 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
881 track.bitrate = static_cast<int> (vbrUpd * track.sampleFreq / 1152);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
882 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
883
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
884 produce_audio(MpcPlugin.output->written_time(), FMT_S16_LE, track.channels, status * 4, xmmsBuffer, NULL);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
885 return status;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
886 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
887
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
888 static void setReplaygain(mpc_streaminfo& info, mpc_decoder& decoder)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
889 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
890 if(!pluginConfig.replaygain && !pluginConfig.clipPrevention)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
891 return;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
892
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
893 int peak = pluginConfig.albumGain ? info.peak_album : info.peak_title;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
894 double gain = pluginConfig.albumGain ? info.gain_album : info.gain_title;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
895
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
896 if(!peak)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
897 peak = 32767;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
898 if(!gain)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
899 gain = 1.;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
900
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
901 double clip = 32767. / peak;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
902 gain = exp((M_LN10 / 2000.) * gain);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
903
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
904 if(pluginConfig.clipPrevention && !pluginConfig.replaygain)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
905 gain = clip;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
906 else if(pluginConfig.replaygain && pluginConfig.clipPrevention)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
907 if(clip < gain)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
908 gain = clip;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
909
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
910 mpc_decoder_scale_output(&decoder, gain);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
911 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
912
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
913 inline static void lockAcquire()
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
914 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
915 g_static_mutex_lock(&threadMutex);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
916 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
917
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
918 inline static void lockRelease()
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
919 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
920 g_static_mutex_unlock(&threadMutex);
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
921 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
922
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
923 inline static bool isAlive()
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
924 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
925 lockAcquire();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
926 bool isAlive = mpcDecoder.isAlive;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
927 lockRelease();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
928 return isAlive;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
929 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
930
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
931 inline static bool isPause()
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
932 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
933 lockAcquire();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
934 bool isPause = mpcDecoder.isPause;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
935 lockRelease();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
936 return isPause;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
937 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
938
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
939 inline static void setAlive(bool isAlive)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
940 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
941 lockAcquire();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
942 mpcDecoder.isAlive = isAlive;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
943 lockRelease();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
944 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
945
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
946 inline static double getOffset()
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
947 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
948 lockAcquire();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
949 double offset = mpcDecoder.offset;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
950 lockRelease();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
951 return offset;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
952 }
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
953
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
954 inline static void setOffset(double offset)
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
955 {
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
956 lockAcquire();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
957 mpcDecoder.offset = offset;
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
958 lockRelease();
6c78d6d3cdb7 [svn] - put musepack support back
nenolod
parents:
diff changeset
959 }