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-2013 Alexandru Munteanu
7  * Contact: m@ioalex.net
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
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 
49 #include <dbus/dbus-glib.h>
50 
52 void myaudacious_get_song_infos(gchar *total_infos, ui_state *ui)
53 {
54  gint freq, rate, nch;
55  audacious_remote_get_info(ui->pi->dbus_proxy, &rate, &freq, &nch);
56 
57  gchar rate_str[32] = { '\0' };
58  gchar freq_str[32] = { '\0' };
59  gchar nch_str[32] = { '\0' };
60 
61  g_snprintf(rate_str,32, "%d", rate/1000);
62  g_snprintf(freq_str,32, "%d", freq/1000);
63 
64  if (nch == 2)
65  {
66  snprintf(nch_str, 32, "%s", _("stereo"));
67  }
68  else
69  {
70  snprintf(nch_str, 32, "%s", _("mono"));
71  }
72 
73  gchar *_Kbps = _("Kbps");
74  gchar *_Khz = _("Khz");
75 
76  if (rate != 0)
77  {
78  g_snprintf(total_infos, 512, "%s %s %s %s %s", rate_str,_Kbps,freq_str, _Khz,nch_str);
79  return;
80  }
81 
82  total_infos[0] = '\0';
83 }
84 
90 {
91  gint playlist_position = audacious_remote_get_playlist_pos(ui->pi->dbus_proxy);
92  gchar *fname = audacious_remote_get_playlist_file(ui->pi->dbus_proxy, playlist_position);
93 
94  if (fname == NULL)
95  {
96  return NULL;
97  }
98 
99  gchar *fname2 = g_filename_from_uri(fname, NULL, NULL);
100  g_free(fname);
101 
102  return fname2;
103 }
104 
107 {
108  return audacious_remote_get_playlist_length(ui->pi->dbus_proxy);
109 }
110 
116 {
117  gint playlist_position = audacious_remote_get_playlist_pos(ui->pi->dbus_proxy);
118  return audacious_remote_get_playlist_title(ui->pi->dbus_proxy, playlist_position);
119 }
120 
123 {
124  return audacious_remote_get_output_time(ui->pi->dbus_proxy);
125 }
126 
129 {
130  static gchar *exec_command = "audacious";
131  gchar *exec_this = g_strdup_printf("%s &", exec_command);
132  system(exec_this);
133 
134  time_t lt;
135  gint timer = time(&lt);
136  while (!audacious_remote_is_running(ui->pi->dbus_proxy) && ((time(&lt) - timer) < 4))
137  {
138  usleep(0);
139  }
140 
141  g_free(exec_this);
142 }
143 
146 {
147  gint number = audacious_remote_get_playlist_length(ui->pi->dbus_proxy);
148  audacious_remote_set_playlist_pos(ui->pi->dbus_proxy, number - 1);
149 }
150 
153 {
155  audacious_remote_play(ui->pi->dbus_proxy);
156 }
157 
159 void myaudacious_add_files(GList *list, ui_state *ui)
160 {
161  GList *list_pos = list;
162  while (list_pos)
163  {
164  gchar *dup_filename = strdup(list_pos->data);
165  list_pos->data = g_filename_to_uri(dup_filename,NULL,NULL);
166  g_free(dup_filename);
167  list_pos = g_list_next(list_pos);
168  }
169 
170  audacious_remote_playlist_add(ui->pi->dbus_proxy, list);
171 }
172 
174 void myaudacious_set_volume(gint volume, ui_state *ui)
175 {
176  audacious_remote_set_main_volume(ui->pi->dbus_proxy, volume);
177 }
178 
181 {
182  return audacious_remote_get_main_volume(ui->pi->dbus_proxy);
183 }
184 
190 {
191  myaudacious_start(ui);
192  myaudacious_add_files(list, ui);
193 }
194 
197 {
198  if (!ui->pi->dbus_connection)
199  {
200  ui->pi->dbus_connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
201  }
202 
203  if (!ui->pi->dbus_proxy)
204  {
205  ui->pi->dbus_proxy = dbus_g_proxy_new_for_name(ui->pi->dbus_connection,
206  AUDACIOUS_DBUS_SERVICE,
207  AUDACIOUS_DBUS_PATH,
208  AUDACIOUS_DBUS_INTERFACE);
209  }
210 
211  if (!audacious_remote_is_running(ui->pi->dbus_proxy))
212  {
213  return FALSE;
214  }
215 
216  return TRUE;
217 }
218 
221 {
222  if (!audacious_remote_is_paused(ui->pi->dbus_proxy))
223  {
224  return FALSE;
225  }
226 
227  return TRUE;
228 }
229 
232 {
233  audacious_remote_play(ui->pi->dbus_proxy);
234 }
235 
238 {
239  audacious_remote_stop(ui->pi->dbus_proxy);
240 }
241 
244 {
245  audacious_remote_pause(ui->pi->dbus_proxy);
246 }
247 
250 {
251  audacious_remote_playlist_next(ui->pi->dbus_proxy);
252 }
253 
256 {
257  audacious_remote_playlist_prev(ui->pi->dbus_proxy);
258 }
259 
261 void myaudacious_jump(gint position, ui_state *ui)
262 {
263  audacious_remote_jump_to_time(ui->pi->dbus_proxy, position);
264 }
265 
268 {
269  gint playlist_position = audacious_remote_get_playlist_pos(ui->pi->dbus_proxy);
270  return audacious_remote_get_playlist_time(ui->pi->dbus_proxy, playlist_position);
271 }
272 
275 {
276  if (audacious_remote_is_playing(ui->pi->dbus_proxy))
277  {
278  return TRUE;
279  }
280 
281  return FALSE;
282 }
283 
284 #endif
285 
void myaudacious_set_volume(gint volume, ui_state *ui)
sets the volume level
void myaudacious_start(ui_state *ui)
starts audacious
void myaudacious_jump(gint position, ui_state *ui)
jump to time
void myaudacious_get_song_infos(gchar *total_infos, ui_state *ui)
Acquires informations about the song.
void myaudacious_select_last_file(ui_state *ui)
selects the last file in the playlist
gint myaudacious_get_volume(ui_state *ui)
returns volume level
gint myaudacious_is_paused(ui_state *ui)
returns TRUE if audacious is paused, if not, FALSE
gint myaudacious_get_time_elapsed(ui_state *ui)
returns elapsed time
gint myaudacious_get_playlist_number(ui_state *ui)
returns the number of songs in the playlist
gint myaudacious_is_running(ui_state *ui)
returns TRUE if audacious is running; if not, FALSE
void myaudacious_play(ui_state *ui)
Start playing the current song.
void myaudacious_prev(ui_state *ui)
Switch to the previous song.
void myaudacious_start_with_songs(GList *list, ui_state *ui)
starts audacious with songs
gint myaudacious_is_playing(ui_state *ui)
returns TRUE if audacious is playing, else FALSE
gchar * myaudacious_get_filename(ui_state *ui)
returns the filename
gint myaudacious_get_total_time(ui_state *ui)
returns the total duration of the current song
void myaudacious_add_files(GList *list, ui_state *ui)
add files to the audacious playlist
void myaudacious_play_last_file(ui_state *ui)
plays the last file of the playlist
void myaudacious_stop(ui_state *ui)
Stop playing the current song.
void myaudacious_pause(ui_state *ui)
Pause playing the current song.
void myaudacious_next(ui_state *ui)
Switch to the next song.
gchar * myaudacious_get_title_song(ui_state *ui)
returns the title of the song