1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
/*
hotkey action handlers for deadbeef hotkeys plugin
Copyright (C) 2009-2013 Alexey Yakovenko and other contributors
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <string.h>
#include "../../gettext.h"
#include "../../deadbeef.h"
extern DB_functions_t *deadbeef;
int
action_jump_to_current_handler (DB_plugin_action_t *act, int ctx) {
deadbeef->sendmessage (DB_EV_TRACKFOCUSCURRENT, 0, 0, 0);
return 0;
}
int
action_reload_metadata_handler (DB_plugin_action_t *act, int ctx) {
DB_playItem_t *it = deadbeef->pl_get_first (PL_MAIN);
while (it) {
deadbeef->pl_lock ();
char decoder_id[100];
const char *dec = deadbeef->pl_find_meta (it, ":DECODER");
if (dec) {
strncpy (decoder_id, dec, sizeof (decoder_id));
}
int match = deadbeef->pl_is_selected (it) && deadbeef->is_local_file (deadbeef->pl_find_meta (it, ":URI")) && dec;
deadbeef->pl_unlock ();
if (match) {
uint32_t f = deadbeef->pl_get_item_flags (it);
if (!(f & DDB_IS_SUBTRACK)) {
f &= ~DDB_TAG_MASK;
deadbeef->pl_set_item_flags (it, f);
DB_decoder_t **decoders = deadbeef->plug_get_decoder_list ();
for (int i = 0; decoders[i]; i++) {
if (!strcmp (decoders[i]->plugin.id, decoder_id)) {
if (decoders[i]->read_metadata) {
decoders[i]->read_metadata (it);
}
break;
}
}
}
}
DB_playItem_t *next = deadbeef->pl_get_next (it, PL_MAIN);
deadbeef->pl_item_unref (it);
it = next;
}
deadbeef->sendmessage (DB_EV_PLAYLIST_REFRESH, 0, 0, 0);
return 0;
}
int
action_next_playlist_handler (DB_plugin_action_t *act, int ctx) {
int tab = deadbeef->plt_get_curr_idx ();
if (tab < deadbeef->plt_get_count ()-1) {
tab++;
deadbeef->plt_set_curr_idx (tab);
deadbeef->conf_set_int ("playlist.current", tab);
}
return 0;
}
int
action_prev_playlist_handler (DB_plugin_action_t *act, int ctx) {
int tab = deadbeef->plt_get_curr_idx ();
if (tab > 0) {
tab--;
deadbeef->plt_set_curr_idx (tab);
deadbeef->conf_set_int ("playlist.current", tab);
}
return 0;
}
int
action_playlist1_handler (DB_plugin_action_t *act, int ctx) {
int pl = 0;
if (pl < deadbeef->plt_get_count ()) {
deadbeef->plt_set_curr_idx (pl);
deadbeef->conf_set_int ("playlist.current", pl);
}
return 0;
}
int
action_playlist2_handler (DB_plugin_action_t *act, int ctx) {
int pl = 1;
if (pl < deadbeef->plt_get_count ()) {
deadbeef->plt_set_curr_idx (pl);
deadbeef->conf_set_int ("playlist.current", pl);
}
return 0;
}
int
action_playlist3_handler (DB_plugin_action_t *act, int ctx) {
int pl = 2;
if (pl < deadbeef->plt_get_count ()) {
deadbeef->plt_set_curr_idx (pl);
deadbeef->conf_set_int ("playlist.current", pl);
}
return 0;
}
int
action_playlist4_handler (DB_plugin_action_t *act, int ctx) {
int pl = 3;
if (pl < deadbeef->plt_get_count ()) {
deadbeef->plt_set_curr_idx (pl);
deadbeef->conf_set_int ("playlist.current", pl);
}
return 0;
}
int
action_playlist5_handler (DB_plugin_action_t *act, int ctx) {
int pl = 4;
if (pl < deadbeef->plt_get_count ()) {
deadbeef->plt_set_curr_idx (pl);
deadbeef->conf_set_int ("playlist.current", pl);
}
return 0;
}
int
action_playlist6_handler (DB_plugin_action_t *act, int ctx) {
int pl = 5;
if (pl < deadbeef->plt_get_count ()) {
deadbeef->plt_set_curr_idx (pl);
deadbeef->conf_set_int ("playlist.current", pl);
}
return 0;
}
int
action_playlist7_handler (DB_plugin_action_t *act, int ctx) {
int pl = 6;
if (pl < deadbeef->plt_get_count ()) {
deadbeef->plt_set_curr_idx (pl);
deadbeef->conf_set_int ("playlist.current", pl);
}
return 0;
}
int
action_playlist8_handler (DB_plugin_action_t *act, int ctx) {
int pl = 7;
if (pl < deadbeef->plt_get_count ()) {
deadbeef->plt_set_curr_idx (pl);
deadbeef->conf_set_int ("playlist.current", pl);
}
return 0;
}
int
action_playlist9_handler (DB_plugin_action_t *act, int ctx) {
int pl = 8;
if (pl < deadbeef->plt_get_count ()) {
deadbeef->plt_set_curr_idx (pl);
deadbeef->conf_set_int ("playlist.current", pl);
}
return 0;
}
int
action_playlist10_handler (DB_plugin_action_t *act, int ctx) {
int pl = 9;
if (pl < deadbeef->plt_get_count ()) {
deadbeef->plt_set_curr_idx (pl);
deadbeef->conf_set_int ("playlist.current", pl);
}
return 0;
}
int
action_sort_randomize_handler (DB_plugin_action_t *act, int ctx) {
ddb_playlist_t *plt = deadbeef->plt_get_curr ();
deadbeef->plt_sort (plt, PL_MAIN, -1, NULL, DDB_SORT_RANDOM);
deadbeef->plt_unref (plt);
deadbeef->sendmessage (DB_EV_PLAYLISTCHANGED, 0, 0, 0);
return 0;
}
int
action_sort_by_date_handler (DB_plugin_action_t *act, int ctx) {
ddb_playlist_t *plt = deadbeef->plt_get_curr ();
deadbeef->plt_sort (plt, PL_MAIN, -1, "%y", DDB_SORT_ASCENDING);
deadbeef->plt_unref (plt);
deadbeef->sendmessage (DB_EV_PLAYLISTCHANGED, 0, 0, 0);
return 0;
}
int
action_sort_by_artist_handler (DB_plugin_action_t *act, int ctx) {
ddb_playlist_t *plt = deadbeef->plt_get_curr ();
deadbeef->plt_sort (plt, PL_MAIN, -1, "%a", DDB_SORT_ASCENDING);
deadbeef->plt_unref (plt);
deadbeef->sendmessage (DB_EV_PLAYLISTCHANGED, 0, 0, 0);
return 0;
}
int
action_sort_by_album_handler (DB_plugin_action_t *act, int ctx) {
ddb_playlist_t *plt = deadbeef->plt_get_curr ();
deadbeef->plt_sort (plt, PL_MAIN, -1, "%b", DDB_SORT_ASCENDING);
deadbeef->plt_unref (plt);
deadbeef->sendmessage (DB_EV_PLAYLISTCHANGED, 0, 0, 0);
return 0;
}
int
action_sort_by_tracknr_handler (DB_plugin_action_t *act, int ctx) {
ddb_playlist_t *plt = deadbeef->plt_get_curr ();
deadbeef->plt_sort (plt, PL_MAIN, -1, "%n", DDB_SORT_ASCENDING);
deadbeef->plt_unref (plt);
deadbeef->sendmessage (DB_EV_PLAYLISTCHANGED, 0, 0, 0);
return 0;
}
int
action_sort_by_title_handler (DB_plugin_action_t *act, int ctx) {
ddb_playlist_t *plt = deadbeef->plt_get_curr ();
deadbeef->plt_sort (plt, PL_MAIN, -1, "%t", DDB_SORT_ASCENDING);
deadbeef->plt_unref (plt);
deadbeef->sendmessage (DB_EV_PLAYLISTCHANGED, 0, 0, 0);
return 0;
}
int
action_invert_selection_handler (DB_plugin_action_t *act, int ctx) {
deadbeef->pl_lock ();
DB_playItem_t *it = deadbeef->pl_get_first (PL_MAIN);
while (it) {
if (deadbeef->pl_is_selected (it)) {
deadbeef->pl_set_selected (it, 0);
}
else {
deadbeef->pl_set_selected (it, 1);
}
DB_playItem_t *next = deadbeef->pl_get_next (it, PL_MAIN);
deadbeef->pl_item_unref (it);
it = next;
}
deadbeef->pl_unlock ();
deadbeef->sendmessage (DB_EV_PLAYLISTCHANGED, 0, 0, 0);
return 0;
}
int
action_clear_playlist_handler (DB_plugin_action_t *act, int ctx) {
deadbeef->pl_clear ();
deadbeef->pl_save_current ();
deadbeef->sendmessage (DB_EV_PLAYLISTCHANGED, 0, 0, 0);
return 0;
}
int
action_add_to_playqueue_handler (DB_plugin_action_t *act, int ctx) {
DB_playItem_t *it = deadbeef->pl_get_first (PL_MAIN);
while (it) {
if (ctx == DDB_ACTION_CTX_PLAYLIST || (ctx == DDB_ACTION_CTX_SELECTION && deadbeef->pl_is_selected (it))) {
deadbeef->pl_playqueue_push (it);
}
DB_playItem_t *next = deadbeef->pl_get_next (it, PL_MAIN);
deadbeef->pl_item_unref (it);
it = next;
}
deadbeef->sendmessage (DB_EV_PLAYLIST_REFRESH, 0, 0, 0);
return 0;
}
int
action_remove_from_playqueue_handler (DB_plugin_action_t *act, int ctx) {
DB_playItem_t *it = deadbeef->pl_get_first (PL_MAIN);
while (it) {
if (ctx == DDB_ACTION_CTX_PLAYLIST || (ctx == DDB_ACTION_CTX_SELECTION && deadbeef->pl_is_selected (it))) {
deadbeef->pl_playqueue_remove (it);
}
DB_playItem_t *next = deadbeef->pl_get_next (it, PL_MAIN);
deadbeef->pl_item_unref (it);
it = next;
}
deadbeef->sendmessage (DB_EV_PLAYLIST_REFRESH, 0, 0, 0);
return 0;
}
int
action_toggle_mute_handler (DB_plugin_action_t *act, int ctx) {
int mute = 1-deadbeef->audio_is_mute ();
deadbeef->audio_set_mute (mute);
return 0;
}
|