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
conremote.cpp
Go to the documentation of this file.
1 /*
2 winamp remote control suite ŠPatrick Michael Martin 2000-2011
3 
4 Copyright (C) 2000,2001,2002 Patrick M. Martin
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 
20 Patrick M. Martin may be reached by email at patrickmmartin@gmail.com.
21 */
22 
23 
24 #include <iostream.h>
25 
26 #include "RPCBind.h"
27 #include "RPCException.h"
28 
29 #include "WinampClientBase.h"
30 
31 #include <sstream>
32 
33 // hack for link failure
34 #include "sysutils.hpp"
35 
36 int main(int argc , char* argv[] )
37 {
38 
39 
40 char inkey;
41 bool loop = true;
42 char * address;
43 char * port;
44 
45  switch (argc)
46  {
47  case 2:
48  port = argv[1];
49  address = "127.0.0.1";
50  break;
51 
52  case 3:
53  port = argv[1];
54  address = argv[2];
55  break;
56 
57  default: // no break
58  address = "127.0.0.1";
59  port = "\\pipe\\winampremote";
60  break;
61  }
62 
63 
64  try
65  {
66 
67  Bind(address, port, pszProtocolSequenceNP);
68 
70 
71  cout << endl;
72  cout << "\t\t****************************************" << endl;
73  cout << "\t\t* console mode winamp remote client *" << endl;
74  cout << "\t\t* (C) patrick m martin 2000 *" << endl;
75  cout << "\t\t****************************************" << endl << endl;
76  cout << "\t\ttalking on " << address << ":" << port << endl << "\t\tserver: " ;
77 
78  cout << "\t\t" << WinampVersionString(cwc->winampVersion()) << endl;
79 
80  cout << "\t\tcommands: " << endl;
81  cout << "\t\tp, s, h, <, >: play, stop, (un)pause, back, forward" << endl;
82  cout << "\t\tw, l, x: status, playlist, exit" << endl << endl;
83 
84  cwc->getPlaybackStatus();
85 
86  while (loop)
87  {
88  cout << endl << "command?";
89  cin >> inkey;
90 
91  switch (inkey)
92  {
93 
94  case 'l':
95  {
96  vector<string> playList (cwc->getPlayList() );
97 
98  stringstream sstr;
99  for (int i = 0 ; i < playList.size() ; i++ )
100  {
101  cout << playList.at(i) << endl;
102  }
103  }
104  break;
105 
106  case '>':
107  cwc->nextSong();
108  break;
109 
110  case '<':
111  cwc->previousSong();
112  break;
113 
114  case 'w':
115  cwc->pause();
116  break;
117 
118  case 'p':
119  cwc->playSong();
120  cwc->getPlaybackStatus();
121  break;
122 
123  case 's':
124  cwc->stopSong();
125  cwc->getPlaybackStatus();
126  break;
127 
128  case 'h':
129  cwc->pause();
130  cwc->getPlaybackStatus();
131  break;
132 
133  case 'x':
134  cout << "bye...";
135  loop = false;
136  break;
137 
138  case 't':
139  /* nothing yet */
140  break;
141 
142 
143  default:
144  cout << inkey << " not understood\r\n" ;
145 
146  }
147  }
148 
149  UnBind();
150  return 0;
151  }
152 
153  catch (ERPCException& E)
154  // the errors I understand
155  {
156  UnBind();
157  cout << endl << "RPC failure : " <<E.what();
158  }
159 
160  catch (...)
161  // all the rest, and provide some explanation, hopefully
162  {
163  perror("Unhandled error ");
164  }
165 
166  return 0;
167 
168 
169 }
170