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 }
void drct_play(void)
Definition: drct.c:38
void drct_set_volume(int l, int r)
Definition: playback.c:604
int playlist_get_playing(void)
Definition: playlist-new.c:921
void drct_set_volume_balance(int balance)
Definition: drct.c:113
bool_t playlist_next_song(int playlist_num, bool_t repeat)
void drct_set_volume_main(int volume)
Definition: drct.c:88
EXPORT Index * index_new(void)
Definition: index.c:41
int playlist_get_active(void)
Definition: playlist-new.c:861
static float a[EQ_BANDS][2]
Definition: equalizer.c:55
const char filename
Definition: misc-api.h:85
void drct_seek(int time)
Definition: playback.c:471
playlist
Definition: playlist-api.h:122
Main API header for accessing Audacious VFS functionality.
int playlist_get_temporary(void)
Definition: playlist-new.c:943
bool_t play
Definition: main.c:58
static float b[EQ_BANDS][2]
Definition: equalizer.c:56
void drct_stop(void)
Definition: drct.c:74
int playlist_entry_count(int playlist_num)
Definition: playlist-new.c:986
void drct_pl_prev(void)
Definition: drct.c:140
#define FALSE
Definition: core.h:37
bool_t playlist_prev_song(int playlist_num)
void drct_get_ab_repeat(int *a, int *b)
Definition: playback.c:646
Index Index bool_t
Definition: playlist-api.h:122
void drct_pl_open_list(Index *filenames)
Definition: drct.c:188
void playlist_queue_delete(int playlist_num, int at, int number)
void drct_pl_add(const char *filename, int at)
Definition: drct.c:169
void drct_get_volume_main(int *volume)
Definition: drct.c:81
static void add_list(Index *filenames, int at, bool_t to_temp, bool_t play)
Definition: drct.c:149
void drct_pl_open_temp(const char *filename)
Definition: drct.c:193
#define NULL
Definition: core.h:29
EXPORT void index_append(Index *index, void *value)
Definition: index.c:104
void playlist_set_active(int playlist_num)
Definition: playlist-new.c:843
void drct_pl_next(void)
Definition: drct.c:131
void drct_pl_delete_selected(int list)
Definition: drct.c:205
#define TRUE
Definition: core.h:39
bool_t get_bool(const char *section, const char *name)
Definition: config.c:300
void drct_pl_open(const char *filename)
Definition: drct.c:181
at
Definition: playlist-api.h:122
void playlist_entry_delete(int playlist_num, int at, int number)
void playlist_entry_insert_batch(int playlist, int at, Index *filenames, Index *tuples, bool_t play)
Definition: adder.c:527
void playlist_set_position(int playlist_num, int entry_num)
void drct_pl_add_list(Index *filenames, int at)
Definition: drct.c:176
bool_t drct_get_paused(void)
Definition: playback.c:466
void drct_pause(void)
Definition: playback.c:202
void drct_pl_open_temp_list(Index *filenames)
Definition: drct.c:200
EXPORT void hook_call(const char *name, void *data)
Definition: hook.c:104
#define MAX(a, b)
Definition: core.h:44
void drct_play_pause(void)
Definition: drct.c:59
void drct_get_volume_balance(int *balance)
Definition: drct.c:100
int playlist_queue_count(int playlist_num)
int playlist_get_position(int playlist_num)
char ** filenames
Definition: main.c:56
void playlist_set_playing(int playlist_num)
Definition: playlist-new.c:868
void playlist_delete_selected(int playlist_num)
void drct_get_volume(int *l, int *r)
Definition: playback.c:595
char * str_get(const char *str)
Definition: strpool.c:68
void drct_play_playlist(int playlist)
Definition: drct.c:67
void drct_quit(void)
Definition: drct.c:31
bool_t drct_get_playing(void)
Definition: playback.c:461