The Winamp Remote Control suite
a remote control client and plugin for Winamp 2.x, 5.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WinampTestServer.cpp
Go to the documentation of this file.
1 
2 #include "WinampTestServer.h"
3 
4 #include <sstream>
5 
6 namespace WinampRemote
7 {
8 namespace Server
9 {
10 
11 
13  m_playbackStatus(WA_NOT_PLAYING),
14  m_playList(),
15  m_playlistPosition(-1),
16  m_volume(0),
17  m_songPosition(0),
18  m_repeat(false), m_shuffle(false),
19  m_eqdata(), m_eqindex(0),
20  m_panning(0),
21  m_stopType(Performed),
22  m_StartCount(0)
23 {
24  char title[MAX_PATH] = "";
25  char filename[MAX_PATH] = "";
26  for (int i = 0 ; i < 20 ; i++)
27  {
28  sprintf(title, "playlist item %d", i);
29  sprintf(filename, "c:\\music\\file%d", i);
30  m_playList.push_back(PlaylistItem(title, filename));
31  }
32 }
33 
35 {
36  // destroy any owned resources here
37 }
38 
40 {
41  return "test server";
42 }
43 
44 void WinampTestServer::wrapPlaylistIndex(int increment)
45 {
46  m_playlistPosition += increment;
47  int length = m_playList.size();
48  m_playlistPosition = m_playlistPosition % length;
49 }
50 
51 void WinampTestServer::updateStatus()
52 {
53  switch (m_stopType)
54  {
55  case Performed:
56  return;
57  case Immediate:
58  break;
59  case WithFade:
60  case AfterCurrent:
61  {
62  DWORD currentCount = GetTickCount();
63  if (currentCount < (m_StartCount + 1000))
64  return;
65  }
66  break;
67 
68  }
69  m_stopType = Performed;
70  m_playbackStatus = WA_NOT_PLAYING;
71 }
72 
73 void WinampTestServer::setPlaying()
74 {
75  m_stopType = Performed;
76  m_playbackStatus = WA_PLAYING;
77 }
78 
79 void WinampTestServer::setStop(StopType stop)
80 {
81  m_StartCount = GetTickCount();
82  m_stopType = stop;
83 }
84 
86 {
87 
88  updateStatus();
89  switch (MessageToExecute)
90  {
91 
92  case WINAMP_FILE_PLAY:
93 
94  setPlaying();
95  break;
96  case WINAMP_PLAYENTRY:
97  case IPC_PLAYFILE:
98  setPlaying();
99  m_playlistPosition = (-1 == m_playlistPosition)? 0 : m_playlistPosition;
100  break;
101 
103  setStop(AfterCurrent);
104  break;
105  case WINAMP_STOPFADE:
106  setStop(WithFade);
107  break;
108  case WINAMP_STOP:
109  setStop(Immediate);
110  break;
111  case WINAMP_PAUSE:
112  m_playbackStatus = WA_PAUSED;
113  break;
114 
115  case WINAMP_NEXT:
116  wrapPlaylistIndex(1);
117  break;
118  case WINAMP_PREVIOUS:
119  wrapPlaylistIndex(-1);
120  break;
121 
122 
123  case WINAMP_FILE_REPEAT:
124  m_repeat = !m_repeat;
125  break;
126  case WINAMP_FILE_SHUFFLE:
127  m_shuffle = !m_shuffle;
128  break;
130  m_playlistPosition = 0;
131  break;
133  m_playlistPosition = m_playList.size() - 1;
134  break;
135  case WINAMP_FORWARD5S:
136  m_songPosition += 5000;
137  break;
138  case WINAMP_BACK5S:
139  m_songPosition -= 5000;
140  break;
141  }
142 
143 // throw std::runtime_error("WinampTestServer::ExecuteCommand not implemented");
144 
145 }
146 
148 {
149 
150  updateStatus();
151  switch (Command)
152  {
153  case IPC_PLAYFILE:
154  {
155  PlaylistItem pi(CommandString, CommandString);
156  m_playList.push_back(pi);
157  }
158  break;
159  default:
160  throw std::runtime_error("WinampTestServer::ExecuteStringCommand not implemented");
161 
162  }
163 }
164 
166 {
167 
168  updateStatus();
169  switch (Command)
170  {
171 
172  case IPC_GETVERSION:
173  return 0x123;
174  case IPC_ISPLAYING:
175  return m_playbackStatus;
176  case IPC_SETPLAYLISTPOS:
177  m_playlistPosition = Data;
178  break;
179  case IPC_GETOUTPUTTIME:
180  if (Data == 0)
181  return m_songPosition;
182  return 202; // 3 minutes 22 seconds
183  case IPC_GETLISTLENGTH:
184  return m_playList.size();
185  case IPC_GETLISTPOS:
186  return m_playlistPosition;
187  case IPC_GETEQDATA:
188  if ((Data >= 0 ) && (Data < 13))
189  {
190  m_eqindex = Data;
191  return m_eqdata[m_eqindex];
192 
193  }
194  return 0;
196  return m_shuffle;
197  case IPC_GETREPEATOPTION:
198  return m_repeat;
199  case IPC_SETVOLUME:
200  {
201  if (Data == -666)
202  return m_volume;
203  m_volume = Data;
204  return 0;
205  }
206  case IPC_JUMPTOTIME:
207  m_songPosition = Data;
208  return 0;
209  case IPC_STARTPLAY:
210  setPlaying();
211  m_playlistPosition = (-1 == m_playlistPosition)? 0 : m_playlistPosition;
212  break;
213  case IPC_SETEQDATA:
214  m_eqdata[m_eqindex] = Data;
215  break;
217  m_shuffle = (Data)?true:false;
218  break;
219  case IPC_SETREPEATOPTION:
220  m_repeat = (Data)?true:false;
221  break;
222  case IPC_SETPANNING:
223  {
224  if (Data == -666)
225  return m_panning;
226  m_panning = Data;
227  return 0;
228  }
229  case IPC_DELETE:
230  m_playList.clear();
231  m_playlistPosition = 0;
232  break;
233  }
234 
235  return 0;
236 }
237 
239 {
240  updateStatus();
241  if ( (Data > -1) && (Data < (int) m_playList.size() ) )
242  {
243  switch (Command)
244  {
245  case IPC_GETPLAYLISTTITLE :
246  return m_playList[Data].title;
247  case IPC_GETPLAYLISTFILE :
248  return m_playList[Data].filename;
249  default:
250  {
251  std::stringstream sstr;
252  sstr << "WinampTestServer::QueryString not implemented for " << Command;
253  throw std::runtime_error(sstr.str());
254  }
255  }
256  }
257  else
258  {
259  return ( std::string("error index out of range" ) );
260  }
261 
262 }
263 
264 } /* namespace Server */
265 } /* namespace WinampRemote */