forked from kran27/Spotiamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spotifyamp.h
333 lines (264 loc) · 7.12 KB
/
spotifyamp.h
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#ifndef SPOTIFYAMP_SPOTIFYAMP_H_
#define SPOTIFYAMP_SPOTIFYAMP_H_
extern "C" {
#include "tiny_spotify.h"
#include "types.h"
};
#include "window.h"
#include <string>
#include <vector>
static inline bool IsInside(int x, int pos, int w) {
return (unsigned)(x - pos) < (unsigned)w;
}
static inline int Clamp(int v, int mi, int ma) {
if (v < mi) v = mi;
if (v > ma) v = ma;
return v;
}
static inline int IntMin(int a, int b) {
return (a < b) ? a : b;
}
static inline int IntMax(int a, int b) {
return (a > b) ? a : b;
}
struct ButtonRect {
int x, y, w, h;
};
#define WND_MAIN_W 275
#define WND_MAIN_H 116
class PlaylistWindow;
class EqWindow;
class MainWindow : public PlatformWindow {
public:
MainWindow();
virtual ~MainWindow();
bool Load();
// -- from PlatformWindow
virtual void LeftButtonDown(int x, int y);
virtual void LeftButtonDouble(int x, int y);
virtual void LeftButtonUp(int x, int y);
virtual void RightButtonDown(int x, int y);
virtual void MouseMove(int x, int y);
virtual void MouseWheel(int x, int y, int dx, int dy);
virtual void Paint();
virtual void KeyDown(int key, int shift);
virtual void MainLoop();
virtual void ScrollText();
virtual bool HandleAppCommandHotKeys(int cmd, int keys);
virtual void GlobalHotkey(int id);
virtual void PumpIOEvents();
void Perform(int cmd);
void OpenUri(const char* query, int track_to_play);
void PaintBigNumber(int num, int x, int y);
void PaintSmallNumber(int num, int x, int y);
int FindButton(int x, int y);
void ButtonClicked(int b);
void SetCompact(bool v);
void SetPositionIndicator(int pos);
void SetPlaylistVisible(bool v);
void SetCoverartVisible(bool v);
bool playlist_visible() const { return playlist_; }
bool coverart_visible() const { return coverart_visible_; }
void SetEqVisible(bool v);
void SetDoubleSize(bool v);
void SetAlwaysOnTop(bool v);
bool eq_visible() const { return equalizer_; }
void ResetScroll() { text_scroll_ = 0; text_scroll_delay_ = 5; }
void Login(const char* username, const char* password);
void SaveNowPlaying();
void ShowEjectMenu();
void ShowSearchDialog();
void ShowLoginDialog();
void ShowOptionsMenu();
void ShowVisualizeMenu();
void Quit();
void AppendPlaylistPopupMenu(MenuBuilder& menu, int base_id,
const char* cur_uri, bool only_writable);
Tsp* tsp() const { return tsp_; }
TspItemList* item_list() const { return item_list_; }
TspItemList* player_list() const { return player_list_; }
public:
void PaintCompact();
void PaintFull();
void InitThreading();
void SetShoutcast(bool shoutcast);
void EnableGlobalHotkeys(bool enable);
Tsp* tsp_;
TspItemList* item_list_, * player_list_;
bool lbutton_down_;
bool equalizer_, playlist_;
bool mono_, stereo_;
bool compact_;
bool dragging_text_;
bool time_mode_;
bool connect_error_;
bool in_dialog_;
bool global_hotkeys_;
bool itemlist_in_sync_with_player_;
bool dragging_vol_;
int8 dragging_vol_delta_;
int volume_pixel_;
bool shoutcast_;
byte curr_vis_plugin_;
bool coverart_visible_;
bool dragging_seek_;
int8 dragging_seek_delta_;
int seek_pixel_;
int seek_target_;
int position_indicator_;
int text_scroll_;
unsigned char text_scroll_delay_;
int mouse_last_x_, mouse_last_y_;
const ButtonRect* buttons_;
int buttons_count_;
int hover_button_;
int delayed_command_;
PlaylistWindow* playlist_window_;
EqWindow* eq_window_;
TspBitrate bitrate_;
std::string username_;
std::string curr_skin_;
std::vector<std::string> pluris_;
std::vector<std::string> remote_device_ids_;
};
class PlaylistWindow : public PlatformWindow {
public:
explicit PlaylistWindow(MainWindow* main_window);
virtual ~PlaylistWindow();
void Load();
// -- from PlatformWindow
virtual void LeftButtonDown(int x, int y);
virtual void LeftButtonDouble(int x, int y);
virtual void LeftButtonUp(int x, int y);
virtual void MouseMove(int x, int y);
virtual void MouseWheel(int x, int y, int dx, int dy);
virtual void Paint();
virtual void KeyDown(int key, int shift);
virtual bool SizeChanging(int* w, int* h);
virtual void RightButtonDown(int x, int y);
void SetCompact(bool compact);
void SelectItem(int item);
void SetScroll(int s);
void ScrollInView();
void ShowRightClickMenu();
void Perform(int cmd);
int CoordToItem(int x, int y);
void FixupScroll() { SetScroll(scroll_); }
private:
void PaintCompact();
void PaintFull();
int VisibleItemCount();
int FindButton(int x, int y);
int ItemCount();
void OpenItem(int itemindex);
bool compact_;
bool left_button_down_;
bool dragging_list_;
int dragging_list_delta_;
int dragging_list_pixel_;
int normal_height_;
MainWindow* main_window_;
int selected_item_;
int scroll_;
int hover_button_;
int font_size_;
int row_height_;
std::string last_added_playlist_uri_;
};
class EqWindow : public PlatformWindow {
public:
explicit EqWindow(MainWindow* main_window);
virtual ~EqWindow();
// -- from PlatformWindow
virtual void LeftButtonDown(int x, int y);
virtual void LeftButtonDouble(int x, int y);
virtual void LeftButtonUp(int x, int y);
virtual void RightButtonUp(int x, int y);
virtual void MouseMove(int x, int y);
virtual void Paint();
virtual void KeyDown(int key, int shift);
void SetCompact(bool compact);
void Load();
bool SetEqVal(int i, int v);
void ShowAutoPopup();
void OnSkinLoaded() { got_colors_ = false; }
private:
void PaintCompact();
void PaintFull();
int FindButton(int x, int y);
int FindEq(int x, int y);
void RepaintEq(int e);
int EqPixel(int j);
void DrawGraph();
void CopyToTsp();
void ShowPresets();
byte gain_mode_;
bool auto_enabled_;
bool compact_;
bool left_button_down_;
bool dragging_eq_;
bool got_colors_;
bool eq_enabled_;
int hover_eq_;
int dragging_eq_delta_;
int hover_button_;
int normal_height_;
MainWindow* main_window_;
int8 eqvals_[11]; // -127..127
uint32 colors_[19];
};
class GenWindow : public PlatformWindow {
public:
GenWindow();
virtual ~GenWindow();
// -- from PlatformWindow
virtual void LeftButtonDown(int x, int y);
virtual void LeftButtonDouble(int x, int y) {}
virtual void LeftButtonUp(int x, int y);
virtual void MouseMove(int x, int y);
virtual void Paint();
virtual void KeyDown(int key, int shift) {}
virtual void SizeChanged() {}
virtual bool SizeChanging(int* w, int* h);
virtual void OnClose() = 0;
int GetStringWidth(const char* s);
void DrawLetters(int x, int y, const char* s);
private:
int FindButton(int x, int y);
int hover_button_;
bool left_button_down_;
};
class CoverArtWindow : public GenWindow {
public:
explicit CoverArtWindow(MainWindow* main_window);
virtual ~CoverArtWindow();
virtual void Paint();
virtual void OnClose();
void SetImage(const char* image);
void GotImagePart(TspImageDownloadResult* part);
private:
void Load();
MainWindow* main_window_;
std::string image_;
std::string accumulating_bytes_;
bool image_needs_load_;
std::vector<char> buffer_;
Bitmap* bitmap_;
};
struct Resources {
Bitmap* main;
Bitmap* cbuttons;
Bitmap* shufrep;
Bitmap* monoster;
Bitmap* titlebar;
Bitmap* text;
Bitmap* numbers;
Bitmap* volume;
Bitmap* posbar;
Bitmap* playpaus;
Bitmap* pledit;
Bitmap* eqmain;
Bitmap* gen;
};
extern Resources res;
#endif // SPOTIFYAMP_SPOTIFYAMP_H_