Audacious $Id:Doxyfile42802007-03-2104:39:00Znenolod$
|
00001 /* 00002 * drct.c 00003 * Copyright 2009-2011 John Lindgren 00004 * 00005 * This file is part of Audacious. 00006 * 00007 * Audacious is free software: you can redistribute it and/or modify it under 00008 * the terms of the GNU General Public License as published by the Free Software 00009 * Foundation, version 2 or version 3 of the License. 00010 * 00011 * Audacious is distributed in the hope that it will be useful, but WITHOUT ANY 00012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00013 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along with 00016 * Audacious. If not, see <http://www.gnu.org/licenses/>. 00017 * 00018 * The Audacious team does not consider modular code linking to Audacious or 00019 * using our public API to be a derived work. 00020 */ 00021 00022 #include <glib.h> 00023 #include <libaudcore/hook.h> 00024 #include <libaudcore/vfs.h> 00025 00026 #include "config.h" 00027 #include "drct.h" 00028 #include "i18n.h" 00029 #include "misc.h" 00030 #include "playback.h" 00031 #include "playlist.h" 00032 00033 /* --- PROGRAM CONTROL --- */ 00034 00035 void drct_quit (void) 00036 { 00037 hook_call ("quit", NULL); 00038 } 00039 00040 /* --- PLAYBACK CONTROL --- */ 00041 00042 void drct_play (void) 00043 { 00044 if (playback_get_playing ()) 00045 { 00046 if (playback_get_paused ()) 00047 playback_pause (); 00048 else 00049 playback_seek (0); 00050 } 00051 else 00052 { 00053 playlist_set_playing (playlist_get_active ()); 00054 playback_play (0, FALSE); 00055 } 00056 } 00057 00058 void drct_pause (void) 00059 { 00060 if (playback_get_playing ()) 00061 playback_pause (); 00062 } 00063 00064 void drct_stop (void) 00065 { 00066 if (playback_get_playing ()) 00067 playback_stop (); 00068 } 00069 00070 bool_t drct_get_playing (void) 00071 { 00072 return playback_get_playing (); 00073 } 00074 00075 bool_t drct_get_ready (void) 00076 { 00077 return playback_get_ready (); 00078 } 00079 00080 bool_t drct_get_paused (void) 00081 { 00082 return playback_get_paused (); 00083 } 00084 00085 char * drct_get_filename (void) 00086 { 00087 return playback_get_filename (); 00088 } 00089 00090 char * drct_get_title (void) 00091 { 00092 return playback_get_title (); 00093 } 00094 00095 void drct_get_info (int * bitrate, int * samplerate, int * channels) 00096 { 00097 playback_get_info (bitrate, samplerate, channels); 00098 } 00099 00100 int drct_get_time (void) 00101 { 00102 return playback_get_time (); 00103 } 00104 00105 int drct_get_length (void) 00106 { 00107 return playback_get_length (); 00108 } 00109 00110 void drct_seek (int time) 00111 { 00112 playback_seek (time); 00113 } 00114 00115 /* --- VOLUME CONTROL --- */ 00116 00117 void drct_get_volume (int * left, int * right) 00118 { 00119 playback_get_volume (left, right); 00120 * left = CLAMP (* left, 0, 100); 00121 * right = CLAMP (* right, 0, 100); 00122 } 00123 00124 void drct_set_volume (int left, int right) 00125 { 00126 playback_set_volume (CLAMP (left, 0, 100), CLAMP (right, 0, 100)); 00127 } 00128 00129 void drct_get_volume_main (int * volume) 00130 { 00131 int left, right; 00132 drct_get_volume (& left, & right); 00133 * volume = MAX (left, right); 00134 } 00135 00136 void drct_set_volume_main (int volume) 00137 { 00138 int left, right, current; 00139 drct_get_volume (& left, & right); 00140 current = MAX (left, right); 00141 00142 if (current > 0) 00143 drct_set_volume (volume * left / current, volume * right / current); 00144 else 00145 drct_set_volume (volume, volume); 00146 } 00147 00148 void drct_get_volume_balance (int * balance) 00149 { 00150 int left, right; 00151 drct_get_volume (& left, & right); 00152 00153 if (left == right) 00154 * balance = 0; 00155 else if (left > right) 00156 * balance = -100 + right * 100 / left; 00157 else 00158 * balance = 100 - left * 100 / right; 00159 } 00160 00161 void drct_set_volume_balance (int balance) 00162 { 00163 int left, right; 00164 drct_get_volume_main (& left); 00165 00166 if (balance < 0) 00167 right = left * (100 + balance) / 100; 00168 else 00169 { 00170 right = left; 00171 left = right * (100 - balance) / 100; 00172 } 00173 00174 drct_set_volume (left, right); 00175 } 00176 00177 /* --- PLAYLIST CONTROL --- */ 00178 00179 void drct_pl_next (void) 00180 { 00181 bool_t play = playback_get_playing (); 00182 if (playlist_get_playing () < 0) 00183 playlist_set_playing (playlist_get_active ()); 00184 if (playlist_next_song (playlist_get_playing (), get_bool (NULL, "repeat")) && play) 00185 playback_play (0, FALSE); 00186 } 00187 00188 void drct_pl_prev (void) 00189 { 00190 bool_t play = playback_get_playing (); 00191 if (playlist_get_playing () < 0) 00192 playlist_set_playing (playlist_get_active ()); 00193 if (playlist_prev_song (playlist_get_playing ()) && play) 00194 playback_play (0, FALSE); 00195 } 00196 00197 static void add_list (Index * filenames, int at, bool_t to_temp, bool_t play) 00198 { 00199 if (to_temp) 00200 playlist_set_active (playlist_get_temporary ()); 00201 00202 int playlist = playlist_get_active (); 00203 00204 if (play) 00205 { 00206 if (get_bool (NULL, "clear_playlist")) 00207 playlist_entry_delete (playlist, 0, playlist_entry_count (playlist)); 00208 else 00209 playlist_queue_delete (playlist, 0, playlist_queue_count (playlist)); 00210 } 00211 00212 playlist_entry_insert_batch (playlist, at, filenames, NULL, play); 00213 } 00214 00215 void drct_pl_add (const char * filename, int at) 00216 { 00217 Index * filenames = index_new (); 00218 index_append (filenames, str_get (filename)); 00219 add_list (filenames, at, FALSE, FALSE); 00220 } 00221 00222 void drct_pl_add_list (Index * filenames, int at) 00223 { 00224 add_list (filenames, at, FALSE, FALSE); 00225 } 00226 00227 void drct_pl_open (const char * filename) 00228 { 00229 Index * filenames = index_new (); 00230 index_append (filenames, str_get (filename)); 00231 add_list (filenames, -1, get_bool (NULL, "open_to_temporary"), TRUE); 00232 } 00233 00234 void drct_pl_open_list (Index * filenames) 00235 { 00236 add_list (filenames, -1, get_bool (NULL, "open_to_temporary"), TRUE); 00237 } 00238 00239 void drct_pl_open_temp (const char * filename) 00240 { 00241 Index * filenames = index_new (); 00242 index_append (filenames, str_get (filename)); 00243 add_list (filenames, -1, TRUE, TRUE); 00244 } 00245 00246 void drct_pl_open_temp_list (Index * filenames) 00247 { 00248 add_list (filenames, -1, TRUE, TRUE); 00249 } 00250 00251 /* Advancing to the next song when the current one is deleted is tricky. First, 00252 * we delete all the selected songs except the current one. We can then advance 00253 * to a new song without worrying about picking one that is also selected. 00254 * Finally, we can delete the former current song without stopping playback. */ 00255 00256 void drct_pl_delete_selected (int list) 00257 { 00258 int pos = playlist_get_position (list); 00259 00260 if (get_bool (NULL, "advance_on_delete") 00261 && ! get_bool (NULL, "no_playlist_advance") 00262 && playback_get_playing () && list == playlist_get_playing () 00263 && pos >= 0 && playlist_entry_get_selected (list, pos)) 00264 { 00265 playlist_entry_set_selected (list, pos, FALSE); 00266 playlist_delete_selected (list); 00267 pos = playlist_get_position (list); /* it may have moved */ 00268 00269 if (playlist_next_song (list, get_bool (NULL, "repeat")) 00270 && playlist_get_position (list) != pos) 00271 playback_play (0, FALSE); 00272 00273 playlist_entry_delete (list, pos, 1); 00274 } 00275 else 00276 playlist_delete_selected (list); 00277 }