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
|
/*
Copyright (C) 2006 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"
Player *players[NUM_PLAYERS];
static LISTENINGTOINFO current = {0};
void InitMusic()
{
players[WATRACK] = new WATrack();
players[GENERIC] = new GenericPlayer();
players[WMP] = new WindowsMediaPlayer();
players[WINAMP] = new Winamp();
players[ITUNES] = new ITunes();
players[FOOBAR] = new Foobar();
players[MRADIO] = new MRadio();
}
void FreeMusic()
{
for (int i = 0; i < NUM_PLAYERS; i++) {
delete players[i];
players[i] = nullptr;
}
}
void EnableDisablePlayers()
{
for (int i = 0; i < NUM_PLAYERS; i++)
players[i]->EnableDisable();
}
void FreeListeningInfo(LISTENINGTOINFO *lti)
{
lti->cbSize = 0;
lti->dwFlags = 0;
MIR_FREE(lti->ptszArtist);
MIR_FREE(lti->ptszAlbum);
MIR_FREE(lti->ptszTitle);
MIR_FREE(lti->ptszTrack);
MIR_FREE(lti->ptszYear);
MIR_FREE(lti->ptszGenre);
MIR_FREE(lti->ptszLength);
MIR_FREE(lti->ptszPlayer);
MIR_FREE(lti->ptszType);
}
void CopyListeningInfo(LISTENINGTOINFO *dest, const LISTENINGTOINFO * const src)
{
FreeListeningInfo(dest);
dest->cbSize = src->cbSize;
dest->dwFlags = src->dwFlags;
dest->ptszArtist = mir_wstrdup(src->ptszArtist);
dest->ptszAlbum = mir_wstrdup(src->ptszAlbum);
dest->ptszTitle = mir_wstrdup(src->ptszTitle);
dest->ptszTrack = mir_wstrdup(src->ptszTrack);
dest->ptszYear = mir_wstrdup(src->ptszYear);
dest->ptszGenre = mir_wstrdup(src->ptszGenre);
dest->ptszLength = mir_wstrdup(src->ptszLength);
dest->ptszPlayer = mir_wstrdup(src->ptszPlayer);
dest->ptszType = mir_wstrdup(src->ptszType);
}
BOOL Equals(const LISTENINGTOINFO *lti1, const LISTENINGTOINFO *lti2)
{
if (lti1->cbSize != lti2->cbSize)
return FALSE;
return mir_wstrcmpi(lti1->ptszArtist, lti2->ptszArtist) == 0
&& mir_wstrcmpi(lti1->ptszAlbum, lti2->ptszAlbum) == 0
&& mir_wstrcmpi(lti1->ptszTitle, lti2->ptszTitle) == 0
&& mir_wstrcmpi(lti1->ptszTrack, lti2->ptszTrack) == 0
&& mir_wstrcmpi(lti1->ptszYear, lti2->ptszYear) == 0
&& mir_wstrcmpi(lti1->ptszGenre, lti2->ptszGenre) == 0
&& mir_wstrcmpi(lti1->ptszLength, lti2->ptszLength) == 0
&& mir_wstrcmpi(lti1->ptszPlayer, lti2->ptszPlayer) == 0
&& mir_wstrcmpi(lti1->ptszType, lti2->ptszType) == 0;
}
int ChangedListeningInfo()
{
BOOL changed = FALSE;
BOOL playing = FALSE;
int first = (players[WATRACK]->enabled ? WATRACK : GENERIC);
int last = (players[WATRACK]->enabled ? WATRACK + 1 : NUM_PLAYERS);
for (int i = first; i < last; i++) {
if (!players[i]->enabled)
continue;
LISTENINGTOINFO lti = { 0 };
if (!players[i]->GetListeningInfo(<i))
continue;
if (!IsTypeEnabled(<i)) {
FreeListeningInfo(<i);
continue;
}
playing = TRUE;
if (Equals(¤t, <i))
FreeListeningInfo(<i);
else {
FreeListeningInfo(¤t);
memcpy(¤t, <i, sizeof(current));
changed = 1;
}
break;
}
if (!playing && current.cbSize != 0) {
FreeListeningInfo(¤t);
changed = 1;
}
if (!changed)
return 0;
else
return current.cbSize == 0 ? -1 : 1;
}
LISTENINGTOINFO * GetListeningInfo()
{
if (current.cbSize == 0)
return nullptr;
return ¤t;
}
|