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
waint.cpp
Go to the documentation of this file.
1 /*
2  winamp remote control suite © Patrick Michael Martin 2000 - 2012
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License
6  as published by the Free Software Foundation; either version 2
7  of the License, or (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 
18  Patrick M. Martin may be reached by email at patrickmmartin@gmail.com.
19  */
20 
21 #include <stdio.h>
22 #include <windows.h>
23 #include <iostream>
24 #pragma hdrstop
25 
26 #include "waint.h"
27 
31 const int WM_WA_IPC = WM_USER;
32 
33 
34 static const char * WAPlaybackStatusDesc[WA_PAUSED + 1] =
35  {"not playing", "playing", "unused", "paused"};
36 
37 std::ostream& operator << (std::ostream& os, WAPlaybackStatus status)
38 {
39  switch (status)
40  {
41  case WA_NOT_PLAYING:
42  case WA_PLAYING:
43  case WA_UNUSED:
44  case WA_PAUSED:
45  os << WAPlaybackStatusDesc[status];
46  break;
47  default:
48  os << "unknown status value";
49  break;
50  };
51  return os;
52 }
53 
54 
55 std::ostream& operator << (std::ostream& os, WinampCommand command)
56 {
57  os << WinampCommandDesc(command);
58  return os;
59 }
60 
61 /*
62  * Utility function to obtain the winamp handle when out of process
63  * uses FindWindow, which is incredibly crufty, so let's not put this in a header.
64 static void GethWnd_WinAmp()
65 {
66  char * windowname = "Winamp v1.x";
67  hwnd_winamp = FindWindow(windowname, NULL);
68 }
69 */
70 
72 {
73  PostMessage(HWinamp, WM_COMMAND, Command, 0);
74 }
75 
76 // 1.7+ send a command with a string parameter
77 void LocalExecuteStringCommand(HWND HWinamp, const char * CommandString, WinampCommand Command)
78 {
79  COPYDATASTRUCT cds;
80 
81  cds.dwData = Command;
82  cds.lpData = (void *) CommandString;
83  cds.cbData = strlen((char *) cds.lpData) + 1;
84  SendMessage(HWinamp, WM_COPYDATA, (WPARAM) NULL, (LPARAM) &cds);
85 }
86 
87 // Send a message to Winamp and return an Integer
88 int LocalQueryInt(HWND HWinamp, WinampCommand Command, int Data)
89 {
90  return SendMessage(HWinamp, WM_WA_IPC, Data, Command);
91 }
92 
93 // Send a message to Winamp and return a String
94 char * LocalQueryString(HWND HWinamp, WinampCommand Command, int Data)
95 {
96  return (char *) SendMessage(HWinamp, WM_WA_IPC, Data, Command);
97 }
98 
99 
103 static char winampver[80];
104 
110 static char * StandardVersion(int version)
111 {
112 // formats the version according to (semi) standard numeric scheme
113  if (((version >> 4) & 0xf) != 0)
114  sprintf(winampver, "winamp %x.%x%x%x", version >> 12,
115  (version >> 8) & 0xf, (version >> 4) & 0xf, version & 0xf);
116  else
117  sprintf(winampver, "winamp %x.%x%x", version >> 12, (version >> 8) & 0xf,
118  version & 0xf);
119  return winampver;
120 }
121 
122 const char * WinampVersionString(int version)
123 {
124 
125  switch (version)
126  {
127  //special cases
128  case 0x00:
129  strcpy(winampver, "Winamp unavailable");
130  break;
131  case 0x1551:
132  strcpy(winampver, "winamp 1.55");
133  break;
134  case 0x16A0:
135  strcpy(winampver, "winamp 1.6b");
136  break;
137  case 0x16AF:
138  strcpy(winampver, "winamp 1.60");
139  break;
140  case 0x16B0:
141  strcpy(winampver, "winamp 1.61");
142  break;
143  case 0x16B1:
144  strcpy(winampver, "winamp 1.62");
145  break;
146  case 0x16B3:
147  strcpy(winampver, "winamp 1.64");
148  break;
149  case 0x16B4:
150  strcpy(winampver, "winamp 1.666");
151  break;
152  case 0x16B5:
153  strcpy(winampver, "winamp 1.69");
154  break;
155 
156  default:
157  if (version > 0x2604)
158  {
159  StandardVersion(version);
160  }
161  else
162  {
163  StandardVersion(version);
164  }
165  break;
166  }
167  return winampver;
168 }
169 
170 const char * LocalGetWinampVersion(HWND HWinamp)
171 {
172  int retval;
173  retval = LocalQueryInt(HWinamp, IPC_GETVERSION, 0);
174  return WinampVersionString(retval);
175 }
176 
177 const char * WinampCommandDesc(int Command)
178 {
179 
180  switch (Command)
181  {
182 
183  case IPC_GETVERSION: return "Get Winamp Version";
184  case IPC_PLAYFILE: return "Play File";
185  case IPC_DELETE: return "Delete Playlist";
186  case IPC_STARTPLAY: return "Start Play";
187  case IPC_CHDIR: return "Change Directory";
188  case IPC_ISPLAYING: return "Winamp Play Status";
189  case IPC_GETOUTPUTTIME: return "Get Output Time";
190  case IPC_JUMPTOTIME: return "Jump To Time";
191  case IPC_WRITEPLAYLIST: return "Write Playlist";
192  case IPC_SETPLAYLISTPOS: return "Set Playlist Position";
193  case IPC_SETVOLUME: return "Set Volume";
194  case IPC_SETPANNING: return "Set Panning";
195  case IPC_GETLISTLENGTH: return "Get Playlist Length";
196 
197  case IPC_GETPLAYLISTFILE: return "Get PlayList File";
198  case IPC_GETPLAYLISTTITLE: return "Get Playlist Title";
199 
200  case IPC_GETLISTPOS: return "Get Playlist Position";
201  case IPC_GETINFO: return "Get Information";
202  case IPC_GETEQDATA: return "Get EQ data";
203  case IPC_SETEQDATA: return "Set EQ Data";
204 
205  case IPC_GETSHUFFLEOPTION: return "Get Shuffle Option";
206  case IPC_GETREPEATOPTION: return "Get Repeat Option";
207  case IPC_SETSHUFFLEOPTION: return "Set Shuffle Option";
208  case IPC_SETREPEATOPTION: return "Set Repeat Option";
209 
210  case WINAMP_FILE_QUIT: return "Quit";
211  case WINAMP_OPTIONS_PREFS: return "Options Preferences";
212  case WINAMP_OPTIONS_AOT: return "Options Always On Top";
213  case WINAMP_FILE_REPEAT: return "File Repeat";
214  case WINAMP_FILE_SHUFFLE: return "File Shuffle";
215  case WINAMP_HIGH_PRIORITY: return "High Priority";
216  case WINAMP_FILE_PLAY: return "Play File";
217  case WINAMP_OPTIONS_EQ: return "Options EQ";
218  case WINAMP_HELP_ABOUT: return "Help About";
219  case WINAMP_OPTIONS_PLEDIT: return "Option Playlist Editor";
220  case WINAMP_VOLUMEUP: return "Volume Up";
221  case WINAMP_VOLUMEDOWN: return "Volume Down";
222  case WINAMP_FFWD5S: return "Forward 5s";
223  case WINAMP_REW5S: return "Back 5s";
224 
225  case WINAMP_PREVIOUS: return "Previous Song";
226  case WINAMP_PLAYENTRY: return "Play Entry";
227  case WINAMP_PAUSE: return "Pause";
228  case WINAMP_STOP: return "Stop";
229  case WINAMP_NEXT: return "Next Song";
230 
231  case WINAMP_BACK5S: return "Back 5s";
232  case WINAMP_OPENFILE: return "Open File";
233  // case ?? WINAMP_BUTTON3_SHIFT
234  case WINAMP_STOPFADE: return "Stop With Fade";
235  case WINAMP_FORWARD5S: return "Foward 5s";
236 
237  case WINAMP_STARTOFPLAYLIST: return "Start OF Playlist";
238  case WINAMP_OPENLOCATION: return "Open Location";
239  // case ?? WINAMP_BUTTON3_CTRL
240  case WINAMP_STOPAFTERCURRENT: return "Stop After Current";
241  case WINAMP_ENDOFPLAYLIST: return "End of Playlist";
242 
243  case IDC_SORT_FILENAME: return "Sort Filename";
244  case IDC_SORT_FILETITLE: return "Sort File Title";
245  case IDC_SORT_ENTIREFILENAME: return "Sort Entire Filename";
246  case IDC_SELECTALL: return "SelectAll";
247  case IDC_SELECTNONE: return "Select None";
248  case IDC_SELECTINV: return "Selection Invert";
249 
250  case IDM_EQ_LOADPRE: return "Load Preset";
251  case IDM_EQ_LOADMP3: return "Load MP3";
252  case IDM_EQ_LOADDEFAULT: return "Load Default";
253  case IDM_EQ_SAVEPRE: return "Save Preset";
254  case IDM_EQ_SAVEMP3: return "Save MP3";
255  case IDM_EQ_SAVEDEFAULT: return "Save Default";
256  case IDM_EQ_DELPRE: return "Delete Preset";
257  case IDM_EQ_DELMP3: return "Delete MP3";
258 
259  case WINAMP_JUMP: return "Jump";
260  case WINAMP_JUMPFILE: return "Jump File";
261  case WINAMP_JUMP10FWD: return "Jump 10 Forward";
262  case WINAMP_JUMP10BACK: return "Jump 10 Back";
263  case WINAMP_PREVSONG: return "Previous Song";
264 
265  default:
266  return "";
267  }
268 
269 }
270