-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMacPlayer.h
158 lines (142 loc) · 3.14 KB
/
MacPlayer.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
#include <Dialogs.h>
#include <Lists.h>
#include <vector>
#include <MacWifi/MacWifiLib.h>
#include "Prefs.h"
#include "CDEF/DarkListDef.h"
#include "CDEF/DarkScrollbarDef.h"
#include "CDEF/DarkSliderDef.h"
#include "SpotifyClient.h"
const double mPollFrequencyMs = 5000;
enum UIState
{
Init,
Login,
Player
};
enum
{
kMenuApple = 128,
kMenuFile,
kMenuDevices
};
enum
{
kItemAbout = 1,
kItemQuit = 1
};
enum UIElements
{
kPlayerDialog = 128,
kPlayerMenubar = 128,
kPlayerLoginButton = 3,
kPlayerPlaylistsLabel = 1,
kPlayerNavList = 2,
kPlayerTrackLabel = 3,
kPlayerArtistLabel = 4,
kPlayerTrackList = 5,
kPlayerPlayButton = 6,
kPlayerPrevTrack = 7,
kPlayerNextTrack = 8,
kPlayerVolumeControl = 12,
kPlayerStartupDITL = 130,
kPlayerLoginDITL = 128,
kPlayerMainDITL = 129,
kPlayerPlayIcon = 128,
kPlayerPauseIcon = 136,
kAboutDialog = 133,
kPlaceholderImage = 134
};
struct Device
{
string name;
string id;
bool active;
};
struct Playlist
{
string name;
string id;
string uri;
};
struct Track
{
string name;
string artist;
string uri;
string image;
string albumId;
};
struct PlayerState
{
bool isPlaying;
};
bool _run = true;
UIState _uiState = Login;
MacWifiLib _wifiLib;
Prefs _prefs;
SpotifyClient _spotifyClient(&_wifiLib, &_prefs);
UnsignedWide _lastPollTime;
PlayerState _playerState;
bool _viewNowPlaying = false;
int main();
void InitToolBox();
void ShowMainWindow();
void MenuInit();
void EventInit();
void EventLoop();
void InitPlayer(DialogPtr dialog);
void DoEvent(EventRecord *eventPtr);
void HandleMouseDown(EventRecord *eventPtr);
void HandleInContent(EventRecord *eventPtr);
void HandleLoginContent(short item);
void HandleUpdate(EventRecord *eventPtr);
void HandleActivate(EventRecord *eventPtr);
void HandleOSEvt(EventRecord *eventPtr);
void ModeInit(DialogPtr dialog);
void ModeLogin(DialogPtr dialog);
void ModePlayer(DialogPtr dialog);
void HandleMenuChoice(long menuChoice);
void ShowAboutBox();
void WaitCursor();
void HandlePlayerContent(EventRecord *eventPtr, short item);
void GetRecentTracks();
void GetPlaylists(DialogPtr dialog);
void GetPlaylistTracks(const string& uri, const string& playlistId);
void InitCustomLDEF();
void PlayTrack();
void ViewNowPlaying();
void UpdateCurrentTrack();
void PopulateTrackList(JsonValue& root);
Track GetTrackObject(JsonValue& track);
void SetTrackImage(JsonValue& track, Track& trackObj);
void PollPlayerState();
void DrawTrackImage();
void TogglePlayButtonIcon();
void ExitApp();
void ActivateDevice(int index);
void GetDevices();
void NoDevicesError();
void DrawTrackName();
void DrawPlaceholderImage();
void TrackChanging();
vector<Device> _devices;
vector<Track> _tracks;
vector<Playlist> _playlists;
Track _currentTrack;
string _currentContext;
bool _activeDevice;
Rect _trackImageRect;
bool _pausePoll;
int _currentVolume;
ListHandle _navList = 0, _trackList = 0;
ListHandle CreateList(
WindowPtr windowPtr,
Rect rect,
int columnsInList,
int ldef,
short cellWidth,
short cellHeight);
void PopulateNavList(ListHandle list);
pascal OSErr Quit(AppleEvent* appleEvent, AppleEvent* reply, long refCon);
pascal OSErr ProcessResponseEvent(AppleEvent* appleEvent, AppleEvent* reply, long refCon);