mp3splt-gtk
|
00001 /********************************************************** 00002 * 00003 * mp3splt-gtk -- utility based on mp3splt, 00004 * for mp3/ogg splitting without decoding 00005 * 00006 * Copyright: (C) 2005-2011 Alexandru Munteanu 00007 * Contact: io_fx@yahoo.fr 00008 * 00009 * from BMP to Audacious patch from Roberto Neri - 2007,2008 00010 * 00011 * http://mp3splt.sourceforge.net/ 00012 * 00013 *********************************************************/ 00014 00015 /********************************************************** 00016 * 00017 * This program is free software; you can redistribute it and/or 00018 * modify it under the terms of the GNU General Public License 00019 * as published by the Free Software Foundation; either version 2 00020 * of the License, or (at your option) any later version. 00021 * 00022 * This program is distributed in the hope that it will be useful, 00023 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00025 * GNU General Public License for more details. 00026 * 00027 * You should have received a copy of the GNU General Public License 00028 * along with this program; if not, write to the Free Software 00029 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00030 * USA. 00031 * 00032 *********************************************************/ 00033 00034 /*!******************************************************** 00035 * \file 00036 * xmms control 00037 * 00038 * this file contains the functions that control the xmms 00039 * player 00040 ********************************************************/ 00041 00042 #include <stdlib.h> 00043 #include <gtk/gtk.h> 00044 #include <glib/gi18n.h> 00045 #include <time.h> 00046 #include <unistd.h> 00047 #include <string.h> 00048 00049 #ifndef NO_AUDACIOUS 00050 #include <audacious/audctrl.h> 00051 #include <audacious/dbus.h> 00052 //ugly hack until fix 00053 DBusGProxy *dbus_proxy = NULL; 00054 static DBusGConnection *dbus_connection = NULL; 00055 #endif 00056 00057 #include "player.h" 00058 00059 #ifndef NO_AUDACIOUS 00060 00061 void myxmms_get_song_infos(gchar *total_infos) 00062 { 00063 //the frequency 00064 gint freq; 00065 //rate kb/s 00066 gint rate; 00067 //number of channels (mono/stereo) 00068 gint nch; 00069 00070 gchar rate_str[32] = { '\0' }; 00071 gchar freq_str[32] = { '\0' }; 00072 gchar nch_str[32] = { '\0' }; 00073 00074 //infos about the song 00075 audacious_remote_get_info(dbus_proxy, &rate, &freq, &nch); 00076 00077 g_snprintf(rate_str,32, "%d", rate/1000); 00078 g_snprintf(freq_str,32, "%d", freq/1000); 00079 00080 if (nch == 2) 00081 { 00082 snprintf(nch_str, 32, "%s", _("stereo")); 00083 } 00084 else 00085 { 00086 snprintf(nch_str, 32, "%s", _("mono")); 00087 } 00088 00089 gchar *_Kbps = _("Kbps"); 00090 gchar *_Khz = _("Khz"); 00091 00092 if (rate != 0) 00093 { 00094 g_snprintf(total_infos,512, 00095 "%s %s %s %s %s", 00096 rate_str,_Kbps,freq_str, _Khz,nch_str); 00097 } 00098 else 00099 { 00100 total_infos[0] = '\0'; 00101 } 00102 } 00103 00108 gchar *myxmms_get_filename() 00109 { 00110 gchar *fname; 00111 00112 //position of the song in the playlist 00113 gint playlist_position; 00114 00115 playlist_position = audacious_remote_get_playlist_pos(dbus_proxy); 00116 00117 fname = audacious_remote_get_playlist_file(dbus_proxy, playlist_position); 00118 00119 //erase file:// and replace %20 with spaces 00120 gchar *fname2 = g_filename_from_uri(fname,NULL,NULL); 00121 g_free(fname); 00122 fname = NULL; 00123 00124 return fname2; 00125 } 00126 00128 gint myxmms_get_playlist_number() 00129 { 00130 return audacious_remote_get_playlist_length(dbus_proxy); 00131 } 00132 00137 gchar *myxmms_get_title_song() 00138 { 00139 gchar *title; 00140 00141 //position of the song in the playlist 00142 gint playlist_position; 00143 00144 playlist_position = audacious_remote_get_playlist_pos(dbus_proxy); 00145 title = audacious_remote_get_playlist_title(dbus_proxy,playlist_position); 00146 00147 return title; 00148 } 00149 00151 gint myxmms_get_time_elapsed() 00152 { 00153 return audacious_remote_get_output_time(dbus_proxy); 00154 } 00155 00157 void myxmms_start() 00158 { 00159 gint timer; 00160 time_t lt; 00161 00162 static gchar *exec_command; 00163 exec_command = "audacious"; 00164 gchar *exec_this = g_strdup_printf("%s &", exec_command); 00165 system(exec_this); 00166 00167 timer = time(<); 00168 while (!audacious_remote_is_running(dbus_proxy) 00169 && ((time(<) - timer) < 4)) 00170 { 00171 usleep(0); 00172 } 00173 00174 g_free(exec_this); 00175 } 00176 00178 void myxmms_select_last_file() 00179 { 00180 gint number; 00181 number = audacious_remote_get_playlist_length(dbus_proxy); 00182 audacious_remote_set_playlist_pos(dbus_proxy,(number-1)); 00183 } 00184 00186 void myxmms_play_last_file() 00187 { 00188 myxmms_select_last_file(); 00189 audacious_remote_play(dbus_proxy); 00190 } 00191 00193 void myxmms_add_files(GList *list) 00194 { 00195 //change filenames into URLs 00196 GList *list_pos = list; 00197 00198 //for each element of the list 00199 while (list_pos) 00200 { 00201 //duplicate the filename 00202 gchar *dup_filename = strdup(list_pos->data); 00203 //free the GList data content 00204 //g_free(list_pos->data); 00205 //put the new GList data content 00206 list_pos->data = g_filename_to_uri(dup_filename,NULL,NULL); 00207 //free the duplicated filename 00208 g_free(dup_filename); 00209 dup_filename = NULL; 00210 //move to the next element 00211 list_pos = g_list_next(list_pos); 00212 } 00213 00214 audacious_remote_playlist_add(dbus_proxy, list); 00215 } 00216 00218 void myxmms_set_volume(gint volume) 00219 { 00220 audacious_remote_set_main_volume(dbus_proxy, volume); 00221 } 00222 00224 gint myxmms_get_volume() 00225 { 00226 return audacious_remote_get_main_volume(dbus_proxy); 00227 } 00228 00234 void myxmms_start_with_songs(GList *list) 00235 { 00236 myxmms_start(); 00237 myxmms_add_files(list); 00238 } 00239 00241 gint myxmms_is_running() 00242 { 00243 if (!dbus_connection) 00244 { 00245 dbus_connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); 00246 } 00247 if (!dbus_proxy) 00248 { 00249 dbus_proxy = dbus_g_proxy_new_for_name(dbus_connection, 00250 AUDACIOUS_DBUS_SERVICE, 00251 AUDACIOUS_DBUS_PATH, 00252 AUDACIOUS_DBUS_INTERFACE); 00253 } 00254 if (!audacious_remote_is_running(dbus_proxy)) 00255 return FALSE; 00256 else 00257 return TRUE; 00258 } 00259 00261 gint myxmms_is_paused() 00262 { 00263 if (!audacious_remote_is_paused(dbus_proxy)) 00264 return FALSE; 00265 else 00266 return TRUE; 00267 } 00268 00270 void myxmms_play() 00271 { 00272 audacious_remote_play(dbus_proxy); 00273 } 00274 00276 void myxmms_stop() 00277 { 00278 audacious_remote_stop(dbus_proxy); 00279 } 00280 00282 void myxmms_pause() 00283 { 00284 audacious_remote_pause(dbus_proxy); 00285 } 00286 00288 void myxmms_next() 00289 { 00290 audacious_remote_playlist_next(dbus_proxy); 00291 } 00292 00294 void myxmms_prev() 00295 { 00296 audacious_remote_playlist_prev(dbus_proxy); 00297 } 00298 00300 void myxmms_jump(gint position) 00301 { 00302 audacious_remote_jump_to_time(dbus_proxy, position); 00303 } 00304 00306 gint myxmms_get_total_time() 00307 { 00308 gint playlist_position; 00309 playlist_position = audacious_remote_get_playlist_pos(dbus_proxy); 00310 return audacious_remote_get_playlist_time(dbus_proxy,playlist_position); 00311 } 00312 00314 gint myxmms_is_playing() 00315 { 00316 if(audacious_remote_is_playing(dbus_proxy)) 00317 return TRUE; 00318 else 00319 return FALSE; 00320 } 00321 00323 void myxmms_quit() 00324 { 00325 audacious_remote_quit(dbus_proxy); 00326 } 00327 00328 #endif 00329