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
|
/*
Copyright (C) 2005-2009 Ricardo Pescuma Domenecci
This is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this file; see the file license.txt. If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "../stdafx.h"
static WATrack *instance = nullptr;
int NewStatusCallback(WPARAM wParam, LPARAM lParam)
{
if (!loaded)
return 0;
if (instance != nullptr)
instance->NewStatus(wParam, lParam);
return 0;
}
WATrack::WATrack()
{
name = L"WATrack";
instance = this;
hNewStatusHook = nullptr;
}
WATrack::~WATrack()
{
if (hNewStatusHook != nullptr) {
UnhookEvent(hNewStatusHook);
hNewStatusHook = nullptr;
}
instance = nullptr;
}
void WATrack::EnableDisable()
{
if (!ServiceExists(MS_WAT_GETMUSICINFO)) {
enabled = FALSE;
return;
}
if (hNewStatusHook == nullptr)
hNewStatusHook = HookEvent(ME_WAT_NEWSTATUS, NewStatusCallback);
}
void WATrack::NewStatus(int event, int value)
{
{
mir_cslock lck(cs);
if (event == WAT_EVENT_PLUGINSTATUS && value != 0)
FreeData();
else
GetData();
}
NotifyInfoChanged();
}
void WATrack::GetData()
{
SONGINFO *si = nullptr;
int playing = CallService(MS_WAT_GETMUSICINFO, WAT_INF_UNICODE, (LPARAM)&si);
FreeData();
// See if something is playing
if (playing == WAT_RES_NOTFOUND || si == nullptr || si->status != 1 || (IsEmpty(si->artist) && IsEmpty(si->title)))
return;
// Copy new data
listening_info.ptszAlbum = DUP(si->album);
listening_info.ptszArtist = DUP(si->artist);
listening_info.ptszTitle = DUP(si->title);
listening_info.ptszYear = DUP(si->year);
if (si->track > 0) {
listening_info.ptszTrack = (wchar_t*)mir_alloc(10 * sizeof(wchar_t));
_itow(si->track, listening_info.ptszTrack, 10);
}
listening_info.ptszGenre = DUP(si->genre);
if (si->total > 0) {
listening_info.ptszLength = (wchar_t*)mir_alloc(10 * sizeof(wchar_t));
int s = si->total % 60;
int m = (si->total / 60) % 60;
int h = (si->total / 60) / 60;
if (h > 0)
mir_snwprintf(listening_info.ptszLength, 9, L"%d:%02d:%02d", h, m, s);
else
mir_snwprintf(listening_info.ptszLength, 9, L"%d:%02d", m, s);
}
if (si->width > 0)
listening_info.ptszType = mir_wstrdup(L"Video");
else
listening_info.ptszType = mir_wstrdup(L"Music");
listening_info.ptszPlayer = DUPD(si->player, name);
listening_info.cbSize = sizeof(listening_info);
listening_info.dwFlags = LTI_TCHAR;
}
|