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
|
#include <string.h>
|
27
|
|
28
|
#include <libfauxdcore/audstrings.h>
|
29
|
#include <libfauxdcore/drct.h>
|
30
|
#include <libfauxdcore/equalizer.h>
|
31
|
#include <libfauxdcore/hook.h>
|
32
|
#include <libfauxdcore/i18n.h>
|
33
|
#include <libfauxdcore/runtime.h>
|
34
|
#include <libfauxdqt/libfauxdqt.h>
|
35
|
|
36
|
#include "menus.h"
|
37
|
#include "plugin.h"
|
38
|
#include "skins_cfg.h"
|
39
|
#include "equalizer.h"
|
40
|
#include "main.h"
|
41
|
#include "button.h"
|
42
|
#include "eq-graph.h"
|
43
|
#include "eq-slider.h"
|
44
|
#include "hslider.h"
|
45
|
#include "window.h"
|
46
|
#include "skins_util.h"
|
47
|
#include "view.h"
|
48
|
|
49
|
class EqWindow : public Window
|
50
|
{
|
51
|
public:
|
52
|
EqWindow (bool shaded) :
|
53
|
Window (WINDOW_EQ, & config.equalizer_x, & config.equalizer_y, 275,
|
54
|
shaded ? 14 : 116, shaded) {}
|
55
|
|
56
|
private:
|
57
|
void draw (QPainter & cr);
|
58
|
bool button_press (QMouseEvent * event);
|
59
|
};
|
60
|
|
61
|
Window * equalizerwin;
|
62
|
|
63
|
static EqGraph * equalizerwin_graph;
|
64
|
static Button * equalizerwin_on, * equalizerwin_auto;
|
65
|
static Button * equalizerwin_close, * equalizerwin_shade;
|
66
|
static Button * equalizerwin_shaded_close, * equalizerwin_shaded_shade;
|
67
|
static Button * equalizerwin_presets;
|
68
|
static EqSlider * equalizerwin_preamp, * equalizerwin_bands[10];
|
69
|
static HSlider * equalizerwin_volume, * equalizerwin_balance;
|
70
|
|
71
|
static void equalizerwin_shade_toggle ()
|
72
|
{
|
73
|
view_set_equalizer_shaded (! aud_get_bool ("skins", "equalizer_shaded"));
|
74
|
}
|
75
|
|
76
|
static void eq_on_cb (Button * button, QMouseEvent * event)
|
77
|
{
|
78
|
aud_set_bool (nullptr, "equalizer_active", button->get_active ());
|
79
|
}
|
80
|
|
81
|
static void eq_preset_cb (Button * button, QMouseEvent * event)
|
82
|
{
|
83
|
audqt::eq_presets_show ();
|
84
|
button->set_active (aud_get_bool (nullptr, "equalizer_songauto"));
|
85
|
}
|
86
|
|
87
|
static void eq_auto_cb (Button * button, QMouseEvent * event)
|
88
|
{
|
89
|
aud_set_bool (nullptr, "equalizer_autoload", button->get_active ());
|
90
|
}
|
91
|
|
92
|
static void update_from_config (void *, void *)
|
93
|
{
|
94
|
equalizerwin_on->set_active (aud_get_bool (nullptr, "equalizer_active"));
|
95
|
equalizerwin_auto->set_active (aud_get_bool (nullptr, "equalizer_autoload"));
|
96
|
equalizerwin_preamp->set_value (aud_get_double (nullptr, "equalizer_preamp"));
|
97
|
equalizerwin_presets->set_active (aud_get_bool (nullptr, "equalizer_songauto"));
|
98
|
|
99
|
double bands[AUD_EQ_NBANDS];
|
100
|
aud_eq_get_bands (bands);
|
101
|
|
102
|
for (int i = 0; i < AUD_EQ_NBANDS; i ++)
|
103
|
equalizerwin_bands[i]->set_value (bands[i]);
|
104
|
|
105
|
equalizerwin_graph->refresh ();
|
106
|
}
|
107
|
|
108
|
bool EqWindow::button_press (QMouseEvent * event)
|
109
|
{
|
110
|
if (event->button () == Qt::LeftButton &&
|
111
|
event->type () == QEvent::MouseButtonDblClick &&
|
112
|
event->y () < 14 * config.scale)
|
113
|
{
|
114
|
equalizerwin_shade_toggle ();
|
115
|
return true;
|
116
|
}
|
117
|
|
118
|
if (event->button () == Qt::RightButton && event->type () == QEvent::MouseButtonPress)
|
119
|
{
|
120
|
menu_popup (UI_MENU_MAIN, event->globalX (), event->globalY (), false, false);
|
121
|
return true;
|
122
|
}
|
123
|
|
124
|
return Window::button_press (event);
|
125
|
}
|
126
|
|
127
|
static void equalizerwin_close_cb ()
|
128
|
{
|
129
|
view_set_show_equalizer (false);
|
130
|
}
|
131
|
|
132
|
static void eqwin_volume_set_knob ()
|
133
|
{
|
134
|
int pos = equalizerwin_volume->get_pos ();
|
135
|
int x = (pos < 32) ? 1 : (pos < 63) ? 4 : 7;
|
136
|
equalizerwin_volume->set_knob (x, 30, x, 30);
|
137
|
}
|
138
|
|
139
|
void equalizerwin_set_volume_slider (int percent)
|
140
|
{
|
141
|
equalizerwin_volume->set_pos ((percent * 94 + 50) / 100);
|
142
|
eqwin_volume_set_knob ();
|
143
|
}
|
144
|
|
145
|
static void eqwin_volume_motion_cb ()
|
146
|
{
|
147
|
eqwin_volume_set_knob ();
|
148
|
int pos = equalizerwin_volume->get_pos ();
|
149
|
int v = (pos * 100 + 47) / 94;
|
150
|
|
151
|
mainwin_adjust_volume_motion (v);
|
152
|
mainwin_set_volume_slider (v);
|
153
|
}
|
154
|
|
155
|
static void eqwin_volume_release_cb ()
|
156
|
{
|
157
|
eqwin_volume_set_knob ();
|
158
|
mainwin_adjust_volume_release ();
|
159
|
}
|
160
|
|
161
|
static void eqwin_balance_set_knob ()
|
162
|
{
|
163
|
int pos = equalizerwin_balance->get_pos ();
|
164
|
int x = (pos < 13) ? 11 : (pos < 26) ? 14 : 17;
|
165
|
equalizerwin_balance->set_knob (x, 30, x, 30);
|
166
|
}
|
167
|
|
168
|
void equalizerwin_set_balance_slider (int percent)
|
169
|
{
|
170
|
if (percent > 0)
|
171
|
equalizerwin_balance->set_pos (19 + (percent * 19 + 50) / 100);
|
172
|
else
|
173
|
equalizerwin_balance->set_pos (19 + (percent * 19 - 50) / 100);
|
174
|
|
175
|
eqwin_balance_set_knob ();
|
176
|
}
|
177
|
|
178
|
static void eqwin_balance_motion_cb ()
|
179
|
{
|
180
|
eqwin_balance_set_knob ();
|
181
|
int pos = equalizerwin_balance->get_pos ();
|
182
|
pos = aud::min(pos, 38);
|
183
|
|
184
|
int b;
|
185
|
if (pos > 19)
|
186
|
b = ((pos - 19) * 100 + 9) / 19;
|
187
|
else
|
188
|
b = ((pos - 19) * 100 - 9) / 19;
|
189
|
|
190
|
mainwin_adjust_balance_motion (b);
|
191
|
mainwin_set_balance_slider (b);
|
192
|
}
|
193
|
|
194
|
static void eqwin_balance_release_cb ()
|
195
|
{
|
196
|
eqwin_balance_set_knob ();
|
197
|
mainwin_adjust_balance_release ();
|
198
|
}
|
199
|
|
200
|
static void equalizerwin_create_widgets ()
|
201
|
{
|
202
|
|
203
|
equalizerwin_on = new Button (25, 12, 10, 119, 128, 119, 69, 119, 187, 119, SKIN_EQMAIN, SKIN_EQMAIN);
|
204
|
equalizerwin->put_widget (false, equalizerwin_on, 14, 18);
|
205
|
equalizerwin_on->set_active (aud_get_bool (nullptr, "equalizer_active"));
|
206
|
equalizerwin_on->on_release (eq_on_cb);
|
207
|
|
208
|
|
209
|
equalizerwin_auto = new Button (33, 12, 35, 119, 153, 119, 94, 119, 212, 119, SKIN_EQMAIN, SKIN_EQMAIN);
|
210
|
equalizerwin->put_widget (false, equalizerwin_auto, 39, 18);
|
211
|
|
212
|
equalizerwin_auto->set_active (aud_get_bool (nullptr, "equalizer_autoload"));
|
213
|
equalizerwin_auto->on_release (eq_auto_cb);
|
214
|
|
215
|
equalizerwin_presets = new Button (44, 12, 224, 164, 224, 176, 224, 176, 224, 164, SKIN_EQMAIN, SKIN_EQMAIN);
|
216
|
equalizerwin->put_widget (false, equalizerwin_presets, 217, 18);
|
217
|
|
218
|
|
219
|
equalizerwin_presets->set_active (aud_get_bool (nullptr, "equalizer_songauto"));
|
220
|
equalizerwin_presets->on_release (eq_preset_cb);
|
221
|
|
222
|
equalizerwin_close = new Button (9, 9, 0, 116, 0, 125, SKIN_EQMAIN, SKIN_EQMAIN);
|
223
|
equalizerwin->put_widget (false, equalizerwin_close, 264, 3);
|
224
|
equalizerwin_close->on_release ((ButtonCB) equalizerwin_close_cb);
|
225
|
|
226
|
equalizerwin_shade = new Button (9, 9, 254, 137, 1, 38, SKIN_EQMAIN, SKIN_EQ_EX);
|
227
|
equalizerwin->put_widget (false, equalizerwin_shade, 254, 3);
|
228
|
equalizerwin_shade->on_release ((ButtonCB) equalizerwin_shade_toggle);
|
229
|
|
230
|
equalizerwin_shaded_close = new Button (9, 9, 11, 38, 11, 47, SKIN_EQ_EX, SKIN_EQ_EX);
|
231
|
equalizerwin->put_widget (true, equalizerwin_shaded_close, 264, 3);
|
232
|
equalizerwin_shaded_close->on_release ((ButtonCB) equalizerwin_close_cb);
|
233
|
|
234
|
equalizerwin_shaded_shade = new Button (9, 9, 254, 3, 1, 47, SKIN_EQ_EX, SKIN_EQ_EX);
|
235
|
equalizerwin->put_widget (true, equalizerwin_shaded_shade, 254, 3);
|
236
|
equalizerwin_shaded_shade->on_release ((ButtonCB) equalizerwin_shade_toggle);
|
237
|
|
238
|
equalizerwin_graph = new EqGraph;
|
239
|
equalizerwin->put_widget (false, equalizerwin_graph, 86, 17);
|
240
|
|
241
|
equalizerwin_preamp = new EqSlider (_("Preamp"), -1);
|
242
|
equalizerwin->put_widget (false, equalizerwin_preamp, 21, 38);
|
243
|
equalizerwin_preamp->set_value (aud_get_double (nullptr, "equalizer_preamp"));
|
244
|
|
245
|
const char * const bandnames[AUD_EQ_NBANDS] = {N_("31 Hz"),
|
246
|
N_("63 Hz"), N_("125 Hz"), N_("250 Hz"), N_("500 Hz"), N_("1 kHz"),
|
247
|
N_("2 kHz"), N_("4 kHz"), N_("8 kHz"), N_("16 kHz")};
|
248
|
double bands[AUD_EQ_NBANDS];
|
249
|
aud_eq_get_bands (bands);
|
250
|
|
251
|
for (int i = 0; i < AUD_EQ_NBANDS; i ++)
|
252
|
{
|
253
|
equalizerwin_bands[i] = new EqSlider (_(bandnames[i]), i);
|
254
|
equalizerwin->put_widget (false, equalizerwin_bands[i], 78 + 18 * i, 38);
|
255
|
equalizerwin_bands[i]->set_value (bands[i]);
|
256
|
}
|
257
|
|
258
|
equalizerwin_volume = new HSlider (0, 94, SKIN_EQ_EX, 97, 8, 61, 4, 3, 7, 1, 30, 1, 30);
|
259
|
equalizerwin->put_widget (true, equalizerwin_volume, 61, 4);
|
260
|
equalizerwin_volume->on_move (eqwin_volume_motion_cb);
|
261
|
equalizerwin_volume->on_release (eqwin_volume_release_cb);
|
262
|
|
263
|
equalizerwin_balance = new HSlider (0, 39, SKIN_EQ_EX, 42, 8, 164, 4, 3, 7, 11, 30, 11, 30);
|
264
|
equalizerwin->put_widget (true, equalizerwin_balance, 164, 4);
|
265
|
equalizerwin_balance->on_move (eqwin_balance_motion_cb);
|
266
|
equalizerwin_balance->on_release (eqwin_balance_release_cb);
|
267
|
}
|
268
|
|
269
|
void EqWindow::draw (QPainter & cr)
|
270
|
{
|
271
|
skin_draw_pixbuf (cr, SKIN_EQMAIN, 0, 0, 0, 0, 275, is_shaded () ? 14 : 116);
|
272
|
|
273
|
if (is_shaded ())
|
274
|
skin_draw_pixbuf (cr, SKIN_EQ_EX, 0, 0, 0, 0, 275, 14);
|
275
|
else
|
276
|
skin_draw_pixbuf (cr, SKIN_EQMAIN, 0, 134, 0, 0, 275, 14);
|
277
|
}
|
278
|
|
279
|
static void equalizerwin_create_window ()
|
280
|
{
|
281
|
bool shaded = aud_get_bool ("skins", "equalizer_shaded");
|
282
|
|
283
|
|
284
|
if (skin.pixmaps[SKIN_EQ_EX].isNull ())
|
285
|
shaded = false;
|
286
|
|
287
|
equalizerwin = new EqWindow (shaded);
|
288
|
equalizerwin->setWindowTitle (_("Fauxdacious Equalizer"));
|
289
|
}
|
290
|
|
291
|
void equalizerwin_unhook ()
|
292
|
{
|
293
|
hook_dissociate ("set equalizer_active", (HookFunction) update_from_config);
|
294
|
hook_dissociate ("set equalizer_bands", (HookFunction) update_from_config);
|
295
|
hook_dissociate ("set equalizer_preamp", (HookFunction) update_from_config);
|
296
|
hook_dissociate ("set equalizer_autoload", (HookFunction) update_from_config);
|
297
|
hook_dissociate ("set equalizer_songauto", (HookFunction) update_from_config);
|
298
|
}
|
299
|
|
300
|
void equalizerwin_create ()
|
301
|
{
|
302
|
equalizerwin_create_window ();
|
303
|
equalizerwin_create_widgets ();
|
304
|
|
305
|
hook_associate ("set equalizer_active", (HookFunction) update_from_config, nullptr);
|
306
|
hook_associate ("set equalizer_bands", (HookFunction) update_from_config, nullptr);
|
307
|
hook_associate ("set equalizer_preamp", (HookFunction) update_from_config, nullptr);
|
308
|
hook_associate ("set equalizer_autoload", (HookFunction) update_from_config, nullptr);
|
309
|
hook_associate ("set equalizer_songauto", (HookFunction) update_from_config, nullptr);
|
310
|
}
|