mp3splt-gtk

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

xmms_control.c
Go to the documentation of this file.
1 /**********************************************************
2 *
3 * mp3splt-gtk -- utility based on mp3splt,
4 * for mp3/ogg splitting without decoding
5 *
6 * Copyright: (C) 2005-2012 Alexandru Munteanu
7 * Contact: io_fx@yahoo.fr
8 *
9 * from BMP to Audacious patch from Roberto Neri - 2007,2008
10 *
11 * http://mp3splt.sourceforge.net/
12 *
13 *********************************************************/
14
15 /**********************************************************
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
30 * USA.
31 *
32 *********************************************************/
33
34 /*!********************************************************
35 * \file
36 * xmms control
37 *
38 * this file contains the functions that control the xmms
39 * player
40 ********************************************************/
41
42 #include <stdlib.h>
43 #include <gtk/gtk.h>
44 #include <glib/gi18n.h>
45 #include <time.h>
46 #include <unistd.h>
47 #include <string.h>
48
49 #ifndef NO_AUDACIOUS
50 #include <audacious/audctrl.h>
51 #include <audacious/dbus.h>
52 //ugly hack until fix
53 DBusGProxy *dbus_proxy = NULL;
54 static DBusGConnection *dbus_connection = NULL;
55 #endif
56
57 #include "player.h"
58
59 #ifndef NO_AUDACIOUS
60
61 void myxmms_get_song_infos(gchar *total_infos)
62 {
63 //the frequency
64 gint freq;
65 //rate kb/s
66 gint rate;
67 //number of channels (mono/stereo)
68 gint nch;
69
70 gchar rate_str[32] = { '\0' };
71 gchar freq_str[32] = { '\0' };
72 gchar nch_str[32] = { '\0' };
73
74 //infos about the song
75 audacious_remote_get_info(dbus_proxy, &rate, &freq, &nch);
76
77 g_snprintf(rate_str,32, "%d", rate/1000);
78 g_snprintf(freq_str,32, "%d", freq/1000);
79
80 if (nch == 2)
81 {
82 snprintf(nch_str, 32, "%s", _("stereo"));
83 }
84 else
85 {
86 snprintf(nch_str, 32, "%s", _("mono"));
87 }
88
89 gchar *_Kbps = _("Kbps");
90 gchar *_Khz = _("Khz");
91
92 if (rate != 0)
93 {
94 g_snprintf(total_infos,512,
95 "%s %s %s %s %s",
96 rate_str,_Kbps,freq_str, _Khz,nch_str);
97 }
98 else
99 {
100 total_infos[0] = '\0';
101 }
102 }
103
108 gchar *myxmms_get_filename()
109 {
110 gchar *fname;
111
112 //position of the song in the playlist
113 gint playlist_position;
114
115 playlist_position = audacious_remote_get_playlist_pos(dbus_proxy);
116
117 fname = audacious_remote_get_playlist_file(dbus_proxy, playlist_position);
118
119 //erase file:// and replace %20 with spaces
120 gchar *fname2 = g_filename_from_uri(fname,NULL,NULL);
121 g_free(fname);
122 fname = NULL;
123
124 return fname2;
125 }
126
128 gint myxmms_get_playlist_number()
129 {
130 return audacious_remote_get_playlist_length(dbus_proxy);
131 }
132
137 gchar *myxmms_get_title_song()
138 {
139 gchar *title;
140
141 //position of the song in the playlist
142 gint playlist_position;
143
144 playlist_position = audacious_remote_get_playlist_pos(dbus_proxy);
145 title = audacious_remote_get_playlist_title(dbus_proxy,playlist_position);
146
147 return title;
148 }
149
151 gint myxmms_get_time_elapsed()
152 {
153 return audacious_remote_get_output_time(dbus_proxy);
154 }
155
157 void myxmms_start()
158 {
159 gint timer;
160 time_t lt;
161
162 static gchar *exec_command;
163 exec_command = "audacious";
164 gchar *exec_this = g_strdup_printf("%s &", exec_command);
165 system(exec_this);
166
167 timer = time(&lt);
168 while (!audacious_remote_is_running(dbus_proxy)
169 && ((time(&lt) - timer) < 4))
170 {
171 usleep(0);
172 }
173
174 g_free(exec_this);
175 }
176
178 void myxmms_select_last_file()
179 {
180 gint number;
181 number = audacious_remote_get_playlist_length(dbus_proxy);
182 audacious_remote_set_playlist_pos(dbus_proxy,(number-1));
183 }
184
186 void myxmms_play_last_file()
187 {
188 myxmms_select_last_file();
189 audacious_remote_play(dbus_proxy);
190 }
191
193 void myxmms_add_files(GList *list)
194 {
195 //change filenames into URLs
196 GList *list_pos = list;
197
198 //for each element of the list
199 while (list_pos)
200 {
201 //duplicate the filename
202 gchar *dup_filename = strdup(list_pos->data);
203 //free the GList data content
204 //g_free(list_pos->data);
205 //put the new GList data content
206 list_pos->data = g_filename_to_uri(dup_filename,NULL,NULL);
207 //free the duplicated filename
208 g_free(dup_filename);
209 dup_filename = NULL;
210 //move to the next element
211 list_pos = g_list_next(list_pos);
212 }
213
214 audacious_remote_playlist_add(dbus_proxy, list);
215 }
216
218 void myxmms_set_volume(gint volume)
219 {
220 audacious_remote_set_main_volume(dbus_proxy, volume);
221 }
222
224 gint myxmms_get_volume()
225 {
226 return audacious_remote_get_main_volume(dbus_proxy);
227 }
228
234 void myxmms_start_with_songs(GList *list)
235 {
236 myxmms_start();
237 myxmms_add_files(list);
238 }
239
241 gint myxmms_is_running()
242 {
243 if (!dbus_connection)
244 {
245 dbus_connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
246 }
247 if (!dbus_proxy)
248 {
249 dbus_proxy = dbus_g_proxy_new_for_name(dbus_connection,
250 AUDACIOUS_DBUS_SERVICE,
251 AUDACIOUS_DBUS_PATH,
252 AUDACIOUS_DBUS_INTERFACE);
253 }
254 if (!audacious_remote_is_running(dbus_proxy))
255 return FALSE;
256 else
257 return TRUE;
258 }
259
261 gint myxmms_is_paused()
262 {
263 if (!audacious_remote_is_paused(dbus_proxy))
264 return FALSE;
265 else
266 return TRUE;
267 }
268
270 void myxmms_play()
271 {
272 audacious_remote_play(dbus_proxy);
273 }
274
276 void myxmms_stop()
277 {
278 audacious_remote_stop(dbus_proxy);
279 }
280
282 void myxmms_pause()
283 {
284 audacious_remote_pause(dbus_proxy);
285 }
286
288 void myxmms_next()
289 {
290 audacious_remote_playlist_next(dbus_proxy);
291 }
292
294 void myxmms_prev()
295 {
296 audacious_remote_playlist_prev(dbus_proxy);
297 }
298
300 void myxmms_jump(gint position)
301 {
302 audacious_remote_jump_to_time(dbus_proxy, position);
303 }
304
306 gint myxmms_get_total_time()
307 {
308 gint playlist_position;
309 playlist_position = audacious_remote_get_playlist_pos(dbus_proxy);
310 return audacious_remote_get_playlist_time(dbus_proxy,playlist_position);
311 }
312
314 gint myxmms_is_playing()
315 {
316 if(audacious_remote_is_playing(dbus_proxy))
317 return TRUE;
318 else
319 return FALSE;
320 }
321
323 void myxmms_quit()
324 {
325 audacious_remote_quit(dbus_proxy);
326 }
327
328 #endif
329