mp3splt-gtk
audacious_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  * audacious control
37  *
38  * this file contains the functions that control the audacious
39  * player
40  ********************************************************/
41 
42 #include "audacious_control.h"
43 
44 #ifndef NO_AUDACIOUS
45 
46 #include <audacious/audctrl.h>
47 #include <audacious/dbus.h>
48 
50 void myaudacious_get_song_infos(gchar *total_infos, ui_state *ui)
51 {
52  gint freq, rate, nch;
53  audacious_remote_get_info(ui->pi->dbus_proxy, &rate, &freq, &nch);
54 
55  gchar rate_str[32] = { '\0' };
56  gchar freq_str[32] = { '\0' };
57  gchar nch_str[32] = { '\0' };
58 
59  g_snprintf(rate_str,32, "%d", rate/1000);
60  g_snprintf(freq_str,32, "%d", freq/1000);
61 
62  if (nch == 2)
63  {
64  snprintf(nch_str, 32, "%s", _("stereo"));
65  }
66  else
67  {
68  snprintf(nch_str, 32, "%s", _("mono"));
69  }
70 
71  gchar *_Kbps = _("Kbps");
72  gchar *_Khz = _("Khz");
73 
74  if (rate != 0)
75  {
76  g_snprintf(total_infos, 512, "%s %s %s %s %s", rate_str,_Kbps,freq_str, _Khz,nch_str);
77  return;
78  }
79 
80  total_infos[0] = '\0';
81 }
82 
88 {
89  gint playlist_position = audacious_remote_get_playlist_pos(ui->pi->dbus_proxy);
90  gchar *fname = audacious_remote_get_playlist_file(ui->pi->dbus_proxy, playlist_position);
91 
92  if (fname == NULL)
93  {
94  return NULL;
95  }
96 
97  gchar *fname2 = g_filename_from_uri(fname, NULL, NULL);
98  g_free(fname);
99 
100  return fname2;
101 }
102 
105 {
106  return audacious_remote_get_playlist_length(ui->pi->dbus_proxy);
107 }
108 
114 {
115  gint playlist_position = audacious_remote_get_playlist_pos(ui->pi->dbus_proxy);
116  return audacious_remote_get_playlist_title(ui->pi->dbus_proxy, playlist_position);
117 }
118 
121 {
122  return audacious_remote_get_output_time(ui->pi->dbus_proxy);
123 }
124 
127 {
128  static gchar *exec_command = "audacious";
129  gchar *exec_this = g_strdup_printf("%s &", exec_command);
130  system(exec_this);
131 
132  time_t lt;
133  gint timer = time(&lt);
134  while (!audacious_remote_is_running(ui->pi->dbus_proxy) && ((time(&lt) - timer) < 4))
135  {
136  usleep(0);
137  }
138 
139  g_free(exec_this);
140 }
141 
144 {
145  gint number = audacious_remote_get_playlist_length(ui->pi->dbus_proxy);
146  audacious_remote_set_playlist_pos(ui->pi->dbus_proxy, number - 1);
147 }
148 
151 {
153  audacious_remote_play(ui->pi->dbus_proxy);
154 }
155 
157 void myaudacious_add_files(GList *list, ui_state *ui)
158 {
159  GList *list_pos = list;
160  while (list_pos)
161  {
162  gchar *dup_filename = strdup(list_pos->data);
163  list_pos->data = g_filename_to_uri(dup_filename,NULL,NULL);
164  g_free(dup_filename);
165  list_pos = g_list_next(list_pos);
166  }
167 
168  audacious_remote_playlist_add(ui->pi->dbus_proxy, list);
169 }
170 
172 void myaudacious_set_volume(gint volume, ui_state *ui)
173 {
174  audacious_remote_set_main_volume(ui->pi->dbus_proxy, volume);
175 }
176 
179 {
180  return audacious_remote_get_main_volume(ui->pi->dbus_proxy);
181 }
182 
188 {
189  myaudacious_start(ui);
190  myaudacious_add_files(list, ui);
191 }
192 
195 {
196  if (!ui->pi->dbus_connection)
197  {
198  ui->pi->dbus_connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
199  }
200 
201  if (!ui->pi->dbus_proxy)
202  {
203  ui->pi->dbus_proxy = dbus_g_proxy_new_for_name(ui->pi->dbus_connection,
204  AUDACIOUS_DBUS_SERVICE,
205  AUDACIOUS_DBUS_PATH,
206  AUDACIOUS_DBUS_INTERFACE);
207  }
208 
209  if (!audacious_remote_is_running(ui->pi->dbus_proxy))
210  {
211  return FALSE;
212  }
213 
214  return TRUE;
215 }
216 
219 {
220  if (!audacious_remote_is_paused(ui->pi->dbus_proxy))
221  {
222  return FALSE;
223  }
224 
225  return TRUE;
226 }
227 
230 {
231  audacious_remote_play(ui->pi->dbus_proxy);
232 }
233 
236 {
237  audacious_remote_stop(ui->pi->dbus_proxy);
238 }
239 
242 {
243  audacious_remote_pause(ui->pi->dbus_proxy);
244 }
245 
248 {
249  audacious_remote_playlist_next(ui->pi->dbus_proxy);
250 }
251 
254 {
255  audacious_remote_playlist_prev(ui->pi->dbus_proxy);
256 }
257 
259 void myaudacious_jump(gint position, ui_state *ui)
260 {
261  audacious_remote_jump_to_time(ui->pi->dbus_proxy, position);
262 }
263 
266 {
267  gint playlist_position = audacious_remote_get_playlist_pos(ui->pi->dbus_proxy);
268  return audacious_remote_get_playlist_time(ui->pi->dbus_proxy, playlist_position);
269 }
270 
273 {
274  if (audacious_remote_is_playing(ui->pi->dbus_proxy))
275  {
276  return TRUE;
277  }
278 
279  return FALSE;
280 }
281 
282 #endif
283