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
|
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gtk/gtk.h>
#include <math.h>
#include <stdlib.h>
#include "callbacks.h"
#include "interface.h"
#include "support.h"
#include "common.h"
#include "psdl.h"
#include "playlist.h"
#include "gtkplaylist.h"
#include "messagepump.h"
#include "messages.h"
#include "codec.h"
extern GtkWidget *mainwin;
static void
addfile_func (gpointer data, gpointer userdata) {
ps_add_file (data);
g_free (data);
}
void
on_volume_value_changed (GtkRange *range,
gpointer user_data)
{
psdl_set_volume (gtk_range_get_value (range) / 100);
}
int g_disable_seekbar_handler = 0;
void
on_playpos_value_changed (GtkRange *range,
gpointer user_data)
{
if (g_disable_seekbar_handler) {
return;
}
if (playlist_current && playlist_current->codec) {
if (playlist_current->codec->info.duration > 0) {
int val = gtk_range_get_value (range);
int upper = gtk_adjustment_get_upper (gtk_range_get_adjustment (range));
float time = playlist_current->codec->info.duration / (float)upper * (float)val;
messagepump_push (M_SONGSEEK, 0, (int)time * 1000, 0);
}
}
}
// change properties
gboolean
on_playlist_configure_event (GtkWidget *widget,
GdkEventConfigure *event,
gpointer user_data)
{
gtkps_reconf (widget);
return FALSE;
}
// redraw
gboolean
on_playlist_expose_event (GtkWidget *widget,
GdkEventExpose *event,
gpointer user_data)
{
// draw visible area of playlist
gtkps_expose (widget, event->area.x, event->area.y, event->area.width, event->area.height);
return FALSE;
}
void
on_playlist_realize (GtkWidget *widget,
gpointer user_data)
{
}
gboolean
on_playlist_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
if (event->button == 1) {
gtkps_mouse1_clicked (widget, event->x, event->y, event->time);
}
return FALSE;
}
void
on_playscroll_value_changed (GtkRange *range,
gpointer user_data)
{
int newscroll = gtk_range_get_value (GTK_RANGE (range));
gtkps_scroll (newscroll);
}
void
on_open_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
}
void
on_add_files_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
GtkWidget *dlg = gtk_file_chooser_dialog_new ("Add file(s) to playlist...", GTK_WINDOW (mainwin), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
GtkFileFilter* flt;
flt = gtk_file_filter_new ();
gtk_file_filter_set_name (flt, "Supported music files");
gtk_file_filter_add_pattern (flt, "*.ogg");
gtk_file_filter_add_pattern (flt, "*.mod");
gtk_file_filter_add_pattern (flt, "*.wav");
gtk_file_filter_add_pattern (flt, "*.mp3");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dlg), flt);
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dlg), flt);
flt = gtk_file_filter_new ();
gtk_file_filter_set_name (flt, "Other files (*)");
gtk_file_filter_add_pattern (flt, "*");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dlg), flt);
gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dlg), TRUE);
if (gtk_dialog_run (GTK_DIALOG (dlg)) == GTK_RESPONSE_OK)
{
GSList *lst = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (dlg));
g_slist_foreach(lst, addfile_func, NULL);
g_slist_free (lst);
}
gtk_widget_destroy (dlg);
gtkps_setup_scrollbar ();
GtkWidget *widget = lookup_widget (mainwin, "playlist");
draw_playlist (widget, 0, 0, widget->allocation.width, widget->allocation.height);
gtkps_expose (widget, 0, 0, widget->allocation.width, widget->allocation.height);
}
void
on_add_folder1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
GtkWidget *dlg = gtk_file_chooser_dialog_new ("Add folder to playlist...", GTK_WINDOW (mainwin), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
if (gtk_dialog_run (GTK_DIALOG (dlg)) == GTK_RESPONSE_OK)
{
gchar *folder = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dlg));
if (folder) {
ps_add_dir (folder);
g_free (folder);
}
}
gtk_widget_destroy (dlg);
gtkps_setup_scrollbar ();
GtkWidget *widget = lookup_widget (mainwin, "playlist");
draw_playlist (widget, 0, 0, widget->allocation.width, widget->allocation.height);
gtkps_expose (widget, 0, 0, widget->allocation.width, widget->allocation.height);
}
void
on_preferences1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
}
void
on_quit1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
}
void
on_clear1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
}
void
on_select_all1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
}
void
on_remove1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
}
void
on_crop1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
}
void
on_about1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
}
gboolean
on_playlist_scroll_event (GtkWidget *widget,
GdkEvent *event,
gpointer user_data)
{
// pass event to scrollbar
GtkWidget *range = lookup_widget (mainwin, "playscroll");
GdkEventScroll *ev = (GdkEventScroll*)event;
GtkAdjustment* adj = gtk_range_get_adjustment (GTK_RANGE (range));
int newscroll = gtk_range_get_value (GTK_RANGE (range));
if (ev->direction == GDK_SCROLL_UP) {
newscroll -= 10;//gtk_adjustment_get_page_increment (adj);
}
else if (ev->direction == GDK_SCROLL_DOWN) {
newscroll += 10;//gtk_adjustment_get_page_increment (adj);
}
gtk_range_set_value (GTK_RANGE (range), newscroll);
return FALSE;
}
void
on_stopbtn_clicked (GtkButton *button,
gpointer user_data)
{
messagepump_push (M_STOPSONG, 0, 0, 0);
}
void
on_playbtn_clicked (GtkButton *button,
gpointer user_data)
{
messagepump_push (M_PLAYSONG, 0, 0, 0);
}
void
on_pausebtn_clicked (GtkButton *button,
gpointer user_data)
{
messagepump_push (M_PAUSESONG, 0, 0, 0);
}
void
on_prevbtn_clicked (GtkButton *button,
gpointer user_data)
{
messagepump_push (M_PREVSONG, 0, 0, 0);
}
void
on_nextbtn_clicked (GtkButton *button,
gpointer user_data)
{
messagepump_push (M_NEXTSONG, 0, 0, 0);
}
void
on_playrand_clicked (GtkButton *button,
gpointer user_data)
{
messagepump_push (M_PLAYRANDOM, 0, 0, 0);
}
|