Audacious  $Id:Doxyfile42802007-03-2104:39:00Znenolod$
drct.c
Go to the documentation of this file.
1 /*
2  * drct.c
3  * Copyright 2009-2011 John Lindgren
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions, and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions, and the following disclaimer in the documentation
13  * provided with the distribution.
14  *
15  * This software is provided "as is" and without any warranty, express or
16  * implied. In no event shall the authors be liable for any damages arising from
17  * the use of this software.
18  */
19 
20 #include <glib.h>
21 #include <libaudcore/hook.h>
22 #include <libaudcore/vfs.h>
23 
24 #include "drct.h"
25 #include "i18n.h"
26 #include "misc.h"
27 #include "playlist.h"
28 
29 /* --- PROGRAM CONTROL --- */
30 
31 void drct_quit (void)
32 {
33  hook_call ("quit", NULL);
34 }
35 
36 /* --- PLAYBACK CONTROL --- */
37 
38 void drct_play (void)
39 {
40  if (drct_get_playing ())
41  {
42  if (drct_get_paused ())
43  drct_pause ();
44  else
45  {
46  int a, b;
47  drct_get_ab_repeat (& a, & b);
48  drct_seek (MAX (a, 0));
49  }
50  }
51  else
52  {
54  playlist_set_position (playlist, playlist_get_position (playlist));
55  drct_play_playlist (playlist);
56  }
57 }
58 
59 void drct_play_pause (void)
60 {
61  if (drct_get_playing ())
62  drct_pause ();
63  else
64  drct_play ();
65 }
66 
68 {
69  playlist_set_playing (playlist);
70  if (drct_get_paused ())
71  drct_pause ();
72 }
73 
74 void drct_stop (void)
75 {
77 }
78 
79 /* --- VOLUME CONTROL --- */
80 
81 void drct_get_volume_main (int * volume)
82 {
83  int left, right;
84  drct_get_volume (& left, & right);
85  * volume = MAX (left, right);
86 }
87 
88 void drct_set_volume_main (int volume)
89 {
90  int left, right, current;
91  drct_get_volume (& left, & right);
92  current = MAX (left, right);
93 
94  if (current > 0)
95  drct_set_volume (volume * left / current, volume * right / current);
96  else
97  drct_set_volume (volume, volume);
98 }
99 
100 void drct_get_volume_balance (int * balance)
101 {
102  int left, right;
103  drct_get_volume (& left, & right);
104 
105  if (left == right)
106  * balance = 0;
107  else if (left > right)
108  * balance = -100 + right * 100 / left;
109  else
110  * balance = 100 - left * 100 / right;
111 }
112 
113 void drct_set_volume_balance (int balance)
114 {
115  int left, right;
116  drct_get_volume_main (& left);
117 
118  if (balance < 0)
119  right = left * (100 + balance) / 100;
120  else
121  {
122  right = left;
123  left = right * (100 - balance) / 100;
124  }
125 
126  drct_set_volume (left, right);
127 }
128 
129 /* --- PLAYLIST CONTROL --- */
130 
131 void drct_pl_next (void)
132 {
134  if (playlist < 0)
135  playlist = playlist_get_active ();
136 
137  playlist_next_song (playlist, get_bool (NULL, "repeat"));
138 }
139 
140 void drct_pl_prev (void)
141 {
143  if (playlist < 0)
144  playlist = playlist_get_active ();
145 
146  playlist_prev_song (playlist);
147 }
148 
149 static void add_list (Index * filenames, int at, bool_t to_temp, bool_t play)
150 {
151  if (to_temp)
153 
154  int playlist = playlist_get_active ();
155 
156  /* queue the new entries before deleting the old ones */
157  /* this is to avoid triggering the --quit-after-play condition */
158  playlist_entry_insert_batch (playlist, at, filenames, NULL, play);
159 
160  if (play)
161  {
162  if (get_bool (NULL, "clear_playlist"))
163  playlist_entry_delete (playlist, 0, playlist_entry_count (playlist));
164  else
165  playlist_queue_delete (playlist, 0, playlist_queue_count (playlist));
166  }
167 }
168 
169 void drct_pl_add (const char * filename, int at)
170 {
171  Index * filenames = index_new ();
172  index_append (filenames, str_get (filename));
173  add_list (filenames, at, FALSE, FALSE);
174 }
175 
176 void drct_pl_add_list (Index * filenames, int at)
177 {
178  add_list (filenames, at, FALSE, FALSE);
179 }
180 
181 void drct_pl_open (const char * filename)
182 {
183  Index * filenames = index_new ();
184  index_append (filenames, str_get (filename));
185  add_list (filenames, -1, get_bool (NULL, "open_to_temporary"), TRUE);
186 }
187 
189 {
190  add_list (filenames, -1, get_bool (NULL, "open_to_temporary"), TRUE);
191 }
192 
193 void drct_pl_open_temp (const char * filename)
194 {
195  Index * filenames = index_new ();
196  index_append (filenames, str_get (filename));
197  add_list (filenames, -1, TRUE, TRUE);
198 }
199 
201 {
202  add_list (filenames, -1, TRUE, TRUE);
203 }
204 
205 void drct_pl_delete_selected (int list)
206 {
208 }